All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 01/16] net: dm9000: Make accessor names lowercase
@ 2022-04-11 17:55 Marek Vasut
  2022-04-11 17:55 ` [PATCH 02/16] net: dm9000: Replace DM9000_DBG() with debug() Marek Vasut
                   ` (15 more replies)
  0 siblings, 16 replies; 32+ messages in thread
From: Marek Vasut @ 2022-04-11 17:55 UTC (permalink / raw)
  To: u-boot; +Cc: marcel.ziswiler, trini, Marek Vasut, Joe Hershberger, Ramon Fried

Make accessor names lowercase to be consistent with coding style.
No functional change.

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Cc: Ramon Fried <rfried.dev@gmail.com>
---
 drivers/net/dm9000x.c | 214 +++++++++++++++++++++---------------------
 1 file changed, 107 insertions(+), 107 deletions(-)

diff --git a/drivers/net/dm9000x.c b/drivers/net/dm9000x.c
index 4f062e99d9b..93699135f75 100644
--- a/drivers/net/dm9000x.c
+++ b/drivers/net/dm9000x.c
@@ -104,24 +104,24 @@ static board_info_t dm9000_info;
 static int dm9000_probe(void);
 static u16 dm9000_phy_read(int);
 static void dm9000_phy_write(int, u16);
-static u8 DM9000_ior(int);
-static void DM9000_iow(int reg, u8 value);
+static u8 dm9000_ior(int);
+static void dm9000_iow(int reg, u8 value);
 
 /* DM9000 network board routine ---------------------------- */
 #ifndef CONFIG_DM9000_BYTE_SWAPPED
-#define DM9000_outb(d,r) writeb(d, (volatile u8 *)(r))
-#define DM9000_outw(d,r) writew(d, (volatile u16 *)(r))
-#define DM9000_outl(d,r) writel(d, (volatile u32 *)(r))
-#define DM9000_inb(r) readb((volatile u8 *)(r))
-#define DM9000_inw(r) readw((volatile u16 *)(r))
-#define DM9000_inl(r) readl((volatile u32 *)(r))
+#define dm9000_outb(d,r) writeb(d, (volatile u8 *)(r))
+#define dm9000_outw(d,r) writew(d, (volatile u16 *)(r))
+#define dm9000_outl(d,r) writel(d, (volatile u32 *)(r))
+#define dm9000_inb(r) readb((volatile u8 *)(r))
+#define dm9000_inw(r) readw((volatile u16 *)(r))
+#define dm9000_inl(r) readl((volatile u32 *)(r))
 #else
-#define DM9000_outb(d, r) __raw_writeb(d, r)
-#define DM9000_outw(d, r) __raw_writew(d, r)
-#define DM9000_outl(d, r) __raw_writel(d, r)
-#define DM9000_inb(r) __raw_readb(r)
-#define DM9000_inw(r) __raw_readw(r)
-#define DM9000_inl(r) __raw_readl(r)
+#define dm9000_outb(d, r) __raw_writeb(d, r)
+#define dm9000_outw(d, r) __raw_writew(d, r)
+#define dm9000_outl(d, r) __raw_writel(d, r)
+#define dm9000_inb(r) __raw_readb(r)
+#define dm9000_inw(r) __raw_readw(r)
+#define dm9000_inl(r) __raw_readl(r)
 #endif
 
 #ifdef CONFIG_DM9000_DEBUG
@@ -129,14 +129,14 @@ static void
 dump_regs(void)
 {
 	DM9000_DBG("\n");
-	DM9000_DBG("NCR   (0x00): %02x\n", DM9000_ior(0));
-	DM9000_DBG("NSR   (0x01): %02x\n", DM9000_ior(1));
-	DM9000_DBG("TCR   (0x02): %02x\n", DM9000_ior(2));
-	DM9000_DBG("TSRI  (0x03): %02x\n", DM9000_ior(3));
-	DM9000_DBG("TSRII (0x04): %02x\n", DM9000_ior(4));
-	DM9000_DBG("RCR   (0x05): %02x\n", DM9000_ior(5));
-	DM9000_DBG("RSR   (0x06): %02x\n", DM9000_ior(6));
-	DM9000_DBG("ISR   (0xFE): %02x\n", DM9000_ior(DM9000_ISR));
+	DM9000_DBG("NCR   (0x00): %02x\n", dm9000_ior(0));
+	DM9000_DBG("NSR   (0x01): %02x\n", dm9000_ior(1));
+	DM9000_DBG("TCR   (0x02): %02x\n", dm9000_ior(2));
+	DM9000_DBG("TSRI  (0x03): %02x\n", dm9000_ior(3));
+	DM9000_DBG("TSRII (0x04): %02x\n", dm9000_ior(4));
+	DM9000_DBG("RCR   (0x05): %02x\n", dm9000_ior(5));
+	DM9000_DBG("RSR   (0x06): %02x\n", dm9000_ior(6));
+	DM9000_DBG("ISR   (0xFE): %02x\n", dm9000_ior(DM9000_ISR));
 	DM9000_DBG("\n");
 }
 #endif
@@ -145,7 +145,7 @@ static void dm9000_outblk_8bit(volatile void *data_ptr, int count)
 {
 	int i;
 	for (i = 0; i < count; i++)
-		DM9000_outb((((u8 *) data_ptr)[i] & 0xff), DM9000_DATA);
+		dm9000_outb((((u8 *) data_ptr)[i] & 0xff), DM9000_DATA);
 }
 
 static void dm9000_outblk_16bit(volatile void *data_ptr, int count)
@@ -154,7 +154,7 @@ static void dm9000_outblk_16bit(volatile void *data_ptr, int count)
 	u32 tmplen = (count + 1) / 2;
 
 	for (i = 0; i < tmplen; i++)
-		DM9000_outw(((u16 *) data_ptr)[i], DM9000_DATA);
+		dm9000_outw(((u16 *) data_ptr)[i], DM9000_DATA);
 }
 static void dm9000_outblk_32bit(volatile void *data_ptr, int count)
 {
@@ -162,14 +162,14 @@ static void dm9000_outblk_32bit(volatile void *data_ptr, int count)
 	u32 tmplen = (count + 3) / 4;
 
 	for (i = 0; i < tmplen; i++)
-		DM9000_outl(((u32 *) data_ptr)[i], DM9000_DATA);
+		dm9000_outl(((u32 *) data_ptr)[i], DM9000_DATA);
 }
 
 static void dm9000_inblk_8bit(void *data_ptr, int count)
 {
 	int i;
 	for (i = 0; i < count; i++)
-		((u8 *) data_ptr)[i] = DM9000_inb(DM9000_DATA);
+		((u8 *) data_ptr)[i] = dm9000_inb(DM9000_DATA);
 }
 
 static void dm9000_inblk_16bit(void *data_ptr, int count)
@@ -178,7 +178,7 @@ static void dm9000_inblk_16bit(void *data_ptr, int count)
 	u32 tmplen = (count + 1) / 2;
 
 	for (i = 0; i < tmplen; i++)
-		((u16 *) data_ptr)[i] = DM9000_inw(DM9000_DATA);
+		((u16 *) data_ptr)[i] = dm9000_inw(DM9000_DATA);
 }
 static void dm9000_inblk_32bit(void *data_ptr, int count)
 {
@@ -186,38 +186,38 @@ static void dm9000_inblk_32bit(void *data_ptr, int count)
 	u32 tmplen = (count + 3) / 4;
 
 	for (i = 0; i < tmplen; i++)
-		((u32 *) data_ptr)[i] = DM9000_inl(DM9000_DATA);
+		((u32 *) data_ptr)[i] = dm9000_inl(DM9000_DATA);
 }
 
 static void dm9000_rx_status_32bit(u16 *RxStatus, u16 *RxLen)
 {
 	u32 tmpdata;
 
-	DM9000_outb(DM9000_MRCMD, DM9000_IO);
+	dm9000_outb(DM9000_MRCMD, DM9000_IO);
 
-	tmpdata = DM9000_inl(DM9000_DATA);
+	tmpdata = dm9000_inl(DM9000_DATA);
 	*RxStatus = __le16_to_cpu(tmpdata);
 	*RxLen = __le16_to_cpu(tmpdata >> 16);
 }
 
 static void dm9000_rx_status_16bit(u16 *RxStatus, u16 *RxLen)
 {
-	DM9000_outb(DM9000_MRCMD, DM9000_IO);
+	dm9000_outb(DM9000_MRCMD, DM9000_IO);
 
-	*RxStatus = __le16_to_cpu(DM9000_inw(DM9000_DATA));
-	*RxLen = __le16_to_cpu(DM9000_inw(DM9000_DATA));
+	*RxStatus = __le16_to_cpu(dm9000_inw(DM9000_DATA));
+	*RxLen = __le16_to_cpu(dm9000_inw(DM9000_DATA));
 }
 
 static void dm9000_rx_status_8bit(u16 *RxStatus, u16 *RxLen)
 {
-	DM9000_outb(DM9000_MRCMD, DM9000_IO);
+	dm9000_outb(DM9000_MRCMD, DM9000_IO);
 
 	*RxStatus =
-	    __le16_to_cpu(DM9000_inb(DM9000_DATA) +
-			  (DM9000_inb(DM9000_DATA) << 8));
+	    __le16_to_cpu(dm9000_inb(DM9000_DATA) +
+			  (dm9000_inb(DM9000_DATA) << 8));
 	*RxLen =
-	    __le16_to_cpu(DM9000_inb(DM9000_DATA) +
-			  (DM9000_inb(DM9000_DATA) << 8));
+	    __le16_to_cpu(dm9000_inb(DM9000_DATA) +
+			  (dm9000_inb(DM9000_DATA) << 8));
 }
 
 /*
@@ -227,10 +227,10 @@ int
 dm9000_probe(void)
 {
 	u32 id_val;
-	id_val = DM9000_ior(DM9000_VIDL);
-	id_val |= DM9000_ior(DM9000_VIDH) << 8;
-	id_val |= DM9000_ior(DM9000_PIDL) << 16;
-	id_val |= DM9000_ior(DM9000_PIDH) << 24;
+	id_val = dm9000_ior(DM9000_VIDL);
+	id_val |= dm9000_ior(DM9000_VIDH) << 8;
+	id_val |= dm9000_ior(DM9000_PIDL) << 16;
+	id_val |= dm9000_ior(DM9000_PIDH) << 24;
 	if (id_val == DM9000_ID) {
 		printf("dm9000 i/o: 0x%x, id: 0x%x \n", CONFIG_DM9000_BASE,
 		       id_val);
@@ -252,28 +252,28 @@ dm9000_reset(void)
 	   see DM9000 Application Notes V1.22 Jun 11, 2004 page 29 */
 
 	/* DEBUG: Make all GPIO0 outputs, all others inputs */
-	DM9000_iow(DM9000_GPCR, GPCR_GPIO0_OUT);
+	dm9000_iow(DM9000_GPCR, GPCR_GPIO0_OUT);
 	/* Step 1: Power internal PHY by writing 0 to GPIO0 pin */
-	DM9000_iow(DM9000_GPR, 0);
+	dm9000_iow(DM9000_GPR, 0);
 	/* Step 2: Software reset */
-	DM9000_iow(DM9000_NCR, (NCR_LBK_INT_MAC | NCR_RST));
+	dm9000_iow(DM9000_NCR, (NCR_LBK_INT_MAC | NCR_RST));
 
 	do {
 		DM9000_DBG("resetting the DM9000, 1st reset\n");
 		udelay(25); /* Wait at least 20 us */
-	} while (DM9000_ior(DM9000_NCR) & 1);
+	} while (dm9000_ior(DM9000_NCR) & 1);
 
-	DM9000_iow(DM9000_NCR, 0);
-	DM9000_iow(DM9000_NCR, (NCR_LBK_INT_MAC | NCR_RST)); /* Issue a second reset */
+	dm9000_iow(DM9000_NCR, 0);
+	dm9000_iow(DM9000_NCR, (NCR_LBK_INT_MAC | NCR_RST)); /* Issue a second reset */
 
 	do {
 		DM9000_DBG("resetting the DM9000, 2nd reset\n");
 		udelay(25); /* Wait at least 20 us */
-	} while (DM9000_ior(DM9000_NCR) & 1);
+	} while (dm9000_ior(DM9000_NCR) & 1);
 
 	/* Check whether the ethernet controller is present */
-	if ((DM9000_ior(DM9000_PIDL) != 0x0) ||
-	    (DM9000_ior(DM9000_PIDH) != 0x90))
+	if ((dm9000_ior(DM9000_PIDL) != 0x0) ||
+	    (dm9000_ior(DM9000_PIDH) != 0x90))
 		printf("ERROR: resetting DM9000 -> not responding\n");
 }
 
@@ -294,7 +294,7 @@ static int dm9000_init(struct eth_device *dev, struct bd_info *bd)
 		return -1;
 
 	/* Auto-detect 8/16/32 bit mode, ISR Bit 6+7 indicate bus width */
-	io_mode = DM9000_ior(DM9000_ISR) >> 6;
+	io_mode = dm9000_ior(DM9000_ISR) >> 6;
 
 	switch (io_mode) {
 	case 0x0:  /* 16-bit mode */
@@ -325,21 +325,21 @@ static int dm9000_init(struct eth_device *dev, struct bd_info *bd)
 	}
 
 	/* Program operating register, only internal phy supported */
-	DM9000_iow(DM9000_NCR, 0x0);
+	dm9000_iow(DM9000_NCR, 0x0);
 	/* TX Polling clear */
-	DM9000_iow(DM9000_TCR, 0);
+	dm9000_iow(DM9000_TCR, 0);
 	/* Less 3Kb, 200us */
-	DM9000_iow(DM9000_BPTR, BPTR_BPHW(3) | BPTR_JPT_600US);
+	dm9000_iow(DM9000_BPTR, BPTR_BPHW(3) | BPTR_JPT_600US);
 	/* Flow Control : High/Low Water */
-	DM9000_iow(DM9000_FCTR, FCTR_HWOT(3) | FCTR_LWOT(8));
+	dm9000_iow(DM9000_FCTR, FCTR_HWOT(3) | FCTR_LWOT(8));
 	/* SH FIXME: This looks strange! Flow Control */
-	DM9000_iow(DM9000_FCR, 0x0);
+	dm9000_iow(DM9000_FCR, 0x0);
 	/* Special Mode */
-	DM9000_iow(DM9000_SMCR, 0);
+	dm9000_iow(DM9000_SMCR, 0);
 	/* clear TX status */
-	DM9000_iow(DM9000_NSR, NSR_WAKEST | NSR_TX2END | NSR_TX1END);
+	dm9000_iow(DM9000_NSR, NSR_WAKEST | NSR_TX2END | NSR_TX1END);
 	/* Clear interrupt status */
-	DM9000_iow(DM9000_ISR, ISR_ROOS | ISR_ROS | ISR_PTS | ISR_PRS);
+	dm9000_iow(DM9000_ISR, ISR_ROOS | ISR_ROS | ISR_PTS | ISR_PRS);
 
 	printf("MAC: %pM\n", dev->enetaddr);
 	if (!is_valid_ethaddr(dev->enetaddr)) {
@@ -348,20 +348,20 @@ static int dm9000_init(struct eth_device *dev, struct bd_info *bd)
 
 	/* fill device MAC address registers */
 	for (i = 0, oft = DM9000_PAR; i < 6; i++, oft++)
-		DM9000_iow(oft, dev->enetaddr[i]);
+		dm9000_iow(oft, dev->enetaddr[i]);
 	for (i = 0, oft = 0x16; i < 8; i++, oft++)
-		DM9000_iow(oft, 0xff);
+		dm9000_iow(oft, 0xff);
 
 	/* read back mac, just to be sure */
 	for (i = 0, oft = 0x10; i < 6; i++, oft++)
-		DM9000_DBG("%02x:", DM9000_ior(oft));
+		DM9000_DBG("%02x:", dm9000_ior(oft));
 	DM9000_DBG("\n");
 
 	/* Activate DM9000 */
 	/* RX enable */
-	DM9000_iow(DM9000_RCR, RCR_DIS_LONG | RCR_DIS_CRC | RCR_RXEN);
+	dm9000_iow(DM9000_RCR, RCR_DIS_LONG | RCR_DIS_CRC | RCR_RXEN);
 	/* Enable TX/RX interrupt mask */
-	DM9000_iow(DM9000_IMR, IMR_PAR);
+	dm9000_iow(DM9000_IMR, IMR_PAR);
 
 	i = 0;
 	while (!(dm9000_phy_read(1) & 0x20)) {	/* autonegation complete bit */
@@ -408,31 +408,31 @@ static int dm9000_send(struct eth_device *netdev, void *packet, int length)
 
 	DM9000_DMP_PACKET(__func__ , packet, length);
 
-	DM9000_iow(DM9000_ISR, IMR_PTM); /* Clear Tx bit in ISR */
+	dm9000_iow(DM9000_ISR, IMR_PTM); /* Clear Tx bit in ISR */
 
 	/* Move data to DM9000 TX RAM */
-	DM9000_outb(DM9000_MWCMD, DM9000_IO); /* Prepare for TX-data */
+	dm9000_outb(DM9000_MWCMD, DM9000_IO); /* Prepare for TX-data */
 
 	/* push the data to the TX-fifo */
 	(db->outblk)(packet, length);
 
 	/* Set TX length to DM9000 */
-	DM9000_iow(DM9000_TXPLL, length & 0xff);
-	DM9000_iow(DM9000_TXPLH, (length >> 8) & 0xff);
+	dm9000_iow(DM9000_TXPLL, length & 0xff);
+	dm9000_iow(DM9000_TXPLH, (length >> 8) & 0xff);
 
 	/* Issue TX polling command */
-	DM9000_iow(DM9000_TCR, TCR_TXREQ); /* Cleared after TX complete */
+	dm9000_iow(DM9000_TCR, TCR_TXREQ); /* Cleared after TX complete */
 
 	/* wait for end of transmission */
 	tmo = get_timer(0) + 5 * CONFIG_SYS_HZ;
-	while ( !(DM9000_ior(DM9000_NSR) & (NSR_TX1END | NSR_TX2END)) ||
-		!(DM9000_ior(DM9000_ISR) & IMR_PTM) ) {
+	while ( !(dm9000_ior(DM9000_NSR) & (NSR_TX1END | NSR_TX2END)) ||
+		!(dm9000_ior(DM9000_ISR) & IMR_PTM) ) {
 		if (get_timer(0) >= tmo) {
 			printf("transmission timeout\n");
 			break;
 		}
 	}
-	DM9000_iow(DM9000_ISR, IMR_PTM); /* Clear Tx bit in ISR */
+	dm9000_iow(DM9000_ISR, IMR_PTM); /* Clear Tx bit in ISR */
 
 	DM9000_DBG("transmit done\n\n");
 	return 0;
@@ -448,9 +448,9 @@ static void dm9000_halt(struct eth_device *netdev)
 
 	/* RESET devie */
 	dm9000_phy_write(0, 0x8000);	/* PHY RESET */
-	DM9000_iow(DM9000_GPR, 0x01);	/* Power-Down PHY */
-	DM9000_iow(DM9000_IMR, 0x80);	/* Disable all interrupt */
-	DM9000_iow(DM9000_RCR, 0x00);	/* Disable RX */
+	dm9000_iow(DM9000_GPR, 0x01);	/* Power-Down PHY */
+	dm9000_iow(DM9000_IMR, 0x80);	/* Disable all interrupt */
+	dm9000_iow(DM9000_RCR, 0x00);	/* Disable RX */
 }
 
 /*
@@ -465,23 +465,23 @@ static int dm9000_rx(struct eth_device *netdev)
 
 	/* Check packet ready or not, we must check
 	   the ISR status first for DM9000A */
-	if (!(DM9000_ior(DM9000_ISR) & 0x01)) /* Rx-ISR bit must be set. */
+	if (!(dm9000_ior(DM9000_ISR) & 0x01)) /* Rx-ISR bit must be set. */
 		return 0;
 
-	DM9000_iow(DM9000_ISR, 0x01); /* clear PR status latched in bit 0 */
+	dm9000_iow(DM9000_ISR, 0x01); /* clear PR status latched in bit 0 */
 
 	/* There is _at least_ 1 package in the fifo, read them all */
 	for (;;) {
-		DM9000_ior(DM9000_MRCMDX);	/* Dummy read */
+		dm9000_ior(DM9000_MRCMDX);	/* Dummy read */
 
 		/* Get most updated data,
 		   only look at bits 0:1, See application notes DM9000 */
-		rxbyte = DM9000_inb(DM9000_DATA) & 0x03;
+		rxbyte = dm9000_inb(DM9000_DATA) & 0x03;
 
 		/* Status check: this byte must be 0 or 1 */
 		if (rxbyte > DM9000_PKT_RDY) {
-			DM9000_iow(DM9000_RCR, 0x00);	/* Stop Device */
-			DM9000_iow(DM9000_ISR, 0x80);	/* Stop INT request */
+			dm9000_iow(DM9000_RCR, 0x00);	/* Stop Device */
+			dm9000_iow(DM9000_ISR, 0x80);	/* Stop INT request */
 			printf("DM9000 error: status check fail: 0x%x\n",
 				rxbyte);
 			return 0;
@@ -532,22 +532,22 @@ static int dm9000_rx(struct eth_device *netdev)
 #if !defined(CONFIG_DM9000_NO_SROM)
 void dm9000_read_srom_word(int offset, u8 *to)
 {
-	DM9000_iow(DM9000_EPAR, offset);
-	DM9000_iow(DM9000_EPCR, 0x4);
+	dm9000_iow(DM9000_EPAR, offset);
+	dm9000_iow(DM9000_EPCR, 0x4);
 	udelay(8000);
-	DM9000_iow(DM9000_EPCR, 0x0);
-	to[0] = DM9000_ior(DM9000_EPDRL);
-	to[1] = DM9000_ior(DM9000_EPDRH);
+	dm9000_iow(DM9000_EPCR, 0x0);
+	to[0] = dm9000_ior(DM9000_EPDRL);
+	to[1] = dm9000_ior(DM9000_EPDRH);
 }
 
 void dm9000_write_srom_word(int offset, u16 val)
 {
-	DM9000_iow(DM9000_EPAR, offset);
-	DM9000_iow(DM9000_EPDRH, ((val >> 8) & 0xff));
-	DM9000_iow(DM9000_EPDRL, (val & 0xff));
-	DM9000_iow(DM9000_EPCR, 0x12);
+	dm9000_iow(DM9000_EPAR, offset);
+	dm9000_iow(DM9000_EPDRH, ((val >> 8) & 0xff));
+	dm9000_iow(DM9000_EPDRL, (val & 0xff));
+	dm9000_iow(DM9000_EPCR, 0x12);
 	udelay(8000);
-	DM9000_iow(DM9000_EPCR, 0);
+	dm9000_iow(DM9000_EPCR, 0);
 }
 #endif
 
@@ -564,20 +564,20 @@ static void dm9000_get_enetaddr(struct eth_device *dev)
    Read a byte from I/O port
 */
 static u8
-DM9000_ior(int reg)
+dm9000_ior(int reg)
 {
-	DM9000_outb(reg, DM9000_IO);
-	return DM9000_inb(DM9000_DATA);
+	dm9000_outb(reg, DM9000_IO);
+	return dm9000_inb(DM9000_DATA);
 }
 
 /*
    Write a byte to I/O port
 */
 static void
-DM9000_iow(int reg, u8 value)
+dm9000_iow(int reg, u8 value)
 {
-	DM9000_outb(reg, DM9000_IO);
-	DM9000_outb(value, DM9000_DATA);
+	dm9000_outb(reg, DM9000_IO);
+	dm9000_outb(value, DM9000_DATA);
 }
 
 /*
@@ -589,11 +589,11 @@ dm9000_phy_read(int reg)
 	u16 val;
 
 	/* Fill the phyxcer register into REG_0C */
-	DM9000_iow(DM9000_EPAR, DM9000_PHY | reg);
-	DM9000_iow(DM9000_EPCR, 0xc);	/* Issue phyxcer read command */
+	dm9000_iow(DM9000_EPAR, DM9000_PHY | reg);
+	dm9000_iow(DM9000_EPCR, 0xc);	/* Issue phyxcer read command */
 	udelay(100);			/* Wait read complete */
-	DM9000_iow(DM9000_EPCR, 0x0);	/* Clear phyxcer read command */
-	val = (DM9000_ior(DM9000_EPDRH) << 8) | DM9000_ior(DM9000_EPDRL);
+	dm9000_iow(DM9000_EPCR, 0x0);	/* Clear phyxcer read command */
+	val = (dm9000_ior(DM9000_EPDRH) << 8) | dm9000_ior(DM9000_EPDRL);
 
 	/* The read data keeps on REG_0D & REG_0E */
 	DM9000_DBG("dm9000_phy_read(0x%x): 0x%x\n", reg, val);
@@ -608,14 +608,14 @@ dm9000_phy_write(int reg, u16 value)
 {
 
 	/* Fill the phyxcer register into REG_0C */
-	DM9000_iow(DM9000_EPAR, DM9000_PHY | reg);
+	dm9000_iow(DM9000_EPAR, DM9000_PHY | reg);
 
 	/* Fill the written data into REG_0D & REG_0E */
-	DM9000_iow(DM9000_EPDRL, (value & 0xff));
-	DM9000_iow(DM9000_EPDRH, ((value >> 8) & 0xff));
-	DM9000_iow(DM9000_EPCR, 0xa);	/* Issue phyxcer write command */
+	dm9000_iow(DM9000_EPDRL, (value & 0xff));
+	dm9000_iow(DM9000_EPDRH, ((value >> 8) & 0xff));
+	dm9000_iow(DM9000_EPCR, 0xa);	/* Issue phyxcer write command */
 	udelay(500);			/* Wait write complete */
-	DM9000_iow(DM9000_EPCR, 0x0);	/* Clear phyxcer write command */
+	dm9000_iow(DM9000_EPCR, 0x0);	/* Clear phyxcer write command */
 	DM9000_DBG("dm9000_phy_write(reg:0x%x, value:0x%x)\n", reg, value);
 }
 
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [PATCH 02/16] net: dm9000: Replace DM9000_DBG() with debug()
  2022-04-11 17:55 [PATCH 01/16] net: dm9000: Make accessor names lowercase Marek Vasut
@ 2022-04-11 17:55 ` Marek Vasut
  2022-04-12 19:46   ` Ramon Fried
  2022-04-11 17:55 ` [PATCH 03/16] net: dm9000: Make RxLen and RxStatus lowercase Marek Vasut
                   ` (14 subsequent siblings)
  15 siblings, 1 reply; 32+ messages in thread
From: Marek Vasut @ 2022-04-11 17:55 UTC (permalink / raw)
  To: u-boot; +Cc: marcel.ziswiler, trini, Marek Vasut, Joe Hershberger, Ramon Fried

Use standard debug() macro to print debug messages instead of
reinventing driver-specific macro again. No functional change.

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Cc: Ramon Fried <rfried.dev@gmail.com>
---
 drivers/net/dm9000x.c | 48 +++++++++++++++++++++----------------------
 1 file changed, 23 insertions(+), 25 deletions(-)

diff --git a/drivers/net/dm9000x.c b/drivers/net/dm9000x.c
index 93699135f75..e83b838fd82 100644
--- a/drivers/net/dm9000x.c
+++ b/drivers/net/dm9000x.c
@@ -63,7 +63,6 @@ TODO: external MII is not functional, only internal at the moment.
 /* #define CONFIG_DM9000_DEBUG */
 
 #ifdef CONFIG_DM9000_DEBUG
-#define DM9000_DBG(fmt,args...) printf(fmt, ##args)
 #define DM9000_DMP_PACKET(func,packet,length)  \
 	do { \
 		int i;							\
@@ -75,7 +74,6 @@ TODO: external MII is not functional, only internal at the moment.
 		} printf("\n");						\
 	} while(0)
 #else
-#define DM9000_DBG(fmt,args...)
 #define DM9000_DMP_PACKET(func,packet,length)
 #endif
 
@@ -128,16 +126,16 @@ static void dm9000_iow(int reg, u8 value);
 static void
 dump_regs(void)
 {
-	DM9000_DBG("\n");
-	DM9000_DBG("NCR   (0x00): %02x\n", dm9000_ior(0));
-	DM9000_DBG("NSR   (0x01): %02x\n", dm9000_ior(1));
-	DM9000_DBG("TCR   (0x02): %02x\n", dm9000_ior(2));
-	DM9000_DBG("TSRI  (0x03): %02x\n", dm9000_ior(3));
-	DM9000_DBG("TSRII (0x04): %02x\n", dm9000_ior(4));
-	DM9000_DBG("RCR   (0x05): %02x\n", dm9000_ior(5));
-	DM9000_DBG("RSR   (0x06): %02x\n", dm9000_ior(6));
-	DM9000_DBG("ISR   (0xFE): %02x\n", dm9000_ior(DM9000_ISR));
-	DM9000_DBG("\n");
+	debug("\n");
+	debug("NCR   (0x00): %02x\n", dm9000_ior(0));
+	debug("NSR   (0x01): %02x\n", dm9000_ior(1));
+	debug("TCR   (0x02): %02x\n", dm9000_ior(2));
+	debug("TSRI  (0x03): %02x\n", dm9000_ior(3));
+	debug("TSRII (0x04): %02x\n", dm9000_ior(4));
+	debug("RCR   (0x05): %02x\n", dm9000_ior(5));
+	debug("RSR   (0x06): %02x\n", dm9000_ior(6));
+	debug("ISR   (0xFE): %02x\n", dm9000_ior(DM9000_ISR));
+	debug("\n");
 }
 #endif
 
@@ -246,7 +244,7 @@ dm9000_probe(void)
 static void
 dm9000_reset(void)
 {
-	DM9000_DBG("resetting DM9000\n");
+	debug("resetting DM9000\n");
 
 	/* Reset DM9000,
 	   see DM9000 Application Notes V1.22 Jun 11, 2004 page 29 */
@@ -259,7 +257,7 @@ dm9000_reset(void)
 	dm9000_iow(DM9000_NCR, (NCR_LBK_INT_MAC | NCR_RST));
 
 	do {
-		DM9000_DBG("resetting the DM9000, 1st reset\n");
+		debug("resetting the DM9000, 1st reset\n");
 		udelay(25); /* Wait at least 20 us */
 	} while (dm9000_ior(DM9000_NCR) & 1);
 
@@ -267,7 +265,7 @@ dm9000_reset(void)
 	dm9000_iow(DM9000_NCR, (NCR_LBK_INT_MAC | NCR_RST)); /* Issue a second reset */
 
 	do {
-		DM9000_DBG("resetting the DM9000, 2nd reset\n");
+		debug("resetting the DM9000, 2nd reset\n");
 		udelay(25); /* Wait at least 20 us */
 	} while (dm9000_ior(DM9000_NCR) & 1);
 
@@ -285,7 +283,7 @@ static int dm9000_init(struct eth_device *dev, struct bd_info *bd)
 	u8 io_mode;
 	struct board_info *db = &dm9000_info;
 
-	DM9000_DBG("%s\n", __func__);
+	debug("%s\n", __func__);
 
 	/* RESET device */
 	dm9000_reset();
@@ -354,8 +352,8 @@ static int dm9000_init(struct eth_device *dev, struct bd_info *bd)
 
 	/* read back mac, just to be sure */
 	for (i = 0, oft = 0x10; i < 6; i++, oft++)
-		DM9000_DBG("%02x:", dm9000_ior(oft));
-	DM9000_DBG("\n");
+		debug("%02x:", dm9000_ior(oft));
+	debug("\n");
 
 	/* Activate DM9000 */
 	/* RX enable */
@@ -434,7 +432,7 @@ static int dm9000_send(struct eth_device *netdev, void *packet, int length)
 	}
 	dm9000_iow(DM9000_ISR, IMR_PTM); /* Clear Tx bit in ISR */
 
-	DM9000_DBG("transmit done\n\n");
+	debug("transmit done\n\n");
 	return 0;
 }
 
@@ -444,7 +442,7 @@ static int dm9000_send(struct eth_device *netdev, void *packet, int length)
 */
 static void dm9000_halt(struct eth_device *netdev)
 {
-	DM9000_DBG("%s\n", __func__);
+	debug("%s\n", __func__);
 
 	/* RESET devie */
 	dm9000_phy_write(0, 0x8000);	/* PHY RESET */
@@ -490,12 +488,12 @@ static int dm9000_rx(struct eth_device *netdev)
 		if (rxbyte != DM9000_PKT_RDY)
 			return 0; /* No packet received, ignore */
 
-		DM9000_DBG("receiving packet\n");
+		debug("receiving packet\n");
 
 		/* A packet ready now  & Get status/length */
 		(db->rx_status)(&RxStatus, &RxLen);
 
-		DM9000_DBG("rx status: 0x%04x rx len: %d\n", RxStatus, RxLen);
+		debug("rx status: 0x%04x rx len: %d\n", RxStatus, RxLen);
 
 		/* Move data from DM9000 */
 		/* Read received packet from RX SRAM */
@@ -519,7 +517,7 @@ static int dm9000_rx(struct eth_device *netdev)
 		} else {
 			DM9000_DMP_PACKET(__func__ , rdptr, RxLen);
 
-			DM9000_DBG("passing packet to upper layer\n");
+			debug("passing packet to upper layer\n");
 			net_process_received_packet(net_rx_packets[0], RxLen);
 		}
 	}
@@ -596,7 +594,7 @@ dm9000_phy_read(int reg)
 	val = (dm9000_ior(DM9000_EPDRH) << 8) | dm9000_ior(DM9000_EPDRL);
 
 	/* The read data keeps on REG_0D & REG_0E */
-	DM9000_DBG("dm9000_phy_read(0x%x): 0x%x\n", reg, val);
+	debug("dm9000_phy_read(0x%x): 0x%x\n", reg, val);
 	return val;
 }
 
@@ -616,7 +614,7 @@ dm9000_phy_write(int reg, u16 value)
 	dm9000_iow(DM9000_EPCR, 0xa);	/* Issue phyxcer write command */
 	udelay(500);			/* Wait write complete */
 	dm9000_iow(DM9000_EPCR, 0x0);	/* Clear phyxcer write command */
-	DM9000_DBG("dm9000_phy_write(reg:0x%x, value:0x%x)\n", reg, value);
+	debug("dm9000_phy_write(reg:0x%x, value:0x%x)\n", reg, value);
 }
 
 int dm9000_initialize(struct bd_info *bis)
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [PATCH 03/16] net: dm9000: Make RxLen and RxStatus lowercase
  2022-04-11 17:55 [PATCH 01/16] net: dm9000: Make accessor names lowercase Marek Vasut
  2022-04-11 17:55 ` [PATCH 02/16] net: dm9000: Replace DM9000_DBG() with debug() Marek Vasut
@ 2022-04-11 17:55 ` Marek Vasut
  2022-04-12 19:46   ` Ramon Fried
  2022-04-11 17:55 ` [PATCH 04/16] net: dm9000: Drop unused dump_regs() Marek Vasut
                   ` (13 subsequent siblings)
  15 siblings, 1 reply; 32+ messages in thread
From: Marek Vasut @ 2022-04-11 17:55 UTC (permalink / raw)
  To: u-boot; +Cc: marcel.ziswiler, trini, Marek Vasut, Joe Hershberger, Ramon Fried

Rename variables to lowercase to be consistent with coding style.
No functional change.

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Cc: Ramon Fried <rfried.dev@gmail.com>
---
 drivers/net/dm9000x.c | 44 +++++++++++++++++++++----------------------
 1 file changed, 22 insertions(+), 22 deletions(-)

diff --git a/drivers/net/dm9000x.c b/drivers/net/dm9000x.c
index e83b838fd82..a99a901e828 100644
--- a/drivers/net/dm9000x.c
+++ b/drivers/net/dm9000x.c
@@ -92,7 +92,7 @@ typedef struct board_info {
 	unsigned char srom[128];
 	void (*outblk)(volatile void *data_ptr, int count);
 	void (*inblk)(void *data_ptr, int count);
-	void (*rx_status)(u16 *RxStatus, u16 *RxLen);
+	void (*rx_status)(u16 *rxstatus, u16 *rxlen);
 	struct eth_device netdev;
 } board_info_t;
 static board_info_t dm9000_info;
@@ -187,33 +187,33 @@ static void dm9000_inblk_32bit(void *data_ptr, int count)
 		((u32 *) data_ptr)[i] = dm9000_inl(DM9000_DATA);
 }
 
-static void dm9000_rx_status_32bit(u16 *RxStatus, u16 *RxLen)
+static void dm9000_rx_status_32bit(u16 *rxstatus, u16 *rxlen)
 {
 	u32 tmpdata;
 
 	dm9000_outb(DM9000_MRCMD, DM9000_IO);
 
 	tmpdata = dm9000_inl(DM9000_DATA);
-	*RxStatus = __le16_to_cpu(tmpdata);
-	*RxLen = __le16_to_cpu(tmpdata >> 16);
+	*rxstatus = __le16_to_cpu(tmpdata);
+	*rxlen = __le16_to_cpu(tmpdata >> 16);
 }
 
-static void dm9000_rx_status_16bit(u16 *RxStatus, u16 *RxLen)
+static void dm9000_rx_status_16bit(u16 *rxstatus, u16 *rxlen)
 {
 	dm9000_outb(DM9000_MRCMD, DM9000_IO);
 
-	*RxStatus = __le16_to_cpu(dm9000_inw(DM9000_DATA));
-	*RxLen = __le16_to_cpu(dm9000_inw(DM9000_DATA));
+	*rxstatus = __le16_to_cpu(dm9000_inw(DM9000_DATA));
+	*rxlen = __le16_to_cpu(dm9000_inw(DM9000_DATA));
 }
 
-static void dm9000_rx_status_8bit(u16 *RxStatus, u16 *RxLen)
+static void dm9000_rx_status_8bit(u16 *rxstatus, u16 *rxlen)
 {
 	dm9000_outb(DM9000_MRCMD, DM9000_IO);
 
-	*RxStatus =
+	*rxstatus =
 	    __le16_to_cpu(dm9000_inb(DM9000_DATA) +
 			  (dm9000_inb(DM9000_DATA) << 8));
-	*RxLen =
+	*rxlen =
 	    __le16_to_cpu(dm9000_inb(DM9000_DATA) +
 			  (dm9000_inb(DM9000_DATA) << 8));
 }
@@ -458,7 +458,7 @@ static int dm9000_rx(struct eth_device *netdev)
 {
 	u8 rxbyte;
 	u8 *rdptr = (u8 *)net_rx_packets[0];
-	u16 RxStatus, RxLen = 0;
+	u16 rxstatus, rxlen = 0;
 	struct board_info *db = &dm9000_info;
 
 	/* Check packet ready or not, we must check
@@ -491,34 +491,34 @@ static int dm9000_rx(struct eth_device *netdev)
 		debug("receiving packet\n");
 
 		/* A packet ready now  & Get status/length */
-		(db->rx_status)(&RxStatus, &RxLen);
+		(db->rx_status)(&rxstatus, &rxlen);
 
-		debug("rx status: 0x%04x rx len: %d\n", RxStatus, RxLen);
+		debug("rx status: 0x%04x rx len: %d\n", rxstatus, rxlen);
 
 		/* Move data from DM9000 */
 		/* Read received packet from RX SRAM */
-		(db->inblk)(rdptr, RxLen);
+		(db->inblk)(rdptr, rxlen);
 
-		if ((RxStatus & 0xbf00) || (RxLen < 0x40)
-			|| (RxLen > DM9000_PKT_MAX)) {
-			if (RxStatus & 0x100) {
+		if ((rxstatus & 0xbf00) || (rxlen < 0x40)
+			|| (rxlen > DM9000_PKT_MAX)) {
+			if (rxstatus & 0x100) {
 				printf("rx fifo error\n");
 			}
-			if (RxStatus & 0x200) {
+			if (rxstatus & 0x200) {
 				printf("rx crc error\n");
 			}
-			if (RxStatus & 0x8000) {
+			if (rxstatus & 0x8000) {
 				printf("rx length error\n");
 			}
-			if (RxLen > DM9000_PKT_MAX) {
+			if (rxlen > DM9000_PKT_MAX) {
 				printf("rx length too big\n");
 				dm9000_reset();
 			}
 		} else {
-			DM9000_DMP_PACKET(__func__ , rdptr, RxLen);
+			DM9000_DMP_PACKET(__func__ , rdptr, rxlen);
 
 			debug("passing packet to upper layer\n");
-			net_process_received_packet(net_rx_packets[0], RxLen);
+			net_process_received_packet(net_rx_packets[0], rxlen);
 		}
 	}
 	return 0;
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [PATCH 04/16] net: dm9000: Drop unused dump_regs()
  2022-04-11 17:55 [PATCH 01/16] net: dm9000: Make accessor names lowercase Marek Vasut
  2022-04-11 17:55 ` [PATCH 02/16] net: dm9000: Replace DM9000_DBG() with debug() Marek Vasut
  2022-04-11 17:55 ` [PATCH 03/16] net: dm9000: Make RxLen and RxStatus lowercase Marek Vasut
@ 2022-04-11 17:55 ` Marek Vasut
  2022-04-12 19:46   ` Ramon Fried
  2022-04-11 17:55 ` [PATCH 05/16] net: dm9000: Turn DM9000_DMP_PACKET() into a function Marek Vasut
                   ` (12 subsequent siblings)
  15 siblings, 1 reply; 32+ messages in thread
From: Marek Vasut @ 2022-04-11 17:55 UTC (permalink / raw)
  To: u-boot; +Cc: marcel.ziswiler, trini, Marek Vasut, Joe Hershberger, Ramon Fried

Drop unused function dump_regs() because it is unused.
No functional change.

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Cc: Ramon Fried <rfried.dev@gmail.com>
---
 drivers/net/dm9000x.c | 17 -----------------
 1 file changed, 17 deletions(-)

diff --git a/drivers/net/dm9000x.c b/drivers/net/dm9000x.c
index a99a901e828..223df944a48 100644
--- a/drivers/net/dm9000x.c
+++ b/drivers/net/dm9000x.c
@@ -122,23 +122,6 @@ static void dm9000_iow(int reg, u8 value);
 #define dm9000_inl(r) __raw_readl(r)
 #endif
 
-#ifdef CONFIG_DM9000_DEBUG
-static void
-dump_regs(void)
-{
-	debug("\n");
-	debug("NCR   (0x00): %02x\n", dm9000_ior(0));
-	debug("NSR   (0x01): %02x\n", dm9000_ior(1));
-	debug("TCR   (0x02): %02x\n", dm9000_ior(2));
-	debug("TSRI  (0x03): %02x\n", dm9000_ior(3));
-	debug("TSRII (0x04): %02x\n", dm9000_ior(4));
-	debug("RCR   (0x05): %02x\n", dm9000_ior(5));
-	debug("RSR   (0x06): %02x\n", dm9000_ior(6));
-	debug("ISR   (0xFE): %02x\n", dm9000_ior(DM9000_ISR));
-	debug("\n");
-}
-#endif
-
 static void dm9000_outblk_8bit(volatile void *data_ptr, int count)
 {
 	int i;
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [PATCH 05/16] net: dm9000: Turn DM9000_DMP_PACKET() into a function
  2022-04-11 17:55 [PATCH 01/16] net: dm9000: Make accessor names lowercase Marek Vasut
                   ` (2 preceding siblings ...)
  2022-04-11 17:55 ` [PATCH 04/16] net: dm9000: Drop unused dump_regs() Marek Vasut
@ 2022-04-11 17:55 ` Marek Vasut
  2022-04-12 19:46   ` Ramon Fried
  2022-04-11 17:55 ` [PATCH 06/16] net: dm9000: Drop volatiles Marek Vasut
                   ` (11 subsequent siblings)
  15 siblings, 1 reply; 32+ messages in thread
From: Marek Vasut @ 2022-04-11 17:55 UTC (permalink / raw)
  To: u-boot; +Cc: marcel.ziswiler, trini, Marek Vasut, Joe Hershberger, Ramon Fried

Rework DM9000_DMP_PACKET() into dm9000_dump_packet() function,
this brings better type checking. No functional change.

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Cc: Ramon Fried <rfried.dev@gmail.com>
---
 drivers/net/dm9000x.c | 42 +++++++++++++++++++++---------------------
 1 file changed, 21 insertions(+), 21 deletions(-)

diff --git a/drivers/net/dm9000x.c b/drivers/net/dm9000x.c
index 223df944a48..da16b64610b 100644
--- a/drivers/net/dm9000x.c
+++ b/drivers/net/dm9000x.c
@@ -58,25 +58,6 @@ TODO: external MII is not functional, only internal at the moment.
 
 #include "dm9000x.h"
 
-/* Board/System/Debug information/definition ---------------- */
-
-/* #define CONFIG_DM9000_DEBUG */
-
-#ifdef CONFIG_DM9000_DEBUG
-#define DM9000_DMP_PACKET(func,packet,length)  \
-	do { \
-		int i;							\
-		printf("%s: length: %d\n", func, length);		\
-		for (i = 0; i < length; i++) {				\
-			if (i % 8 == 0)					\
-				printf("\n%s: %02x: ", func, i);	\
-			printf("%02x ", ((unsigned char *) packet)[i]);	\
-		} printf("\n");						\
-	} while(0)
-#else
-#define DM9000_DMP_PACKET(func,packet,length)
-#endif
-
 /* Structure/enum declaration ------------------------------- */
 typedef struct board_info {
 	u32 runt_length_counter;	/* counter: RX length < 64byte */
@@ -122,6 +103,25 @@ static void dm9000_iow(int reg, u8 value);
 #define dm9000_inl(r) __raw_readl(r)
 #endif
 
+#ifdef DEBUG
+static void dm9000_dump_packet(const char *func, u8 *packet, int length)
+{
+	int i;
+
+	printf("%s: length: %d\n", func, length);
+
+	for (i = 0; i < length; i++) {
+		if (i % 8 == 0)
+			printf("\n%s: %02x: ", func, i);
+		printf("%02x ", packet[i]);
+	}
+
+	printf("\n");
+}
+#else
+static void dm9000_dump_packet(const char *func, u8 *packet, int length) {}
+#endif
+
 static void dm9000_outblk_8bit(volatile void *data_ptr, int count)
 {
 	int i;
@@ -387,7 +387,7 @@ static int dm9000_send(struct eth_device *netdev, void *packet, int length)
 	int tmo;
 	struct board_info *db = &dm9000_info;
 
-	DM9000_DMP_PACKET(__func__ , packet, length);
+	dm9000_dump_packet(__func__ , packet, length);
 
 	dm9000_iow(DM9000_ISR, IMR_PTM); /* Clear Tx bit in ISR */
 
@@ -498,7 +498,7 @@ static int dm9000_rx(struct eth_device *netdev)
 				dm9000_reset();
 			}
 		} else {
-			DM9000_DMP_PACKET(__func__ , rdptr, rxlen);
+			dm9000_dump_packet(__func__ , rdptr, rxlen);
 
 			debug("passing packet to upper layer\n");
 			net_process_received_packet(net_rx_packets[0], rxlen);
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [PATCH 06/16] net: dm9000: Drop volatiles
  2022-04-11 17:55 [PATCH 01/16] net: dm9000: Make accessor names lowercase Marek Vasut
                   ` (3 preceding siblings ...)
  2022-04-11 17:55 ` [PATCH 05/16] net: dm9000: Turn DM9000_DMP_PACKET() into a function Marek Vasut
@ 2022-04-11 17:55 ` Marek Vasut
  2022-04-12 19:47   ` Ramon Fried
  2022-04-11 17:55 ` [PATCH 07/16] net: dm9000: Checkpatch cleanup Marek Vasut
                   ` (10 subsequent siblings)
  15 siblings, 1 reply; 32+ messages in thread
From: Marek Vasut @ 2022-04-11 17:55 UTC (permalink / raw)
  To: u-boot; +Cc: marcel.ziswiler, trini, Marek Vasut, Joe Hershberger, Ramon Fried

Remove volatile keyword usage from arrays, they are not really volatile
in any way, so this keyword is misused here. No functional change.

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Cc: Ramon Fried <rfried.dev@gmail.com>
---
 drivers/net/dm9000x.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/drivers/net/dm9000x.c b/drivers/net/dm9000x.c
index da16b64610b..aacf5f670e9 100644
--- a/drivers/net/dm9000x.c
+++ b/drivers/net/dm9000x.c
@@ -71,7 +71,7 @@ typedef struct board_info {
 	u8 phy_addr;
 	u8 device_wait_reset;	/* device state */
 	unsigned char srom[128];
-	void (*outblk)(volatile void *data_ptr, int count);
+	void (*outblk)(void *data_ptr, int count);
 	void (*inblk)(void *data_ptr, int count);
 	void (*rx_status)(u16 *rxstatus, u16 *rxlen);
 	struct eth_device netdev;
@@ -88,12 +88,12 @@ static void dm9000_iow(int reg, u8 value);
 
 /* DM9000 network board routine ---------------------------- */
 #ifndef CONFIG_DM9000_BYTE_SWAPPED
-#define dm9000_outb(d,r) writeb(d, (volatile u8 *)(r))
-#define dm9000_outw(d,r) writew(d, (volatile u16 *)(r))
-#define dm9000_outl(d,r) writel(d, (volatile u32 *)(r))
-#define dm9000_inb(r) readb((volatile u8 *)(r))
-#define dm9000_inw(r) readw((volatile u16 *)(r))
-#define dm9000_inl(r) readl((volatile u32 *)(r))
+#define dm9000_outb(d,r) writeb((d), (r))
+#define dm9000_outw(d,r) writew((d), (r))
+#define dm9000_outl(d,r) writel((d), (r))
+#define dm9000_inb(r) readb(r)
+#define dm9000_inw(r) readw(r)
+#define dm9000_inl(r) readl(r)
 #else
 #define dm9000_outb(d, r) __raw_writeb(d, r)
 #define dm9000_outw(d, r) __raw_writew(d, r)
@@ -122,14 +122,14 @@ static void dm9000_dump_packet(const char *func, u8 *packet, int length)
 static void dm9000_dump_packet(const char *func, u8 *packet, int length) {}
 #endif
 
-static void dm9000_outblk_8bit(volatile void *data_ptr, int count)
+static void dm9000_outblk_8bit(void *data_ptr, int count)
 {
 	int i;
 	for (i = 0; i < count; i++)
 		dm9000_outb((((u8 *) data_ptr)[i] & 0xff), DM9000_DATA);
 }
 
-static void dm9000_outblk_16bit(volatile void *data_ptr, int count)
+static void dm9000_outblk_16bit(void *data_ptr, int count)
 {
 	int i;
 	u32 tmplen = (count + 1) / 2;
@@ -137,7 +137,7 @@ static void dm9000_outblk_16bit(volatile void *data_ptr, int count)
 	for (i = 0; i < tmplen; i++)
 		dm9000_outw(((u16 *) data_ptr)[i], DM9000_DATA);
 }
-static void dm9000_outblk_32bit(volatile void *data_ptr, int count)
+static void dm9000_outblk_32bit(void *data_ptr, int count)
 {
 	int i;
 	u32 tmplen = (count + 3) / 4;
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [PATCH 07/16] net: dm9000: Checkpatch cleanup
  2022-04-11 17:55 [PATCH 01/16] net: dm9000: Make accessor names lowercase Marek Vasut
                   ` (4 preceding siblings ...)
  2022-04-11 17:55 ` [PATCH 06/16] net: dm9000: Drop volatiles Marek Vasut
@ 2022-04-11 17:55 ` Marek Vasut
  2022-04-12 19:47   ` Ramon Fried
  2022-04-11 17:55 ` [PATCH 08/16] net: dm9000: Reorder and staticize Marek Vasut
                   ` (9 subsequent siblings)
  15 siblings, 1 reply; 32+ messages in thread
From: Marek Vasut @ 2022-04-11 17:55 UTC (permalink / raw)
  To: u-boot; +Cc: marcel.ziswiler, trini, Marek Vasut, Joe Hershberger, Ramon Fried

Fix checkpatch errors and warnings. No functional change.

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Cc: Ramon Fried <rfried.dev@gmail.com>
---
 drivers/net/dm9000x.c | 251 +++++++++++++++++++++---------------------
 1 file changed, 126 insertions(+), 125 deletions(-)

diff --git a/drivers/net/dm9000x.c b/drivers/net/dm9000x.c
index aacf5f670e9..becf7aec828 100644
--- a/drivers/net/dm9000x.c
+++ b/drivers/net/dm9000x.c
@@ -1,53 +1,53 @@
 // SPDX-License-Identifier: GPL-2.0+
 /*
-  dm9000.c: Version 1.2 12/15/2003
-
-	A Davicom DM9000 ISA NIC fast Ethernet driver for Linux.
-	Copyright (C) 1997  Sten Wang
-
-  (C)Copyright 1997-1998 DAVICOM Semiconductor,Inc. All Rights Reserved.
-
-V0.11	06/20/2001	REG_0A bit3=1, default enable BP with DA match
-	06/22/2001	Support DM9801 progrmming
-			E3: R25 = ((R24 + NF) & 0x00ff) | 0xf000
-			E4: R25 = ((R24 + NF) & 0x00ff) | 0xc200
-		R17 = (R17 & 0xfff0) | NF + 3
-			E5: R25 = ((R24 + NF - 3) & 0x00ff) | 0xc200
-		R17 = (R17 & 0xfff0) | NF
-
-v1.00			modify by simon 2001.9.5
-			change for kernel 2.4.x
-
-v1.1   11/09/2001	fix force mode bug
-
-v1.2   03/18/2003       Weilun Huang <weilun_huang@davicom.com.tw>:
-			Fixed phy reset.
-			Added tx/rx 32 bit mode.
-			Cleaned up for kernel merge.
-
---------------------------------------
-
-       12/15/2003       Initial port to u-boot by
-			Sascha Hauer <saschahauer@web.de>
-
-       06/03/2008	Remy Bohmer <linux@bohmer.net>
-			- Fixed the driver to work with DM9000A.
-			  (check on ISR receive status bit before reading the
-			  FIFO as described in DM9000 programming guide and
-			  application notes)
-			- Added autodetect of databus width.
-			- Made debug code compile again.
-			- Adapt eth_send such that it matches the DM9000*
-			  application notes. Needed to make it work properly
-			  for DM9000A.
-			- Adapted reset procedure to match DM9000 application
-			  notes (i.e. double reset)
-			- some minor code cleanups
-			These changes are tested with DM9000{A,EP,E} together
-			with a 200MHz Atmel AT91SAM9261 core
-
-TODO: external MII is not functional, only internal at the moment.
-*/
+ *   dm9000.c: Version 1.2 12/15/2003
+ *
+ *	A Davicom DM9000 ISA NIC fast Ethernet driver for Linux.
+ *	Copyright (C) 1997  Sten Wang
+ *
+ *   (C)Copyright 1997-1998 DAVICOM Semiconductor,Inc. All Rights Reserved.
+ *
+ * V0.11	06/20/2001	REG_0A bit3=1, default enable BP with DA match
+ *	06/22/2001	Support DM9801 progrmming
+ *			E3: R25 = ((R24 + NF) & 0x00ff) | 0xf000
+ *			E4: R25 = ((R24 + NF) & 0x00ff) | 0xc200
+ *		R17 = (R17 & 0xfff0) | NF + 3
+ *			E5: R25 = ((R24 + NF - 3) & 0x00ff) | 0xc200
+ *		R17 = (R17 & 0xfff0) | NF
+ *
+ * v1.00			modify by simon 2001.9.5
+ *			change for kernel 2.4.x
+ *
+ * v1.1   11/09/2001	fix force mode bug
+ *
+ * v1.2   03/18/2003       Weilun Huang <weilun_huang@davicom.com.tw>:
+ *			Fixed phy reset.
+ *			Added tx/rx 32 bit mode.
+ *			Cleaned up for kernel merge.
+ *
+ * --------------------------------------
+ *
+ *        12/15/2003       Initial port to u-boot by
+ *			Sascha Hauer <saschahauer@web.de>
+ *
+ *        06/03/2008	Remy Bohmer <linux@bohmer.net>
+ *			- Fixed the driver to work with DM9000A.
+ *			  (check on ISR receive status bit before reading the
+ *			  FIFO as described in DM9000 programming guide and
+ *			  application notes)
+ *			- Added autodetect of databus width.
+ *			- Made debug code compile again.
+ *			- Adapt eth_send such that it matches the DM9000*
+ *			  application notes. Needed to make it work properly
+ *			  for DM9000A.
+ *			- Adapted reset procedure to match DM9000 application
+ *			  notes (i.e. double reset)
+ *			- some minor code cleanups
+ *			These changes are tested with DM9000{A,EP,E} together
+ *			with a 200MHz Atmel AT91SAM9261 core
+ *
+ * TODO: external MII is not functional, only internal at the moment.
+ */
 
 #include <common.h>
 #include <command.h>
@@ -59,7 +59,7 @@ TODO: external MII is not functional, only internal at the moment.
 #include "dm9000x.h"
 
 /* Structure/enum declaration ------------------------------- */
-typedef struct board_info {
+struct board_info {
 	u32 runt_length_counter;	/* counter: RX length < 64byte */
 	u32 long_length_counter;	/* counter: RX length > 1514byte */
 	u32 reset_counter;	/* counter: RESET */
@@ -75,9 +75,9 @@ typedef struct board_info {
 	void (*inblk)(void *data_ptr, int count);
 	void (*rx_status)(u16 *rxstatus, u16 *rxlen);
 	struct eth_device netdev;
-} board_info_t;
-static board_info_t dm9000_info;
+};
 
+static struct board_info dm9000_info;
 
 /* function declaration ------------------------------------- */
 static int dm9000_probe(void);
@@ -88,9 +88,9 @@ static void dm9000_iow(int reg, u8 value);
 
 /* DM9000 network board routine ---------------------------- */
 #ifndef CONFIG_DM9000_BYTE_SWAPPED
-#define dm9000_outb(d,r) writeb((d), (r))
-#define dm9000_outw(d,r) writew((d), (r))
-#define dm9000_outl(d,r) writel((d), (r))
+#define dm9000_outb(d, r) writeb((d), (r))
+#define dm9000_outw(d, r) writew((d), (r))
+#define dm9000_outl(d, r) writel((d), (r))
 #define dm9000_inb(r) readb(r)
 #define dm9000_inw(r) readw(r)
 #define dm9000_inl(r) readl(r)
@@ -125,8 +125,9 @@ static void dm9000_dump_packet(const char *func, u8 *packet, int length) {}
 static void dm9000_outblk_8bit(void *data_ptr, int count)
 {
 	int i;
+
 	for (i = 0; i < count; i++)
-		dm9000_outb((((u8 *) data_ptr)[i] & 0xff), DM9000_DATA);
+		dm9000_outb((((u8 *)data_ptr)[i] & 0xff), DM9000_DATA);
 }
 
 static void dm9000_outblk_16bit(void *data_ptr, int count)
@@ -135,22 +136,24 @@ static void dm9000_outblk_16bit(void *data_ptr, int count)
 	u32 tmplen = (count + 1) / 2;
 
 	for (i = 0; i < tmplen; i++)
-		dm9000_outw(((u16 *) data_ptr)[i], DM9000_DATA);
+		dm9000_outw(((u16 *)data_ptr)[i], DM9000_DATA);
 }
+
 static void dm9000_outblk_32bit(void *data_ptr, int count)
 {
 	int i;
 	u32 tmplen = (count + 3) / 4;
 
 	for (i = 0; i < tmplen; i++)
-		dm9000_outl(((u32 *) data_ptr)[i], DM9000_DATA);
+		dm9000_outl(((u32 *)data_ptr)[i], DM9000_DATA);
 }
 
 static void dm9000_inblk_8bit(void *data_ptr, int count)
 {
 	int i;
+
 	for (i = 0; i < count; i++)
-		((u8 *) data_ptr)[i] = dm9000_inb(DM9000_DATA);
+		((u8 *)data_ptr)[i] = dm9000_inb(DM9000_DATA);
 }
 
 static void dm9000_inblk_16bit(void *data_ptr, int count)
@@ -159,15 +162,16 @@ static void dm9000_inblk_16bit(void *data_ptr, int count)
 	u32 tmplen = (count + 1) / 2;
 
 	for (i = 0; i < tmplen; i++)
-		((u16 *) data_ptr)[i] = dm9000_inw(DM9000_DATA);
+		((u16 *)data_ptr)[i] = dm9000_inw(DM9000_DATA);
 }
+
 static void dm9000_inblk_32bit(void *data_ptr, int count)
 {
 	int i;
 	u32 tmplen = (count + 3) / 4;
 
 	for (i = 0; i < tmplen; i++)
-		((u32 *) data_ptr)[i] = dm9000_inl(DM9000_DATA);
+		((u32 *)data_ptr)[i] = dm9000_inl(DM9000_DATA);
 }
 
 static void dm9000_rx_status_32bit(u16 *rxstatus, u16 *rxlen)
@@ -202,25 +206,25 @@ static void dm9000_rx_status_8bit(u16 *rxstatus, u16 *rxlen)
 }
 
 /*
-  Search DM9000 board, allocate space and register it
-*/
+ * Search DM9000 board, allocate space and register it
+ */
 int
 dm9000_probe(void)
 {
 	u32 id_val;
+
 	id_val = dm9000_ior(DM9000_VIDL);
 	id_val |= dm9000_ior(DM9000_VIDH) << 8;
 	id_val |= dm9000_ior(DM9000_PIDL) << 16;
 	id_val |= dm9000_ior(DM9000_PIDH) << 24;
-	if (id_val == DM9000_ID) {
-		printf("dm9000 i/o: 0x%x, id: 0x%x \n", CONFIG_DM9000_BASE,
-		       id_val);
-		return 0;
-	} else {
+	if (id_val != DM9000_ID) {
 		printf("dm9000 not found at 0x%08x id: 0x%08x\n",
 		       CONFIG_DM9000_BASE, id_val);
 		return -1;
 	}
+
+	printf("dm9000 i/o: 0x%x, id: 0x%x\n", CONFIG_DM9000_BASE, id_val);
+	return 0;
 }
 
 /* General Purpose dm9000 reset routine */
@@ -229,8 +233,10 @@ dm9000_reset(void)
 {
 	debug("resetting DM9000\n");
 
-	/* Reset DM9000,
-	   see DM9000 Application Notes V1.22 Jun 11, 2004 page 29 */
+	/*
+	 * Reset DM9000,
+	 * see DM9000 Application Notes V1.22 Jun 11, 2004 page 29
+	 */
 
 	/* DEBUG: Make all GPIO0 outputs, all others inputs */
 	dm9000_iow(DM9000_GPCR, GPCR_GPIO0_OUT);
@@ -258,16 +264,13 @@ dm9000_reset(void)
 		printf("ERROR: resetting DM9000 -> not responding\n");
 }
 
-/* Initialize dm9000 board
-*/
+/* Initialize dm9000 board */
 static int dm9000_init(struct eth_device *dev, struct bd_info *bd)
 {
 	int i, oft, lnk;
 	u8 io_mode;
 	struct board_info *db = &dm9000_info;
 
-	debug("%s\n", __func__);
-
 	/* RESET device */
 	dm9000_reset();
 
@@ -323,9 +326,8 @@ static int dm9000_init(struct eth_device *dev, struct bd_info *bd)
 	dm9000_iow(DM9000_ISR, ISR_ROOS | ISR_ROS | ISR_PTS | ISR_PRS);
 
 	printf("MAC: %pM\n", dev->enetaddr);
-	if (!is_valid_ethaddr(dev->enetaddr)) {
+	if (!is_valid_ethaddr(dev->enetaddr))
 		printf("WARNING: Bad MAC address (uninitialized EEPROM?)\n");
-	}
 
 	/* fill device MAC address registers */
 	for (i = 0, oft = DM9000_PAR; i < 6; i++, oft++)
@@ -379,15 +381,15 @@ static int dm9000_init(struct eth_device *dev, struct bd_info *bd)
 }
 
 /*
-  Hardware start transmission.
-  Send a packet to media from the upper layer.
-*/
+ * Hardware start transmission.
+ * Send a packet to media from the upper layer.
+ */
 static int dm9000_send(struct eth_device *netdev, void *packet, int length)
 {
 	int tmo;
 	struct board_info *db = &dm9000_info;
 
-	dm9000_dump_packet(__func__ , packet, length);
+	dm9000_dump_packet(__func__, packet, length);
 
 	dm9000_iow(DM9000_ISR, IMR_PTM); /* Clear Tx bit in ISR */
 
@@ -395,7 +397,7 @@ static int dm9000_send(struct eth_device *netdev, void *packet, int length)
 	dm9000_outb(DM9000_MWCMD, DM9000_IO); /* Prepare for TX-data */
 
 	/* push the data to the TX-fifo */
-	(db->outblk)(packet, length);
+	db->outblk(packet, length);
 
 	/* Set TX length to DM9000 */
 	dm9000_iow(DM9000_TXPLL, length & 0xff);
@@ -406,8 +408,8 @@ static int dm9000_send(struct eth_device *netdev, void *packet, int length)
 
 	/* wait for end of transmission */
 	tmo = get_timer(0) + 5 * CONFIG_SYS_HZ;
-	while ( !(dm9000_ior(DM9000_NSR) & (NSR_TX1END | NSR_TX2END)) ||
-		!(dm9000_ior(DM9000_ISR) & IMR_PTM) ) {
+	while (!(dm9000_ior(DM9000_NSR) & (NSR_TX1END | NSR_TX2END)) ||
+	       !(dm9000_ior(DM9000_ISR) & IMR_PTM)) {
 		if (get_timer(0) >= tmo) {
 			printf("transmission timeout\n");
 			break;
@@ -420,14 +422,12 @@ static int dm9000_send(struct eth_device *netdev, void *packet, int length)
 }
 
 /*
-  Stop the interface.
-  The interface is stopped when it is brought.
-*/
+ * Stop the interface.
+ * The interface is stopped when it is brought.
+ */
 static void dm9000_halt(struct eth_device *netdev)
 {
-	debug("%s\n", __func__);
-
-	/* RESET devie */
+	/* RESET device */
 	dm9000_phy_write(0, 0x8000);	/* PHY RESET */
 	dm9000_iow(DM9000_GPR, 0x01);	/* Power-Down PHY */
 	dm9000_iow(DM9000_IMR, 0x80);	/* Disable all interrupt */
@@ -435,8 +435,8 @@ static void dm9000_halt(struct eth_device *netdev)
 }
 
 /*
-  Received a packet and pass to upper layer
-*/
+ * Received a packet and pass to upper layer
+ */
 static int dm9000_rx(struct eth_device *netdev)
 {
 	u8 rxbyte;
@@ -444,8 +444,10 @@ static int dm9000_rx(struct eth_device *netdev)
 	u16 rxstatus, rxlen = 0;
 	struct board_info *db = &dm9000_info;
 
-	/* Check packet ready or not, we must check
-	   the ISR status first for DM9000A */
+	/*
+	 * Check packet ready or not, we must check
+	 * the ISR status first for DM9000A
+	 */
 	if (!(dm9000_ior(DM9000_ISR) & 0x01)) /* Rx-ISR bit must be set. */
 		return 0;
 
@@ -455,8 +457,10 @@ static int dm9000_rx(struct eth_device *netdev)
 	for (;;) {
 		dm9000_ior(DM9000_MRCMDX);	/* Dummy read */
 
-		/* Get most updated data,
-		   only look at bits 0:1, See application notes DM9000 */
+		/*
+		 * Get most updated data,
+		 * only look at bits 0:1, See application notes DM9000
+		 */
 		rxbyte = dm9000_inb(DM9000_DATA) & 0x03;
 
 		/* Status check: this byte must be 0 or 1 */
@@ -464,7 +468,7 @@ static int dm9000_rx(struct eth_device *netdev)
 			dm9000_iow(DM9000_RCR, 0x00);	/* Stop Device */
 			dm9000_iow(DM9000_ISR, 0x80);	/* Stop INT request */
 			printf("DM9000 error: status check fail: 0x%x\n",
-				rxbyte);
+			       rxbyte);
 			return 0;
 		}
 
@@ -474,31 +478,28 @@ static int dm9000_rx(struct eth_device *netdev)
 		debug("receiving packet\n");
 
 		/* A packet ready now  & Get status/length */
-		(db->rx_status)(&rxstatus, &rxlen);
+		db->rx_status(&rxstatus, &rxlen);
 
 		debug("rx status: 0x%04x rx len: %d\n", rxstatus, rxlen);
 
 		/* Move data from DM9000 */
 		/* Read received packet from RX SRAM */
-		(db->inblk)(rdptr, rxlen);
+		db->inblk(rdptr, rxlen);
 
-		if ((rxstatus & 0xbf00) || (rxlen < 0x40)
-			|| (rxlen > DM9000_PKT_MAX)) {
-			if (rxstatus & 0x100) {
+		if (rxstatus & 0xbf00 || rxlen < 0x40 ||
+		    rxlen > DM9000_PKT_MAX) {
+			if (rxstatus & 0x100)
 				printf("rx fifo error\n");
-			}
-			if (rxstatus & 0x200) {
+			if (rxstatus & 0x200)
 				printf("rx crc error\n");
-			}
-			if (rxstatus & 0x8000) {
+			if (rxstatus & 0x8000)
 				printf("rx length error\n");
-			}
 			if (rxlen > DM9000_PKT_MAX) {
 				printf("rx length too big\n");
 				dm9000_reset();
 			}
 		} else {
-			dm9000_dump_packet(__func__ , rdptr, rxlen);
+			dm9000_dump_packet(__func__, rdptr, rxlen);
 
 			debug("passing packet to upper layer\n");
 			net_process_received_packet(net_rx_packets[0], rxlen);
@@ -508,14 +509,14 @@ static int dm9000_rx(struct eth_device *netdev)
 }
 
 /*
-  Read a word data from SROM
-*/
+ * Read a word data from SROM
+ */
 #if !defined(CONFIG_DM9000_NO_SROM)
 void dm9000_read_srom_word(int offset, u8 *to)
 {
 	dm9000_iow(DM9000_EPAR, offset);
 	dm9000_iow(DM9000_EPCR, 0x4);
-	udelay(8000);
+	mdelay(8);
 	dm9000_iow(DM9000_EPCR, 0x0);
 	to[0] = dm9000_ior(DM9000_EPDRL);
 	to[1] = dm9000_ior(DM9000_EPDRH);
@@ -527,23 +528,24 @@ void dm9000_write_srom_word(int offset, u16 val)
 	dm9000_iow(DM9000_EPDRH, ((val >> 8) & 0xff));
 	dm9000_iow(DM9000_EPDRL, (val & 0xff));
 	dm9000_iow(DM9000_EPCR, 0x12);
-	udelay(8000);
+	mdelay(8);
 	dm9000_iow(DM9000_EPCR, 0);
 }
-#endif
 
 static void dm9000_get_enetaddr(struct eth_device *dev)
 {
-#if !defined(CONFIG_DM9000_NO_SROM)
 	int i;
+
 	for (i = 0; i < 3; i++)
 		dm9000_read_srom_word(i, dev->enetaddr + (2 * i));
-#endif
 }
+#else
+static void dm9000_get_enetaddr(struct eth_device *dev) {}
+#endif
 
 /*
-   Read a byte from I/O port
-*/
+ *  Read a byte from I/O port
+ */
 static u8
 dm9000_ior(int reg)
 {
@@ -552,8 +554,8 @@ dm9000_ior(int reg)
 }
 
 /*
-   Write a byte to I/O port
-*/
+ *  Write a byte to I/O port
+ */
 static void
 dm9000_iow(int reg, u8 value)
 {
@@ -562,8 +564,8 @@ dm9000_iow(int reg, u8 value)
 }
 
 /*
-   Read a word from phyxcer
-*/
+ *  Read a word from phyxcer
+ */
 static u16
 dm9000_phy_read(int reg)
 {
@@ -577,17 +579,16 @@ dm9000_phy_read(int reg)
 	val = (dm9000_ior(DM9000_EPDRH) << 8) | dm9000_ior(DM9000_EPDRL);
 
 	/* The read data keeps on REG_0D & REG_0E */
-	debug("dm9000_phy_read(0x%x): 0x%x\n", reg, val);
+	debug("%s(0x%x): 0x%x\n", __func__, reg, val);
 	return val;
 }
 
 /*
-   Write a word to phyxcer
-*/
+ *  Write a word to phyxcer
+ */
 static void
 dm9000_phy_write(int reg, u16 value)
 {
-
 	/* Fill the phyxcer register into REG_0C */
 	dm9000_iow(DM9000_EPAR, DM9000_PHY | reg);
 
@@ -597,12 +598,12 @@ dm9000_phy_write(int reg, u16 value)
 	dm9000_iow(DM9000_EPCR, 0xa);	/* Issue phyxcer write command */
 	udelay(500);			/* Wait write complete */
 	dm9000_iow(DM9000_EPCR, 0x0);	/* Clear phyxcer write command */
-	debug("dm9000_phy_write(reg:0x%x, value:0x%x)\n", reg, value);
+	debug("%s(reg:0x%x, value:0x%x)\n", __func__, reg, value);
 }
 
 int dm9000_initialize(struct bd_info *bis)
 {
-	struct eth_device *dev = &(dm9000_info.netdev);
+	struct eth_device *dev = &dm9000_info.netdev;
 
 	/* Load MAC address from EEPROM */
 	dm9000_get_enetaddr(dev);
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [PATCH 08/16] net: dm9000: Reorder and staticize
  2022-04-11 17:55 [PATCH 01/16] net: dm9000: Make accessor names lowercase Marek Vasut
                   ` (5 preceding siblings ...)
  2022-04-11 17:55 ` [PATCH 07/16] net: dm9000: Checkpatch cleanup Marek Vasut
@ 2022-04-11 17:55 ` Marek Vasut
  2022-04-12 19:48   ` Ramon Fried
  2022-04-11 17:56 ` [PATCH 09/16] net: dm9000: Rename board_info to dm9000_priv Marek Vasut
                   ` (8 subsequent siblings)
  15 siblings, 1 reply; 32+ messages in thread
From: Marek Vasut @ 2022-04-11 17:55 UTC (permalink / raw)
  To: u-boot; +Cc: marcel.ziswiler, trini, Marek Vasut, Joe Hershberger, Ramon Fried

Reorder the driver functions to get rid of forward declarations.
Staticize whatever is possible. No functional change.

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Cc: Ramon Fried <rfried.dev@gmail.com>
---
 drivers/net/dm9000x.c | 122 +++++++++++++++++++-----------------------
 1 file changed, 55 insertions(+), 67 deletions(-)

diff --git a/drivers/net/dm9000x.c b/drivers/net/dm9000x.c
index becf7aec828..85f3c079ec1 100644
--- a/drivers/net/dm9000x.c
+++ b/drivers/net/dm9000x.c
@@ -79,13 +79,6 @@ struct board_info {
 
 static struct board_info dm9000_info;
 
-/* function declaration ------------------------------------- */
-static int dm9000_probe(void);
-static u16 dm9000_phy_read(int);
-static void dm9000_phy_write(int, u16);
-static u8 dm9000_ior(int);
-static void dm9000_iow(int reg, u8 value);
-
 /* DM9000 network board routine ---------------------------- */
 #ifndef CONFIG_DM9000_BYTE_SWAPPED
 #define dm9000_outb(d, r) writeb((d), (r))
@@ -205,11 +198,64 @@ static void dm9000_rx_status_8bit(u16 *rxstatus, u16 *rxlen)
 			  (dm9000_inb(DM9000_DATA) << 8));
 }
 
+/*
+ *  Read a byte from I/O port
+ */
+static u8 dm9000_ior(int reg)
+{
+	dm9000_outb(reg, DM9000_IO);
+	return dm9000_inb(DM9000_DATA);
+}
+
+/*
+ *  Write a byte to I/O port
+ */
+static void dm9000_iow(int reg, u8 value)
+{
+	dm9000_outb(reg, DM9000_IO);
+	dm9000_outb(value, DM9000_DATA);
+}
+
+/*
+ *  Read a word from phyxcer
+ */
+static u16 dm9000_phy_read(int reg)
+{
+	u16 val;
+
+	/* Fill the phyxcer register into REG_0C */
+	dm9000_iow(DM9000_EPAR, DM9000_PHY | reg);
+	dm9000_iow(DM9000_EPCR, 0xc);	/* Issue phyxcer read command */
+	udelay(100);			/* Wait read complete */
+	dm9000_iow(DM9000_EPCR, 0x0);	/* Clear phyxcer read command */
+	val = (dm9000_ior(DM9000_EPDRH) << 8) | dm9000_ior(DM9000_EPDRL);
+
+	/* The read data keeps on REG_0D & REG_0E */
+	debug("%s(0x%x): 0x%x\n", __func__, reg, val);
+	return val;
+}
+
+/*
+ *  Write a word to phyxcer
+ */
+static void dm9000_phy_write(int reg, u16 value)
+{
+	/* Fill the phyxcer register into REG_0C */
+	dm9000_iow(DM9000_EPAR, DM9000_PHY | reg);
+
+	/* Fill the written data into REG_0D & REG_0E */
+	dm9000_iow(DM9000_EPDRL, (value & 0xff));
+	dm9000_iow(DM9000_EPDRH, ((value >> 8) & 0xff));
+	dm9000_iow(DM9000_EPCR, 0xa);	/* Issue phyxcer write command */
+	udelay(500);			/* Wait write complete */
+	dm9000_iow(DM9000_EPCR, 0x0);	/* Clear phyxcer write command */
+	debug("%s(reg:0x%x, value:0x%x)\n", __func__, reg, value);
+}
+
 /*
  * Search DM9000 board, allocate space and register it
  */
-int
-dm9000_probe(void)
+static int dm9000_probe(void)
 {
 	u32 id_val;
 
@@ -543,64 +589,6 @@ static void dm9000_get_enetaddr(struct eth_device *dev)
 static void dm9000_get_enetaddr(struct eth_device *dev) {}
 #endif
 
-/*
- *  Read a byte from I/O port
- */
-static u8
-dm9000_ior(int reg)
-{
-	dm9000_outb(reg, DM9000_IO);
-	return dm9000_inb(DM9000_DATA);
-}
-
-/*
- *  Write a byte to I/O port
- */
-static void
-dm9000_iow(int reg, u8 value)
-{
-	dm9000_outb(reg, DM9000_IO);
-	dm9000_outb(value, DM9000_DATA);
-}
-
-/*
- *  Read a word from phyxcer
- */
-static u16
-dm9000_phy_read(int reg)
-{
-	u16 val;
-
-	/* Fill the phyxcer register into REG_0C */
-	dm9000_iow(DM9000_EPAR, DM9000_PHY | reg);
-	dm9000_iow(DM9000_EPCR, 0xc);	/* Issue phyxcer read command */
-	udelay(100);			/* Wait read complete */
-	dm9000_iow(DM9000_EPCR, 0x0);	/* Clear phyxcer read command */
-	val = (dm9000_ior(DM9000_EPDRH) << 8) | dm9000_ior(DM9000_EPDRL);
-
-	/* The read data keeps on REG_0D & REG_0E */
-	debug("%s(0x%x): 0x%x\n", __func__, reg, val);
-	return val;
-}
-
-/*
- *  Write a word to phyxcer
- */
-static void
-dm9000_phy_write(int reg, u16 value)
-{
-	/* Fill the phyxcer register into REG_0C */
-	dm9000_iow(DM9000_EPAR, DM9000_PHY | reg);
-
-	/* Fill the written data into REG_0D & REG_0E */
-	dm9000_iow(DM9000_EPDRL, (value & 0xff));
-	dm9000_iow(DM9000_EPDRH, ((value >> 8) & 0xff));
-	dm9000_iow(DM9000_EPCR, 0xa);	/* Issue phyxcer write command */
-	udelay(500);			/* Wait write complete */
-	dm9000_iow(DM9000_EPCR, 0x0);	/* Clear phyxcer write command */
-	debug("%s(reg:0x%x, value:0x%x)\n", __func__, reg, value);
-}
-
 int dm9000_initialize(struct bd_info *bis)
 {
 	struct eth_device *dev = &dm9000_info.netdev;
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [PATCH 09/16] net: dm9000: Rename board_info to dm9000_priv
  2022-04-11 17:55 [PATCH 01/16] net: dm9000: Make accessor names lowercase Marek Vasut
                   ` (6 preceding siblings ...)
  2022-04-11 17:55 ` [PATCH 08/16] net: dm9000: Reorder and staticize Marek Vasut
@ 2022-04-11 17:56 ` Marek Vasut
  2022-04-12 19:48   ` Ramon Fried
  2022-04-11 17:56 ` [PATCH 10/16] net: dm9000: Drop static device private data Marek Vasut
                   ` (7 subsequent siblings)
  15 siblings, 1 reply; 32+ messages in thread
From: Marek Vasut @ 2022-04-11 17:56 UTC (permalink / raw)
  To: u-boot; +Cc: marcel.ziswiler, trini, Marek Vasut, Joe Hershberger, Ramon Fried

Rename board_info structure to dm9000_priv to make it clear what this
structure really contains, the driver private data. No functional change.

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Cc: Ramon Fried <rfried.dev@gmail.com>
---
 drivers/net/dm9000x.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/net/dm9000x.c b/drivers/net/dm9000x.c
index 85f3c079ec1..7e1368a1be9 100644
--- a/drivers/net/dm9000x.c
+++ b/drivers/net/dm9000x.c
@@ -59,7 +59,7 @@
 #include "dm9000x.h"
 
 /* Structure/enum declaration ------------------------------- */
-struct board_info {
+struct dm9000_priv {
 	u32 runt_length_counter;	/* counter: RX length < 64byte */
 	u32 long_length_counter;	/* counter: RX length > 1514byte */
 	u32 reset_counter;	/* counter: RESET */
@@ -77,7 +77,7 @@ struct board_info {
 	struct eth_device netdev;
 };
 
-static struct board_info dm9000_info;
+static struct dm9000_priv dm9000_info;
 
 /* DM9000 network board routine ---------------------------- */
 #ifndef CONFIG_DM9000_BYTE_SWAPPED
@@ -315,7 +315,7 @@ static int dm9000_init(struct eth_device *dev, struct bd_info *bd)
 {
 	int i, oft, lnk;
 	u8 io_mode;
-	struct board_info *db = &dm9000_info;
+	struct dm9000_priv *db = &dm9000_info;
 
 	/* RESET device */
 	dm9000_reset();
@@ -433,7 +433,7 @@ static int dm9000_init(struct eth_device *dev, struct bd_info *bd)
 static int dm9000_send(struct eth_device *netdev, void *packet, int length)
 {
 	int tmo;
-	struct board_info *db = &dm9000_info;
+	struct dm9000_priv *db = &dm9000_info;
 
 	dm9000_dump_packet(__func__, packet, length);
 
@@ -488,7 +488,7 @@ static int dm9000_rx(struct eth_device *netdev)
 	u8 rxbyte;
 	u8 *rdptr = (u8 *)net_rx_packets[0];
 	u16 rxstatus, rxlen = 0;
-	struct board_info *db = &dm9000_info;
+	struct dm9000_priv *db = &dm9000_info;
 
 	/*
 	 * Check packet ready or not, we must check
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [PATCH 10/16] net: dm9000: Drop static device private data
  2022-04-11 17:55 [PATCH 01/16] net: dm9000: Make accessor names lowercase Marek Vasut
                   ` (7 preceding siblings ...)
  2022-04-11 17:56 ` [PATCH 09/16] net: dm9000: Rename board_info to dm9000_priv Marek Vasut
@ 2022-04-11 17:56 ` Marek Vasut
  2022-04-12 19:49   ` Ramon Fried
  2022-04-11 17:56 ` [PATCH 11/16] net: dm9000: Drop dm9000.h and staticize SROM access Marek Vasut
                   ` (6 subsequent siblings)
  15 siblings, 1 reply; 32+ messages in thread
From: Marek Vasut @ 2022-04-11 17:56 UTC (permalink / raw)
  To: u-boot; +Cc: marcel.ziswiler, trini, Marek Vasut, Joe Hershberger, Ramon Fried

Allocate driver private data dynamically in its init function and drop
the static driver private data variable. Pass the dynamic private data
throughout the driver. This is done in preparation for DM conversion.

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Cc: Ramon Fried <rfried.dev@gmail.com>
---
 drivers/net/dm9000x.c | 24 +++++++++++++-----------
 1 file changed, 13 insertions(+), 11 deletions(-)

diff --git a/drivers/net/dm9000x.c b/drivers/net/dm9000x.c
index 7e1368a1be9..666883ee19e 100644
--- a/drivers/net/dm9000x.c
+++ b/drivers/net/dm9000x.c
@@ -77,8 +77,6 @@ struct dm9000_priv {
 	struct eth_device netdev;
 };
 
-static struct dm9000_priv dm9000_info;
-
 /* DM9000 network board routine ---------------------------- */
 #ifndef CONFIG_DM9000_BYTE_SWAPPED
 #define dm9000_outb(d, r) writeb((d), (r))
@@ -313,9 +311,9 @@ dm9000_reset(void)
 /* Initialize dm9000 board */
 static int dm9000_init(struct eth_device *dev, struct bd_info *bd)
 {
+	struct dm9000_priv *db = container_of(dev, struct dm9000_priv, dev);
 	int i, oft, lnk;
 	u8 io_mode;
-	struct dm9000_priv *db = &dm9000_info;
 
 	/* RESET device */
 	dm9000_reset();
@@ -430,10 +428,10 @@ static int dm9000_init(struct eth_device *dev, struct bd_info *bd)
  * Hardware start transmission.
  * Send a packet to media from the upper layer.
  */
-static int dm9000_send(struct eth_device *netdev, void *packet, int length)
+static int dm9000_send(struct eth_device *dev, void *packet, int length)
 {
+	struct dm9000_priv *db = container_of(dev, struct dm9000_priv, dev);
 	int tmo;
-	struct dm9000_priv *db = &dm9000_info;
 
 	dm9000_dump_packet(__func__, packet, length);
 
@@ -483,12 +481,12 @@ static void dm9000_halt(struct eth_device *netdev)
 /*
  * Received a packet and pass to upper layer
  */
-static int dm9000_rx(struct eth_device *netdev)
+static int dm9000_rx(struct eth_device *dev)
 {
+	struct dm9000_priv *db = container_of(dev, struct dm9000_priv, dev);
 	u8 rxbyte;
 	u8 *rdptr = (u8 *)net_rx_packets[0];
 	u16 rxstatus, rxlen = 0;
-	struct dm9000_priv *db = &dm9000_info;
 
 	/*
 	 * Check packet ready or not, we must check
@@ -591,18 +589,22 @@ static void dm9000_get_enetaddr(struct eth_device *dev) {}
 
 int dm9000_initialize(struct bd_info *bis)
 {
-	struct eth_device *dev = &dm9000_info.netdev;
+	struct dm9000_priv *priv;
+
+	priv = kcalloc(1, sizeof(*priv));
+	if (!priv)
+		return -ENOMEM;
 
 	/* Load MAC address from EEPROM */
-	dm9000_get_enetaddr(dev);
+	dm9000_get_enetaddr(&priv->dev);
 
 	dev->init = dm9000_init;
 	dev->halt = dm9000_halt;
 	dev->send = dm9000_send;
 	dev->recv = dm9000_rx;
-	strcpy(dev->name, "dm9000");
+	strcpy(&priv->dev.name, "dm9000");
 
-	eth_register(dev);
+	eth_register(&priv->dev);
 
 	return 0;
 }
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [PATCH 11/16] net: dm9000: Drop dm9000.h and staticize SROM access
  2022-04-11 17:55 [PATCH 01/16] net: dm9000: Make accessor names lowercase Marek Vasut
                   ` (8 preceding siblings ...)
  2022-04-11 17:56 ` [PATCH 10/16] net: dm9000: Drop static device private data Marek Vasut
@ 2022-04-11 17:56 ` Marek Vasut
  2022-04-12 19:49   ` Ramon Fried
  2022-04-11 17:56 ` [PATCH 12/16] net: dm9000: Pass private data around for IO Marek Vasut
                   ` (5 subsequent siblings)
  15 siblings, 1 reply; 32+ messages in thread
From: Marek Vasut @ 2022-04-11 17:56 UTC (permalink / raw)
  To: u-boot; +Cc: marcel.ziswiler, trini, Marek Vasut, Joe Hershberger, Ramon Fried

Dispose of dm9000.h because none of the function prototypes declared in
it are called anywhere in the codebase. Staticize dm9000_read_srom_word()
because it is now called only from within the dm9000 driver. Drop
dm9000_write_srom_word() because it is no longer used.

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Cc: Ramon Fried <rfried.dev@gmail.com>
---
 drivers/net/dm9000x.c | 13 +------------
 include/dm9000.h      | 16 ----------------
 2 files changed, 1 insertion(+), 28 deletions(-)
 delete mode 100644 include/dm9000.h

diff --git a/drivers/net/dm9000x.c b/drivers/net/dm9000x.c
index 666883ee19e..3c0d848b10f 100644
--- a/drivers/net/dm9000x.c
+++ b/drivers/net/dm9000x.c
@@ -53,7 +53,6 @@
 #include <command.h>
 #include <net.h>
 #include <asm/io.h>
-#include <dm9000.h>
 #include <linux/delay.h>
 
 #include "dm9000x.h"
@@ -556,7 +555,7 @@ static int dm9000_rx(struct eth_device *dev)
  * Read a word data from SROM
  */
 #if !defined(CONFIG_DM9000_NO_SROM)
-void dm9000_read_srom_word(int offset, u8 *to)
+static void dm9000_read_srom_word(int offset, u8 *to)
 {
 	dm9000_iow(DM9000_EPAR, offset);
 	dm9000_iow(DM9000_EPCR, 0x4);
@@ -566,16 +565,6 @@ void dm9000_read_srom_word(int offset, u8 *to)
 	to[1] = dm9000_ior(DM9000_EPDRH);
 }
 
-void dm9000_write_srom_word(int offset, u16 val)
-{
-	dm9000_iow(DM9000_EPAR, offset);
-	dm9000_iow(DM9000_EPDRH, ((val >> 8) & 0xff));
-	dm9000_iow(DM9000_EPDRL, (val & 0xff));
-	dm9000_iow(DM9000_EPCR, 0x12);
-	mdelay(8);
-	dm9000_iow(DM9000_EPCR, 0);
-}
-
 static void dm9000_get_enetaddr(struct eth_device *dev)
 {
 	int i;
diff --git a/include/dm9000.h b/include/dm9000.h
deleted file mode 100644
index f780e513f69..00000000000
--- a/include/dm9000.h
+++ /dev/null
@@ -1,16 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0+ */
-/*
- * NOTE:        DAVICOM DM9000 ethernet driver interface
- *
- * Authors:     Remy Bohmer <linux@bohmer.net>
- */
-#ifndef __DM9000_H__
-#define __DM9000_H__
-
-/******************  function prototypes **********************/
-#if !defined(CONFIG_DM9000_NO_SROM)
-void dm9000_write_srom_word(int offset, u16 val);
-void dm9000_read_srom_word(int offset, u8 *to);
-#endif
-
-#endif /* __DM9000_H__ */
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [PATCH 12/16] net: dm9000: Pass private data around for IO
  2022-04-11 17:55 [PATCH 01/16] net: dm9000: Make accessor names lowercase Marek Vasut
                   ` (9 preceding siblings ...)
  2022-04-11 17:56 ` [PATCH 11/16] net: dm9000: Drop dm9000.h and staticize SROM access Marek Vasut
@ 2022-04-11 17:56 ` Marek Vasut
  2022-04-12 19:50   ` Ramon Fried
  2022-04-11 17:56 ` [PATCH 13/16] net: dm9000: Split non-DM specific bits from common code Marek Vasut
                   ` (4 subsequent siblings)
  15 siblings, 1 reply; 32+ messages in thread
From: Marek Vasut @ 2022-04-11 17:56 UTC (permalink / raw)
  To: u-boot; +Cc: marcel.ziswiler, trini, Marek Vasut, Joe Hershberger, Ramon Fried

Pass private data into IO accessors and use the base addresses of
IO and DATA window from the private data instead of using the hard
coded macros DM9000_IO/DM9000_DATA. Currently both the DM9000_IO
and DM9000_DATA are assigned to the respecive private data fields
for the non-DM case backward compatibility.

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Cc: Ramon Fried <rfried.dev@gmail.com>
---
 drivers/net/dm9000x.c | 230 ++++++++++++++++++++++--------------------
 1 file changed, 119 insertions(+), 111 deletions(-)

diff --git a/drivers/net/dm9000x.c b/drivers/net/dm9000x.c
index 3c0d848b10f..54b8f848397 100644
--- a/drivers/net/dm9000x.c
+++ b/drivers/net/dm9000x.c
@@ -70,10 +70,12 @@ struct dm9000_priv {
 	u8 phy_addr;
 	u8 device_wait_reset;	/* device state */
 	unsigned char srom[128];
-	void (*outblk)(void *data_ptr, int count);
-	void (*inblk)(void *data_ptr, int count);
-	void (*rx_status)(u16 *rxstatus, u16 *rxlen);
+	void (*outblk)(struct dm9000_priv *db, void *data_ptr, int count);
+	void (*inblk)(struct dm9000_priv *db, void *data_ptr, int count);
+	void (*rx_status)(struct dm9000_priv *db, u16 *rxstatus, u16 *rxlen);
 	struct eth_device netdev;
+	phys_addr_t base_io;
+	phys_addr_t base_data;
 };
 
 /* DM9000 network board routine ---------------------------- */
@@ -112,120 +114,121 @@ static void dm9000_dump_packet(const char *func, u8 *packet, int length)
 static void dm9000_dump_packet(const char *func, u8 *packet, int length) {}
 #endif
 
-static void dm9000_outblk_8bit(void *data_ptr, int count)
+static void dm9000_outblk_8bit(struct dm9000_priv *db, void *data_ptr, int count)
 {
 	int i;
 
 	for (i = 0; i < count; i++)
-		dm9000_outb((((u8 *)data_ptr)[i] & 0xff), DM9000_DATA);
+		dm9000_outb((((u8 *)data_ptr)[i] & 0xff), db->base_data);
 }
 
-static void dm9000_outblk_16bit(void *data_ptr, int count)
+static void dm9000_outblk_16bit(struct dm9000_priv *db, void *data_ptr, int count)
 {
 	int i;
 	u32 tmplen = (count + 1) / 2;
 
 	for (i = 0; i < tmplen; i++)
-		dm9000_outw(((u16 *)data_ptr)[i], DM9000_DATA);
+		dm9000_outw(((u16 *)data_ptr)[i], db->base_data);
 }
 
-static void dm9000_outblk_32bit(void *data_ptr, int count)
+static void dm9000_outblk_32bit(struct dm9000_priv *db, void *data_ptr, int count)
 {
 	int i;
 	u32 tmplen = (count + 3) / 4;
 
 	for (i = 0; i < tmplen; i++)
-		dm9000_outl(((u32 *)data_ptr)[i], DM9000_DATA);
+		dm9000_outl(((u32 *)data_ptr)[i], db->base_data);
 }
 
-static void dm9000_inblk_8bit(void *data_ptr, int count)
+static void dm9000_inblk_8bit(struct dm9000_priv *db, void *data_ptr, int count)
 {
 	int i;
 
 	for (i = 0; i < count; i++)
-		((u8 *)data_ptr)[i] = dm9000_inb(DM9000_DATA);
+		((u8 *)data_ptr)[i] = dm9000_inb(db->base_data);
 }
 
-static void dm9000_inblk_16bit(void *data_ptr, int count)
+static void dm9000_inblk_16bit(struct dm9000_priv *db, void *data_ptr, int count)
 {
 	int i;
 	u32 tmplen = (count + 1) / 2;
 
 	for (i = 0; i < tmplen; i++)
-		((u16 *)data_ptr)[i] = dm9000_inw(DM9000_DATA);
+		((u16 *)data_ptr)[i] = dm9000_inw(db->base_data);
 }
 
-static void dm9000_inblk_32bit(void *data_ptr, int count)
+static void dm9000_inblk_32bit(struct dm9000_priv *db, void *data_ptr, int count)
 {
 	int i;
 	u32 tmplen = (count + 3) / 4;
 
 	for (i = 0; i < tmplen; i++)
-		((u32 *)data_ptr)[i] = dm9000_inl(DM9000_DATA);
+		((u32 *)data_ptr)[i] = dm9000_inl(db->base_data);
 }
 
-static void dm9000_rx_status_32bit(u16 *rxstatus, u16 *rxlen)
+static void dm9000_rx_status_32bit(struct dm9000_priv *db, u16 *rxstatus, u16 *rxlen)
 {
 	u32 tmpdata;
 
-	dm9000_outb(DM9000_MRCMD, DM9000_IO);
+	dm9000_outb(DM9000_MRCMD, db->base_io);
 
-	tmpdata = dm9000_inl(DM9000_DATA);
+	tmpdata = dm9000_inl(db->base_data);
 	*rxstatus = __le16_to_cpu(tmpdata);
 	*rxlen = __le16_to_cpu(tmpdata >> 16);
 }
 
-static void dm9000_rx_status_16bit(u16 *rxstatus, u16 *rxlen)
+static void dm9000_rx_status_16bit(struct dm9000_priv *db, u16 *rxstatus, u16 *rxlen)
 {
-	dm9000_outb(DM9000_MRCMD, DM9000_IO);
+	dm9000_outb(DM9000_MRCMD, db->base_io);
 
-	*rxstatus = __le16_to_cpu(dm9000_inw(DM9000_DATA));
-	*rxlen = __le16_to_cpu(dm9000_inw(DM9000_DATA));
+	*rxstatus = __le16_to_cpu(dm9000_inw(db->base_data));
+	*rxlen = __le16_to_cpu(dm9000_inw(db->base_data));
 }
 
-static void dm9000_rx_status_8bit(u16 *rxstatus, u16 *rxlen)
+static void dm9000_rx_status_8bit(struct dm9000_priv *db, u16 *rxstatus, u16 *rxlen)
 {
-	dm9000_outb(DM9000_MRCMD, DM9000_IO);
+	dm9000_outb(DM9000_MRCMD, db->base_io);
 
 	*rxstatus =
-	    __le16_to_cpu(dm9000_inb(DM9000_DATA) +
-			  (dm9000_inb(DM9000_DATA) << 8));
+	    __le16_to_cpu(dm9000_inb(db->base_data) +
+			  (dm9000_inb(db->base_data) << 8));
 	*rxlen =
-	    __le16_to_cpu(dm9000_inb(DM9000_DATA) +
-			  (dm9000_inb(DM9000_DATA) << 8));
+	    __le16_to_cpu(dm9000_inb(db->base_data) +
+			  (dm9000_inb(db->base_data) << 8));
 }
 
 /*
  *  Read a byte from I/O port
  */
-static u8 dm9000_ior(int reg)
+static u8 dm9000_ior(struct dm9000_priv *db, int reg)
 {
-	dm9000_outb(reg, DM9000_IO);
-	return dm9000_inb(DM9000_DATA);
+	dm9000_outb(reg, db->base_io);
+	return dm9000_inb(db->base_data);
 }
 
 /*
  *  Write a byte to I/O port
  */
-static void dm9000_iow(int reg, u8 value)
+static void dm9000_iow(struct dm9000_priv *db, int reg, u8 value)
 {
-	dm9000_outb(reg, DM9000_IO);
-	dm9000_outb(value, DM9000_DATA);
+	dm9000_outb(reg, db->base_io);
+	dm9000_outb(value, db->base_data);
 }
 
 /*
  *  Read a word from phyxcer
  */
-static u16 dm9000_phy_read(int reg)
+static u16 dm9000_phy_read(struct dm9000_priv *db, int reg)
 {
 	u16 val;
 
 	/* Fill the phyxcer register into REG_0C */
-	dm9000_iow(DM9000_EPAR, DM9000_PHY | reg);
-	dm9000_iow(DM9000_EPCR, 0xc);	/* Issue phyxcer read command */
+	dm9000_iow(db, DM9000_EPAR, DM9000_PHY | reg);
+	dm9000_iow(db, DM9000_EPCR, 0xc);	/* Issue phyxcer read command */
 	udelay(100);			/* Wait read complete */
-	dm9000_iow(DM9000_EPCR, 0x0);	/* Clear phyxcer read command */
-	val = (dm9000_ior(DM9000_EPDRH) << 8) | dm9000_ior(DM9000_EPDRL);
+	dm9000_iow(db, DM9000_EPCR, 0x0);	/* Clear phyxcer read command */
+	val = (dm9000_ior(db, DM9000_EPDRH) << 8) |
+	      dm9000_ior(db, DM9000_EPDRL);
 
 	/* The read data keeps on REG_0D & REG_0E */
 	debug("%s(0x%x): 0x%x\n", __func__, reg, val);
@@ -235,44 +238,43 @@ static u16 dm9000_phy_read(int reg)
 /*
  *  Write a word to phyxcer
  */
-static void dm9000_phy_write(int reg, u16 value)
+static void dm9000_phy_write(struct dm9000_priv *db, int reg, u16 value)
 {
 	/* Fill the phyxcer register into REG_0C */
-	dm9000_iow(DM9000_EPAR, DM9000_PHY | reg);
+	dm9000_iow(db, DM9000_EPAR, DM9000_PHY | reg);
 
 	/* Fill the written data into REG_0D & REG_0E */
-	dm9000_iow(DM9000_EPDRL, (value & 0xff));
-	dm9000_iow(DM9000_EPDRH, ((value >> 8) & 0xff));
-	dm9000_iow(DM9000_EPCR, 0xa);	/* Issue phyxcer write command */
+	dm9000_iow(db, DM9000_EPDRL, (value & 0xff));
+	dm9000_iow(db, DM9000_EPDRH, ((value >> 8) & 0xff));
+	dm9000_iow(db, DM9000_EPCR, 0xa);	/* Issue phyxcer write command */
 	udelay(500);			/* Wait write complete */
-	dm9000_iow(DM9000_EPCR, 0x0);	/* Clear phyxcer write command */
+	dm9000_iow(db, DM9000_EPCR, 0x0);	/* Clear phyxcer write command */
 	debug("%s(reg:0x%x, value:0x%x)\n", __func__, reg, value);
 }
 
 /*
  * Search DM9000 board, allocate space and register it
  */
-static int dm9000_probe(void)
+static int dm9000_probe(struct dm9000_priv *db)
 {
 	u32 id_val;
 
-	id_val = dm9000_ior(DM9000_VIDL);
-	id_val |= dm9000_ior(DM9000_VIDH) << 8;
-	id_val |= dm9000_ior(DM9000_PIDL) << 16;
-	id_val |= dm9000_ior(DM9000_PIDH) << 24;
+	id_val = dm9000_ior(db, DM9000_VIDL);
+	id_val |= dm9000_ior(db, DM9000_VIDH) << 8;
+	id_val |= dm9000_ior(db, DM9000_PIDL) << 16;
+	id_val |= dm9000_ior(db, DM9000_PIDH) << 24;
 	if (id_val != DM9000_ID) {
-		printf("dm9000 not found at 0x%08x id: 0x%08x\n",
-		       CONFIG_DM9000_BASE, id_val);
+		printf("dm9000 not found at 0x%08lx id: 0x%08x\n",
+		       db->base_io, id_val);
 		return -1;
 	}
 
-	printf("dm9000 i/o: 0x%x, id: 0x%x\n", CONFIG_DM9000_BASE, id_val);
+	printf("dm9000 i/o: 0x%lx, id: 0x%x\n", db->base_io, id_val);
 	return 0;
 }
 
 /* General Purpose dm9000 reset routine */
-static void
-dm9000_reset(void)
+static void dm9000_reset(struct dm9000_priv *db)
 {
 	debug("resetting DM9000\n");
 
@@ -282,28 +284,28 @@ dm9000_reset(void)
 	 */
 
 	/* DEBUG: Make all GPIO0 outputs, all others inputs */
-	dm9000_iow(DM9000_GPCR, GPCR_GPIO0_OUT);
+	dm9000_iow(db, DM9000_GPCR, GPCR_GPIO0_OUT);
 	/* Step 1: Power internal PHY by writing 0 to GPIO0 pin */
-	dm9000_iow(DM9000_GPR, 0);
+	dm9000_iow(db, DM9000_GPR, 0);
 	/* Step 2: Software reset */
-	dm9000_iow(DM9000_NCR, (NCR_LBK_INT_MAC | NCR_RST));
+	dm9000_iow(db, DM9000_NCR, (NCR_LBK_INT_MAC | NCR_RST));
 
 	do {
 		debug("resetting the DM9000, 1st reset\n");
 		udelay(25); /* Wait at least 20 us */
-	} while (dm9000_ior(DM9000_NCR) & 1);
+	} while (dm9000_ior(db, DM9000_NCR) & 1);
 
-	dm9000_iow(DM9000_NCR, 0);
-	dm9000_iow(DM9000_NCR, (NCR_LBK_INT_MAC | NCR_RST)); /* Issue a second reset */
+	dm9000_iow(db, DM9000_NCR, 0);
+	dm9000_iow(db, DM9000_NCR, (NCR_LBK_INT_MAC | NCR_RST)); /* Issue a second reset */
 
 	do {
 		debug("resetting the DM9000, 2nd reset\n");
 		udelay(25); /* Wait at least 20 us */
-	} while (dm9000_ior(DM9000_NCR) & 1);
+	} while (dm9000_ior(db, DM9000_NCR) & 1);
 
 	/* Check whether the ethernet controller is present */
-	if ((dm9000_ior(DM9000_PIDL) != 0x0) ||
-	    (dm9000_ior(DM9000_PIDH) != 0x90))
+	if ((dm9000_ior(db, DM9000_PIDL) != 0x0) ||
+	    (dm9000_ior(db, DM9000_PIDH) != 0x90))
 		printf("ERROR: resetting DM9000 -> not responding\n");
 }
 
@@ -315,13 +317,13 @@ static int dm9000_init(struct eth_device *dev, struct bd_info *bd)
 	u8 io_mode;
 
 	/* RESET device */
-	dm9000_reset();
+	dm9000_reset(db);
 
-	if (dm9000_probe() < 0)
+	if (dm9000_probe(db) < 0)
 		return -1;
 
 	/* Auto-detect 8/16/32 bit mode, ISR Bit 6+7 indicate bus width */
-	io_mode = dm9000_ior(DM9000_ISR) >> 6;
+	io_mode = dm9000_ior(db, DM9000_ISR) >> 6;
 
 	switch (io_mode) {
 	case 0x0:  /* 16-bit mode */
@@ -352,21 +354,21 @@ static int dm9000_init(struct eth_device *dev, struct bd_info *bd)
 	}
 
 	/* Program operating register, only internal phy supported */
-	dm9000_iow(DM9000_NCR, 0x0);
+	dm9000_iow(db, DM9000_NCR, 0x0);
 	/* TX Polling clear */
-	dm9000_iow(DM9000_TCR, 0);
+	dm9000_iow(db, DM9000_TCR, 0);
 	/* Less 3Kb, 200us */
-	dm9000_iow(DM9000_BPTR, BPTR_BPHW(3) | BPTR_JPT_600US);
+	dm9000_iow(db, DM9000_BPTR, BPTR_BPHW(3) | BPTR_JPT_600US);
 	/* Flow Control : High/Low Water */
-	dm9000_iow(DM9000_FCTR, FCTR_HWOT(3) | FCTR_LWOT(8));
+	dm9000_iow(db, DM9000_FCTR, FCTR_HWOT(3) | FCTR_LWOT(8));
 	/* SH FIXME: This looks strange! Flow Control */
-	dm9000_iow(DM9000_FCR, 0x0);
+	dm9000_iow(db, DM9000_FCR, 0x0);
 	/* Special Mode */
-	dm9000_iow(DM9000_SMCR, 0);
+	dm9000_iow(db, DM9000_SMCR, 0);
 	/* clear TX status */
-	dm9000_iow(DM9000_NSR, NSR_WAKEST | NSR_TX2END | NSR_TX1END);
+	dm9000_iow(db, DM9000_NSR, NSR_WAKEST | NSR_TX2END | NSR_TX1END);
 	/* Clear interrupt status */
-	dm9000_iow(DM9000_ISR, ISR_ROOS | ISR_ROS | ISR_PTS | ISR_PRS);
+	dm9000_iow(db, DM9000_ISR, ISR_ROOS | ISR_ROS | ISR_PTS | ISR_PRS);
 
 	printf("MAC: %pM\n", dev->enetaddr);
 	if (!is_valid_ethaddr(dev->enetaddr))
@@ -374,23 +376,23 @@ static int dm9000_init(struct eth_device *dev, struct bd_info *bd)
 
 	/* fill device MAC address registers */
 	for (i = 0, oft = DM9000_PAR; i < 6; i++, oft++)
-		dm9000_iow(oft, dev->enetaddr[i]);
+		dm9000_iow(db, oft, dev->enetaddr[i]);
 	for (i = 0, oft = 0x16; i < 8; i++, oft++)
-		dm9000_iow(oft, 0xff);
+		dm9000_iow(db, oft, 0xff);
 
 	/* read back mac, just to be sure */
 	for (i = 0, oft = 0x10; i < 6; i++, oft++)
-		debug("%02x:", dm9000_ior(oft));
+		debug("%02x:", dm9000_ior(db, oft));
 	debug("\n");
 
 	/* Activate DM9000 */
 	/* RX enable */
-	dm9000_iow(DM9000_RCR, RCR_DIS_LONG | RCR_DIS_CRC | RCR_RXEN);
+	dm9000_iow(db, DM9000_RCR, RCR_DIS_LONG | RCR_DIS_CRC | RCR_RXEN);
 	/* Enable TX/RX interrupt mask */
-	dm9000_iow(DM9000_IMR, IMR_PAR);
+	dm9000_iow(db, DM9000_IMR, IMR_PAR);
 
 	i = 0;
-	while (!(dm9000_phy_read(1) & 0x20)) {	/* autonegation complete bit */
+	while (!(dm9000_phy_read(db, 1) & 0x20)) {	/* autonegation complete bit */
 		udelay(1000);
 		i++;
 		if (i == 10000) {
@@ -400,7 +402,7 @@ static int dm9000_init(struct eth_device *dev, struct bd_info *bd)
 	}
 
 	/* see what we've got */
-	lnk = dm9000_phy_read(17) >> 12;
+	lnk = dm9000_phy_read(db, 17) >> 12;
 	printf("operating at ");
 	switch (lnk) {
 	case 1:
@@ -434,31 +436,31 @@ static int dm9000_send(struct eth_device *dev, void *packet, int length)
 
 	dm9000_dump_packet(__func__, packet, length);
 
-	dm9000_iow(DM9000_ISR, IMR_PTM); /* Clear Tx bit in ISR */
+	dm9000_iow(db, DM9000_ISR, IMR_PTM); /* Clear Tx bit in ISR */
 
 	/* Move data to DM9000 TX RAM */
-	dm9000_outb(DM9000_MWCMD, DM9000_IO); /* Prepare for TX-data */
+	dm9000_outb(DM9000_MWCMD, db->base_io); /* Prepare for TX-data */
 
 	/* push the data to the TX-fifo */
-	db->outblk(packet, length);
+	db->outblk(db, packet, length);
 
 	/* Set TX length to DM9000 */
-	dm9000_iow(DM9000_TXPLL, length & 0xff);
-	dm9000_iow(DM9000_TXPLH, (length >> 8) & 0xff);
+	dm9000_iow(db, DM9000_TXPLL, length & 0xff);
+	dm9000_iow(db, DM9000_TXPLH, (length >> 8) & 0xff);
 
 	/* Issue TX polling command */
-	dm9000_iow(DM9000_TCR, TCR_TXREQ); /* Cleared after TX complete */
+	dm9000_iow(db, DM9000_TCR, TCR_TXREQ); /* Cleared after TX complete */
 
 	/* wait for end of transmission */
 	tmo = get_timer(0) + 5 * CONFIG_SYS_HZ;
-	while (!(dm9000_ior(DM9000_NSR) & (NSR_TX1END | NSR_TX2END)) ||
-	       !(dm9000_ior(DM9000_ISR) & IMR_PTM)) {
+	while (!(dm9000_ior(db, DM9000_NSR) & (NSR_TX1END | NSR_TX2END)) ||
+	       !(dm9000_ior(db, DM9000_ISR) & IMR_PTM)) {
 		if (get_timer(0) >= tmo) {
 			printf("transmission timeout\n");
 			break;
 		}
 	}
-	dm9000_iow(DM9000_ISR, IMR_PTM); /* Clear Tx bit in ISR */
+	dm9000_iow(db, DM9000_ISR, IMR_PTM); /* Clear Tx bit in ISR */
 
 	debug("transmit done\n\n");
 	return 0;
@@ -470,11 +472,13 @@ static int dm9000_send(struct eth_device *dev, void *packet, int length)
  */
 static void dm9000_halt(struct eth_device *netdev)
 {
+	struct dm9000_priv *db = container_of(dev, struct dm9000_priv, dev);
+
 	/* RESET device */
-	dm9000_phy_write(0, 0x8000);	/* PHY RESET */
-	dm9000_iow(DM9000_GPR, 0x01);	/* Power-Down PHY */
-	dm9000_iow(DM9000_IMR, 0x80);	/* Disable all interrupt */
-	dm9000_iow(DM9000_RCR, 0x00);	/* Disable RX */
+	dm9000_phy_write(db, 0, 0x8000);	/* PHY RESET */
+	dm9000_iow(db, DM9000_GPR, 0x01);	/* Power-Down PHY */
+	dm9000_iow(db, DM9000_IMR, 0x80);	/* Disable all interrupt */
+	dm9000_iow(db, DM9000_RCR, 0x00);	/* Disable RX */
 }
 
 /*
@@ -491,25 +495,25 @@ static int dm9000_rx(struct eth_device *dev)
 	 * Check packet ready or not, we must check
 	 * the ISR status first for DM9000A
 	 */
-	if (!(dm9000_ior(DM9000_ISR) & 0x01)) /* Rx-ISR bit must be set. */
+	if (!(dm9000_ior(db, DM9000_ISR) & 0x01)) /* Rx-ISR bit must be set. */
 		return 0;
 
-	dm9000_iow(DM9000_ISR, 0x01); /* clear PR status latched in bit 0 */
+	dm9000_iow(db, DM9000_ISR, 0x01); /* clear PR status latched in bit 0 */
 
 	/* There is _at least_ 1 package in the fifo, read them all */
 	for (;;) {
-		dm9000_ior(DM9000_MRCMDX);	/* Dummy read */
+		dm9000_ior(db, DM9000_MRCMDX);	/* Dummy read */
 
 		/*
 		 * Get most updated data,
 		 * only look at bits 0:1, See application notes DM9000
 		 */
-		rxbyte = dm9000_inb(DM9000_DATA) & 0x03;
+		rxbyte = dm9000_inb(db->base_data) & 0x03;
 
 		/* Status check: this byte must be 0 or 1 */
 		if (rxbyte > DM9000_PKT_RDY) {
-			dm9000_iow(DM9000_RCR, 0x00);	/* Stop Device */
-			dm9000_iow(DM9000_ISR, 0x80);	/* Stop INT request */
+			dm9000_iow(db, DM9000_RCR, 0x00);	/* Stop Device */
+			dm9000_iow(db, DM9000_ISR, 0x80);	/* Stop INT request */
 			printf("DM9000 error: status check fail: 0x%x\n",
 			       rxbyte);
 			return 0;
@@ -521,13 +525,13 @@ static int dm9000_rx(struct eth_device *dev)
 		debug("receiving packet\n");
 
 		/* A packet ready now  & Get status/length */
-		db->rx_status(&rxstatus, &rxlen);
+		db->rx_status(db, &rxstatus, &rxlen);
 
 		debug("rx status: 0x%04x rx len: %d\n", rxstatus, rxlen);
 
 		/* Move data from DM9000 */
 		/* Read received packet from RX SRAM */
-		db->inblk(rdptr, rxlen);
+		db->inblk(db, rdptr, rxlen);
 
 		if (rxstatus & 0xbf00 || rxlen < 0x40 ||
 		    rxlen > DM9000_PKT_MAX) {
@@ -539,7 +543,7 @@ static int dm9000_rx(struct eth_device *dev)
 				printf("rx length error\n");
 			if (rxlen > DM9000_PKT_MAX) {
 				printf("rx length too big\n");
-				dm9000_reset();
+				dm9000_reset(db);
 			}
 		} else {
 			dm9000_dump_packet(__func__, rdptr, rxlen);
@@ -555,22 +559,23 @@ static int dm9000_rx(struct eth_device *dev)
  * Read a word data from SROM
  */
 #if !defined(CONFIG_DM9000_NO_SROM)
-static void dm9000_read_srom_word(int offset, u8 *to)
+static void dm9000_read_srom_word(struct dm9000_priv *db, int offset, u8 *to)
 {
-	dm9000_iow(DM9000_EPAR, offset);
-	dm9000_iow(DM9000_EPCR, 0x4);
+	dm9000_iow(db, DM9000_EPAR, offset);
+	dm9000_iow(db, DM9000_EPCR, 0x4);
 	mdelay(8);
-	dm9000_iow(DM9000_EPCR, 0x0);
-	to[0] = dm9000_ior(DM9000_EPDRL);
-	to[1] = dm9000_ior(DM9000_EPDRH);
+	dm9000_iow(db, DM9000_EPCR, 0x0);
+	to[0] = dm9000_ior(db, DM9000_EPDRL);
+	to[1] = dm9000_ior(db, DM9000_EPDRH);
 }
 
 static void dm9000_get_enetaddr(struct eth_device *dev)
 {
+	struct dm9000_priv *db = container_of(dev, struct dm9000_priv, dev);
 	int i;
 
 	for (i = 0; i < 3; i++)
-		dm9000_read_srom_word(i, dev->enetaddr + (2 * i));
+		dm9000_read_srom_word(db, i, dev->enetaddr + (2 * i));
 }
 #else
 static void dm9000_get_enetaddr(struct eth_device *dev) {}
@@ -584,6 +589,9 @@ int dm9000_initialize(struct bd_info *bis)
 	if (!priv)
 		return -ENOMEM;
 
+	priv->base_io = DM9000_IO;
+	priv->base_data = DM9000_DATA;
+
 	/* Load MAC address from EEPROM */
 	dm9000_get_enetaddr(&priv->dev);
 
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [PATCH 13/16] net: dm9000: Split non-DM specific bits from common code
  2022-04-11 17:55 [PATCH 01/16] net: dm9000: Make accessor names lowercase Marek Vasut
                   ` (10 preceding siblings ...)
  2022-04-11 17:56 ` [PATCH 12/16] net: dm9000: Pass private data around for IO Marek Vasut
@ 2022-04-11 17:56 ` Marek Vasut
  2022-04-12 19:51   ` Ramon Fried
  2022-04-11 17:56 ` [PATCH 14/16] net: dm9000: Receive one packet per recv call Marek Vasut
                   ` (3 subsequent siblings)
  15 siblings, 1 reply; 32+ messages in thread
From: Marek Vasut @ 2022-04-11 17:56 UTC (permalink / raw)
  To: u-boot; +Cc: marcel.ziswiler, trini, Marek Vasut, Joe Hershberger, Ramon Fried

Split network handling functions into non-DM specific parts and
common code in preparation for conversion to DM.

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Cc: Ramon Fried <rfried.dev@gmail.com>
---
 drivers/net/dm9000x.c | 58 +++++++++++++++++++++++++++++--------------
 1 file changed, 40 insertions(+), 18 deletions(-)

diff --git a/drivers/net/dm9000x.c b/drivers/net/dm9000x.c
index 54b8f848397..97084d16ffa 100644
--- a/drivers/net/dm9000x.c
+++ b/drivers/net/dm9000x.c
@@ -310,9 +310,8 @@ static void dm9000_reset(struct dm9000_priv *db)
 }
 
 /* Initialize dm9000 board */
-static int dm9000_init(struct eth_device *dev, struct bd_info *bd)
+static int dm9000_init_common(struct dm9000_priv *db, u8 enetaddr[6])
 {
-	struct dm9000_priv *db = container_of(dev, struct dm9000_priv, dev);
 	int i, oft, lnk;
 	u8 io_mode;
 
@@ -370,13 +369,13 @@ static int dm9000_init(struct eth_device *dev, struct bd_info *bd)
 	/* Clear interrupt status */
 	dm9000_iow(db, DM9000_ISR, ISR_ROOS | ISR_ROS | ISR_PTS | ISR_PRS);
 
-	printf("MAC: %pM\n", dev->enetaddr);
-	if (!is_valid_ethaddr(dev->enetaddr))
+	printf("MAC: %pM\n", enetaddr);
+	if (!is_valid_ethaddr(enetaddr))
 		printf("WARNING: Bad MAC address (uninitialized EEPROM?)\n");
 
 	/* fill device MAC address registers */
 	for (i = 0, oft = DM9000_PAR; i < 6; i++, oft++)
-		dm9000_iow(db, oft, dev->enetaddr[i]);
+		dm9000_iow(db, oft, enetaddr[i]);
 	for (i = 0, oft = 0x16; i < 8; i++, oft++)
 		dm9000_iow(db, oft, 0xff);
 
@@ -429,9 +428,8 @@ static int dm9000_init(struct eth_device *dev, struct bd_info *bd)
  * Hardware start transmission.
  * Send a packet to media from the upper layer.
  */
-static int dm9000_send(struct eth_device *dev, void *packet, int length)
+static int dm9000_send_common(struct dm9000_priv *db, void *packet, int length)
 {
-	struct dm9000_priv *db = container_of(dev, struct dm9000_priv, dev);
 	int tmo;
 
 	dm9000_dump_packet(__func__, packet, length);
@@ -470,10 +468,8 @@ static int dm9000_send(struct eth_device *dev, void *packet, int length)
  * Stop the interface.
  * The interface is stopped when it is brought.
  */
-static void dm9000_halt(struct eth_device *netdev)
+static void dm9000_halt_common(struct dm9000_priv *db)
 {
-	struct dm9000_priv *db = container_of(dev, struct dm9000_priv, dev);
-
 	/* RESET device */
 	dm9000_phy_write(db, 0, 0x8000);	/* PHY RESET */
 	dm9000_iow(db, DM9000_GPR, 0x01);	/* Power-Down PHY */
@@ -484,9 +480,8 @@ static void dm9000_halt(struct eth_device *netdev)
 /*
  * Received a packet and pass to upper layer
  */
-static int dm9000_rx(struct eth_device *dev)
+static int dm9000_recv_common(struct dm9000_priv *db)
 {
-	struct dm9000_priv *db = container_of(dev, struct dm9000_priv, dev);
 	u8 rxbyte;
 	u8 *rdptr = (u8 *)net_rx_packets[0];
 	u16 rxstatus, rxlen = 0;
@@ -569,18 +564,45 @@ static void dm9000_read_srom_word(struct dm9000_priv *db, int offset, u8 *to)
 	to[1] = dm9000_ior(db, DM9000_EPDRH);
 }
 
-static void dm9000_get_enetaddr(struct eth_device *dev)
+static void dm9000_get_enetaddr(struct dm9000_priv *db, u8 *enetaddr)
 {
-	struct dm9000_priv *db = container_of(dev, struct dm9000_priv, dev);
 	int i;
 
 	for (i = 0; i < 3; i++)
-		dm9000_read_srom_word(db, i, dev->enetaddr + (2 * i));
+		dm9000_read_srom_word(db, i, enetaddr + (2 * i));
 }
 #else
-static void dm9000_get_enetaddr(struct eth_device *dev) {}
+static void dm9000_get_enetaddr(struct dm9000_priv *db, u8 *enetaddr) {}
 #endif
 
+static int dm9000_init(struct eth_device *dev, struct bd_info *bd)
+{
+	struct dm9000_priv *db = container_of(dev, struct dm9000_priv, dev);
+
+	return dm9000_init_common(db, dev->enetaddr);
+}
+
+static int dm9000_halt(struct eth_device *dev, struct bd_info *bd)
+{
+	struct dm9000_priv *db = container_of(dev, struct dm9000_priv, dev);
+
+	return dm9000_halt_common(db);
+}
+
+static int dm9000_send(struct eth_device *dev, void *packet, int length)
+{
+	struct dm9000_priv *db = container_of(dev, struct dm9000_priv, dev);
+
+	return dm9000_send_common(db, packet, length);
+}
+
+static int dm9000_recv(struct eth_device *dev)
+{
+	struct dm9000_priv *db = container_of(dev, struct dm9000_priv, dev);
+
+	return dm9000_recv_common(db);
+}
+
 int dm9000_initialize(struct bd_info *bis)
 {
 	struct dm9000_priv *priv;
@@ -593,12 +615,12 @@ int dm9000_initialize(struct bd_info *bis)
 	priv->base_data = DM9000_DATA;
 
 	/* Load MAC address from EEPROM */
-	dm9000_get_enetaddr(&priv->dev);
+	dm9000_get_enetaddr(priv, dev->enetaddr);
 
 	dev->init = dm9000_init;
 	dev->halt = dm9000_halt;
 	dev->send = dm9000_send;
-	dev->recv = dm9000_rx;
+	dev->recv = dm9000_recv;
 	strcpy(&priv->dev.name, "dm9000");
 
 	eth_register(&priv->dev);
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [PATCH 14/16] net: dm9000: Receive one packet per recv call
  2022-04-11 17:55 [PATCH 01/16] net: dm9000: Make accessor names lowercase Marek Vasut
                   ` (11 preceding siblings ...)
  2022-04-11 17:56 ` [PATCH 13/16] net: dm9000: Split non-DM specific bits from common code Marek Vasut
@ 2022-04-11 17:56 ` Marek Vasut
  2022-04-12 19:51   ` Ramon Fried
  2022-04-11 17:56 ` [PATCH 15/16] net: dm9000: Add DM support Marek Vasut
                   ` (2 subsequent siblings)
  15 siblings, 1 reply; 32+ messages in thread
From: Marek Vasut @ 2022-04-11 17:56 UTC (permalink / raw)
  To: u-boot; +Cc: marcel.ziswiler, trini, Marek Vasut, Joe Hershberger, Ramon Fried

Instead of reading out the entire FIFO and possibly overwriting U-Boot
memory, read out one packet per recv call, pass it to U-Boot network
stack, and repeat.

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Cc: Ramon Fried <rfried.dev@gmail.com>
---
 drivers/net/dm9000x.c | 102 +++++++++++++++++++++---------------------
 1 file changed, 50 insertions(+), 52 deletions(-)

diff --git a/drivers/net/dm9000x.c b/drivers/net/dm9000x.c
index 97084d16ffa..84b012ec65d 100644
--- a/drivers/net/dm9000x.c
+++ b/drivers/net/dm9000x.c
@@ -480,10 +480,9 @@ static void dm9000_halt_common(struct dm9000_priv *db)
 /*
  * Received a packet and pass to upper layer
  */
-static int dm9000_recv_common(struct dm9000_priv *db)
+static int dm9000_recv_common(struct dm9000_priv *db, uchar *rdptr)
 {
 	u8 rxbyte;
-	u8 *rdptr = (u8 *)net_rx_packets[0];
 	u16 rxstatus, rxlen = 0;
 
 	/*
@@ -496,58 +495,52 @@ static int dm9000_recv_common(struct dm9000_priv *db)
 	dm9000_iow(db, DM9000_ISR, 0x01); /* clear PR status latched in bit 0 */
 
 	/* There is _at least_ 1 package in the fifo, read them all */
-	for (;;) {
-		dm9000_ior(db, DM9000_MRCMDX);	/* Dummy read */
-
-		/*
-		 * Get most updated data,
-		 * only look at bits 0:1, See application notes DM9000
-		 */
-		rxbyte = dm9000_inb(db->base_data) & 0x03;
-
-		/* Status check: this byte must be 0 or 1 */
-		if (rxbyte > DM9000_PKT_RDY) {
-			dm9000_iow(db, DM9000_RCR, 0x00);	/* Stop Device */
-			dm9000_iow(db, DM9000_ISR, 0x80);	/* Stop INT request */
-			printf("DM9000 error: status check fail: 0x%x\n",
-			       rxbyte);
-			return 0;
-		}
+	dm9000_ior(db, DM9000_MRCMDX);	/* Dummy read */
+
+	/*
+	 * Get most updated data,
+	 * only look at bits 0:1, See application notes DM9000
+	 */
+	rxbyte = dm9000_inb(db->base_data) & 0x03;
+
+	/* Status check: this byte must be 0 or 1 */
+	if (rxbyte > DM9000_PKT_RDY) {
+		dm9000_iow(db, DM9000_RCR, 0x00);	/* Stop Device */
+		dm9000_iow(db, DM9000_ISR, 0x80);	/* Stop INT request */
+		printf("DM9000 error: status check fail: 0x%x\n",
+		       rxbyte);
+		return -EINVAL;
+	}
+
+	if (rxbyte != DM9000_PKT_RDY)
+		return 0; /* No packet received, ignore */
 
-		if (rxbyte != DM9000_PKT_RDY)
-			return 0; /* No packet received, ignore */
-
-		debug("receiving packet\n");
-
-		/* A packet ready now  & Get status/length */
-		db->rx_status(db, &rxstatus, &rxlen);
-
-		debug("rx status: 0x%04x rx len: %d\n", rxstatus, rxlen);
-
-		/* Move data from DM9000 */
-		/* Read received packet from RX SRAM */
-		db->inblk(db, rdptr, rxlen);
-
-		if (rxstatus & 0xbf00 || rxlen < 0x40 ||
-		    rxlen > DM9000_PKT_MAX) {
-			if (rxstatus & 0x100)
-				printf("rx fifo error\n");
-			if (rxstatus & 0x200)
-				printf("rx crc error\n");
-			if (rxstatus & 0x8000)
-				printf("rx length error\n");
-			if (rxlen > DM9000_PKT_MAX) {
-				printf("rx length too big\n");
-				dm9000_reset(db);
-			}
-		} else {
-			dm9000_dump_packet(__func__, rdptr, rxlen);
-
-			debug("passing packet to upper layer\n");
-			net_process_received_packet(net_rx_packets[0], rxlen);
+	debug("receiving packet\n");
+
+	/* A packet ready now  & Get status/length */
+	db->rx_status(db, &rxstatus, &rxlen);
+
+	debug("rx status: 0x%04x rx len: %d\n", rxstatus, rxlen);
+
+	/* Move data from DM9000 */
+	/* Read received packet from RX SRAM */
+	db->inblk(db, rdptr, rxlen);
+
+	if (rxstatus & 0xbf00 || rxlen < 0x40 || rxlen > DM9000_PKT_MAX) {
+		if (rxstatus & 0x100)
+			printf("rx fifo error\n");
+		if (rxstatus & 0x200)
+			printf("rx crc error\n");
+		if (rxstatus & 0x8000)
+			printf("rx length error\n");
+		if (rxlen > DM9000_PKT_MAX) {
+			printf("rx length too big\n");
+			dm9000_reset(db);
 		}
+		return -EINVAL;
 	}
-	return 0;
+
+	return rxlen;
 }
 
 /*
@@ -599,8 +592,13 @@ static int dm9000_send(struct eth_device *dev, void *packet, int length)
 static int dm9000_recv(struct eth_device *dev)
 {
 	struct dm9000_priv *db = container_of(dev, struct dm9000_priv, dev);
+	int ret;
+
+	ret = dm9000_recv_common(db, net_rx_packets[0]);
+	if (ret > 0)
+		net_process_received_packet(net_rx_packets[0], ret);
 
-	return dm9000_recv_common(db);
+	return ret;
 }
 
 int dm9000_initialize(struct bd_info *bis)
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [PATCH 15/16] net: dm9000: Add DM support
  2022-04-11 17:55 [PATCH 01/16] net: dm9000: Make accessor names lowercase Marek Vasut
                   ` (12 preceding siblings ...)
  2022-04-11 17:56 ` [PATCH 14/16] net: dm9000: Receive one packet per recv call Marek Vasut
@ 2022-04-11 17:56 ` Marek Vasut
  2022-04-12 19:51   ` Ramon Fried
  2022-04-11 17:56 ` [PATCH 16/16] net: dm9000: Add Kconfig entry Marek Vasut
  2022-04-12 19:46 ` [PATCH 01/16] net: dm9000: Make accessor names lowercase Ramon Fried
  15 siblings, 1 reply; 32+ messages in thread
From: Marek Vasut @ 2022-04-11 17:56 UTC (permalink / raw)
  To: u-boot; +Cc: marcel.ziswiler, trini, Marek Vasut, Joe Hershberger, Ramon Fried

Add support for U-Boot DM and DT probing.

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Cc: Ramon Fried <rfried.dev@gmail.com>
---
 drivers/net/dm9000x.c | 118 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 118 insertions(+)

diff --git a/drivers/net/dm9000x.c b/drivers/net/dm9000x.c
index 84b012ec65d..d63a7c442c9 100644
--- a/drivers/net/dm9000x.c
+++ b/drivers/net/dm9000x.c
@@ -51,6 +51,7 @@
 
 #include <common.h>
 #include <command.h>
+#include <dm.h>
 #include <net.h>
 #include <asm/io.h>
 #include <linux/delay.h>
@@ -73,7 +74,9 @@ struct dm9000_priv {
 	void (*outblk)(struct dm9000_priv *db, void *data_ptr, int count);
 	void (*inblk)(struct dm9000_priv *db, void *data_ptr, int count);
 	void (*rx_status)(struct dm9000_priv *db, u16 *rxstatus, u16 *rxlen);
+#ifndef CONFIG_DM_ETH
 	struct eth_device netdev;
+#endif
 	phys_addr_t base_io;
 	phys_addr_t base_data;
 };
@@ -568,6 +571,7 @@ static void dm9000_get_enetaddr(struct dm9000_priv *db, u8 *enetaddr)
 static void dm9000_get_enetaddr(struct dm9000_priv *db, u8 *enetaddr) {}
 #endif
 
+#ifndef CONFIG_DM_ETH
 static int dm9000_init(struct eth_device *dev, struct bd_info *bd)
 {
 	struct dm9000_priv *db = container_of(dev, struct dm9000_priv, dev);
@@ -625,3 +629,117 @@ int dm9000_initialize(struct bd_info *bis)
 
 	return 0;
 }
+#else	/* ifdef CONFIG_DM_ETH */
+static int dm9000_start(struct udevice *dev)
+{
+	struct dm9000_priv *db = dev_get_priv(dev);
+	struct eth_pdata *pdata = dev_get_plat(dev);
+
+	return dm9000_init_common(db, pdata->enetaddr);
+}
+
+static void dm9000_stop(struct udevice *dev)
+{
+	struct dm9000_priv *db = dev_get_priv(dev);
+
+	dm9000_halt_common(db);
+}
+
+static int dm9000_send(struct udevice *dev, void *packet, int length)
+{
+	struct dm9000_priv *db = dev_get_priv(dev);
+	int ret;
+
+	ret = dm9000_send_common(db, packet, length);
+
+	return ret ? 0 : -ETIMEDOUT;
+}
+
+static int dm9000_recv(struct udevice *dev, int flags, uchar **packetp)
+{
+	struct dm9000_priv *db = dev_get_priv(dev);
+	uchar *data = net_rx_packets[0];
+	int ret;
+
+	ret = dm9000_recv_common(db, data);
+	if (ret)
+		*packetp = (void *)data;
+
+	return ret ? ret : -EAGAIN;
+}
+
+static int dm9000_write_hwaddr(struct udevice *dev)
+{
+	struct dm9000_priv *db = dev_get_priv(dev);
+	struct eth_pdata *pdata = dev_get_plat(dev);
+	int i, oft;
+
+	/* fill device MAC address registers */
+	for (i = 0, oft = DM9000_PAR; i < 6; i++, oft++)
+		dm9000_iow(db, oft, pdata->enetaddr[i]);
+
+	for (i = 0, oft = 0x16; i < 8; i++, oft++)
+		dm9000_iow(db, oft, 0xff);
+
+	/* read back mac, just to be sure */
+	for (i = 0, oft = 0x10; i < 6; i++, oft++)
+		debug("%02x:", dm9000_ior(db, oft));
+
+	debug("\n");
+
+	return 0;
+}
+
+static int dm9000_read_rom_hwaddr(struct udevice *dev)
+{
+	struct dm9000_priv *db = dev_get_priv(dev);
+	struct eth_pdata *pdata = dev_get_plat(dev);
+
+	dm9000_get_enetaddr(db, pdata->enetaddr);
+
+	return !is_valid_ethaddr(pdata->enetaddr);
+}
+
+static int dm9000_bind(struct udevice *dev)
+{
+	return device_set_name(dev, dev->name);
+}
+
+static int dm9000_of_to_plat(struct udevice *dev)
+{
+	struct dm9000_priv *db = dev_get_priv(dev);
+	struct eth_pdata *pdata = dev_get_plat(dev);
+
+	pdata->iobase = dev_read_addr_index(dev, 0);
+	db->base_io = pdata->iobase;
+	db->base_data = dev_read_addr_index(dev, 1);
+
+	return 0;
+}
+
+static const struct eth_ops dm9000_ops = {
+	.start		= dm9000_start,
+	.stop		= dm9000_stop,
+	.send		= dm9000_send,
+	.recv		= dm9000_recv,
+	.write_hwaddr	= dm9000_write_hwaddr,
+	.read_rom_hwaddr = dm9000_read_rom_hwaddr,
+};
+
+static const struct udevice_id dm9000_ids[] = {
+	{ .compatible = "davicom,dm9000" },
+	{ }
+};
+
+U_BOOT_DRIVER(dm9000) = {
+	.name		= "eth_dm9000",
+	.id		= UCLASS_ETH,
+	.of_match	= dm9000_ids,
+	.bind		= dm9000_bind,
+	.of_to_plat = dm9000_of_to_plat,
+	.ops		= &dm9000_ops,
+	.priv_auto	= sizeof(struct dm9000_priv),
+	.plat_auto	= sizeof(struct eth_pdata),
+	.flags		= DM_FLAG_ALLOC_PRIV_DMA,
+};
+#endif
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 32+ messages in thread

* [PATCH 16/16] net: dm9000: Add Kconfig entry
  2022-04-11 17:55 [PATCH 01/16] net: dm9000: Make accessor names lowercase Marek Vasut
                   ` (13 preceding siblings ...)
  2022-04-11 17:56 ` [PATCH 15/16] net: dm9000: Add DM support Marek Vasut
@ 2022-04-11 17:56 ` Marek Vasut
  2022-04-12 19:51   ` Ramon Fried
  2022-04-12 19:46 ` [PATCH 01/16] net: dm9000: Make accessor names lowercase Ramon Fried
  15 siblings, 1 reply; 32+ messages in thread
From: Marek Vasut @ 2022-04-11 17:56 UTC (permalink / raw)
  To: u-boot; +Cc: marcel.ziswiler, trini, Marek Vasut, Joe Hershberger, Ramon Fried

Add Kconfig entry for the DM9000 MAC.

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Cc: Ramon Fried <rfried.dev@gmail.com>
---
 drivers/net/Kconfig | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig
index a6171a7c7ff..347fe8aa425 100644
--- a/drivers/net/Kconfig
+++ b/drivers/net/Kconfig
@@ -191,6 +191,11 @@ config CALXEDA_XGMAC
 	  This driver supports the XGMAC in Calxeda Highbank and Midway
 	  machines.
 
+config DRIVER_DM9000
+	bool "Davicom DM9000 controller driver"
+	help
+	  The Davicom DM9000 parallel bus external ethernet interface chip.
+
 config DWC_ETH_QOS
 	bool "Synopsys DWC Ethernet QOS device support"
 	depends on DM_ETH
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 32+ messages in thread

* Re: [PATCH 01/16] net: dm9000: Make accessor names lowercase
  2022-04-11 17:55 [PATCH 01/16] net: dm9000: Make accessor names lowercase Marek Vasut
                   ` (14 preceding siblings ...)
  2022-04-11 17:56 ` [PATCH 16/16] net: dm9000: Add Kconfig entry Marek Vasut
@ 2022-04-12 19:46 ` Ramon Fried
  15 siblings, 0 replies; 32+ messages in thread
From: Ramon Fried @ 2022-04-12 19:46 UTC (permalink / raw)
  To: Marek Vasut
  Cc: U-Boot Mailing List, Marcel Ziswiler, Tom Rini, Joe Hershberger

On Mon, Apr 11, 2022 at 8:56 PM Marek Vasut <marex@denx.de> wrote:
>
> Make accessor names lowercase to be consistent with coding style.
> No functional change.
>
> Signed-off-by: Marek Vasut <marex@denx.de>
> Cc: Joe Hershberger <joe.hershberger@ni.com>
> Cc: Ramon Fried <rfried.dev@gmail.com>
> ---
>  drivers/net/dm9000x.c | 214 +++++++++++++++++++++---------------------
>  1 file changed, 107 insertions(+), 107 deletions(-)
>
> diff --git a/drivers/net/dm9000x.c b/drivers/net/dm9000x.c
> index 4f062e99d9b..93699135f75 100644
> --- a/drivers/net/dm9000x.c
> +++ b/drivers/net/dm9000x.c
> @@ -104,24 +104,24 @@ static board_info_t dm9000_info;
>  static int dm9000_probe(void);
>  static u16 dm9000_phy_read(int);
>  static void dm9000_phy_write(int, u16);
> -static u8 DM9000_ior(int);
> -static void DM9000_iow(int reg, u8 value);
> +static u8 dm9000_ior(int);
> +static void dm9000_iow(int reg, u8 value);
>
>  /* DM9000 network board routine ---------------------------- */
>  #ifndef CONFIG_DM9000_BYTE_SWAPPED
> -#define DM9000_outb(d,r) writeb(d, (volatile u8 *)(r))
> -#define DM9000_outw(d,r) writew(d, (volatile u16 *)(r))
> -#define DM9000_outl(d,r) writel(d, (volatile u32 *)(r))
> -#define DM9000_inb(r) readb((volatile u8 *)(r))
> -#define DM9000_inw(r) readw((volatile u16 *)(r))
> -#define DM9000_inl(r) readl((volatile u32 *)(r))
> +#define dm9000_outb(d,r) writeb(d, (volatile u8 *)(r))
> +#define dm9000_outw(d,r) writew(d, (volatile u16 *)(r))
> +#define dm9000_outl(d,r) writel(d, (volatile u32 *)(r))
> +#define dm9000_inb(r) readb((volatile u8 *)(r))
> +#define dm9000_inw(r) readw((volatile u16 *)(r))
> +#define dm9000_inl(r) readl((volatile u32 *)(r))
>  #else
> -#define DM9000_outb(d, r) __raw_writeb(d, r)
> -#define DM9000_outw(d, r) __raw_writew(d, r)
> -#define DM9000_outl(d, r) __raw_writel(d, r)
> -#define DM9000_inb(r) __raw_readb(r)
> -#define DM9000_inw(r) __raw_readw(r)
> -#define DM9000_inl(r) __raw_readl(r)
> +#define dm9000_outb(d, r) __raw_writeb(d, r)
> +#define dm9000_outw(d, r) __raw_writew(d, r)
> +#define dm9000_outl(d, r) __raw_writel(d, r)
> +#define dm9000_inb(r) __raw_readb(r)
> +#define dm9000_inw(r) __raw_readw(r)
> +#define dm9000_inl(r) __raw_readl(r)
>  #endif
>
>  #ifdef CONFIG_DM9000_DEBUG
> @@ -129,14 +129,14 @@ static void
>  dump_regs(void)
>  {
>         DM9000_DBG("\n");
> -       DM9000_DBG("NCR   (0x00): %02x\n", DM9000_ior(0));
> -       DM9000_DBG("NSR   (0x01): %02x\n", DM9000_ior(1));
> -       DM9000_DBG("TCR   (0x02): %02x\n", DM9000_ior(2));
> -       DM9000_DBG("TSRI  (0x03): %02x\n", DM9000_ior(3));
> -       DM9000_DBG("TSRII (0x04): %02x\n", DM9000_ior(4));
> -       DM9000_DBG("RCR   (0x05): %02x\n", DM9000_ior(5));
> -       DM9000_DBG("RSR   (0x06): %02x\n", DM9000_ior(6));
> -       DM9000_DBG("ISR   (0xFE): %02x\n", DM9000_ior(DM9000_ISR));
> +       DM9000_DBG("NCR   (0x00): %02x\n", dm9000_ior(0));
> +       DM9000_DBG("NSR   (0x01): %02x\n", dm9000_ior(1));
> +       DM9000_DBG("TCR   (0x02): %02x\n", dm9000_ior(2));
> +       DM9000_DBG("TSRI  (0x03): %02x\n", dm9000_ior(3));
> +       DM9000_DBG("TSRII (0x04): %02x\n", dm9000_ior(4));
> +       DM9000_DBG("RCR   (0x05): %02x\n", dm9000_ior(5));
> +       DM9000_DBG("RSR   (0x06): %02x\n", dm9000_ior(6));
> +       DM9000_DBG("ISR   (0xFE): %02x\n", dm9000_ior(DM9000_ISR));
>         DM9000_DBG("\n");
>  }
>  #endif
> @@ -145,7 +145,7 @@ static void dm9000_outblk_8bit(volatile void *data_ptr, int count)
>  {
>         int i;
>         for (i = 0; i < count; i++)
> -               DM9000_outb((((u8 *) data_ptr)[i] & 0xff), DM9000_DATA);
> +               dm9000_outb((((u8 *) data_ptr)[i] & 0xff), DM9000_DATA);
>  }
>
>  static void dm9000_outblk_16bit(volatile void *data_ptr, int count)
> @@ -154,7 +154,7 @@ static void dm9000_outblk_16bit(volatile void *data_ptr, int count)
>         u32 tmplen = (count + 1) / 2;
>
>         for (i = 0; i < tmplen; i++)
> -               DM9000_outw(((u16 *) data_ptr)[i], DM9000_DATA);
> +               dm9000_outw(((u16 *) data_ptr)[i], DM9000_DATA);
>  }
>  static void dm9000_outblk_32bit(volatile void *data_ptr, int count)
>  {
> @@ -162,14 +162,14 @@ static void dm9000_outblk_32bit(volatile void *data_ptr, int count)
>         u32 tmplen = (count + 3) / 4;
>
>         for (i = 0; i < tmplen; i++)
> -               DM9000_outl(((u32 *) data_ptr)[i], DM9000_DATA);
> +               dm9000_outl(((u32 *) data_ptr)[i], DM9000_DATA);
>  }
>
>  static void dm9000_inblk_8bit(void *data_ptr, int count)
>  {
>         int i;
>         for (i = 0; i < count; i++)
> -               ((u8 *) data_ptr)[i] = DM9000_inb(DM9000_DATA);
> +               ((u8 *) data_ptr)[i] = dm9000_inb(DM9000_DATA);
>  }
>
>  static void dm9000_inblk_16bit(void *data_ptr, int count)
> @@ -178,7 +178,7 @@ static void dm9000_inblk_16bit(void *data_ptr, int count)
>         u32 tmplen = (count + 1) / 2;
>
>         for (i = 0; i < tmplen; i++)
> -               ((u16 *) data_ptr)[i] = DM9000_inw(DM9000_DATA);
> +               ((u16 *) data_ptr)[i] = dm9000_inw(DM9000_DATA);
>  }
>  static void dm9000_inblk_32bit(void *data_ptr, int count)
>  {
> @@ -186,38 +186,38 @@ static void dm9000_inblk_32bit(void *data_ptr, int count)
>         u32 tmplen = (count + 3) / 4;
>
>         for (i = 0; i < tmplen; i++)
> -               ((u32 *) data_ptr)[i] = DM9000_inl(DM9000_DATA);
> +               ((u32 *) data_ptr)[i] = dm9000_inl(DM9000_DATA);
>  }
>
>  static void dm9000_rx_status_32bit(u16 *RxStatus, u16 *RxLen)
>  {
>         u32 tmpdata;
>
> -       DM9000_outb(DM9000_MRCMD, DM9000_IO);
> +       dm9000_outb(DM9000_MRCMD, DM9000_IO);
>
> -       tmpdata = DM9000_inl(DM9000_DATA);
> +       tmpdata = dm9000_inl(DM9000_DATA);
>         *RxStatus = __le16_to_cpu(tmpdata);
>         *RxLen = __le16_to_cpu(tmpdata >> 16);
>  }
>
>  static void dm9000_rx_status_16bit(u16 *RxStatus, u16 *RxLen)
>  {
> -       DM9000_outb(DM9000_MRCMD, DM9000_IO);
> +       dm9000_outb(DM9000_MRCMD, DM9000_IO);
>
> -       *RxStatus = __le16_to_cpu(DM9000_inw(DM9000_DATA));
> -       *RxLen = __le16_to_cpu(DM9000_inw(DM9000_DATA));
> +       *RxStatus = __le16_to_cpu(dm9000_inw(DM9000_DATA));
> +       *RxLen = __le16_to_cpu(dm9000_inw(DM9000_DATA));
>  }
>
>  static void dm9000_rx_status_8bit(u16 *RxStatus, u16 *RxLen)
>  {
> -       DM9000_outb(DM9000_MRCMD, DM9000_IO);
> +       dm9000_outb(DM9000_MRCMD, DM9000_IO);
>
>         *RxStatus =
> -           __le16_to_cpu(DM9000_inb(DM9000_DATA) +
> -                         (DM9000_inb(DM9000_DATA) << 8));
> +           __le16_to_cpu(dm9000_inb(DM9000_DATA) +
> +                         (dm9000_inb(DM9000_DATA) << 8));
>         *RxLen =
> -           __le16_to_cpu(DM9000_inb(DM9000_DATA) +
> -                         (DM9000_inb(DM9000_DATA) << 8));
> +           __le16_to_cpu(dm9000_inb(DM9000_DATA) +
> +                         (dm9000_inb(DM9000_DATA) << 8));
>  }
>
>  /*
> @@ -227,10 +227,10 @@ int
>  dm9000_probe(void)
>  {
>         u32 id_val;
> -       id_val = DM9000_ior(DM9000_VIDL);
> -       id_val |= DM9000_ior(DM9000_VIDH) << 8;
> -       id_val |= DM9000_ior(DM9000_PIDL) << 16;
> -       id_val |= DM9000_ior(DM9000_PIDH) << 24;
> +       id_val = dm9000_ior(DM9000_VIDL);
> +       id_val |= dm9000_ior(DM9000_VIDH) << 8;
> +       id_val |= dm9000_ior(DM9000_PIDL) << 16;
> +       id_val |= dm9000_ior(DM9000_PIDH) << 24;
>         if (id_val == DM9000_ID) {
>                 printf("dm9000 i/o: 0x%x, id: 0x%x \n", CONFIG_DM9000_BASE,
>                        id_val);
> @@ -252,28 +252,28 @@ dm9000_reset(void)
>            see DM9000 Application Notes V1.22 Jun 11, 2004 page 29 */
>
>         /* DEBUG: Make all GPIO0 outputs, all others inputs */
> -       DM9000_iow(DM9000_GPCR, GPCR_GPIO0_OUT);
> +       dm9000_iow(DM9000_GPCR, GPCR_GPIO0_OUT);
>         /* Step 1: Power internal PHY by writing 0 to GPIO0 pin */
> -       DM9000_iow(DM9000_GPR, 0);
> +       dm9000_iow(DM9000_GPR, 0);
>         /* Step 2: Software reset */
> -       DM9000_iow(DM9000_NCR, (NCR_LBK_INT_MAC | NCR_RST));
> +       dm9000_iow(DM9000_NCR, (NCR_LBK_INT_MAC | NCR_RST));
>
>         do {
>                 DM9000_DBG("resetting the DM9000, 1st reset\n");
>                 udelay(25); /* Wait at least 20 us */
> -       } while (DM9000_ior(DM9000_NCR) & 1);
> +       } while (dm9000_ior(DM9000_NCR) & 1);
>
> -       DM9000_iow(DM9000_NCR, 0);
> -       DM9000_iow(DM9000_NCR, (NCR_LBK_INT_MAC | NCR_RST)); /* Issue a second reset */
> +       dm9000_iow(DM9000_NCR, 0);
> +       dm9000_iow(DM9000_NCR, (NCR_LBK_INT_MAC | NCR_RST)); /* Issue a second reset */
>
>         do {
>                 DM9000_DBG("resetting the DM9000, 2nd reset\n");
>                 udelay(25); /* Wait at least 20 us */
> -       } while (DM9000_ior(DM9000_NCR) & 1);
> +       } while (dm9000_ior(DM9000_NCR) & 1);
>
>         /* Check whether the ethernet controller is present */
> -       if ((DM9000_ior(DM9000_PIDL) != 0x0) ||
> -           (DM9000_ior(DM9000_PIDH) != 0x90))
> +       if ((dm9000_ior(DM9000_PIDL) != 0x0) ||
> +           (dm9000_ior(DM9000_PIDH) != 0x90))
>                 printf("ERROR: resetting DM9000 -> not responding\n");
>  }
>
> @@ -294,7 +294,7 @@ static int dm9000_init(struct eth_device *dev, struct bd_info *bd)
>                 return -1;
>
>         /* Auto-detect 8/16/32 bit mode, ISR Bit 6+7 indicate bus width */
> -       io_mode = DM9000_ior(DM9000_ISR) >> 6;
> +       io_mode = dm9000_ior(DM9000_ISR) >> 6;
>
>         switch (io_mode) {
>         case 0x0:  /* 16-bit mode */
> @@ -325,21 +325,21 @@ static int dm9000_init(struct eth_device *dev, struct bd_info *bd)
>         }
>
>         /* Program operating register, only internal phy supported */
> -       DM9000_iow(DM9000_NCR, 0x0);
> +       dm9000_iow(DM9000_NCR, 0x0);
>         /* TX Polling clear */
> -       DM9000_iow(DM9000_TCR, 0);
> +       dm9000_iow(DM9000_TCR, 0);
>         /* Less 3Kb, 200us */
> -       DM9000_iow(DM9000_BPTR, BPTR_BPHW(3) | BPTR_JPT_600US);
> +       dm9000_iow(DM9000_BPTR, BPTR_BPHW(3) | BPTR_JPT_600US);
>         /* Flow Control : High/Low Water */
> -       DM9000_iow(DM9000_FCTR, FCTR_HWOT(3) | FCTR_LWOT(8));
> +       dm9000_iow(DM9000_FCTR, FCTR_HWOT(3) | FCTR_LWOT(8));
>         /* SH FIXME: This looks strange! Flow Control */
> -       DM9000_iow(DM9000_FCR, 0x0);
> +       dm9000_iow(DM9000_FCR, 0x0);
>         /* Special Mode */
> -       DM9000_iow(DM9000_SMCR, 0);
> +       dm9000_iow(DM9000_SMCR, 0);
>         /* clear TX status */
> -       DM9000_iow(DM9000_NSR, NSR_WAKEST | NSR_TX2END | NSR_TX1END);
> +       dm9000_iow(DM9000_NSR, NSR_WAKEST | NSR_TX2END | NSR_TX1END);
>         /* Clear interrupt status */
> -       DM9000_iow(DM9000_ISR, ISR_ROOS | ISR_ROS | ISR_PTS | ISR_PRS);
> +       dm9000_iow(DM9000_ISR, ISR_ROOS | ISR_ROS | ISR_PTS | ISR_PRS);
>
>         printf("MAC: %pM\n", dev->enetaddr);
>         if (!is_valid_ethaddr(dev->enetaddr)) {
> @@ -348,20 +348,20 @@ static int dm9000_init(struct eth_device *dev, struct bd_info *bd)
>
>         /* fill device MAC address registers */
>         for (i = 0, oft = DM9000_PAR; i < 6; i++, oft++)
> -               DM9000_iow(oft, dev->enetaddr[i]);
> +               dm9000_iow(oft, dev->enetaddr[i]);
>         for (i = 0, oft = 0x16; i < 8; i++, oft++)
> -               DM9000_iow(oft, 0xff);
> +               dm9000_iow(oft, 0xff);
>
>         /* read back mac, just to be sure */
>         for (i = 0, oft = 0x10; i < 6; i++, oft++)
> -               DM9000_DBG("%02x:", DM9000_ior(oft));
> +               DM9000_DBG("%02x:", dm9000_ior(oft));
>         DM9000_DBG("\n");
>
>         /* Activate DM9000 */
>         /* RX enable */
> -       DM9000_iow(DM9000_RCR, RCR_DIS_LONG | RCR_DIS_CRC | RCR_RXEN);
> +       dm9000_iow(DM9000_RCR, RCR_DIS_LONG | RCR_DIS_CRC | RCR_RXEN);
>         /* Enable TX/RX interrupt mask */
> -       DM9000_iow(DM9000_IMR, IMR_PAR);
> +       dm9000_iow(DM9000_IMR, IMR_PAR);
>
>         i = 0;
>         while (!(dm9000_phy_read(1) & 0x20)) {  /* autonegation complete bit */
> @@ -408,31 +408,31 @@ static int dm9000_send(struct eth_device *netdev, void *packet, int length)
>
>         DM9000_DMP_PACKET(__func__ , packet, length);
>
> -       DM9000_iow(DM9000_ISR, IMR_PTM); /* Clear Tx bit in ISR */
> +       dm9000_iow(DM9000_ISR, IMR_PTM); /* Clear Tx bit in ISR */
>
>         /* Move data to DM9000 TX RAM */
> -       DM9000_outb(DM9000_MWCMD, DM9000_IO); /* Prepare for TX-data */
> +       dm9000_outb(DM9000_MWCMD, DM9000_IO); /* Prepare for TX-data */
>
>         /* push the data to the TX-fifo */
>         (db->outblk)(packet, length);
>
>         /* Set TX length to DM9000 */
> -       DM9000_iow(DM9000_TXPLL, length & 0xff);
> -       DM9000_iow(DM9000_TXPLH, (length >> 8) & 0xff);
> +       dm9000_iow(DM9000_TXPLL, length & 0xff);
> +       dm9000_iow(DM9000_TXPLH, (length >> 8) & 0xff);
>
>         /* Issue TX polling command */
> -       DM9000_iow(DM9000_TCR, TCR_TXREQ); /* Cleared after TX complete */
> +       dm9000_iow(DM9000_TCR, TCR_TXREQ); /* Cleared after TX complete */
>
>         /* wait for end of transmission */
>         tmo = get_timer(0) + 5 * CONFIG_SYS_HZ;
> -       while ( !(DM9000_ior(DM9000_NSR) & (NSR_TX1END | NSR_TX2END)) ||
> -               !(DM9000_ior(DM9000_ISR) & IMR_PTM) ) {
> +       while ( !(dm9000_ior(DM9000_NSR) & (NSR_TX1END | NSR_TX2END)) ||
> +               !(dm9000_ior(DM9000_ISR) & IMR_PTM) ) {
>                 if (get_timer(0) >= tmo) {
>                         printf("transmission timeout\n");
>                         break;
>                 }
>         }
> -       DM9000_iow(DM9000_ISR, IMR_PTM); /* Clear Tx bit in ISR */
> +       dm9000_iow(DM9000_ISR, IMR_PTM); /* Clear Tx bit in ISR */
>
>         DM9000_DBG("transmit done\n\n");
>         return 0;
> @@ -448,9 +448,9 @@ static void dm9000_halt(struct eth_device *netdev)
>
>         /* RESET devie */
>         dm9000_phy_write(0, 0x8000);    /* PHY RESET */
> -       DM9000_iow(DM9000_GPR, 0x01);   /* Power-Down PHY */
> -       DM9000_iow(DM9000_IMR, 0x80);   /* Disable all interrupt */
> -       DM9000_iow(DM9000_RCR, 0x00);   /* Disable RX */
> +       dm9000_iow(DM9000_GPR, 0x01);   /* Power-Down PHY */
> +       dm9000_iow(DM9000_IMR, 0x80);   /* Disable all interrupt */
> +       dm9000_iow(DM9000_RCR, 0x00);   /* Disable RX */
>  }
>
>  /*
> @@ -465,23 +465,23 @@ static int dm9000_rx(struct eth_device *netdev)
>
>         /* Check packet ready or not, we must check
>            the ISR status first for DM9000A */
> -       if (!(DM9000_ior(DM9000_ISR) & 0x01)) /* Rx-ISR bit must be set. */
> +       if (!(dm9000_ior(DM9000_ISR) & 0x01)) /* Rx-ISR bit must be set. */
>                 return 0;
>
> -       DM9000_iow(DM9000_ISR, 0x01); /* clear PR status latched in bit 0 */
> +       dm9000_iow(DM9000_ISR, 0x01); /* clear PR status latched in bit 0 */
>
>         /* There is _at least_ 1 package in the fifo, read them all */
>         for (;;) {
> -               DM9000_ior(DM9000_MRCMDX);      /* Dummy read */
> +               dm9000_ior(DM9000_MRCMDX);      /* Dummy read */
>
>                 /* Get most updated data,
>                    only look at bits 0:1, See application notes DM9000 */
> -               rxbyte = DM9000_inb(DM9000_DATA) & 0x03;
> +               rxbyte = dm9000_inb(DM9000_DATA) & 0x03;
>
>                 /* Status check: this byte must be 0 or 1 */
>                 if (rxbyte > DM9000_PKT_RDY) {
> -                       DM9000_iow(DM9000_RCR, 0x00);   /* Stop Device */
> -                       DM9000_iow(DM9000_ISR, 0x80);   /* Stop INT request */
> +                       dm9000_iow(DM9000_RCR, 0x00);   /* Stop Device */
> +                       dm9000_iow(DM9000_ISR, 0x80);   /* Stop INT request */
>                         printf("DM9000 error: status check fail: 0x%x\n",
>                                 rxbyte);
>                         return 0;
> @@ -532,22 +532,22 @@ static int dm9000_rx(struct eth_device *netdev)
>  #if !defined(CONFIG_DM9000_NO_SROM)
>  void dm9000_read_srom_word(int offset, u8 *to)
>  {
> -       DM9000_iow(DM9000_EPAR, offset);
> -       DM9000_iow(DM9000_EPCR, 0x4);
> +       dm9000_iow(DM9000_EPAR, offset);
> +       dm9000_iow(DM9000_EPCR, 0x4);
>         udelay(8000);
> -       DM9000_iow(DM9000_EPCR, 0x0);
> -       to[0] = DM9000_ior(DM9000_EPDRL);
> -       to[1] = DM9000_ior(DM9000_EPDRH);
> +       dm9000_iow(DM9000_EPCR, 0x0);
> +       to[0] = dm9000_ior(DM9000_EPDRL);
> +       to[1] = dm9000_ior(DM9000_EPDRH);
>  }
>
>  void dm9000_write_srom_word(int offset, u16 val)
>  {
> -       DM9000_iow(DM9000_EPAR, offset);
> -       DM9000_iow(DM9000_EPDRH, ((val >> 8) & 0xff));
> -       DM9000_iow(DM9000_EPDRL, (val & 0xff));
> -       DM9000_iow(DM9000_EPCR, 0x12);
> +       dm9000_iow(DM9000_EPAR, offset);
> +       dm9000_iow(DM9000_EPDRH, ((val >> 8) & 0xff));
> +       dm9000_iow(DM9000_EPDRL, (val & 0xff));
> +       dm9000_iow(DM9000_EPCR, 0x12);
>         udelay(8000);
> -       DM9000_iow(DM9000_EPCR, 0);
> +       dm9000_iow(DM9000_EPCR, 0);
>  }
>  #endif
>
> @@ -564,20 +564,20 @@ static void dm9000_get_enetaddr(struct eth_device *dev)
>     Read a byte from I/O port
>  */
>  static u8
> -DM9000_ior(int reg)
> +dm9000_ior(int reg)
>  {
> -       DM9000_outb(reg, DM9000_IO);
> -       return DM9000_inb(DM9000_DATA);
> +       dm9000_outb(reg, DM9000_IO);
> +       return dm9000_inb(DM9000_DATA);
>  }
>
>  /*
>     Write a byte to I/O port
>  */
>  static void
> -DM9000_iow(int reg, u8 value)
> +dm9000_iow(int reg, u8 value)
>  {
> -       DM9000_outb(reg, DM9000_IO);
> -       DM9000_outb(value, DM9000_DATA);
> +       dm9000_outb(reg, DM9000_IO);
> +       dm9000_outb(value, DM9000_DATA);
>  }
>
>  /*
> @@ -589,11 +589,11 @@ dm9000_phy_read(int reg)
>         u16 val;
>
>         /* Fill the phyxcer register into REG_0C */
> -       DM9000_iow(DM9000_EPAR, DM9000_PHY | reg);
> -       DM9000_iow(DM9000_EPCR, 0xc);   /* Issue phyxcer read command */
> +       dm9000_iow(DM9000_EPAR, DM9000_PHY | reg);
> +       dm9000_iow(DM9000_EPCR, 0xc);   /* Issue phyxcer read command */
>         udelay(100);                    /* Wait read complete */
> -       DM9000_iow(DM9000_EPCR, 0x0);   /* Clear phyxcer read command */
> -       val = (DM9000_ior(DM9000_EPDRH) << 8) | DM9000_ior(DM9000_EPDRL);
> +       dm9000_iow(DM9000_EPCR, 0x0);   /* Clear phyxcer read command */
> +       val = (dm9000_ior(DM9000_EPDRH) << 8) | dm9000_ior(DM9000_EPDRL);
>
>         /* The read data keeps on REG_0D & REG_0E */
>         DM9000_DBG("dm9000_phy_read(0x%x): 0x%x\n", reg, val);
> @@ -608,14 +608,14 @@ dm9000_phy_write(int reg, u16 value)
>  {
>
>         /* Fill the phyxcer register into REG_0C */
> -       DM9000_iow(DM9000_EPAR, DM9000_PHY | reg);
> +       dm9000_iow(DM9000_EPAR, DM9000_PHY | reg);
>
>         /* Fill the written data into REG_0D & REG_0E */
> -       DM9000_iow(DM9000_EPDRL, (value & 0xff));
> -       DM9000_iow(DM9000_EPDRH, ((value >> 8) & 0xff));
> -       DM9000_iow(DM9000_EPCR, 0xa);   /* Issue phyxcer write command */
> +       dm9000_iow(DM9000_EPDRL, (value & 0xff));
> +       dm9000_iow(DM9000_EPDRH, ((value >> 8) & 0xff));
> +       dm9000_iow(DM9000_EPCR, 0xa);   /* Issue phyxcer write command */
>         udelay(500);                    /* Wait write complete */
> -       DM9000_iow(DM9000_EPCR, 0x0);   /* Clear phyxcer write command */
> +       dm9000_iow(DM9000_EPCR, 0x0);   /* Clear phyxcer write command */
>         DM9000_DBG("dm9000_phy_write(reg:0x%x, value:0x%x)\n", reg, value);
>  }
>
> --
> 2.35.1
>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH 02/16] net: dm9000: Replace DM9000_DBG() with debug()
  2022-04-11 17:55 ` [PATCH 02/16] net: dm9000: Replace DM9000_DBG() with debug() Marek Vasut
@ 2022-04-12 19:46   ` Ramon Fried
  0 siblings, 0 replies; 32+ messages in thread
From: Ramon Fried @ 2022-04-12 19:46 UTC (permalink / raw)
  To: Marek Vasut
  Cc: U-Boot Mailing List, Marcel Ziswiler, Tom Rini, Joe Hershberger

On Mon, Apr 11, 2022 at 8:56 PM Marek Vasut <marex@denx.de> wrote:
>
> Use standard debug() macro to print debug messages instead of
> reinventing driver-specific macro again. No functional change.
>
> Signed-off-by: Marek Vasut <marex@denx.de>
> Cc: Joe Hershberger <joe.hershberger@ni.com>
> Cc: Ramon Fried <rfried.dev@gmail.com>
> ---
>  drivers/net/dm9000x.c | 48 +++++++++++++++++++++----------------------
>  1 file changed, 23 insertions(+), 25 deletions(-)
>
> diff --git a/drivers/net/dm9000x.c b/drivers/net/dm9000x.c
> index 93699135f75..e83b838fd82 100644
> --- a/drivers/net/dm9000x.c
> +++ b/drivers/net/dm9000x.c
> @@ -63,7 +63,6 @@ TODO: external MII is not functional, only internal at the moment.
>  /* #define CONFIG_DM9000_DEBUG */
>
>  #ifdef CONFIG_DM9000_DEBUG
> -#define DM9000_DBG(fmt,args...) printf(fmt, ##args)
>  #define DM9000_DMP_PACKET(func,packet,length)  \
>         do { \
>                 int i;                                                  \
> @@ -75,7 +74,6 @@ TODO: external MII is not functional, only internal at the moment.
>                 } printf("\n");                                         \
>         } while(0)
>  #else
> -#define DM9000_DBG(fmt,args...)
>  #define DM9000_DMP_PACKET(func,packet,length)
>  #endif
>
> @@ -128,16 +126,16 @@ static void dm9000_iow(int reg, u8 value);
>  static void
>  dump_regs(void)
>  {
> -       DM9000_DBG("\n");
> -       DM9000_DBG("NCR   (0x00): %02x\n", dm9000_ior(0));
> -       DM9000_DBG("NSR   (0x01): %02x\n", dm9000_ior(1));
> -       DM9000_DBG("TCR   (0x02): %02x\n", dm9000_ior(2));
> -       DM9000_DBG("TSRI  (0x03): %02x\n", dm9000_ior(3));
> -       DM9000_DBG("TSRII (0x04): %02x\n", dm9000_ior(4));
> -       DM9000_DBG("RCR   (0x05): %02x\n", dm9000_ior(5));
> -       DM9000_DBG("RSR   (0x06): %02x\n", dm9000_ior(6));
> -       DM9000_DBG("ISR   (0xFE): %02x\n", dm9000_ior(DM9000_ISR));
> -       DM9000_DBG("\n");
> +       debug("\n");
> +       debug("NCR   (0x00): %02x\n", dm9000_ior(0));
> +       debug("NSR   (0x01): %02x\n", dm9000_ior(1));
> +       debug("TCR   (0x02): %02x\n", dm9000_ior(2));
> +       debug("TSRI  (0x03): %02x\n", dm9000_ior(3));
> +       debug("TSRII (0x04): %02x\n", dm9000_ior(4));
> +       debug("RCR   (0x05): %02x\n", dm9000_ior(5));
> +       debug("RSR   (0x06): %02x\n", dm9000_ior(6));
> +       debug("ISR   (0xFE): %02x\n", dm9000_ior(DM9000_ISR));
> +       debug("\n");
>  }
>  #endif
>
> @@ -246,7 +244,7 @@ dm9000_probe(void)
>  static void
>  dm9000_reset(void)
>  {
> -       DM9000_DBG("resetting DM9000\n");
> +       debug("resetting DM9000\n");
>
>         /* Reset DM9000,
>            see DM9000 Application Notes V1.22 Jun 11, 2004 page 29 */
> @@ -259,7 +257,7 @@ dm9000_reset(void)
>         dm9000_iow(DM9000_NCR, (NCR_LBK_INT_MAC | NCR_RST));
>
>         do {
> -               DM9000_DBG("resetting the DM9000, 1st reset\n");
> +               debug("resetting the DM9000, 1st reset\n");
>                 udelay(25); /* Wait at least 20 us */
>         } while (dm9000_ior(DM9000_NCR) & 1);
>
> @@ -267,7 +265,7 @@ dm9000_reset(void)
>         dm9000_iow(DM9000_NCR, (NCR_LBK_INT_MAC | NCR_RST)); /* Issue a second reset */
>
>         do {
> -               DM9000_DBG("resetting the DM9000, 2nd reset\n");
> +               debug("resetting the DM9000, 2nd reset\n");
>                 udelay(25); /* Wait at least 20 us */
>         } while (dm9000_ior(DM9000_NCR) & 1);
>
> @@ -285,7 +283,7 @@ static int dm9000_init(struct eth_device *dev, struct bd_info *bd)
>         u8 io_mode;
>         struct board_info *db = &dm9000_info;
>
> -       DM9000_DBG("%s\n", __func__);
> +       debug("%s\n", __func__);
>
>         /* RESET device */
>         dm9000_reset();
> @@ -354,8 +352,8 @@ static int dm9000_init(struct eth_device *dev, struct bd_info *bd)
>
>         /* read back mac, just to be sure */
>         for (i = 0, oft = 0x10; i < 6; i++, oft++)
> -               DM9000_DBG("%02x:", dm9000_ior(oft));
> -       DM9000_DBG("\n");
> +               debug("%02x:", dm9000_ior(oft));
> +       debug("\n");
>
>         /* Activate DM9000 */
>         /* RX enable */
> @@ -434,7 +432,7 @@ static int dm9000_send(struct eth_device *netdev, void *packet, int length)
>         }
>         dm9000_iow(DM9000_ISR, IMR_PTM); /* Clear Tx bit in ISR */
>
> -       DM9000_DBG("transmit done\n\n");
> +       debug("transmit done\n\n");
>         return 0;
>  }
>
> @@ -444,7 +442,7 @@ static int dm9000_send(struct eth_device *netdev, void *packet, int length)
>  */
>  static void dm9000_halt(struct eth_device *netdev)
>  {
> -       DM9000_DBG("%s\n", __func__);
> +       debug("%s\n", __func__);
>
>         /* RESET devie */
>         dm9000_phy_write(0, 0x8000);    /* PHY RESET */
> @@ -490,12 +488,12 @@ static int dm9000_rx(struct eth_device *netdev)
>                 if (rxbyte != DM9000_PKT_RDY)
>                         return 0; /* No packet received, ignore */
>
> -               DM9000_DBG("receiving packet\n");
> +               debug("receiving packet\n");
>
>                 /* A packet ready now  & Get status/length */
>                 (db->rx_status)(&RxStatus, &RxLen);
>
> -               DM9000_DBG("rx status: 0x%04x rx len: %d\n", RxStatus, RxLen);
> +               debug("rx status: 0x%04x rx len: %d\n", RxStatus, RxLen);
>
>                 /* Move data from DM9000 */
>                 /* Read received packet from RX SRAM */
> @@ -519,7 +517,7 @@ static int dm9000_rx(struct eth_device *netdev)
>                 } else {
>                         DM9000_DMP_PACKET(__func__ , rdptr, RxLen);
>
> -                       DM9000_DBG("passing packet to upper layer\n");
> +                       debug("passing packet to upper layer\n");
>                         net_process_received_packet(net_rx_packets[0], RxLen);
>                 }
>         }
> @@ -596,7 +594,7 @@ dm9000_phy_read(int reg)
>         val = (dm9000_ior(DM9000_EPDRH) << 8) | dm9000_ior(DM9000_EPDRL);
>
>         /* The read data keeps on REG_0D & REG_0E */
> -       DM9000_DBG("dm9000_phy_read(0x%x): 0x%x\n", reg, val);
> +       debug("dm9000_phy_read(0x%x): 0x%x\n", reg, val);
>         return val;
>  }
>
> @@ -616,7 +614,7 @@ dm9000_phy_write(int reg, u16 value)
>         dm9000_iow(DM9000_EPCR, 0xa);   /* Issue phyxcer write command */
>         udelay(500);                    /* Wait write complete */
>         dm9000_iow(DM9000_EPCR, 0x0);   /* Clear phyxcer write command */
> -       DM9000_DBG("dm9000_phy_write(reg:0x%x, value:0x%x)\n", reg, value);
> +       debug("dm9000_phy_write(reg:0x%x, value:0x%x)\n", reg, value);
>  }
>
>  int dm9000_initialize(struct bd_info *bis)
> --
> 2.35.1
>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH 03/16] net: dm9000: Make RxLen and RxStatus lowercase
  2022-04-11 17:55 ` [PATCH 03/16] net: dm9000: Make RxLen and RxStatus lowercase Marek Vasut
@ 2022-04-12 19:46   ` Ramon Fried
  0 siblings, 0 replies; 32+ messages in thread
From: Ramon Fried @ 2022-04-12 19:46 UTC (permalink / raw)
  To: Marek Vasut
  Cc: U-Boot Mailing List, Marcel Ziswiler, Tom Rini, Joe Hershberger

On Mon, Apr 11, 2022 at 8:56 PM Marek Vasut <marex@denx.de> wrote:
>
> Rename variables to lowercase to be consistent with coding style.
> No functional change.
>
> Signed-off-by: Marek Vasut <marex@denx.de>
> Cc: Joe Hershberger <joe.hershberger@ni.com>
> Cc: Ramon Fried <rfried.dev@gmail.com>
> ---
>  drivers/net/dm9000x.c | 44 +++++++++++++++++++++----------------------
>  1 file changed, 22 insertions(+), 22 deletions(-)
>
> diff --git a/drivers/net/dm9000x.c b/drivers/net/dm9000x.c
> index e83b838fd82..a99a901e828 100644
> --- a/drivers/net/dm9000x.c
> +++ b/drivers/net/dm9000x.c
> @@ -92,7 +92,7 @@ typedef struct board_info {
>         unsigned char srom[128];
>         void (*outblk)(volatile void *data_ptr, int count);
>         void (*inblk)(void *data_ptr, int count);
> -       void (*rx_status)(u16 *RxStatus, u16 *RxLen);
> +       void (*rx_status)(u16 *rxstatus, u16 *rxlen);
>         struct eth_device netdev;
>  } board_info_t;
>  static board_info_t dm9000_info;
> @@ -187,33 +187,33 @@ static void dm9000_inblk_32bit(void *data_ptr, int count)
>                 ((u32 *) data_ptr)[i] = dm9000_inl(DM9000_DATA);
>  }
>
> -static void dm9000_rx_status_32bit(u16 *RxStatus, u16 *RxLen)
> +static void dm9000_rx_status_32bit(u16 *rxstatus, u16 *rxlen)
>  {
>         u32 tmpdata;
>
>         dm9000_outb(DM9000_MRCMD, DM9000_IO);
>
>         tmpdata = dm9000_inl(DM9000_DATA);
> -       *RxStatus = __le16_to_cpu(tmpdata);
> -       *RxLen = __le16_to_cpu(tmpdata >> 16);
> +       *rxstatus = __le16_to_cpu(tmpdata);
> +       *rxlen = __le16_to_cpu(tmpdata >> 16);
>  }
>
> -static void dm9000_rx_status_16bit(u16 *RxStatus, u16 *RxLen)
> +static void dm9000_rx_status_16bit(u16 *rxstatus, u16 *rxlen)
>  {
>         dm9000_outb(DM9000_MRCMD, DM9000_IO);
>
> -       *RxStatus = __le16_to_cpu(dm9000_inw(DM9000_DATA));
> -       *RxLen = __le16_to_cpu(dm9000_inw(DM9000_DATA));
> +       *rxstatus = __le16_to_cpu(dm9000_inw(DM9000_DATA));
> +       *rxlen = __le16_to_cpu(dm9000_inw(DM9000_DATA));
>  }
>
> -static void dm9000_rx_status_8bit(u16 *RxStatus, u16 *RxLen)
> +static void dm9000_rx_status_8bit(u16 *rxstatus, u16 *rxlen)
>  {
>         dm9000_outb(DM9000_MRCMD, DM9000_IO);
>
> -       *RxStatus =
> +       *rxstatus =
>             __le16_to_cpu(dm9000_inb(DM9000_DATA) +
>                           (dm9000_inb(DM9000_DATA) << 8));
> -       *RxLen =
> +       *rxlen =
>             __le16_to_cpu(dm9000_inb(DM9000_DATA) +
>                           (dm9000_inb(DM9000_DATA) << 8));
>  }
> @@ -458,7 +458,7 @@ static int dm9000_rx(struct eth_device *netdev)
>  {
>         u8 rxbyte;
>         u8 *rdptr = (u8 *)net_rx_packets[0];
> -       u16 RxStatus, RxLen = 0;
> +       u16 rxstatus, rxlen = 0;
>         struct board_info *db = &dm9000_info;
>
>         /* Check packet ready or not, we must check
> @@ -491,34 +491,34 @@ static int dm9000_rx(struct eth_device *netdev)
>                 debug("receiving packet\n");
>
>                 /* A packet ready now  & Get status/length */
> -               (db->rx_status)(&RxStatus, &RxLen);
> +               (db->rx_status)(&rxstatus, &rxlen);
>
> -               debug("rx status: 0x%04x rx len: %d\n", RxStatus, RxLen);
> +               debug("rx status: 0x%04x rx len: %d\n", rxstatus, rxlen);
>
>                 /* Move data from DM9000 */
>                 /* Read received packet from RX SRAM */
> -               (db->inblk)(rdptr, RxLen);
> +               (db->inblk)(rdptr, rxlen);
>
> -               if ((RxStatus & 0xbf00) || (RxLen < 0x40)
> -                       || (RxLen > DM9000_PKT_MAX)) {
> -                       if (RxStatus & 0x100) {
> +               if ((rxstatus & 0xbf00) || (rxlen < 0x40)
> +                       || (rxlen > DM9000_PKT_MAX)) {
> +                       if (rxstatus & 0x100) {
>                                 printf("rx fifo error\n");
>                         }
> -                       if (RxStatus & 0x200) {
> +                       if (rxstatus & 0x200) {
>                                 printf("rx crc error\n");
>                         }
> -                       if (RxStatus & 0x8000) {
> +                       if (rxstatus & 0x8000) {
>                                 printf("rx length error\n");
>                         }
> -                       if (RxLen > DM9000_PKT_MAX) {
> +                       if (rxlen > DM9000_PKT_MAX) {
>                                 printf("rx length too big\n");
>                                 dm9000_reset();
>                         }
>                 } else {
> -                       DM9000_DMP_PACKET(__func__ , rdptr, RxLen);
> +                       DM9000_DMP_PACKET(__func__ , rdptr, rxlen);
>
>                         debug("passing packet to upper layer\n");
> -                       net_process_received_packet(net_rx_packets[0], RxLen);
> +                       net_process_received_packet(net_rx_packets[0], rxlen);
>                 }
>         }
>         return 0;
> --
> 2.35.1
>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH 04/16] net: dm9000: Drop unused dump_regs()
  2022-04-11 17:55 ` [PATCH 04/16] net: dm9000: Drop unused dump_regs() Marek Vasut
@ 2022-04-12 19:46   ` Ramon Fried
  0 siblings, 0 replies; 32+ messages in thread
From: Ramon Fried @ 2022-04-12 19:46 UTC (permalink / raw)
  To: Marek Vasut
  Cc: U-Boot Mailing List, Marcel Ziswiler, Tom Rini, Joe Hershberger

On Mon, Apr 11, 2022 at 8:56 PM Marek Vasut <marex@denx.de> wrote:
>
> Drop unused function dump_regs() because it is unused.
> No functional change.
>
> Signed-off-by: Marek Vasut <marex@denx.de>
> Cc: Joe Hershberger <joe.hershberger@ni.com>
> Cc: Ramon Fried <rfried.dev@gmail.com>
> ---
>  drivers/net/dm9000x.c | 17 -----------------
>  1 file changed, 17 deletions(-)
>
> diff --git a/drivers/net/dm9000x.c b/drivers/net/dm9000x.c
> index a99a901e828..223df944a48 100644
> --- a/drivers/net/dm9000x.c
> +++ b/drivers/net/dm9000x.c
> @@ -122,23 +122,6 @@ static void dm9000_iow(int reg, u8 value);
>  #define dm9000_inl(r) __raw_readl(r)
>  #endif
>
> -#ifdef CONFIG_DM9000_DEBUG
> -static void
> -dump_regs(void)
> -{
> -       debug("\n");
> -       debug("NCR   (0x00): %02x\n", dm9000_ior(0));
> -       debug("NSR   (0x01): %02x\n", dm9000_ior(1));
> -       debug("TCR   (0x02): %02x\n", dm9000_ior(2));
> -       debug("TSRI  (0x03): %02x\n", dm9000_ior(3));
> -       debug("TSRII (0x04): %02x\n", dm9000_ior(4));
> -       debug("RCR   (0x05): %02x\n", dm9000_ior(5));
> -       debug("RSR   (0x06): %02x\n", dm9000_ior(6));
> -       debug("ISR   (0xFE): %02x\n", dm9000_ior(DM9000_ISR));
> -       debug("\n");
> -}
> -#endif
> -
>  static void dm9000_outblk_8bit(volatile void *data_ptr, int count)
>  {
>         int i;
> --
> 2.35.1
>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH 05/16] net: dm9000: Turn DM9000_DMP_PACKET() into a function
  2022-04-11 17:55 ` [PATCH 05/16] net: dm9000: Turn DM9000_DMP_PACKET() into a function Marek Vasut
@ 2022-04-12 19:46   ` Ramon Fried
  0 siblings, 0 replies; 32+ messages in thread
From: Ramon Fried @ 2022-04-12 19:46 UTC (permalink / raw)
  To: Marek Vasut
  Cc: U-Boot Mailing List, Marcel Ziswiler, Tom Rini, Joe Hershberger

On Mon, Apr 11, 2022 at 8:56 PM Marek Vasut <marex@denx.de> wrote:
>
> Rework DM9000_DMP_PACKET() into dm9000_dump_packet() function,
> this brings better type checking. No functional change.
>
> Signed-off-by: Marek Vasut <marex@denx.de>
> Cc: Joe Hershberger <joe.hershberger@ni.com>
> Cc: Ramon Fried <rfried.dev@gmail.com>
> ---
>  drivers/net/dm9000x.c | 42 +++++++++++++++++++++---------------------
>  1 file changed, 21 insertions(+), 21 deletions(-)
>
> diff --git a/drivers/net/dm9000x.c b/drivers/net/dm9000x.c
> index 223df944a48..da16b64610b 100644
> --- a/drivers/net/dm9000x.c
> +++ b/drivers/net/dm9000x.c
> @@ -58,25 +58,6 @@ TODO: external MII is not functional, only internal at the moment.
>
>  #include "dm9000x.h"
>
> -/* Board/System/Debug information/definition ---------------- */
> -
> -/* #define CONFIG_DM9000_DEBUG */
> -
> -#ifdef CONFIG_DM9000_DEBUG
> -#define DM9000_DMP_PACKET(func,packet,length)  \
> -       do { \
> -               int i;                                                  \
> -               printf("%s: length: %d\n", func, length);               \
> -               for (i = 0; i < length; i++) {                          \
> -                       if (i % 8 == 0)                                 \
> -                               printf("\n%s: %02x: ", func, i);        \
> -                       printf("%02x ", ((unsigned char *) packet)[i]); \
> -               } printf("\n");                                         \
> -       } while(0)
> -#else
> -#define DM9000_DMP_PACKET(func,packet,length)
> -#endif
> -
>  /* Structure/enum declaration ------------------------------- */
>  typedef struct board_info {
>         u32 runt_length_counter;        /* counter: RX length < 64byte */
> @@ -122,6 +103,25 @@ static void dm9000_iow(int reg, u8 value);
>  #define dm9000_inl(r) __raw_readl(r)
>  #endif
>
> +#ifdef DEBUG
> +static void dm9000_dump_packet(const char *func, u8 *packet, int length)
> +{
> +       int i;
> +
> +       printf("%s: length: %d\n", func, length);
> +
> +       for (i = 0; i < length; i++) {
> +               if (i % 8 == 0)
> +                       printf("\n%s: %02x: ", func, i);
> +               printf("%02x ", packet[i]);
> +       }
> +
> +       printf("\n");
> +}
> +#else
> +static void dm9000_dump_packet(const char *func, u8 *packet, int length) {}
> +#endif
> +
>  static void dm9000_outblk_8bit(volatile void *data_ptr, int count)
>  {
>         int i;
> @@ -387,7 +387,7 @@ static int dm9000_send(struct eth_device *netdev, void *packet, int length)
>         int tmo;
>         struct board_info *db = &dm9000_info;
>
> -       DM9000_DMP_PACKET(__func__ , packet, length);
> +       dm9000_dump_packet(__func__ , packet, length);
>
>         dm9000_iow(DM9000_ISR, IMR_PTM); /* Clear Tx bit in ISR */
>
> @@ -498,7 +498,7 @@ static int dm9000_rx(struct eth_device *netdev)
>                                 dm9000_reset();
>                         }
>                 } else {
> -                       DM9000_DMP_PACKET(__func__ , rdptr, rxlen);
> +                       dm9000_dump_packet(__func__ , rdptr, rxlen);
>
>                         debug("passing packet to upper layer\n");
>                         net_process_received_packet(net_rx_packets[0], rxlen);
> --
> 2.35.1
>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH 06/16] net: dm9000: Drop volatiles
  2022-04-11 17:55 ` [PATCH 06/16] net: dm9000: Drop volatiles Marek Vasut
@ 2022-04-12 19:47   ` Ramon Fried
  0 siblings, 0 replies; 32+ messages in thread
From: Ramon Fried @ 2022-04-12 19:47 UTC (permalink / raw)
  To: Marek Vasut
  Cc: U-Boot Mailing List, Marcel Ziswiler, Tom Rini, Joe Hershberger

On Mon, Apr 11, 2022 at 8:56 PM Marek Vasut <marex@denx.de> wrote:
>
> Remove volatile keyword usage from arrays, they are not really volatile
> in any way, so this keyword is misused here. No functional change.
>
> Signed-off-by: Marek Vasut <marex@denx.de>
> Cc: Joe Hershberger <joe.hershberger@ni.com>
> Cc: Ramon Fried <rfried.dev@gmail.com>
> ---
>  drivers/net/dm9000x.c | 20 ++++++++++----------
>  1 file changed, 10 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/net/dm9000x.c b/drivers/net/dm9000x.c
> index da16b64610b..aacf5f670e9 100644
> --- a/drivers/net/dm9000x.c
> +++ b/drivers/net/dm9000x.c
> @@ -71,7 +71,7 @@ typedef struct board_info {
>         u8 phy_addr;
>         u8 device_wait_reset;   /* device state */
>         unsigned char srom[128];
> -       void (*outblk)(volatile void *data_ptr, int count);
> +       void (*outblk)(void *data_ptr, int count);
>         void (*inblk)(void *data_ptr, int count);
>         void (*rx_status)(u16 *rxstatus, u16 *rxlen);
>         struct eth_device netdev;
> @@ -88,12 +88,12 @@ static void dm9000_iow(int reg, u8 value);
>
>  /* DM9000 network board routine ---------------------------- */
>  #ifndef CONFIG_DM9000_BYTE_SWAPPED
> -#define dm9000_outb(d,r) writeb(d, (volatile u8 *)(r))
> -#define dm9000_outw(d,r) writew(d, (volatile u16 *)(r))
> -#define dm9000_outl(d,r) writel(d, (volatile u32 *)(r))
> -#define dm9000_inb(r) readb((volatile u8 *)(r))
> -#define dm9000_inw(r) readw((volatile u16 *)(r))
> -#define dm9000_inl(r) readl((volatile u32 *)(r))
> +#define dm9000_outb(d,r) writeb((d), (r))
> +#define dm9000_outw(d,r) writew((d), (r))
> +#define dm9000_outl(d,r) writel((d), (r))
> +#define dm9000_inb(r) readb(r)
> +#define dm9000_inw(r) readw(r)
> +#define dm9000_inl(r) readl(r)
>  #else
>  #define dm9000_outb(d, r) __raw_writeb(d, r)
>  #define dm9000_outw(d, r) __raw_writew(d, r)
> @@ -122,14 +122,14 @@ static void dm9000_dump_packet(const char *func, u8 *packet, int length)
>  static void dm9000_dump_packet(const char *func, u8 *packet, int length) {}
>  #endif
>
> -static void dm9000_outblk_8bit(volatile void *data_ptr, int count)
> +static void dm9000_outblk_8bit(void *data_ptr, int count)
>  {
>         int i;
>         for (i = 0; i < count; i++)
>                 dm9000_outb((((u8 *) data_ptr)[i] & 0xff), DM9000_DATA);
>  }
>
> -static void dm9000_outblk_16bit(volatile void *data_ptr, int count)
> +static void dm9000_outblk_16bit(void *data_ptr, int count)
>  {
>         int i;
>         u32 tmplen = (count + 1) / 2;
> @@ -137,7 +137,7 @@ static void dm9000_outblk_16bit(volatile void *data_ptr, int count)
>         for (i = 0; i < tmplen; i++)
>                 dm9000_outw(((u16 *) data_ptr)[i], DM9000_DATA);
>  }
> -static void dm9000_outblk_32bit(volatile void *data_ptr, int count)
> +static void dm9000_outblk_32bit(void *data_ptr, int count)
>  {
>         int i;
>         u32 tmplen = (count + 3) / 4;
> --
> 2.35.1
>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH 07/16] net: dm9000: Checkpatch cleanup
  2022-04-11 17:55 ` [PATCH 07/16] net: dm9000: Checkpatch cleanup Marek Vasut
@ 2022-04-12 19:47   ` Ramon Fried
  0 siblings, 0 replies; 32+ messages in thread
From: Ramon Fried @ 2022-04-12 19:47 UTC (permalink / raw)
  To: Marek Vasut
  Cc: U-Boot Mailing List, Marcel Ziswiler, Tom Rini, Joe Hershberger

On Mon, Apr 11, 2022 at 8:56 PM Marek Vasut <marex@denx.de> wrote:
>
> Fix checkpatch errors and warnings. No functional change.
>
> Signed-off-by: Marek Vasut <marex@denx.de>
> Cc: Joe Hershberger <joe.hershberger@ni.com>
> Cc: Ramon Fried <rfried.dev@gmail.com>
> ---
>  drivers/net/dm9000x.c | 251 +++++++++++++++++++++---------------------
>  1 file changed, 126 insertions(+), 125 deletions(-)
>
> diff --git a/drivers/net/dm9000x.c b/drivers/net/dm9000x.c
> index aacf5f670e9..becf7aec828 100644
> --- a/drivers/net/dm9000x.c
> +++ b/drivers/net/dm9000x.c
> @@ -1,53 +1,53 @@
>  // SPDX-License-Identifier: GPL-2.0+
>  /*
> -  dm9000.c: Version 1.2 12/15/2003
> -
> -       A Davicom DM9000 ISA NIC fast Ethernet driver for Linux.
> -       Copyright (C) 1997  Sten Wang
> -
> -  (C)Copyright 1997-1998 DAVICOM Semiconductor,Inc. All Rights Reserved.
> -
> -V0.11  06/20/2001      REG_0A bit3=1, default enable BP with DA match
> -       06/22/2001      Support DM9801 progrmming
> -                       E3: R25 = ((R24 + NF) & 0x00ff) | 0xf000
> -                       E4: R25 = ((R24 + NF) & 0x00ff) | 0xc200
> -               R17 = (R17 & 0xfff0) | NF + 3
> -                       E5: R25 = ((R24 + NF - 3) & 0x00ff) | 0xc200
> -               R17 = (R17 & 0xfff0) | NF
> -
> -v1.00                  modify by simon 2001.9.5
> -                       change for kernel 2.4.x
> -
> -v1.1   11/09/2001      fix force mode bug
> -
> -v1.2   03/18/2003       Weilun Huang <weilun_huang@davicom.com.tw>:
> -                       Fixed phy reset.
> -                       Added tx/rx 32 bit mode.
> -                       Cleaned up for kernel merge.
> -
> ---------------------------------------
> -
> -       12/15/2003       Initial port to u-boot by
> -                       Sascha Hauer <saschahauer@web.de>
> -
> -       06/03/2008      Remy Bohmer <linux@bohmer.net>
> -                       - Fixed the driver to work with DM9000A.
> -                         (check on ISR receive status bit before reading the
> -                         FIFO as described in DM9000 programming guide and
> -                         application notes)
> -                       - Added autodetect of databus width.
> -                       - Made debug code compile again.
> -                       - Adapt eth_send such that it matches the DM9000*
> -                         application notes. Needed to make it work properly
> -                         for DM9000A.
> -                       - Adapted reset procedure to match DM9000 application
> -                         notes (i.e. double reset)
> -                       - some minor code cleanups
> -                       These changes are tested with DM9000{A,EP,E} together
> -                       with a 200MHz Atmel AT91SAM9261 core
> -
> -TODO: external MII is not functional, only internal at the moment.
> -*/
> + *   dm9000.c: Version 1.2 12/15/2003
> + *
> + *     A Davicom DM9000 ISA NIC fast Ethernet driver for Linux.
> + *     Copyright (C) 1997  Sten Wang
> + *
> + *   (C)Copyright 1997-1998 DAVICOM Semiconductor,Inc. All Rights Reserved.
> + *
> + * V0.11       06/20/2001      REG_0A bit3=1, default enable BP with DA match
> + *     06/22/2001      Support DM9801 progrmming
> + *                     E3: R25 = ((R24 + NF) & 0x00ff) | 0xf000
> + *                     E4: R25 = ((R24 + NF) & 0x00ff) | 0xc200
> + *             R17 = (R17 & 0xfff0) | NF + 3
> + *                     E5: R25 = ((R24 + NF - 3) & 0x00ff) | 0xc200
> + *             R17 = (R17 & 0xfff0) | NF
> + *
> + * v1.00                       modify by simon 2001.9.5
> + *                     change for kernel 2.4.x
> + *
> + * v1.1   11/09/2001   fix force mode bug
> + *
> + * v1.2   03/18/2003       Weilun Huang <weilun_huang@davicom.com.tw>:
> + *                     Fixed phy reset.
> + *                     Added tx/rx 32 bit mode.
> + *                     Cleaned up for kernel merge.
> + *
> + * --------------------------------------
> + *
> + *        12/15/2003       Initial port to u-boot by
> + *                     Sascha Hauer <saschahauer@web.de>
> + *
> + *        06/03/2008   Remy Bohmer <linux@bohmer.net>
> + *                     - Fixed the driver to work with DM9000A.
> + *                       (check on ISR receive status bit before reading the
> + *                       FIFO as described in DM9000 programming guide and
> + *                       application notes)
> + *                     - Added autodetect of databus width.
> + *                     - Made debug code compile again.
> + *                     - Adapt eth_send such that it matches the DM9000*
> + *                       application notes. Needed to make it work properly
> + *                       for DM9000A.
> + *                     - Adapted reset procedure to match DM9000 application
> + *                       notes (i.e. double reset)
> + *                     - some minor code cleanups
> + *                     These changes are tested with DM9000{A,EP,E} together
> + *                     with a 200MHz Atmel AT91SAM9261 core
> + *
> + * TODO: external MII is not functional, only internal at the moment.
> + */
>
>  #include <common.h>
>  #include <command.h>
> @@ -59,7 +59,7 @@ TODO: external MII is not functional, only internal at the moment.
>  #include "dm9000x.h"
>
>  /* Structure/enum declaration ------------------------------- */
> -typedef struct board_info {
> +struct board_info {
>         u32 runt_length_counter;        /* counter: RX length < 64byte */
>         u32 long_length_counter;        /* counter: RX length > 1514byte */
>         u32 reset_counter;      /* counter: RESET */
> @@ -75,9 +75,9 @@ typedef struct board_info {
>         void (*inblk)(void *data_ptr, int count);
>         void (*rx_status)(u16 *rxstatus, u16 *rxlen);
>         struct eth_device netdev;
> -} board_info_t;
> -static board_info_t dm9000_info;
> +};
>
> +static struct board_info dm9000_info;
>
>  /* function declaration ------------------------------------- */
>  static int dm9000_probe(void);
> @@ -88,9 +88,9 @@ static void dm9000_iow(int reg, u8 value);
>
>  /* DM9000 network board routine ---------------------------- */
>  #ifndef CONFIG_DM9000_BYTE_SWAPPED
> -#define dm9000_outb(d,r) writeb((d), (r))
> -#define dm9000_outw(d,r) writew((d), (r))
> -#define dm9000_outl(d,r) writel((d), (r))
> +#define dm9000_outb(d, r) writeb((d), (r))
> +#define dm9000_outw(d, r) writew((d), (r))
> +#define dm9000_outl(d, r) writel((d), (r))
>  #define dm9000_inb(r) readb(r)
>  #define dm9000_inw(r) readw(r)
>  #define dm9000_inl(r) readl(r)
> @@ -125,8 +125,9 @@ static void dm9000_dump_packet(const char *func, u8 *packet, int length) {}
>  static void dm9000_outblk_8bit(void *data_ptr, int count)
>  {
>         int i;
> +
>         for (i = 0; i < count; i++)
> -               dm9000_outb((((u8 *) data_ptr)[i] & 0xff), DM9000_DATA);
> +               dm9000_outb((((u8 *)data_ptr)[i] & 0xff), DM9000_DATA);
>  }
>
>  static void dm9000_outblk_16bit(void *data_ptr, int count)
> @@ -135,22 +136,24 @@ static void dm9000_outblk_16bit(void *data_ptr, int count)
>         u32 tmplen = (count + 1) / 2;
>
>         for (i = 0; i < tmplen; i++)
> -               dm9000_outw(((u16 *) data_ptr)[i], DM9000_DATA);
> +               dm9000_outw(((u16 *)data_ptr)[i], DM9000_DATA);
>  }
> +
>  static void dm9000_outblk_32bit(void *data_ptr, int count)
>  {
>         int i;
>         u32 tmplen = (count + 3) / 4;
>
>         for (i = 0; i < tmplen; i++)
> -               dm9000_outl(((u32 *) data_ptr)[i], DM9000_DATA);
> +               dm9000_outl(((u32 *)data_ptr)[i], DM9000_DATA);
>  }
>
>  static void dm9000_inblk_8bit(void *data_ptr, int count)
>  {
>         int i;
> +
>         for (i = 0; i < count; i++)
> -               ((u8 *) data_ptr)[i] = dm9000_inb(DM9000_DATA);
> +               ((u8 *)data_ptr)[i] = dm9000_inb(DM9000_DATA);
>  }
>
>  static void dm9000_inblk_16bit(void *data_ptr, int count)
> @@ -159,15 +162,16 @@ static void dm9000_inblk_16bit(void *data_ptr, int count)
>         u32 tmplen = (count + 1) / 2;
>
>         for (i = 0; i < tmplen; i++)
> -               ((u16 *) data_ptr)[i] = dm9000_inw(DM9000_DATA);
> +               ((u16 *)data_ptr)[i] = dm9000_inw(DM9000_DATA);
>  }
> +
>  static void dm9000_inblk_32bit(void *data_ptr, int count)
>  {
>         int i;
>         u32 tmplen = (count + 3) / 4;
>
>         for (i = 0; i < tmplen; i++)
> -               ((u32 *) data_ptr)[i] = dm9000_inl(DM9000_DATA);
> +               ((u32 *)data_ptr)[i] = dm9000_inl(DM9000_DATA);
>  }
>
>  static void dm9000_rx_status_32bit(u16 *rxstatus, u16 *rxlen)
> @@ -202,25 +206,25 @@ static void dm9000_rx_status_8bit(u16 *rxstatus, u16 *rxlen)
>  }
>
>  /*
> -  Search DM9000 board, allocate space and register it
> -*/
> + * Search DM9000 board, allocate space and register it
> + */
>  int
>  dm9000_probe(void)
>  {
>         u32 id_val;
> +
>         id_val = dm9000_ior(DM9000_VIDL);
>         id_val |= dm9000_ior(DM9000_VIDH) << 8;
>         id_val |= dm9000_ior(DM9000_PIDL) << 16;
>         id_val |= dm9000_ior(DM9000_PIDH) << 24;
> -       if (id_val == DM9000_ID) {
> -               printf("dm9000 i/o: 0x%x, id: 0x%x \n", CONFIG_DM9000_BASE,
> -                      id_val);
> -               return 0;
> -       } else {
> +       if (id_val != DM9000_ID) {
>                 printf("dm9000 not found at 0x%08x id: 0x%08x\n",
>                        CONFIG_DM9000_BASE, id_val);
>                 return -1;
>         }
> +
> +       printf("dm9000 i/o: 0x%x, id: 0x%x\n", CONFIG_DM9000_BASE, id_val);
> +       return 0;
>  }
>
>  /* General Purpose dm9000 reset routine */
> @@ -229,8 +233,10 @@ dm9000_reset(void)
>  {
>         debug("resetting DM9000\n");
>
> -       /* Reset DM9000,
> -          see DM9000 Application Notes V1.22 Jun 11, 2004 page 29 */
> +       /*
> +        * Reset DM9000,
> +        * see DM9000 Application Notes V1.22 Jun 11, 2004 page 29
> +        */
>
>         /* DEBUG: Make all GPIO0 outputs, all others inputs */
>         dm9000_iow(DM9000_GPCR, GPCR_GPIO0_OUT);
> @@ -258,16 +264,13 @@ dm9000_reset(void)
>                 printf("ERROR: resetting DM9000 -> not responding\n");
>  }
>
> -/* Initialize dm9000 board
> -*/
> +/* Initialize dm9000 board */
>  static int dm9000_init(struct eth_device *dev, struct bd_info *bd)
>  {
>         int i, oft, lnk;
>         u8 io_mode;
>         struct board_info *db = &dm9000_info;
>
> -       debug("%s\n", __func__);
> -
>         /* RESET device */
>         dm9000_reset();
>
> @@ -323,9 +326,8 @@ static int dm9000_init(struct eth_device *dev, struct bd_info *bd)
>         dm9000_iow(DM9000_ISR, ISR_ROOS | ISR_ROS | ISR_PTS | ISR_PRS);
>
>         printf("MAC: %pM\n", dev->enetaddr);
> -       if (!is_valid_ethaddr(dev->enetaddr)) {
> +       if (!is_valid_ethaddr(dev->enetaddr))
>                 printf("WARNING: Bad MAC address (uninitialized EEPROM?)\n");
> -       }
>
>         /* fill device MAC address registers */
>         for (i = 0, oft = DM9000_PAR; i < 6; i++, oft++)
> @@ -379,15 +381,15 @@ static int dm9000_init(struct eth_device *dev, struct bd_info *bd)
>  }
>
>  /*
> -  Hardware start transmission.
> -  Send a packet to media from the upper layer.
> -*/
> + * Hardware start transmission.
> + * Send a packet to media from the upper layer.
> + */
>  static int dm9000_send(struct eth_device *netdev, void *packet, int length)
>  {
>         int tmo;
>         struct board_info *db = &dm9000_info;
>
> -       dm9000_dump_packet(__func__ , packet, length);
> +       dm9000_dump_packet(__func__, packet, length);
>
>         dm9000_iow(DM9000_ISR, IMR_PTM); /* Clear Tx bit in ISR */
>
> @@ -395,7 +397,7 @@ static int dm9000_send(struct eth_device *netdev, void *packet, int length)
>         dm9000_outb(DM9000_MWCMD, DM9000_IO); /* Prepare for TX-data */
>
>         /* push the data to the TX-fifo */
> -       (db->outblk)(packet, length);
> +       db->outblk(packet, length);
>
>         /* Set TX length to DM9000 */
>         dm9000_iow(DM9000_TXPLL, length & 0xff);
> @@ -406,8 +408,8 @@ static int dm9000_send(struct eth_device *netdev, void *packet, int length)
>
>         /* wait for end of transmission */
>         tmo = get_timer(0) + 5 * CONFIG_SYS_HZ;
> -       while ( !(dm9000_ior(DM9000_NSR) & (NSR_TX1END | NSR_TX2END)) ||
> -               !(dm9000_ior(DM9000_ISR) & IMR_PTM) ) {
> +       while (!(dm9000_ior(DM9000_NSR) & (NSR_TX1END | NSR_TX2END)) ||
> +              !(dm9000_ior(DM9000_ISR) & IMR_PTM)) {
>                 if (get_timer(0) >= tmo) {
>                         printf("transmission timeout\n");
>                         break;
> @@ -420,14 +422,12 @@ static int dm9000_send(struct eth_device *netdev, void *packet, int length)
>  }
>
>  /*
> -  Stop the interface.
> -  The interface is stopped when it is brought.
> -*/
> + * Stop the interface.
> + * The interface is stopped when it is brought.
> + */
>  static void dm9000_halt(struct eth_device *netdev)
>  {
> -       debug("%s\n", __func__);
> -
> -       /* RESET devie */
> +       /* RESET device */
>         dm9000_phy_write(0, 0x8000);    /* PHY RESET */
>         dm9000_iow(DM9000_GPR, 0x01);   /* Power-Down PHY */
>         dm9000_iow(DM9000_IMR, 0x80);   /* Disable all interrupt */
> @@ -435,8 +435,8 @@ static void dm9000_halt(struct eth_device *netdev)
>  }
>
>  /*
> -  Received a packet and pass to upper layer
> -*/
> + * Received a packet and pass to upper layer
> + */
>  static int dm9000_rx(struct eth_device *netdev)
>  {
>         u8 rxbyte;
> @@ -444,8 +444,10 @@ static int dm9000_rx(struct eth_device *netdev)
>         u16 rxstatus, rxlen = 0;
>         struct board_info *db = &dm9000_info;
>
> -       /* Check packet ready or not, we must check
> -          the ISR status first for DM9000A */
> +       /*
> +        * Check packet ready or not, we must check
> +        * the ISR status first for DM9000A
> +        */
>         if (!(dm9000_ior(DM9000_ISR) & 0x01)) /* Rx-ISR bit must be set. */
>                 return 0;
>
> @@ -455,8 +457,10 @@ static int dm9000_rx(struct eth_device *netdev)
>         for (;;) {
>                 dm9000_ior(DM9000_MRCMDX);      /* Dummy read */
>
> -               /* Get most updated data,
> -                  only look at bits 0:1, See application notes DM9000 */
> +               /*
> +                * Get most updated data,
> +                * only look at bits 0:1, See application notes DM9000
> +                */
>                 rxbyte = dm9000_inb(DM9000_DATA) & 0x03;
>
>                 /* Status check: this byte must be 0 or 1 */
> @@ -464,7 +468,7 @@ static int dm9000_rx(struct eth_device *netdev)
>                         dm9000_iow(DM9000_RCR, 0x00);   /* Stop Device */
>                         dm9000_iow(DM9000_ISR, 0x80);   /* Stop INT request */
>                         printf("DM9000 error: status check fail: 0x%x\n",
> -                               rxbyte);
> +                              rxbyte);
>                         return 0;
>                 }
>
> @@ -474,31 +478,28 @@ static int dm9000_rx(struct eth_device *netdev)
>                 debug("receiving packet\n");
>
>                 /* A packet ready now  & Get status/length */
> -               (db->rx_status)(&rxstatus, &rxlen);
> +               db->rx_status(&rxstatus, &rxlen);
>
>                 debug("rx status: 0x%04x rx len: %d\n", rxstatus, rxlen);
>
>                 /* Move data from DM9000 */
>                 /* Read received packet from RX SRAM */
> -               (db->inblk)(rdptr, rxlen);
> +               db->inblk(rdptr, rxlen);
>
> -               if ((rxstatus & 0xbf00) || (rxlen < 0x40)
> -                       || (rxlen > DM9000_PKT_MAX)) {
> -                       if (rxstatus & 0x100) {
> +               if (rxstatus & 0xbf00 || rxlen < 0x40 ||
> +                   rxlen > DM9000_PKT_MAX) {
> +                       if (rxstatus & 0x100)
>                                 printf("rx fifo error\n");
> -                       }
> -                       if (rxstatus & 0x200) {
> +                       if (rxstatus & 0x200)
>                                 printf("rx crc error\n");
> -                       }
> -                       if (rxstatus & 0x8000) {
> +                       if (rxstatus & 0x8000)
>                                 printf("rx length error\n");
> -                       }
>                         if (rxlen > DM9000_PKT_MAX) {
>                                 printf("rx length too big\n");
>                                 dm9000_reset();
>                         }
>                 } else {
> -                       dm9000_dump_packet(__func__ , rdptr, rxlen);
> +                       dm9000_dump_packet(__func__, rdptr, rxlen);
>
>                         debug("passing packet to upper layer\n");
>                         net_process_received_packet(net_rx_packets[0], rxlen);
> @@ -508,14 +509,14 @@ static int dm9000_rx(struct eth_device *netdev)
>  }
>
>  /*
> -  Read a word data from SROM
> -*/
> + * Read a word data from SROM
> + */
>  #if !defined(CONFIG_DM9000_NO_SROM)
>  void dm9000_read_srom_word(int offset, u8 *to)
>  {
>         dm9000_iow(DM9000_EPAR, offset);
>         dm9000_iow(DM9000_EPCR, 0x4);
> -       udelay(8000);
> +       mdelay(8);
>         dm9000_iow(DM9000_EPCR, 0x0);
>         to[0] = dm9000_ior(DM9000_EPDRL);
>         to[1] = dm9000_ior(DM9000_EPDRH);
> @@ -527,23 +528,24 @@ void dm9000_write_srom_word(int offset, u16 val)
>         dm9000_iow(DM9000_EPDRH, ((val >> 8) & 0xff));
>         dm9000_iow(DM9000_EPDRL, (val & 0xff));
>         dm9000_iow(DM9000_EPCR, 0x12);
> -       udelay(8000);
> +       mdelay(8);
>         dm9000_iow(DM9000_EPCR, 0);
>  }
> -#endif
>
>  static void dm9000_get_enetaddr(struct eth_device *dev)
>  {
> -#if !defined(CONFIG_DM9000_NO_SROM)
>         int i;
> +
>         for (i = 0; i < 3; i++)
>                 dm9000_read_srom_word(i, dev->enetaddr + (2 * i));
> -#endif
>  }
> +#else
> +static void dm9000_get_enetaddr(struct eth_device *dev) {}
> +#endif
>
>  /*
> -   Read a byte from I/O port
> -*/
> + *  Read a byte from I/O port
> + */
>  static u8
>  dm9000_ior(int reg)
>  {
> @@ -552,8 +554,8 @@ dm9000_ior(int reg)
>  }
>
>  /*
> -   Write a byte to I/O port
> -*/
> + *  Write a byte to I/O port
> + */
>  static void
>  dm9000_iow(int reg, u8 value)
>  {
> @@ -562,8 +564,8 @@ dm9000_iow(int reg, u8 value)
>  }
>
>  /*
> -   Read a word from phyxcer
> -*/
> + *  Read a word from phyxcer
> + */
>  static u16
>  dm9000_phy_read(int reg)
>  {
> @@ -577,17 +579,16 @@ dm9000_phy_read(int reg)
>         val = (dm9000_ior(DM9000_EPDRH) << 8) | dm9000_ior(DM9000_EPDRL);
>
>         /* The read data keeps on REG_0D & REG_0E */
> -       debug("dm9000_phy_read(0x%x): 0x%x\n", reg, val);
> +       debug("%s(0x%x): 0x%x\n", __func__, reg, val);
>         return val;
>  }
>
>  /*
> -   Write a word to phyxcer
> -*/
> + *  Write a word to phyxcer
> + */
>  static void
>  dm9000_phy_write(int reg, u16 value)
>  {
> -
>         /* Fill the phyxcer register into REG_0C */
>         dm9000_iow(DM9000_EPAR, DM9000_PHY | reg);
>
> @@ -597,12 +598,12 @@ dm9000_phy_write(int reg, u16 value)
>         dm9000_iow(DM9000_EPCR, 0xa);   /* Issue phyxcer write command */
>         udelay(500);                    /* Wait write complete */
>         dm9000_iow(DM9000_EPCR, 0x0);   /* Clear phyxcer write command */
> -       debug("dm9000_phy_write(reg:0x%x, value:0x%x)\n", reg, value);
> +       debug("%s(reg:0x%x, value:0x%x)\n", __func__, reg, value);
>  }
>
>  int dm9000_initialize(struct bd_info *bis)
>  {
> -       struct eth_device *dev = &(dm9000_info.netdev);
> +       struct eth_device *dev = &dm9000_info.netdev;
>
>         /* Load MAC address from EEPROM */
>         dm9000_get_enetaddr(dev);
> --
> 2.35.1
>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH 08/16] net: dm9000: Reorder and staticize
  2022-04-11 17:55 ` [PATCH 08/16] net: dm9000: Reorder and staticize Marek Vasut
@ 2022-04-12 19:48   ` Ramon Fried
  0 siblings, 0 replies; 32+ messages in thread
From: Ramon Fried @ 2022-04-12 19:48 UTC (permalink / raw)
  To: Marek Vasut
  Cc: U-Boot Mailing List, Marcel Ziswiler, Tom Rini, Joe Hershberger

On Mon, Apr 11, 2022 at 8:56 PM Marek Vasut <marex@denx.de> wrote:
>
> Reorder the driver functions to get rid of forward declarations.
> Staticize whatever is possible. No functional change.
>
> Signed-off-by: Marek Vasut <marex@denx.de>
> Cc: Joe Hershberger <joe.hershberger@ni.com>
> Cc: Ramon Fried <rfried.dev@gmail.com>
> ---
>  drivers/net/dm9000x.c | 122 +++++++++++++++++++-----------------------
>  1 file changed, 55 insertions(+), 67 deletions(-)
>
> diff --git a/drivers/net/dm9000x.c b/drivers/net/dm9000x.c
> index becf7aec828..85f3c079ec1 100644
> --- a/drivers/net/dm9000x.c
> +++ b/drivers/net/dm9000x.c
> @@ -79,13 +79,6 @@ struct board_info {
>
>  static struct board_info dm9000_info;
>
> -/* function declaration ------------------------------------- */
> -static int dm9000_probe(void);
> -static u16 dm9000_phy_read(int);
> -static void dm9000_phy_write(int, u16);
> -static u8 dm9000_ior(int);
> -static void dm9000_iow(int reg, u8 value);
> -
>  /* DM9000 network board routine ---------------------------- */
>  #ifndef CONFIG_DM9000_BYTE_SWAPPED
>  #define dm9000_outb(d, r) writeb((d), (r))
> @@ -205,11 +198,64 @@ static void dm9000_rx_status_8bit(u16 *rxstatus, u16 *rxlen)
>                           (dm9000_inb(DM9000_DATA) << 8));
>  }
>
> +/*
> + *  Read a byte from I/O port
> + */
> +static u8 dm9000_ior(int reg)
> +{
> +       dm9000_outb(reg, DM9000_IO);
> +       return dm9000_inb(DM9000_DATA);
> +}
> +
> +/*
> + *  Write a byte to I/O port
> + */
> +static void dm9000_iow(int reg, u8 value)
> +{
> +       dm9000_outb(reg, DM9000_IO);
> +       dm9000_outb(value, DM9000_DATA);
> +}
> +
> +/*
> + *  Read a word from phyxcer
> + */
> +static u16 dm9000_phy_read(int reg)
> +{
> +       u16 val;
> +
> +       /* Fill the phyxcer register into REG_0C */
> +       dm9000_iow(DM9000_EPAR, DM9000_PHY | reg);
> +       dm9000_iow(DM9000_EPCR, 0xc);   /* Issue phyxcer read command */
> +       udelay(100);                    /* Wait read complete */
> +       dm9000_iow(DM9000_EPCR, 0x0);   /* Clear phyxcer read command */
> +       val = (dm9000_ior(DM9000_EPDRH) << 8) | dm9000_ior(DM9000_EPDRL);
> +
> +       /* The read data keeps on REG_0D & REG_0E */
> +       debug("%s(0x%x): 0x%x\n", __func__, reg, val);
> +       return val;
> +}
> +
> +/*
> + *  Write a word to phyxcer
> + */
> +static void dm9000_phy_write(int reg, u16 value)
> +{
> +       /* Fill the phyxcer register into REG_0C */
> +       dm9000_iow(DM9000_EPAR, DM9000_PHY | reg);
> +
> +       /* Fill the written data into REG_0D & REG_0E */
> +       dm9000_iow(DM9000_EPDRL, (value & 0xff));
> +       dm9000_iow(DM9000_EPDRH, ((value >> 8) & 0xff));
> +       dm9000_iow(DM9000_EPCR, 0xa);   /* Issue phyxcer write command */
> +       udelay(500);                    /* Wait write complete */
> +       dm9000_iow(DM9000_EPCR, 0x0);   /* Clear phyxcer write command */
> +       debug("%s(reg:0x%x, value:0x%x)\n", __func__, reg, value);
> +}
> +
>  /*
>   * Search DM9000 board, allocate space and register it
>   */
> -int
> -dm9000_probe(void)
> +static int dm9000_probe(void)
>  {
>         u32 id_val;
>
> @@ -543,64 +589,6 @@ static void dm9000_get_enetaddr(struct eth_device *dev)
>  static void dm9000_get_enetaddr(struct eth_device *dev) {}
>  #endif
>
> -/*
> - *  Read a byte from I/O port
> - */
> -static u8
> -dm9000_ior(int reg)
> -{
> -       dm9000_outb(reg, DM9000_IO);
> -       return dm9000_inb(DM9000_DATA);
> -}
> -
> -/*
> - *  Write a byte to I/O port
> - */
> -static void
> -dm9000_iow(int reg, u8 value)
> -{
> -       dm9000_outb(reg, DM9000_IO);
> -       dm9000_outb(value, DM9000_DATA);
> -}
> -
> -/*
> - *  Read a word from phyxcer
> - */
> -static u16
> -dm9000_phy_read(int reg)
> -{
> -       u16 val;
> -
> -       /* Fill the phyxcer register into REG_0C */
> -       dm9000_iow(DM9000_EPAR, DM9000_PHY | reg);
> -       dm9000_iow(DM9000_EPCR, 0xc);   /* Issue phyxcer read command */
> -       udelay(100);                    /* Wait read complete */
> -       dm9000_iow(DM9000_EPCR, 0x0);   /* Clear phyxcer read command */
> -       val = (dm9000_ior(DM9000_EPDRH) << 8) | dm9000_ior(DM9000_EPDRL);
> -
> -       /* The read data keeps on REG_0D & REG_0E */
> -       debug("%s(0x%x): 0x%x\n", __func__, reg, val);
> -       return val;
> -}
> -
> -/*
> - *  Write a word to phyxcer
> - */
> -static void
> -dm9000_phy_write(int reg, u16 value)
> -{
> -       /* Fill the phyxcer register into REG_0C */
> -       dm9000_iow(DM9000_EPAR, DM9000_PHY | reg);
> -
> -       /* Fill the written data into REG_0D & REG_0E */
> -       dm9000_iow(DM9000_EPDRL, (value & 0xff));
> -       dm9000_iow(DM9000_EPDRH, ((value >> 8) & 0xff));
> -       dm9000_iow(DM9000_EPCR, 0xa);   /* Issue phyxcer write command */
> -       udelay(500);                    /* Wait write complete */
> -       dm9000_iow(DM9000_EPCR, 0x0);   /* Clear phyxcer write command */
> -       debug("%s(reg:0x%x, value:0x%x)\n", __func__, reg, value);
> -}
> -
>  int dm9000_initialize(struct bd_info *bis)
>  {
>         struct eth_device *dev = &dm9000_info.netdev;
> --
> 2.35.1
>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH 09/16] net: dm9000: Rename board_info to dm9000_priv
  2022-04-11 17:56 ` [PATCH 09/16] net: dm9000: Rename board_info to dm9000_priv Marek Vasut
@ 2022-04-12 19:48   ` Ramon Fried
  0 siblings, 0 replies; 32+ messages in thread
From: Ramon Fried @ 2022-04-12 19:48 UTC (permalink / raw)
  To: Marek Vasut
  Cc: U-Boot Mailing List, Marcel Ziswiler, Tom Rini, Joe Hershberger

On Mon, Apr 11, 2022 at 8:56 PM Marek Vasut <marex@denx.de> wrote:
>
> Rename board_info structure to dm9000_priv to make it clear what this
> structure really contains, the driver private data. No functional change.
>
> Signed-off-by: Marek Vasut <marex@denx.de>
> Cc: Joe Hershberger <joe.hershberger@ni.com>
> Cc: Ramon Fried <rfried.dev@gmail.com>
> ---
>  drivers/net/dm9000x.c | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/net/dm9000x.c b/drivers/net/dm9000x.c
> index 85f3c079ec1..7e1368a1be9 100644
> --- a/drivers/net/dm9000x.c
> +++ b/drivers/net/dm9000x.c
> @@ -59,7 +59,7 @@
>  #include "dm9000x.h"
>
>  /* Structure/enum declaration ------------------------------- */
> -struct board_info {
> +struct dm9000_priv {
>         u32 runt_length_counter;        /* counter: RX length < 64byte */
>         u32 long_length_counter;        /* counter: RX length > 1514byte */
>         u32 reset_counter;      /* counter: RESET */
> @@ -77,7 +77,7 @@ struct board_info {
>         struct eth_device netdev;
>  };
>
> -static struct board_info dm9000_info;
> +static struct dm9000_priv dm9000_info;
>
>  /* DM9000 network board routine ---------------------------- */
>  #ifndef CONFIG_DM9000_BYTE_SWAPPED
> @@ -315,7 +315,7 @@ static int dm9000_init(struct eth_device *dev, struct bd_info *bd)
>  {
>         int i, oft, lnk;
>         u8 io_mode;
> -       struct board_info *db = &dm9000_info;
> +       struct dm9000_priv *db = &dm9000_info;
>
>         /* RESET device */
>         dm9000_reset();
> @@ -433,7 +433,7 @@ static int dm9000_init(struct eth_device *dev, struct bd_info *bd)
>  static int dm9000_send(struct eth_device *netdev, void *packet, int length)
>  {
>         int tmo;
> -       struct board_info *db = &dm9000_info;
> +       struct dm9000_priv *db = &dm9000_info;
>
>         dm9000_dump_packet(__func__, packet, length);
>
> @@ -488,7 +488,7 @@ static int dm9000_rx(struct eth_device *netdev)
>         u8 rxbyte;
>         u8 *rdptr = (u8 *)net_rx_packets[0];
>         u16 rxstatus, rxlen = 0;
> -       struct board_info *db = &dm9000_info;
> +       struct dm9000_priv *db = &dm9000_info;
>
>         /*
>          * Check packet ready or not, we must check
> --
> 2.35.1
>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH 10/16] net: dm9000: Drop static device private data
  2022-04-11 17:56 ` [PATCH 10/16] net: dm9000: Drop static device private data Marek Vasut
@ 2022-04-12 19:49   ` Ramon Fried
  0 siblings, 0 replies; 32+ messages in thread
From: Ramon Fried @ 2022-04-12 19:49 UTC (permalink / raw)
  To: Marek Vasut
  Cc: U-Boot Mailing List, Marcel Ziswiler, Tom Rini, Joe Hershberger

On Mon, Apr 11, 2022 at 8:56 PM Marek Vasut <marex@denx.de> wrote:
>
> Allocate driver private data dynamically in its init function and drop
> the static driver private data variable. Pass the dynamic private data
> throughout the driver. This is done in preparation for DM conversion.
>
> Signed-off-by: Marek Vasut <marex@denx.de>
> Cc: Joe Hershberger <joe.hershberger@ni.com>
> Cc: Ramon Fried <rfried.dev@gmail.com>
> ---
>  drivers/net/dm9000x.c | 24 +++++++++++++-----------
>  1 file changed, 13 insertions(+), 11 deletions(-)
>
> diff --git a/drivers/net/dm9000x.c b/drivers/net/dm9000x.c
> index 7e1368a1be9..666883ee19e 100644
> --- a/drivers/net/dm9000x.c
> +++ b/drivers/net/dm9000x.c
> @@ -77,8 +77,6 @@ struct dm9000_priv {
>         struct eth_device netdev;
>  };
>
> -static struct dm9000_priv dm9000_info;
> -
>  /* DM9000 network board routine ---------------------------- */
>  #ifndef CONFIG_DM9000_BYTE_SWAPPED
>  #define dm9000_outb(d, r) writeb((d), (r))
> @@ -313,9 +311,9 @@ dm9000_reset(void)
>  /* Initialize dm9000 board */
>  static int dm9000_init(struct eth_device *dev, struct bd_info *bd)
>  {
> +       struct dm9000_priv *db = container_of(dev, struct dm9000_priv, dev);
>         int i, oft, lnk;
>         u8 io_mode;
> -       struct dm9000_priv *db = &dm9000_info;
>
>         /* RESET device */
>         dm9000_reset();
> @@ -430,10 +428,10 @@ static int dm9000_init(struct eth_device *dev, struct bd_info *bd)
>   * Hardware start transmission.
>   * Send a packet to media from the upper layer.
>   */
> -static int dm9000_send(struct eth_device *netdev, void *packet, int length)
> +static int dm9000_send(struct eth_device *dev, void *packet, int length)
>  {
> +       struct dm9000_priv *db = container_of(dev, struct dm9000_priv, dev);
>         int tmo;
> -       struct dm9000_priv *db = &dm9000_info;
>
>         dm9000_dump_packet(__func__, packet, length);
>
> @@ -483,12 +481,12 @@ static void dm9000_halt(struct eth_device *netdev)
>  /*
>   * Received a packet and pass to upper layer
>   */
> -static int dm9000_rx(struct eth_device *netdev)
> +static int dm9000_rx(struct eth_device *dev)
>  {
> +       struct dm9000_priv *db = container_of(dev, struct dm9000_priv, dev);
>         u8 rxbyte;
>         u8 *rdptr = (u8 *)net_rx_packets[0];
>         u16 rxstatus, rxlen = 0;
> -       struct dm9000_priv *db = &dm9000_info;
>
>         /*
>          * Check packet ready or not, we must check
> @@ -591,18 +589,22 @@ static void dm9000_get_enetaddr(struct eth_device *dev) {}
>
>  int dm9000_initialize(struct bd_info *bis)
>  {
> -       struct eth_device *dev = &dm9000_info.netdev;
> +       struct dm9000_priv *priv;
> +
> +       priv = kcalloc(1, sizeof(*priv));
> +       if (!priv)
> +               return -ENOMEM;
>
>         /* Load MAC address from EEPROM */
> -       dm9000_get_enetaddr(dev);
> +       dm9000_get_enetaddr(&priv->dev);
>
>         dev->init = dm9000_init;
>         dev->halt = dm9000_halt;
>         dev->send = dm9000_send;
>         dev->recv = dm9000_rx;
> -       strcpy(dev->name, "dm9000");
> +       strcpy(&priv->dev.name, "dm9000");
>
> -       eth_register(dev);
> +       eth_register(&priv->dev);
>
>         return 0;
>  }
> --
> 2.35.1
>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH 11/16] net: dm9000: Drop dm9000.h and staticize SROM access
  2022-04-11 17:56 ` [PATCH 11/16] net: dm9000: Drop dm9000.h and staticize SROM access Marek Vasut
@ 2022-04-12 19:49   ` Ramon Fried
  0 siblings, 0 replies; 32+ messages in thread
From: Ramon Fried @ 2022-04-12 19:49 UTC (permalink / raw)
  To: Marek Vasut
  Cc: U-Boot Mailing List, Marcel Ziswiler, Tom Rini, Joe Hershberger

On Mon, Apr 11, 2022 at 8:56 PM Marek Vasut <marex@denx.de> wrote:
>
> Dispose of dm9000.h because none of the function prototypes declared in
> it are called anywhere in the codebase. Staticize dm9000_read_srom_word()
> because it is now called only from within the dm9000 driver. Drop
> dm9000_write_srom_word() because it is no longer used.
>
> Signed-off-by: Marek Vasut <marex@denx.de>
> Cc: Joe Hershberger <joe.hershberger@ni.com>
> Cc: Ramon Fried <rfried.dev@gmail.com>
> ---
>  drivers/net/dm9000x.c | 13 +------------
>  include/dm9000.h      | 16 ----------------
>  2 files changed, 1 insertion(+), 28 deletions(-)
>  delete mode 100644 include/dm9000.h
>
> diff --git a/drivers/net/dm9000x.c b/drivers/net/dm9000x.c
> index 666883ee19e..3c0d848b10f 100644
> --- a/drivers/net/dm9000x.c
> +++ b/drivers/net/dm9000x.c
> @@ -53,7 +53,6 @@
>  #include <command.h>
>  #include <net.h>
>  #include <asm/io.h>
> -#include <dm9000.h>
>  #include <linux/delay.h>
>
>  #include "dm9000x.h"
> @@ -556,7 +555,7 @@ static int dm9000_rx(struct eth_device *dev)
>   * Read a word data from SROM
>   */
>  #if !defined(CONFIG_DM9000_NO_SROM)
> -void dm9000_read_srom_word(int offset, u8 *to)
> +static void dm9000_read_srom_word(int offset, u8 *to)
>  {
>         dm9000_iow(DM9000_EPAR, offset);
>         dm9000_iow(DM9000_EPCR, 0x4);
> @@ -566,16 +565,6 @@ void dm9000_read_srom_word(int offset, u8 *to)
>         to[1] = dm9000_ior(DM9000_EPDRH);
>  }
>
> -void dm9000_write_srom_word(int offset, u16 val)
> -{
> -       dm9000_iow(DM9000_EPAR, offset);
> -       dm9000_iow(DM9000_EPDRH, ((val >> 8) & 0xff));
> -       dm9000_iow(DM9000_EPDRL, (val & 0xff));
> -       dm9000_iow(DM9000_EPCR, 0x12);
> -       mdelay(8);
> -       dm9000_iow(DM9000_EPCR, 0);
> -}
> -
>  static void dm9000_get_enetaddr(struct eth_device *dev)
>  {
>         int i;
> diff --git a/include/dm9000.h b/include/dm9000.h
> deleted file mode 100644
> index f780e513f69..00000000000
> --- a/include/dm9000.h
> +++ /dev/null
> @@ -1,16 +0,0 @@
> -/* SPDX-License-Identifier: GPL-2.0+ */
> -/*
> - * NOTE:        DAVICOM DM9000 ethernet driver interface
> - *
> - * Authors:     Remy Bohmer <linux@bohmer.net>
> - */
> -#ifndef __DM9000_H__
> -#define __DM9000_H__
> -
> -/******************  function prototypes **********************/
> -#if !defined(CONFIG_DM9000_NO_SROM)
> -void dm9000_write_srom_word(int offset, u16 val);
> -void dm9000_read_srom_word(int offset, u8 *to);
> -#endif
> -
> -#endif /* __DM9000_H__ */
> --
> 2.35.1
>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH 12/16] net: dm9000: Pass private data around for IO
  2022-04-11 17:56 ` [PATCH 12/16] net: dm9000: Pass private data around for IO Marek Vasut
@ 2022-04-12 19:50   ` Ramon Fried
  0 siblings, 0 replies; 32+ messages in thread
From: Ramon Fried @ 2022-04-12 19:50 UTC (permalink / raw)
  To: Marek Vasut
  Cc: U-Boot Mailing List, Marcel Ziswiler, Tom Rini, Joe Hershberger

On Mon, Apr 11, 2022 at 8:56 PM Marek Vasut <marex@denx.de> wrote:
>
> Pass private data into IO accessors and use the base addresses of
> IO and DATA window from the private data instead of using the hard
> coded macros DM9000_IO/DM9000_DATA. Currently both the DM9000_IO
> and DM9000_DATA are assigned to the respecive private data fields
> for the non-DM case backward compatibility.
>
> Signed-off-by: Marek Vasut <marex@denx.de>
> Cc: Joe Hershberger <joe.hershberger@ni.com>
> Cc: Ramon Fried <rfried.dev@gmail.com>
> ---
>  drivers/net/dm9000x.c | 230 ++++++++++++++++++++++--------------------
>  1 file changed, 119 insertions(+), 111 deletions(-)
>
> diff --git a/drivers/net/dm9000x.c b/drivers/net/dm9000x.c
> index 3c0d848b10f..54b8f848397 100644
> --- a/drivers/net/dm9000x.c
> +++ b/drivers/net/dm9000x.c
> @@ -70,10 +70,12 @@ struct dm9000_priv {
>         u8 phy_addr;
>         u8 device_wait_reset;   /* device state */
>         unsigned char srom[128];
> -       void (*outblk)(void *data_ptr, int count);
> -       void (*inblk)(void *data_ptr, int count);
> -       void (*rx_status)(u16 *rxstatus, u16 *rxlen);
> +       void (*outblk)(struct dm9000_priv *db, void *data_ptr, int count);
> +       void (*inblk)(struct dm9000_priv *db, void *data_ptr, int count);
> +       void (*rx_status)(struct dm9000_priv *db, u16 *rxstatus, u16 *rxlen);
>         struct eth_device netdev;
> +       phys_addr_t base_io;
> +       phys_addr_t base_data;
>  };
>
>  /* DM9000 network board routine ---------------------------- */
> @@ -112,120 +114,121 @@ static void dm9000_dump_packet(const char *func, u8 *packet, int length)
>  static void dm9000_dump_packet(const char *func, u8 *packet, int length) {}
>  #endif
>
> -static void dm9000_outblk_8bit(void *data_ptr, int count)
> +static void dm9000_outblk_8bit(struct dm9000_priv *db, void *data_ptr, int count)
>  {
>         int i;
>
>         for (i = 0; i < count; i++)
> -               dm9000_outb((((u8 *)data_ptr)[i] & 0xff), DM9000_DATA);
> +               dm9000_outb((((u8 *)data_ptr)[i] & 0xff), db->base_data);
>  }
>
> -static void dm9000_outblk_16bit(void *data_ptr, int count)
> +static void dm9000_outblk_16bit(struct dm9000_priv *db, void *data_ptr, int count)
>  {
>         int i;
>         u32 tmplen = (count + 1) / 2;
>
>         for (i = 0; i < tmplen; i++)
> -               dm9000_outw(((u16 *)data_ptr)[i], DM9000_DATA);
> +               dm9000_outw(((u16 *)data_ptr)[i], db->base_data);
>  }
>
> -static void dm9000_outblk_32bit(void *data_ptr, int count)
> +static void dm9000_outblk_32bit(struct dm9000_priv *db, void *data_ptr, int count)
>  {
>         int i;
>         u32 tmplen = (count + 3) / 4;
>
>         for (i = 0; i < tmplen; i++)
> -               dm9000_outl(((u32 *)data_ptr)[i], DM9000_DATA);
> +               dm9000_outl(((u32 *)data_ptr)[i], db->base_data);
>  }
>
> -static void dm9000_inblk_8bit(void *data_ptr, int count)
> +static void dm9000_inblk_8bit(struct dm9000_priv *db, void *data_ptr, int count)
>  {
>         int i;
>
>         for (i = 0; i < count; i++)
> -               ((u8 *)data_ptr)[i] = dm9000_inb(DM9000_DATA);
> +               ((u8 *)data_ptr)[i] = dm9000_inb(db->base_data);
>  }
>
> -static void dm9000_inblk_16bit(void *data_ptr, int count)
> +static void dm9000_inblk_16bit(struct dm9000_priv *db, void *data_ptr, int count)
>  {
>         int i;
>         u32 tmplen = (count + 1) / 2;
>
>         for (i = 0; i < tmplen; i++)
> -               ((u16 *)data_ptr)[i] = dm9000_inw(DM9000_DATA);
> +               ((u16 *)data_ptr)[i] = dm9000_inw(db->base_data);
>  }
>
> -static void dm9000_inblk_32bit(void *data_ptr, int count)
> +static void dm9000_inblk_32bit(struct dm9000_priv *db, void *data_ptr, int count)
>  {
>         int i;
>         u32 tmplen = (count + 3) / 4;
>
>         for (i = 0; i < tmplen; i++)
> -               ((u32 *)data_ptr)[i] = dm9000_inl(DM9000_DATA);
> +               ((u32 *)data_ptr)[i] = dm9000_inl(db->base_data);
>  }
>
> -static void dm9000_rx_status_32bit(u16 *rxstatus, u16 *rxlen)
> +static void dm9000_rx_status_32bit(struct dm9000_priv *db, u16 *rxstatus, u16 *rxlen)
>  {
>         u32 tmpdata;
>
> -       dm9000_outb(DM9000_MRCMD, DM9000_IO);
> +       dm9000_outb(DM9000_MRCMD, db->base_io);
>
> -       tmpdata = dm9000_inl(DM9000_DATA);
> +       tmpdata = dm9000_inl(db->base_data);
>         *rxstatus = __le16_to_cpu(tmpdata);
>         *rxlen = __le16_to_cpu(tmpdata >> 16);
>  }
>
> -static void dm9000_rx_status_16bit(u16 *rxstatus, u16 *rxlen)
> +static void dm9000_rx_status_16bit(struct dm9000_priv *db, u16 *rxstatus, u16 *rxlen)
>  {
> -       dm9000_outb(DM9000_MRCMD, DM9000_IO);
> +       dm9000_outb(DM9000_MRCMD, db->base_io);
>
> -       *rxstatus = __le16_to_cpu(dm9000_inw(DM9000_DATA));
> -       *rxlen = __le16_to_cpu(dm9000_inw(DM9000_DATA));
> +       *rxstatus = __le16_to_cpu(dm9000_inw(db->base_data));
> +       *rxlen = __le16_to_cpu(dm9000_inw(db->base_data));
>  }
>
> -static void dm9000_rx_status_8bit(u16 *rxstatus, u16 *rxlen)
> +static void dm9000_rx_status_8bit(struct dm9000_priv *db, u16 *rxstatus, u16 *rxlen)
>  {
> -       dm9000_outb(DM9000_MRCMD, DM9000_IO);
> +       dm9000_outb(DM9000_MRCMD, db->base_io);
>
>         *rxstatus =
> -           __le16_to_cpu(dm9000_inb(DM9000_DATA) +
> -                         (dm9000_inb(DM9000_DATA) << 8));
> +           __le16_to_cpu(dm9000_inb(db->base_data) +
> +                         (dm9000_inb(db->base_data) << 8));
>         *rxlen =
> -           __le16_to_cpu(dm9000_inb(DM9000_DATA) +
> -                         (dm9000_inb(DM9000_DATA) << 8));
> +           __le16_to_cpu(dm9000_inb(db->base_data) +
> +                         (dm9000_inb(db->base_data) << 8));
>  }
>
>  /*
>   *  Read a byte from I/O port
>   */
> -static u8 dm9000_ior(int reg)
> +static u8 dm9000_ior(struct dm9000_priv *db, int reg)
>  {
> -       dm9000_outb(reg, DM9000_IO);
> -       return dm9000_inb(DM9000_DATA);
> +       dm9000_outb(reg, db->base_io);
> +       return dm9000_inb(db->base_data);
>  }
>
>  /*
>   *  Write a byte to I/O port
>   */
> -static void dm9000_iow(int reg, u8 value)
> +static void dm9000_iow(struct dm9000_priv *db, int reg, u8 value)
>  {
> -       dm9000_outb(reg, DM9000_IO);
> -       dm9000_outb(value, DM9000_DATA);
> +       dm9000_outb(reg, db->base_io);
> +       dm9000_outb(value, db->base_data);
>  }
>
>  /*
>   *  Read a word from phyxcer
>   */
> -static u16 dm9000_phy_read(int reg)
> +static u16 dm9000_phy_read(struct dm9000_priv *db, int reg)
>  {
>         u16 val;
>
>         /* Fill the phyxcer register into REG_0C */
> -       dm9000_iow(DM9000_EPAR, DM9000_PHY | reg);
> -       dm9000_iow(DM9000_EPCR, 0xc);   /* Issue phyxcer read command */
> +       dm9000_iow(db, DM9000_EPAR, DM9000_PHY | reg);
> +       dm9000_iow(db, DM9000_EPCR, 0xc);       /* Issue phyxcer read command */
>         udelay(100);                    /* Wait read complete */
> -       dm9000_iow(DM9000_EPCR, 0x0);   /* Clear phyxcer read command */
> -       val = (dm9000_ior(DM9000_EPDRH) << 8) | dm9000_ior(DM9000_EPDRL);
> +       dm9000_iow(db, DM9000_EPCR, 0x0);       /* Clear phyxcer read command */
> +       val = (dm9000_ior(db, DM9000_EPDRH) << 8) |
> +             dm9000_ior(db, DM9000_EPDRL);
>
>         /* The read data keeps on REG_0D & REG_0E */
>         debug("%s(0x%x): 0x%x\n", __func__, reg, val);
> @@ -235,44 +238,43 @@ static u16 dm9000_phy_read(int reg)
>  /*
>   *  Write a word to phyxcer
>   */
> -static void dm9000_phy_write(int reg, u16 value)
> +static void dm9000_phy_write(struct dm9000_priv *db, int reg, u16 value)
>  {
>         /* Fill the phyxcer register into REG_0C */
> -       dm9000_iow(DM9000_EPAR, DM9000_PHY | reg);
> +       dm9000_iow(db, DM9000_EPAR, DM9000_PHY | reg);
>
>         /* Fill the written data into REG_0D & REG_0E */
> -       dm9000_iow(DM9000_EPDRL, (value & 0xff));
> -       dm9000_iow(DM9000_EPDRH, ((value >> 8) & 0xff));
> -       dm9000_iow(DM9000_EPCR, 0xa);   /* Issue phyxcer write command */
> +       dm9000_iow(db, DM9000_EPDRL, (value & 0xff));
> +       dm9000_iow(db, DM9000_EPDRH, ((value >> 8) & 0xff));
> +       dm9000_iow(db, DM9000_EPCR, 0xa);       /* Issue phyxcer write command */
>         udelay(500);                    /* Wait write complete */
> -       dm9000_iow(DM9000_EPCR, 0x0);   /* Clear phyxcer write command */
> +       dm9000_iow(db, DM9000_EPCR, 0x0);       /* Clear phyxcer write command */
>         debug("%s(reg:0x%x, value:0x%x)\n", __func__, reg, value);
>  }
>
>  /*
>   * Search DM9000 board, allocate space and register it
>   */
> -static int dm9000_probe(void)
> +static int dm9000_probe(struct dm9000_priv *db)
>  {
>         u32 id_val;
>
> -       id_val = dm9000_ior(DM9000_VIDL);
> -       id_val |= dm9000_ior(DM9000_VIDH) << 8;
> -       id_val |= dm9000_ior(DM9000_PIDL) << 16;
> -       id_val |= dm9000_ior(DM9000_PIDH) << 24;
> +       id_val = dm9000_ior(db, DM9000_VIDL);
> +       id_val |= dm9000_ior(db, DM9000_VIDH) << 8;
> +       id_val |= dm9000_ior(db, DM9000_PIDL) << 16;
> +       id_val |= dm9000_ior(db, DM9000_PIDH) << 24;
>         if (id_val != DM9000_ID) {
> -               printf("dm9000 not found at 0x%08x id: 0x%08x\n",
> -                      CONFIG_DM9000_BASE, id_val);
> +               printf("dm9000 not found at 0x%08lx id: 0x%08x\n",
> +                      db->base_io, id_val);
>                 return -1;
>         }
>
> -       printf("dm9000 i/o: 0x%x, id: 0x%x\n", CONFIG_DM9000_BASE, id_val);
> +       printf("dm9000 i/o: 0x%lx, id: 0x%x\n", db->base_io, id_val);
>         return 0;
>  }
>
>  /* General Purpose dm9000 reset routine */
> -static void
> -dm9000_reset(void)
> +static void dm9000_reset(struct dm9000_priv *db)
>  {
>         debug("resetting DM9000\n");
>
> @@ -282,28 +284,28 @@ dm9000_reset(void)
>          */
>
>         /* DEBUG: Make all GPIO0 outputs, all others inputs */
> -       dm9000_iow(DM9000_GPCR, GPCR_GPIO0_OUT);
> +       dm9000_iow(db, DM9000_GPCR, GPCR_GPIO0_OUT);
>         /* Step 1: Power internal PHY by writing 0 to GPIO0 pin */
> -       dm9000_iow(DM9000_GPR, 0);
> +       dm9000_iow(db, DM9000_GPR, 0);
>         /* Step 2: Software reset */
> -       dm9000_iow(DM9000_NCR, (NCR_LBK_INT_MAC | NCR_RST));
> +       dm9000_iow(db, DM9000_NCR, (NCR_LBK_INT_MAC | NCR_RST));
>
>         do {
>                 debug("resetting the DM9000, 1st reset\n");
>                 udelay(25); /* Wait at least 20 us */
> -       } while (dm9000_ior(DM9000_NCR) & 1);
> +       } while (dm9000_ior(db, DM9000_NCR) & 1);
>
> -       dm9000_iow(DM9000_NCR, 0);
> -       dm9000_iow(DM9000_NCR, (NCR_LBK_INT_MAC | NCR_RST)); /* Issue a second reset */
> +       dm9000_iow(db, DM9000_NCR, 0);
> +       dm9000_iow(db, DM9000_NCR, (NCR_LBK_INT_MAC | NCR_RST)); /* Issue a second reset */
>
>         do {
>                 debug("resetting the DM9000, 2nd reset\n");
>                 udelay(25); /* Wait at least 20 us */
> -       } while (dm9000_ior(DM9000_NCR) & 1);
> +       } while (dm9000_ior(db, DM9000_NCR) & 1);
>
>         /* Check whether the ethernet controller is present */
> -       if ((dm9000_ior(DM9000_PIDL) != 0x0) ||
> -           (dm9000_ior(DM9000_PIDH) != 0x90))
> +       if ((dm9000_ior(db, DM9000_PIDL) != 0x0) ||
> +           (dm9000_ior(db, DM9000_PIDH) != 0x90))
>                 printf("ERROR: resetting DM9000 -> not responding\n");
>  }
>
> @@ -315,13 +317,13 @@ static int dm9000_init(struct eth_device *dev, struct bd_info *bd)
>         u8 io_mode;
>
>         /* RESET device */
> -       dm9000_reset();
> +       dm9000_reset(db);
>
> -       if (dm9000_probe() < 0)
> +       if (dm9000_probe(db) < 0)
>                 return -1;
>
>         /* Auto-detect 8/16/32 bit mode, ISR Bit 6+7 indicate bus width */
> -       io_mode = dm9000_ior(DM9000_ISR) >> 6;
> +       io_mode = dm9000_ior(db, DM9000_ISR) >> 6;
>
>         switch (io_mode) {
>         case 0x0:  /* 16-bit mode */
> @@ -352,21 +354,21 @@ static int dm9000_init(struct eth_device *dev, struct bd_info *bd)
>         }
>
>         /* Program operating register, only internal phy supported */
> -       dm9000_iow(DM9000_NCR, 0x0);
> +       dm9000_iow(db, DM9000_NCR, 0x0);
>         /* TX Polling clear */
> -       dm9000_iow(DM9000_TCR, 0);
> +       dm9000_iow(db, DM9000_TCR, 0);
>         /* Less 3Kb, 200us */
> -       dm9000_iow(DM9000_BPTR, BPTR_BPHW(3) | BPTR_JPT_600US);
> +       dm9000_iow(db, DM9000_BPTR, BPTR_BPHW(3) | BPTR_JPT_600US);
>         /* Flow Control : High/Low Water */
> -       dm9000_iow(DM9000_FCTR, FCTR_HWOT(3) | FCTR_LWOT(8));
> +       dm9000_iow(db, DM9000_FCTR, FCTR_HWOT(3) | FCTR_LWOT(8));
>         /* SH FIXME: This looks strange! Flow Control */
> -       dm9000_iow(DM9000_FCR, 0x0);
> +       dm9000_iow(db, DM9000_FCR, 0x0);
>         /* Special Mode */
> -       dm9000_iow(DM9000_SMCR, 0);
> +       dm9000_iow(db, DM9000_SMCR, 0);
>         /* clear TX status */
> -       dm9000_iow(DM9000_NSR, NSR_WAKEST | NSR_TX2END | NSR_TX1END);
> +       dm9000_iow(db, DM9000_NSR, NSR_WAKEST | NSR_TX2END | NSR_TX1END);
>         /* Clear interrupt status */
> -       dm9000_iow(DM9000_ISR, ISR_ROOS | ISR_ROS | ISR_PTS | ISR_PRS);
> +       dm9000_iow(db, DM9000_ISR, ISR_ROOS | ISR_ROS | ISR_PTS | ISR_PRS);
>
>         printf("MAC: %pM\n", dev->enetaddr);
>         if (!is_valid_ethaddr(dev->enetaddr))
> @@ -374,23 +376,23 @@ static int dm9000_init(struct eth_device *dev, struct bd_info *bd)
>
>         /* fill device MAC address registers */
>         for (i = 0, oft = DM9000_PAR; i < 6; i++, oft++)
> -               dm9000_iow(oft, dev->enetaddr[i]);
> +               dm9000_iow(db, oft, dev->enetaddr[i]);
>         for (i = 0, oft = 0x16; i < 8; i++, oft++)
> -               dm9000_iow(oft, 0xff);
> +               dm9000_iow(db, oft, 0xff);
>
>         /* read back mac, just to be sure */
>         for (i = 0, oft = 0x10; i < 6; i++, oft++)
> -               debug("%02x:", dm9000_ior(oft));
> +               debug("%02x:", dm9000_ior(db, oft));
>         debug("\n");
>
>         /* Activate DM9000 */
>         /* RX enable */
> -       dm9000_iow(DM9000_RCR, RCR_DIS_LONG | RCR_DIS_CRC | RCR_RXEN);
> +       dm9000_iow(db, DM9000_RCR, RCR_DIS_LONG | RCR_DIS_CRC | RCR_RXEN);
>         /* Enable TX/RX interrupt mask */
> -       dm9000_iow(DM9000_IMR, IMR_PAR);
> +       dm9000_iow(db, DM9000_IMR, IMR_PAR);
>
>         i = 0;
> -       while (!(dm9000_phy_read(1) & 0x20)) {  /* autonegation complete bit */
> +       while (!(dm9000_phy_read(db, 1) & 0x20)) {      /* autonegation complete bit */
>                 udelay(1000);
>                 i++;
>                 if (i == 10000) {
> @@ -400,7 +402,7 @@ static int dm9000_init(struct eth_device *dev, struct bd_info *bd)
>         }
>
>         /* see what we've got */
> -       lnk = dm9000_phy_read(17) >> 12;
> +       lnk = dm9000_phy_read(db, 17) >> 12;
>         printf("operating at ");
>         switch (lnk) {
>         case 1:
> @@ -434,31 +436,31 @@ static int dm9000_send(struct eth_device *dev, void *packet, int length)
>
>         dm9000_dump_packet(__func__, packet, length);
>
> -       dm9000_iow(DM9000_ISR, IMR_PTM); /* Clear Tx bit in ISR */
> +       dm9000_iow(db, DM9000_ISR, IMR_PTM); /* Clear Tx bit in ISR */
>
>         /* Move data to DM9000 TX RAM */
> -       dm9000_outb(DM9000_MWCMD, DM9000_IO); /* Prepare for TX-data */
> +       dm9000_outb(DM9000_MWCMD, db->base_io); /* Prepare for TX-data */
>
>         /* push the data to the TX-fifo */
> -       db->outblk(packet, length);
> +       db->outblk(db, packet, length);
>
>         /* Set TX length to DM9000 */
> -       dm9000_iow(DM9000_TXPLL, length & 0xff);
> -       dm9000_iow(DM9000_TXPLH, (length >> 8) & 0xff);
> +       dm9000_iow(db, DM9000_TXPLL, length & 0xff);
> +       dm9000_iow(db, DM9000_TXPLH, (length >> 8) & 0xff);
>
>         /* Issue TX polling command */
> -       dm9000_iow(DM9000_TCR, TCR_TXREQ); /* Cleared after TX complete */
> +       dm9000_iow(db, DM9000_TCR, TCR_TXREQ); /* Cleared after TX complete */
>
>         /* wait for end of transmission */
>         tmo = get_timer(0) + 5 * CONFIG_SYS_HZ;
> -       while (!(dm9000_ior(DM9000_NSR) & (NSR_TX1END | NSR_TX2END)) ||
> -              !(dm9000_ior(DM9000_ISR) & IMR_PTM)) {
> +       while (!(dm9000_ior(db, DM9000_NSR) & (NSR_TX1END | NSR_TX2END)) ||
> +              !(dm9000_ior(db, DM9000_ISR) & IMR_PTM)) {
>                 if (get_timer(0) >= tmo) {
>                         printf("transmission timeout\n");
>                         break;
>                 }
>         }
> -       dm9000_iow(DM9000_ISR, IMR_PTM); /* Clear Tx bit in ISR */
> +       dm9000_iow(db, DM9000_ISR, IMR_PTM); /* Clear Tx bit in ISR */
>
>         debug("transmit done\n\n");
>         return 0;
> @@ -470,11 +472,13 @@ static int dm9000_send(struct eth_device *dev, void *packet, int length)
>   */
>  static void dm9000_halt(struct eth_device *netdev)
>  {
> +       struct dm9000_priv *db = container_of(dev, struct dm9000_priv, dev);
> +
>         /* RESET device */
> -       dm9000_phy_write(0, 0x8000);    /* PHY RESET */
> -       dm9000_iow(DM9000_GPR, 0x01);   /* Power-Down PHY */
> -       dm9000_iow(DM9000_IMR, 0x80);   /* Disable all interrupt */
> -       dm9000_iow(DM9000_RCR, 0x00);   /* Disable RX */
> +       dm9000_phy_write(db, 0, 0x8000);        /* PHY RESET */
> +       dm9000_iow(db, DM9000_GPR, 0x01);       /* Power-Down PHY */
> +       dm9000_iow(db, DM9000_IMR, 0x80);       /* Disable all interrupt */
> +       dm9000_iow(db, DM9000_RCR, 0x00);       /* Disable RX */
>  }
>
>  /*
> @@ -491,25 +495,25 @@ static int dm9000_rx(struct eth_device *dev)
>          * Check packet ready or not, we must check
>          * the ISR status first for DM9000A
>          */
> -       if (!(dm9000_ior(DM9000_ISR) & 0x01)) /* Rx-ISR bit must be set. */
> +       if (!(dm9000_ior(db, DM9000_ISR) & 0x01)) /* Rx-ISR bit must be set. */
>                 return 0;
>
> -       dm9000_iow(DM9000_ISR, 0x01); /* clear PR status latched in bit 0 */
> +       dm9000_iow(db, DM9000_ISR, 0x01); /* clear PR status latched in bit 0 */
>
>         /* There is _at least_ 1 package in the fifo, read them all */
>         for (;;) {
> -               dm9000_ior(DM9000_MRCMDX);      /* Dummy read */
> +               dm9000_ior(db, DM9000_MRCMDX);  /* Dummy read */
>
>                 /*
>                  * Get most updated data,
>                  * only look at bits 0:1, See application notes DM9000
>                  */
> -               rxbyte = dm9000_inb(DM9000_DATA) & 0x03;
> +               rxbyte = dm9000_inb(db->base_data) & 0x03;
>
>                 /* Status check: this byte must be 0 or 1 */
>                 if (rxbyte > DM9000_PKT_RDY) {
> -                       dm9000_iow(DM9000_RCR, 0x00);   /* Stop Device */
> -                       dm9000_iow(DM9000_ISR, 0x80);   /* Stop INT request */
> +                       dm9000_iow(db, DM9000_RCR, 0x00);       /* Stop Device */
> +                       dm9000_iow(db, DM9000_ISR, 0x80);       /* Stop INT request */
>                         printf("DM9000 error: status check fail: 0x%x\n",
>                                rxbyte);
>                         return 0;
> @@ -521,13 +525,13 @@ static int dm9000_rx(struct eth_device *dev)
>                 debug("receiving packet\n");
>
>                 /* A packet ready now  & Get status/length */
> -               db->rx_status(&rxstatus, &rxlen);
> +               db->rx_status(db, &rxstatus, &rxlen);
>
>                 debug("rx status: 0x%04x rx len: %d\n", rxstatus, rxlen);
>
>                 /* Move data from DM9000 */
>                 /* Read received packet from RX SRAM */
> -               db->inblk(rdptr, rxlen);
> +               db->inblk(db, rdptr, rxlen);
>
>                 if (rxstatus & 0xbf00 || rxlen < 0x40 ||
>                     rxlen > DM9000_PKT_MAX) {
> @@ -539,7 +543,7 @@ static int dm9000_rx(struct eth_device *dev)
>                                 printf("rx length error\n");
>                         if (rxlen > DM9000_PKT_MAX) {
>                                 printf("rx length too big\n");
> -                               dm9000_reset();
> +                               dm9000_reset(db);
>                         }
>                 } else {
>                         dm9000_dump_packet(__func__, rdptr, rxlen);
> @@ -555,22 +559,23 @@ static int dm9000_rx(struct eth_device *dev)
>   * Read a word data from SROM
>   */
>  #if !defined(CONFIG_DM9000_NO_SROM)
> -static void dm9000_read_srom_word(int offset, u8 *to)
> +static void dm9000_read_srom_word(struct dm9000_priv *db, int offset, u8 *to)
>  {
> -       dm9000_iow(DM9000_EPAR, offset);
> -       dm9000_iow(DM9000_EPCR, 0x4);
> +       dm9000_iow(db, DM9000_EPAR, offset);
> +       dm9000_iow(db, DM9000_EPCR, 0x4);
>         mdelay(8);
> -       dm9000_iow(DM9000_EPCR, 0x0);
> -       to[0] = dm9000_ior(DM9000_EPDRL);
> -       to[1] = dm9000_ior(DM9000_EPDRH);
> +       dm9000_iow(db, DM9000_EPCR, 0x0);
> +       to[0] = dm9000_ior(db, DM9000_EPDRL);
> +       to[1] = dm9000_ior(db, DM9000_EPDRH);
>  }
>
>  static void dm9000_get_enetaddr(struct eth_device *dev)
>  {
> +       struct dm9000_priv *db = container_of(dev, struct dm9000_priv, dev);
>         int i;
>
>         for (i = 0; i < 3; i++)
> -               dm9000_read_srom_word(i, dev->enetaddr + (2 * i));
> +               dm9000_read_srom_word(db, i, dev->enetaddr + (2 * i));
>  }
>  #else
>  static void dm9000_get_enetaddr(struct eth_device *dev) {}
> @@ -584,6 +589,9 @@ int dm9000_initialize(struct bd_info *bis)
>         if (!priv)
>                 return -ENOMEM;
>
> +       priv->base_io = DM9000_IO;
> +       priv->base_data = DM9000_DATA;
> +
>         /* Load MAC address from EEPROM */
>         dm9000_get_enetaddr(&priv->dev);
>
> --
> 2.35.1
>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH 13/16] net: dm9000: Split non-DM specific bits from common code
  2022-04-11 17:56 ` [PATCH 13/16] net: dm9000: Split non-DM specific bits from common code Marek Vasut
@ 2022-04-12 19:51   ` Ramon Fried
  0 siblings, 0 replies; 32+ messages in thread
From: Ramon Fried @ 2022-04-12 19:51 UTC (permalink / raw)
  To: Marek Vasut
  Cc: U-Boot Mailing List, Marcel Ziswiler, Tom Rini, Joe Hershberger

On Mon, Apr 11, 2022 at 8:56 PM Marek Vasut <marex@denx.de> wrote:
>
> Split network handling functions into non-DM specific parts and
> common code in preparation for conversion to DM.
>
> Signed-off-by: Marek Vasut <marex@denx.de>
> Cc: Joe Hershberger <joe.hershberger@ni.com>
> Cc: Ramon Fried <rfried.dev@gmail.com>
> ---
>  drivers/net/dm9000x.c | 58 +++++++++++++++++++++++++++++--------------
>  1 file changed, 40 insertions(+), 18 deletions(-)
>
> diff --git a/drivers/net/dm9000x.c b/drivers/net/dm9000x.c
> index 54b8f848397..97084d16ffa 100644
> --- a/drivers/net/dm9000x.c
> +++ b/drivers/net/dm9000x.c
> @@ -310,9 +310,8 @@ static void dm9000_reset(struct dm9000_priv *db)
>  }
>
>  /* Initialize dm9000 board */
> -static int dm9000_init(struct eth_device *dev, struct bd_info *bd)
> +static int dm9000_init_common(struct dm9000_priv *db, u8 enetaddr[6])
>  {
> -       struct dm9000_priv *db = container_of(dev, struct dm9000_priv, dev);
>         int i, oft, lnk;
>         u8 io_mode;
>
> @@ -370,13 +369,13 @@ static int dm9000_init(struct eth_device *dev, struct bd_info *bd)
>         /* Clear interrupt status */
>         dm9000_iow(db, DM9000_ISR, ISR_ROOS | ISR_ROS | ISR_PTS | ISR_PRS);
>
> -       printf("MAC: %pM\n", dev->enetaddr);
> -       if (!is_valid_ethaddr(dev->enetaddr))
> +       printf("MAC: %pM\n", enetaddr);
> +       if (!is_valid_ethaddr(enetaddr))
>                 printf("WARNING: Bad MAC address (uninitialized EEPROM?)\n");
>
>         /* fill device MAC address registers */
>         for (i = 0, oft = DM9000_PAR; i < 6; i++, oft++)
> -               dm9000_iow(db, oft, dev->enetaddr[i]);
> +               dm9000_iow(db, oft, enetaddr[i]);
>         for (i = 0, oft = 0x16; i < 8; i++, oft++)
>                 dm9000_iow(db, oft, 0xff);
>
> @@ -429,9 +428,8 @@ static int dm9000_init(struct eth_device *dev, struct bd_info *bd)
>   * Hardware start transmission.
>   * Send a packet to media from the upper layer.
>   */
> -static int dm9000_send(struct eth_device *dev, void *packet, int length)
> +static int dm9000_send_common(struct dm9000_priv *db, void *packet, int length)
>  {
> -       struct dm9000_priv *db = container_of(dev, struct dm9000_priv, dev);
>         int tmo;
>
>         dm9000_dump_packet(__func__, packet, length);
> @@ -470,10 +468,8 @@ static int dm9000_send(struct eth_device *dev, void *packet, int length)
>   * Stop the interface.
>   * The interface is stopped when it is brought.
>   */
> -static void dm9000_halt(struct eth_device *netdev)
> +static void dm9000_halt_common(struct dm9000_priv *db)
>  {
> -       struct dm9000_priv *db = container_of(dev, struct dm9000_priv, dev);
> -
>         /* RESET device */
>         dm9000_phy_write(db, 0, 0x8000);        /* PHY RESET */
>         dm9000_iow(db, DM9000_GPR, 0x01);       /* Power-Down PHY */
> @@ -484,9 +480,8 @@ static void dm9000_halt(struct eth_device *netdev)
>  /*
>   * Received a packet and pass to upper layer
>   */
> -static int dm9000_rx(struct eth_device *dev)
> +static int dm9000_recv_common(struct dm9000_priv *db)
>  {
> -       struct dm9000_priv *db = container_of(dev, struct dm9000_priv, dev);
>         u8 rxbyte;
>         u8 *rdptr = (u8 *)net_rx_packets[0];
>         u16 rxstatus, rxlen = 0;
> @@ -569,18 +564,45 @@ static void dm9000_read_srom_word(struct dm9000_priv *db, int offset, u8 *to)
>         to[1] = dm9000_ior(db, DM9000_EPDRH);
>  }
>
> -static void dm9000_get_enetaddr(struct eth_device *dev)
> +static void dm9000_get_enetaddr(struct dm9000_priv *db, u8 *enetaddr)
>  {
> -       struct dm9000_priv *db = container_of(dev, struct dm9000_priv, dev);
>         int i;
>
>         for (i = 0; i < 3; i++)
> -               dm9000_read_srom_word(db, i, dev->enetaddr + (2 * i));
> +               dm9000_read_srom_word(db, i, enetaddr + (2 * i));
>  }
>  #else
> -static void dm9000_get_enetaddr(struct eth_device *dev) {}
> +static void dm9000_get_enetaddr(struct dm9000_priv *db, u8 *enetaddr) {}
>  #endif
>
> +static int dm9000_init(struct eth_device *dev, struct bd_info *bd)
> +{
> +       struct dm9000_priv *db = container_of(dev, struct dm9000_priv, dev);
> +
> +       return dm9000_init_common(db, dev->enetaddr);
> +}
> +
> +static int dm9000_halt(struct eth_device *dev, struct bd_info *bd)
> +{
> +       struct dm9000_priv *db = container_of(dev, struct dm9000_priv, dev);
> +
> +       return dm9000_halt_common(db);
> +}
> +
> +static int dm9000_send(struct eth_device *dev, void *packet, int length)
> +{
> +       struct dm9000_priv *db = container_of(dev, struct dm9000_priv, dev);
> +
> +       return dm9000_send_common(db, packet, length);
> +}
> +
> +static int dm9000_recv(struct eth_device *dev)
> +{
> +       struct dm9000_priv *db = container_of(dev, struct dm9000_priv, dev);
> +
> +       return dm9000_recv_common(db);
> +}
> +
>  int dm9000_initialize(struct bd_info *bis)
>  {
>         struct dm9000_priv *priv;
> @@ -593,12 +615,12 @@ int dm9000_initialize(struct bd_info *bis)
>         priv->base_data = DM9000_DATA;
>
>         /* Load MAC address from EEPROM */
> -       dm9000_get_enetaddr(&priv->dev);
> +       dm9000_get_enetaddr(priv, dev->enetaddr);
>
>         dev->init = dm9000_init;
>         dev->halt = dm9000_halt;
>         dev->send = dm9000_send;
> -       dev->recv = dm9000_rx;
> +       dev->recv = dm9000_recv;
>         strcpy(&priv->dev.name, "dm9000");
>
>         eth_register(&priv->dev);
> --
> 2.35.1
>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH 14/16] net: dm9000: Receive one packet per recv call
  2022-04-11 17:56 ` [PATCH 14/16] net: dm9000: Receive one packet per recv call Marek Vasut
@ 2022-04-12 19:51   ` Ramon Fried
  0 siblings, 0 replies; 32+ messages in thread
From: Ramon Fried @ 2022-04-12 19:51 UTC (permalink / raw)
  To: Marek Vasut
  Cc: U-Boot Mailing List, Marcel Ziswiler, Tom Rini, Joe Hershberger

On Mon, Apr 11, 2022 at 8:56 PM Marek Vasut <marex@denx.de> wrote:
>
> Instead of reading out the entire FIFO and possibly overwriting U-Boot
> memory, read out one packet per recv call, pass it to U-Boot network
> stack, and repeat.
>
> Signed-off-by: Marek Vasut <marex@denx.de>
> Cc: Joe Hershberger <joe.hershberger@ni.com>
> Cc: Ramon Fried <rfried.dev@gmail.com>
> ---
>  drivers/net/dm9000x.c | 102 +++++++++++++++++++++---------------------
>  1 file changed, 50 insertions(+), 52 deletions(-)
>
> diff --git a/drivers/net/dm9000x.c b/drivers/net/dm9000x.c
> index 97084d16ffa..84b012ec65d 100644
> --- a/drivers/net/dm9000x.c
> +++ b/drivers/net/dm9000x.c
> @@ -480,10 +480,9 @@ static void dm9000_halt_common(struct dm9000_priv *db)
>  /*
>   * Received a packet and pass to upper layer
>   */
> -static int dm9000_recv_common(struct dm9000_priv *db)
> +static int dm9000_recv_common(struct dm9000_priv *db, uchar *rdptr)
>  {
>         u8 rxbyte;
> -       u8 *rdptr = (u8 *)net_rx_packets[0];
>         u16 rxstatus, rxlen = 0;
>
>         /*
> @@ -496,58 +495,52 @@ static int dm9000_recv_common(struct dm9000_priv *db)
>         dm9000_iow(db, DM9000_ISR, 0x01); /* clear PR status latched in bit 0 */
>
>         /* There is _at least_ 1 package in the fifo, read them all */
> -       for (;;) {
> -               dm9000_ior(db, DM9000_MRCMDX);  /* Dummy read */
> -
> -               /*
> -                * Get most updated data,
> -                * only look at bits 0:1, See application notes DM9000
> -                */
> -               rxbyte = dm9000_inb(db->base_data) & 0x03;
> -
> -               /* Status check: this byte must be 0 or 1 */
> -               if (rxbyte > DM9000_PKT_RDY) {
> -                       dm9000_iow(db, DM9000_RCR, 0x00);       /* Stop Device */
> -                       dm9000_iow(db, DM9000_ISR, 0x80);       /* Stop INT request */
> -                       printf("DM9000 error: status check fail: 0x%x\n",
> -                              rxbyte);
> -                       return 0;
> -               }
> +       dm9000_ior(db, DM9000_MRCMDX);  /* Dummy read */
> +
> +       /*
> +        * Get most updated data,
> +        * only look at bits 0:1, See application notes DM9000
> +        */
> +       rxbyte = dm9000_inb(db->base_data) & 0x03;
> +
> +       /* Status check: this byte must be 0 or 1 */
> +       if (rxbyte > DM9000_PKT_RDY) {
> +               dm9000_iow(db, DM9000_RCR, 0x00);       /* Stop Device */
> +               dm9000_iow(db, DM9000_ISR, 0x80);       /* Stop INT request */
> +               printf("DM9000 error: status check fail: 0x%x\n",
> +                      rxbyte);
> +               return -EINVAL;
> +       }
> +
> +       if (rxbyte != DM9000_PKT_RDY)
> +               return 0; /* No packet received, ignore */
>
> -               if (rxbyte != DM9000_PKT_RDY)
> -                       return 0; /* No packet received, ignore */
> -
> -               debug("receiving packet\n");
> -
> -               /* A packet ready now  & Get status/length */
> -               db->rx_status(db, &rxstatus, &rxlen);
> -
> -               debug("rx status: 0x%04x rx len: %d\n", rxstatus, rxlen);
> -
> -               /* Move data from DM9000 */
> -               /* Read received packet from RX SRAM */
> -               db->inblk(db, rdptr, rxlen);
> -
> -               if (rxstatus & 0xbf00 || rxlen < 0x40 ||
> -                   rxlen > DM9000_PKT_MAX) {
> -                       if (rxstatus & 0x100)
> -                               printf("rx fifo error\n");
> -                       if (rxstatus & 0x200)
> -                               printf("rx crc error\n");
> -                       if (rxstatus & 0x8000)
> -                               printf("rx length error\n");
> -                       if (rxlen > DM9000_PKT_MAX) {
> -                               printf("rx length too big\n");
> -                               dm9000_reset(db);
> -                       }
> -               } else {
> -                       dm9000_dump_packet(__func__, rdptr, rxlen);
> -
> -                       debug("passing packet to upper layer\n");
> -                       net_process_received_packet(net_rx_packets[0], rxlen);
> +       debug("receiving packet\n");
> +
> +       /* A packet ready now  & Get status/length */
> +       db->rx_status(db, &rxstatus, &rxlen);
> +
> +       debug("rx status: 0x%04x rx len: %d\n", rxstatus, rxlen);
> +
> +       /* Move data from DM9000 */
> +       /* Read received packet from RX SRAM */
> +       db->inblk(db, rdptr, rxlen);
> +
> +       if (rxstatus & 0xbf00 || rxlen < 0x40 || rxlen > DM9000_PKT_MAX) {
> +               if (rxstatus & 0x100)
> +                       printf("rx fifo error\n");
> +               if (rxstatus & 0x200)
> +                       printf("rx crc error\n");
> +               if (rxstatus & 0x8000)
> +                       printf("rx length error\n");
> +               if (rxlen > DM9000_PKT_MAX) {
> +                       printf("rx length too big\n");
> +                       dm9000_reset(db);
>                 }
> +               return -EINVAL;
>         }
> -       return 0;
> +
> +       return rxlen;
>  }
>
>  /*
> @@ -599,8 +592,13 @@ static int dm9000_send(struct eth_device *dev, void *packet, int length)
>  static int dm9000_recv(struct eth_device *dev)
>  {
>         struct dm9000_priv *db = container_of(dev, struct dm9000_priv, dev);
> +       int ret;
> +
> +       ret = dm9000_recv_common(db, net_rx_packets[0]);
> +       if (ret > 0)
> +               net_process_received_packet(net_rx_packets[0], ret);
>
> -       return dm9000_recv_common(db);
> +       return ret;
>  }
>
>  int dm9000_initialize(struct bd_info *bis)
> --
> 2.35.1
>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH 15/16] net: dm9000: Add DM support
  2022-04-11 17:56 ` [PATCH 15/16] net: dm9000: Add DM support Marek Vasut
@ 2022-04-12 19:51   ` Ramon Fried
  0 siblings, 0 replies; 32+ messages in thread
From: Ramon Fried @ 2022-04-12 19:51 UTC (permalink / raw)
  To: Marek Vasut
  Cc: U-Boot Mailing List, Marcel Ziswiler, Tom Rini, Joe Hershberger

On Mon, Apr 11, 2022 at 8:56 PM Marek Vasut <marex@denx.de> wrote:
>
> Add support for U-Boot DM and DT probing.
>
> Signed-off-by: Marek Vasut <marex@denx.de>
> Cc: Joe Hershberger <joe.hershberger@ni.com>
> Cc: Ramon Fried <rfried.dev@gmail.com>
> ---
>  drivers/net/dm9000x.c | 118 ++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 118 insertions(+)
>
> diff --git a/drivers/net/dm9000x.c b/drivers/net/dm9000x.c
> index 84b012ec65d..d63a7c442c9 100644
> --- a/drivers/net/dm9000x.c
> +++ b/drivers/net/dm9000x.c
> @@ -51,6 +51,7 @@
>
>  #include <common.h>
>  #include <command.h>
> +#include <dm.h>
>  #include <net.h>
>  #include <asm/io.h>
>  #include <linux/delay.h>
> @@ -73,7 +74,9 @@ struct dm9000_priv {
>         void (*outblk)(struct dm9000_priv *db, void *data_ptr, int count);
>         void (*inblk)(struct dm9000_priv *db, void *data_ptr, int count);
>         void (*rx_status)(struct dm9000_priv *db, u16 *rxstatus, u16 *rxlen);
> +#ifndef CONFIG_DM_ETH
>         struct eth_device netdev;
> +#endif
>         phys_addr_t base_io;
>         phys_addr_t base_data;
>  };
> @@ -568,6 +571,7 @@ static void dm9000_get_enetaddr(struct dm9000_priv *db, u8 *enetaddr)
>  static void dm9000_get_enetaddr(struct dm9000_priv *db, u8 *enetaddr) {}
>  #endif
>
> +#ifndef CONFIG_DM_ETH
>  static int dm9000_init(struct eth_device *dev, struct bd_info *bd)
>  {
>         struct dm9000_priv *db = container_of(dev, struct dm9000_priv, dev);
> @@ -625,3 +629,117 @@ int dm9000_initialize(struct bd_info *bis)
>
>         return 0;
>  }
> +#else  /* ifdef CONFIG_DM_ETH */
> +static int dm9000_start(struct udevice *dev)
> +{
> +       struct dm9000_priv *db = dev_get_priv(dev);
> +       struct eth_pdata *pdata = dev_get_plat(dev);
> +
> +       return dm9000_init_common(db, pdata->enetaddr);
> +}
> +
> +static void dm9000_stop(struct udevice *dev)
> +{
> +       struct dm9000_priv *db = dev_get_priv(dev);
> +
> +       dm9000_halt_common(db);
> +}
> +
> +static int dm9000_send(struct udevice *dev, void *packet, int length)
> +{
> +       struct dm9000_priv *db = dev_get_priv(dev);
> +       int ret;
> +
> +       ret = dm9000_send_common(db, packet, length);
> +
> +       return ret ? 0 : -ETIMEDOUT;
> +}
> +
> +static int dm9000_recv(struct udevice *dev, int flags, uchar **packetp)
> +{
> +       struct dm9000_priv *db = dev_get_priv(dev);
> +       uchar *data = net_rx_packets[0];
> +       int ret;
> +
> +       ret = dm9000_recv_common(db, data);
> +       if (ret)
> +               *packetp = (void *)data;
> +
> +       return ret ? ret : -EAGAIN;
> +}
> +
> +static int dm9000_write_hwaddr(struct udevice *dev)
> +{
> +       struct dm9000_priv *db = dev_get_priv(dev);
> +       struct eth_pdata *pdata = dev_get_plat(dev);
> +       int i, oft;
> +
> +       /* fill device MAC address registers */
> +       for (i = 0, oft = DM9000_PAR; i < 6; i++, oft++)
> +               dm9000_iow(db, oft, pdata->enetaddr[i]);
> +
> +       for (i = 0, oft = 0x16; i < 8; i++, oft++)
> +               dm9000_iow(db, oft, 0xff);
> +
> +       /* read back mac, just to be sure */
> +       for (i = 0, oft = 0x10; i < 6; i++, oft++)
> +               debug("%02x:", dm9000_ior(db, oft));
> +
> +       debug("\n");
> +
> +       return 0;
> +}
> +
> +static int dm9000_read_rom_hwaddr(struct udevice *dev)
> +{
> +       struct dm9000_priv *db = dev_get_priv(dev);
> +       struct eth_pdata *pdata = dev_get_plat(dev);
> +
> +       dm9000_get_enetaddr(db, pdata->enetaddr);
> +
> +       return !is_valid_ethaddr(pdata->enetaddr);
> +}
> +
> +static int dm9000_bind(struct udevice *dev)
> +{
> +       return device_set_name(dev, dev->name);
> +}
> +
> +static int dm9000_of_to_plat(struct udevice *dev)
> +{
> +       struct dm9000_priv *db = dev_get_priv(dev);
> +       struct eth_pdata *pdata = dev_get_plat(dev);
> +
> +       pdata->iobase = dev_read_addr_index(dev, 0);
> +       db->base_io = pdata->iobase;
> +       db->base_data = dev_read_addr_index(dev, 1);
> +
> +       return 0;
> +}
> +
> +static const struct eth_ops dm9000_ops = {
> +       .start          = dm9000_start,
> +       .stop           = dm9000_stop,
> +       .send           = dm9000_send,
> +       .recv           = dm9000_recv,
> +       .write_hwaddr   = dm9000_write_hwaddr,
> +       .read_rom_hwaddr = dm9000_read_rom_hwaddr,
> +};
> +
> +static const struct udevice_id dm9000_ids[] = {
> +       { .compatible = "davicom,dm9000" },
> +       { }
> +};
> +
> +U_BOOT_DRIVER(dm9000) = {
> +       .name           = "eth_dm9000",
> +       .id             = UCLASS_ETH,
> +       .of_match       = dm9000_ids,
> +       .bind           = dm9000_bind,
> +       .of_to_plat = dm9000_of_to_plat,
> +       .ops            = &dm9000_ops,
> +       .priv_auto      = sizeof(struct dm9000_priv),
> +       .plat_auto      = sizeof(struct eth_pdata),
> +       .flags          = DM_FLAG_ALLOC_PRIV_DMA,
> +};
> +#endif
> --
> 2.35.1
>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH 16/16] net: dm9000: Add Kconfig entry
  2022-04-11 17:56 ` [PATCH 16/16] net: dm9000: Add Kconfig entry Marek Vasut
@ 2022-04-12 19:51   ` Ramon Fried
  0 siblings, 0 replies; 32+ messages in thread
From: Ramon Fried @ 2022-04-12 19:51 UTC (permalink / raw)
  To: Marek Vasut
  Cc: U-Boot Mailing List, Marcel Ziswiler, Tom Rini, Joe Hershberger

On Mon, Apr 11, 2022 at 8:56 PM Marek Vasut <marex@denx.de> wrote:
>
> Add Kconfig entry for the DM9000 MAC.
>
> Signed-off-by: Marek Vasut <marex@denx.de>
> Cc: Joe Hershberger <joe.hershberger@ni.com>
> Cc: Ramon Fried <rfried.dev@gmail.com>
> ---
>  drivers/net/Kconfig | 5 +++++
>  1 file changed, 5 insertions(+)
>
> diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig
> index a6171a7c7ff..347fe8aa425 100644
> --- a/drivers/net/Kconfig
> +++ b/drivers/net/Kconfig
> @@ -191,6 +191,11 @@ config CALXEDA_XGMAC
>           This driver supports the XGMAC in Calxeda Highbank and Midway
>           machines.
>
> +config DRIVER_DM9000
> +       bool "Davicom DM9000 controller driver"
> +       help
> +         The Davicom DM9000 parallel bus external ethernet interface chip.
> +
>  config DWC_ETH_QOS
>         bool "Synopsys DWC Ethernet QOS device support"
>         depends on DM_ETH
> --
> 2.35.1
>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

^ permalink raw reply	[flat|nested] 32+ messages in thread

end of thread, other threads:[~2022-04-12 19:52 UTC | newest]

Thread overview: 32+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-11 17:55 [PATCH 01/16] net: dm9000: Make accessor names lowercase Marek Vasut
2022-04-11 17:55 ` [PATCH 02/16] net: dm9000: Replace DM9000_DBG() with debug() Marek Vasut
2022-04-12 19:46   ` Ramon Fried
2022-04-11 17:55 ` [PATCH 03/16] net: dm9000: Make RxLen and RxStatus lowercase Marek Vasut
2022-04-12 19:46   ` Ramon Fried
2022-04-11 17:55 ` [PATCH 04/16] net: dm9000: Drop unused dump_regs() Marek Vasut
2022-04-12 19:46   ` Ramon Fried
2022-04-11 17:55 ` [PATCH 05/16] net: dm9000: Turn DM9000_DMP_PACKET() into a function Marek Vasut
2022-04-12 19:46   ` Ramon Fried
2022-04-11 17:55 ` [PATCH 06/16] net: dm9000: Drop volatiles Marek Vasut
2022-04-12 19:47   ` Ramon Fried
2022-04-11 17:55 ` [PATCH 07/16] net: dm9000: Checkpatch cleanup Marek Vasut
2022-04-12 19:47   ` Ramon Fried
2022-04-11 17:55 ` [PATCH 08/16] net: dm9000: Reorder and staticize Marek Vasut
2022-04-12 19:48   ` Ramon Fried
2022-04-11 17:56 ` [PATCH 09/16] net: dm9000: Rename board_info to dm9000_priv Marek Vasut
2022-04-12 19:48   ` Ramon Fried
2022-04-11 17:56 ` [PATCH 10/16] net: dm9000: Drop static device private data Marek Vasut
2022-04-12 19:49   ` Ramon Fried
2022-04-11 17:56 ` [PATCH 11/16] net: dm9000: Drop dm9000.h and staticize SROM access Marek Vasut
2022-04-12 19:49   ` Ramon Fried
2022-04-11 17:56 ` [PATCH 12/16] net: dm9000: Pass private data around for IO Marek Vasut
2022-04-12 19:50   ` Ramon Fried
2022-04-11 17:56 ` [PATCH 13/16] net: dm9000: Split non-DM specific bits from common code Marek Vasut
2022-04-12 19:51   ` Ramon Fried
2022-04-11 17:56 ` [PATCH 14/16] net: dm9000: Receive one packet per recv call Marek Vasut
2022-04-12 19:51   ` Ramon Fried
2022-04-11 17:56 ` [PATCH 15/16] net: dm9000: Add DM support Marek Vasut
2022-04-12 19:51   ` Ramon Fried
2022-04-11 17:56 ` [PATCH 16/16] net: dm9000: Add Kconfig entry Marek Vasut
2022-04-12 19:51   ` Ramon Fried
2022-04-12 19:46 ` [PATCH 01/16] net: dm9000: Make accessor names lowercase Ramon Fried

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.