mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 4/7] net: gianfar: replace global NetRxPackets with per-interface allocation
Date: Wed, 13 Mar 2024 12:07:01 +0100	[thread overview]
Message-ID: <20240313110704.1095554-5-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20240313110704.1095554-1-a.fatoum@pengutronix.de>

NetRxPackets is a remnant of times, where a board had at most one
Ethernet controller. This is outdated and we should drop NetRxPackets.

Switch over the driver to allocate the receive buffers needed.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 drivers/net/gianfar.c | 14 +++++++-------
 drivers/net/gianfar.h |  6 ++++++
 2 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/drivers/net/gianfar.c b/drivers/net/gianfar.c
index 1a07059db4f3..21ffe822e1cc 100644
--- a/drivers/net/gianfar.c
+++ b/drivers/net/gianfar.c
@@ -21,11 +21,6 @@
 #include <linux/err.h>
 #include "gianfar.h"
 
-/* 2 seems to be the minimum number of TX descriptors to make it work. */
-#define TX_BUF_CNT 	2
-#define RX_BUF_CNT 	PKTBUFSRX
-#define BUF_ALIGN	8
-
 /*
  * Initialize required registers to appropriate values, zeroing
  * those we don't care about (unless zero is bad, in which case,
@@ -199,7 +194,7 @@ static int gfar_open(struct eth_device *edev)
 	for (ix = 0; ix < RX_BUF_CNT; ix++) {
 		out_be16(&priv->rxbd[ix].status, RXBD_EMPTY);
 		out_be16(&priv->rxbd[ix].length, 0);
-		out_be32(&priv->rxbd[ix].bufPtr, (uint) NetRxPackets[ix]);
+		out_be32(&priv->rxbd[ix].bufPtr, (uint) priv->rx_buffer[ix]);
 	}
 	out_be16(&priv->rxbd[RX_BUF_CNT - 1].status, RXBD_EMPTY | RXBD_WRAP);
 
@@ -407,7 +402,7 @@ static int gfar_recv(struct eth_device *edev)
 	/* Send the packet up if there were no errors */
 	status = in_be16(&priv->rxbd[priv->rxidx].status);
 	if (!(status & RXBD_STATS))
-		net_receive(edev, NetRxPackets[priv->rxidx], length - 4);
+		net_receive(edev, priv->rx_buffer[priv->rxidx], length - 4);
 	else
 		dev_err(dev, "Got error %x\n", status & RXBD_STATS);
 
@@ -471,9 +466,14 @@ static int gfar_probe(struct device *dev)
 	size_t size;
 	char devname[16];
 	char *p;
+	int ret;
 
 	priv = xzalloc(sizeof(struct gfar_private));
 
+	ret = net_alloc_packets(priv->rx_buffer, ARRAY_SIZE(priv->rx_buffer));
+	if (ret)
+		return ret;
+
 	edev = &priv->edev;
 
 	priv->mdiobus_tbi = gfar_info->mdiobus_tbi;
diff --git a/drivers/net/gianfar.h b/drivers/net/gianfar.h
index cea41218a71c..8a60c7f38eca 100644
--- a/drivers/net/gianfar.h
+++ b/drivers/net/gianfar.h
@@ -265,6 +265,11 @@ struct gfar_phy {
 	struct mii_bus miibus;
 };
 
+/* 2 seems to be the minimum number of TX descriptors to make it work. */
+#define TX_BUF_CNT 	2
+#define RX_BUF_CNT 	PKTBUFSRX
+#define BUF_ALIGN	8
+
 struct gfar_private {
 	struct eth_device edev;
 	void __iomem *regs;
@@ -282,5 +287,6 @@ struct gfar_private {
 	uint link;
 	uint duplexity;
 	uint speed;
+	void *rx_buffer[PKTBUFSRX];
 };
 #endif /* __GIANFAR_H */
-- 
2.39.2




  parent reply	other threads:[~2024-03-13 11:07 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-13 11:06 [PATCH 0/7] net: replace global NetRxPackets arrays " Ahmad Fatoum
2024-03-13 11:06 ` [PATCH 1/7] net: add net_alloc_packets helper Ahmad Fatoum
2024-03-13 11:06 ` [PATCH 2/7] net: ep93xx: replace global NetRxPackets with per-interface allocation Ahmad Fatoum
2024-03-13 11:07 ` [PATCH 3/7] net: enc28j60: " Ahmad Fatoum
2024-03-13 11:07 ` Ahmad Fatoum [this message]
2024-03-13 11:07 ` [PATCH 5/7] net: ethoc: " Ahmad Fatoum
2024-03-13 11:07 ` [PATCH 6/7] net: cpsw: " Ahmad Fatoum
2024-03-13 11:07 ` [PATCH 7/7] net: retire global NetRxPackets arrays Ahmad Fatoum
2024-03-13 11:38 ` [PATCH 0/7] net: replace global NetRxPackets arrays with per-interface allocation Sascha Hauer

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=20240313110704.1095554-5-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.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