All of lore.kernel.org
 help / color / mirror / Atom feed
From: Marek Vasut <marek.vasut@gmail.com>
To: u-boot@lists.denx.de
Subject: [PATCH 04/15] net: pcnet: Simplify private data allocation
Date: Sun, 17 May 2020 18:24:14 +0200	[thread overview]
Message-ID: <20200517162425.76584-4-marek.vasut+renesas@gmail.com> (raw)
In-Reply-To: <20200517162425.76584-1-marek.vasut+renesas@gmail.com>

The current code is horribly complex. Both the RX and TX buffer
descriptors are 16 bytes in size, the init block is 32 bytes in
size, so simplify the code such that the entire private data of
the driver are allocated cache aligned and the RX and TX buffer
descriptors are part of the private data.

This removes multiple malloc calls and cache flushes.

Signed-off-by: Marek Vasut <marek.vasut+renesas@gmail.com>
Cc: Daniel Schwierzeck <daniel.schwierzeck@gmail.com>
Cc: Joe Hershberger <joe.hershberger@ni.com>
---
 drivers/net/pcnet.c | 33 ++++++++++++---------------------
 1 file changed, 12 insertions(+), 21 deletions(-)

diff --git a/drivers/net/pcnet.c b/drivers/net/pcnet.c
index d3f3297e12..5bbd290eec 100644
--- a/drivers/net/pcnet.c
+++ b/drivers/net/pcnet.c
@@ -9,6 +9,7 @@
 #include <common.h>
 #include <cpu_func.h>
 #include <malloc.h>
+#include <memalign.h>
 #include <net.h>
 #include <netdev.h>
 #include <asm/io.h>
@@ -71,12 +72,13 @@ struct pcnet_uncached_priv {
 	struct pcnet_rx_head rx_ring[RX_RING_SIZE];
 	struct pcnet_tx_head tx_ring[TX_RING_SIZE];
 	struct pcnet_init_block init_block;
-};
+} __aligned(ARCH_DMA_MINALIGN);
 
 struct pcnet_priv {
-	struct pcnet_uncached_priv *uc;
+	struct pcnet_uncached_priv ucp;
 	/* Receive Buffer space */
-	unsigned char (*rx_buf)[RX_RING_SIZE][PKT_BUF_SZ + 4];
+	unsigned char rx_buf[RX_RING_SIZE][PKT_BUF_SZ + 4];
+	struct pcnet_uncached_priv *uc;
 	int cur_rx;
 	int cur_tx;
 };
@@ -332,22 +334,11 @@ static int pcnet_init(struct eth_device *dev, bd_t *bis)
 	 * must be aligned on 16-byte boundaries.
 	 */
 	if (lp == NULL) {
-		addr = (unsigned long)malloc(sizeof(*lp) + 0x10);
-		addr = (addr + 0xf) & ~0xf;
-		lp = (struct pcnet_priv *)addr;
-
-		addr = (unsigned long)memalign(ARCH_DMA_MINALIGN,
-					       sizeof(*lp->uc));
-		flush_dcache_range(addr, addr + sizeof(*lp->uc));
-		addr = (unsigned long)map_physmem(addr,
-				roundup(sizeof(*lp->uc), ARCH_DMA_MINALIGN),
-				MAP_NOCACHE);
-		lp->uc = (struct pcnet_uncached_priv *)addr;
-
-		addr = (unsigned long)memalign(ARCH_DMA_MINALIGN,
-					       sizeof(*lp->rx_buf));
-		flush_dcache_range(addr, addr + sizeof(*lp->rx_buf));
-		lp->rx_buf = (void *)addr;
+		lp = malloc_cache_aligned(sizeof(*lp));
+		lp->uc = map_physmem((phys_addr_t)&lp->ucp,
+				     sizeof(lp->ucp), MAP_NOCACHE);
+		flush_dcache_range((unsigned long)lp,
+				   (unsigned long)lp + sizeof(*lp));
 	}
 
 	uc = lp->uc;
@@ -361,7 +352,7 @@ static int pcnet_init(struct eth_device *dev, bd_t *bis)
 	 */
 	lp->cur_rx = 0;
 	for (i = 0; i < RX_RING_SIZE; i++) {
-		addr = pcnet_virt_to_mem(dev, (*lp->rx_buf)[i]);
+		addr = pcnet_virt_to_mem(dev, lp->rx_buf[i]);
 		uc->rx_ring[i].base = cpu_to_le32(addr);
 		uc->rx_ring[i].buf_length = cpu_to_le16(-PKT_BUF_SZ);
 		uc->rx_ring[i].status = cpu_to_le16(0x8000);
@@ -518,7 +509,7 @@ static int pcnet_recv (struct eth_device *dev)
 				printf("%s: Rx%d: invalid packet length %d\n",
 				       dev->name, lp->cur_rx, pkt_len);
 			} else {
-				buf = (*lp->rx_buf)[lp->cur_rx];
+				buf = lp->rx_buf[lp->cur_rx];
 				invalidate_dcache_range((unsigned long)buf,
 					(unsigned long)buf + pkt_len);
 				net_process_received_packet(buf, pkt_len);
-- 
2.25.1

  parent reply	other threads:[~2020-05-17 16:24 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-17 16:24 [PATCH 01/15] net: pcnet: Drop typedef struct pcnet_priv_t Marek Vasut
2020-05-17 16:24 ` [PATCH 02/15] net: pcnet: Drop PCNET_HAS_PROM Marek Vasut
2020-05-17 16:24 ` [PATCH 03/15] net: pcnet: Use PCI_DEVICE() to define PCI device compat list Marek Vasut
2020-05-17 16:24 ` Marek Vasut [this message]
2020-05-17 16:24 ` [PATCH 05/15] net: pcnet: Replace memset+malloc with calloc Marek Vasut
2020-05-17 16:24 ` [PATCH 06/15] net: pcnet: Move private data allocation to initialize Marek Vasut
2020-05-17 16:24 ` [PATCH 07/15] net: pcnet: Move initialize function at the end Marek Vasut
2020-05-17 16:24 ` [PATCH 08/15] net: pcnet: Drop useless forward declarations Marek Vasut
2020-05-17 16:24 ` [PATCH 09/15] net: pcnet: Wrap devbusfn into private data Marek Vasut
2020-05-17 16:24 ` [PATCH 10/15] net: pcnet: Pass private data through dev->priv Marek Vasut
2020-05-17 16:24 ` [PATCH 11/15] net: pcnet: Wrap iobase into private data Marek Vasut
2020-05-17 16:24 ` [PATCH 12/15] net: pcnet: Wrap name and enetaddr " Marek Vasut
2020-05-17 16:24 ` [PATCH 13/15] net: pcnet: Split common and non-DM functions Marek Vasut
2020-05-17 16:24 ` [PATCH 14/15] net: pcnet: Add DM support Marek Vasut
2020-05-17 16:24 ` [PATCH 15/15] net: pcnet: Add Kconfig entries Marek Vasut
2020-05-18  9:18   ` Daniel Schwierzeck
2020-05-18  9:54     ` Marek Vasut
2020-05-18 16:03       ` Daniel Schwierzeck
2020-06-05 15:28 ` [PATCH 01/15] net: pcnet: Drop typedef struct pcnet_priv_t Daniel Schwierzeck
2020-06-05 16:22   ` Marek Vasut
2020-06-05 16:38     ` Daniel Schwierzeck
2020-06-05 17:50       ` Marek Vasut
2020-06-05 23:56         ` Daniel Schwierzeck
2020-06-06 12:00           ` Marek Vasut

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=20200517162425.76584-4-marek.vasut+renesas@gmail.com \
    --to=marek.vasut@gmail.com \
    --cc=u-boot@lists.denx.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.