diff mbox series

[06/15] net: pcnet: Move private data allocation to initialize

Message ID 20200517162425.76584-6-marek.vasut+renesas@gmail.com
State Accepted
Commit ada6a2cea5a0d44c3bd64713babd9d73eaf64863
Headers show
Series [01/15] net: pcnet: Drop typedef struct pcnet_priv_t | expand

Commit Message

Marek Vasut May 17, 2020, 4:24 p.m. UTC
The private data allocation does not have to be done every time the
NIC is initialized at run time, move the allocation to initialize
function, which means it will be done only once when the driver
starts.

Signed-off-by: Marek Vasut <marek.vasut+renesas at gmail.com>
Cc: Daniel Schwierzeck <daniel.schwierzeck at gmail.com>
Cc: Joe Hershberger <joe.hershberger at ni.com>
---
 drivers/net/pcnet.c | 27 ++++++++++++++-------------
 1 file changed, 14 insertions(+), 13 deletions(-)
diff mbox series

Patch

diff --git a/drivers/net/pcnet.c b/drivers/net/pcnet.c
index f5e14ca60d..3a9f20a7f0 100644
--- a/drivers/net/pcnet.c
+++ b/drivers/net/pcnet.c
@@ -186,6 +186,20 @@  int pcnet_initialize(bd_t *bis)
 			printf("pcnet: Can not allocate memory\n");
 			break;
 		}
+
+		/*
+		 * We only maintain one structure because the drivers will
+		 * never be used concurrently. In 32bit mode the RX and TX
+		 * ring entries must be aligned on 16-byte boundaries.
+		 */
+		if (!lp) {
+			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));
+		}
+
 		dev->priv = (void *)(unsigned long)devbusfn;
 		sprintf(dev->name, "pcnet#%d", dev_nr);
 
@@ -327,19 +341,6 @@  static int pcnet_init(struct eth_device *dev, bd_t *bis)
 	val |= 0x3 << 10;
 	pcnet_write_csr(dev, 80, val);
 
-	/*
-	 * We only maintain one structure because the drivers will never
-	 * be used concurrently. In 32bit mode the RX and TX ring entries
-	 * must be aligned on 16-byte boundaries.
-	 */
-	if (lp == NULL) {
-		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;
 
 	uc->init_block.mode = cpu_to_le16(0x0000);