Skip to contentSkip to conversation

net: macb: sync header definitions as taken from Linux

PATCH In review Ramon Fried 2 participants 7 messages Jul 16, 2019 – Jul 25, 2019 Network drivers

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/6 net: macb: sync header definitions as taken from Linux

Few registers and bits were added by Cadence and they were not updated in the headers. Take the latest definitions as defined in Linux header (5.1) that also includes some comments about existing registers.

One register was improperly named (UR), fix that.

---
V2: Fix missed UR registers.

 drivers/net/macb.c |   8 +-
 drivers/net/macb.h | 868 ++++++++++++++++++++++++++++++++++-----------
 2 files changed, 662 insertions(+), 214 deletions(-)
drivers/net/macb.c +4 -4
index a7eddd647d..0032d4e000 100644
@@ -774,14 +774,14 @@ static int _macb_init(struct macb_device *macb, const char *name)
 #ifdef CONFIG_DM_ETH
 		if ((macb->phy_interface == PHY_INTERFACE_MODE_RMII) ||
 		    (macb->phy_interface == PHY_INTERFACE_MODE_RGMII))
-			gem_writel(macb, UR, GEM_BIT(RGMII));
+			gem_writel(macb, USRIO, GEM_BIT(RGMII));
 		else
-			gem_writel(macb, UR, 0);
+			gem_writel(macb, USRIO, 0);
 #else
 #if defined(CONFIG_RGMII) || defined(CONFIG_RMII)
-		gem_writel(macb, UR, GEM_BIT(RGMII));
+		gem_writel(macb, USRIO, GEM_BIT(RGMII));
 #else
-		gem_writel(macb, UR, 0);
+		gem_writel(macb, USRIO, 0);
 #endif
 #endif
 	} else {
drivers/net/macb.h +658 -210

927 lines not on this page · raw message

Signature · 1 line
2.22.0
#1 lore raw

PATCH 2/6 net: macb: add support for faster clk rates

add support for clock rates higher than 2.4Mhz

---
v2: nothing.

 drivers/net/macb.c | 6 +++++-
 drivers/net/macb.h | 2 ++
 2 files changed, 7 insertions(+), 1 deletion(-)
drivers/net/macb.c +5 -1
index 0032d4e000..0fed43bbe2 100644
@@ -903,8 +903,12 @@ static u32 gem_mdc_clk_div(int id, struct macb_device *macb)
 		config = GEM_BF(CLK, GEM_CLK_DIV48);
 	else if (macb_hz < 160000000)
 		config = GEM_BF(CLK, GEM_CLK_DIV64);
-	else
+	else if (macb_hz < 240000000)
 		config = GEM_BF(CLK, GEM_CLK_DIV96);
+	else if (macb_hz < 320000000)
+		config = GEM_BF(CLK, GEM_CLK_DIV128);
+	else
+		config = GEM_BF(CLK, GEM_CLK_DIV224);
 
 	return config;
 }
drivers/net/macb.h +2 -0
index 8966c793a7..9b16383eba 100644
@@ -613,6 +613,8 @@
 #define GEM_CLK_DIV48				3
 #define GEM_CLK_DIV64				4
 #define GEM_CLK_DIV96				5
+#define GEM_CLK_DIV128				6
+#define GEM_CLK_DIV224				7
 
 /* Constants for MAN register */
 #define MACB_MAN_SOF				1
Signature · 1 line
2.22.0
#2 lore raw

PATCH 3/6 net: macb: use bit access macro from header file

In reply to Ramon Fried

macb.h provides macros for reading/setting bitfields, in macb registers and descriptors. use that instead of redefining them in the source file.

---
v2: nothing.

 drivers/net/macb.c | 48 +++++++++++++++-------------------------------
 1 file changed, 15 insertions(+), 33 deletions(-)
drivers/net/macb.c +15 -33
index 0fed43bbe2..a968a4bd06 100644
@@ -77,27 +77,8 @@ struct macb_dma_desc {
 #define MACB_RX_DMA_DESC_SIZE	(DMA_DESC_BYTES(MACB_RX_RING_SIZE))
 #define MACB_TX_DUMMY_DMA_DESC_SIZE	(DMA_DESC_BYTES(1))
 
-#define RXADDR_USED		0x00000001
-#define RXADDR_WRAP		0x00000002
-
 #define RXBUF_FRMLEN_MASK	0x00000fff
-#define RXBUF_FRAME_START	0x00004000
-#define RXBUF_FRAME_END		0x00008000
-#define RXBUF_TYPEID_MATCH	0x00400000
-#define RXBUF_ADDR4_MATCH	0x00800000
-#define RXBUF_ADDR3_MATCH	0x01000000
-#define RXBUF_ADDR2_MATCH	0x02000000
-#define RXBUF_ADDR1_MATCH	0x04000000
-#define RXBUF_BROADCAST		0x80000000
-
 #define TXBUF_FRMLEN_MASK	0x000007ff
-#define TXBUF_FRAME_END		0x00008000
-#define TXBUF_NOCRC		0x00010000
-#define TXBUF_EXHAUSTED		0x08000000
-#define TXBUF_UNDERRUN		0x10000000
-#define TXBUF_MAXRETRY		0x20000000
-#define TXBUF_WRAP		0x40000000
-#define TXBUF_USED		0x80000000
 
 struct macb_device {
 	void			*regs;
@@ -316,9 +297,9 @@ static int _macb_send(struct macb_device *macb, const char *name, void *packet,
 	paddr = dma_map_single(packet, length, DMA_TO_DEVICE);
 
 	ctrl = length & TXBUF_FRMLEN_MASK;
-	ctrl |= TXBUF_FRAME_END;
+	ctrl |= MACB_BIT(TX_LAST);
 	if (tx_head == (MACB_TX_RING_SIZE - 1)) {
-		ctrl |= TXBUF_WRAP;
+		ctrl |= MACB_BIT(TX_WRAP);
 		macb->tx_head = 0;
 	} else {
 		macb->tx_head++;
@@ -340,7 +321,7 @@ static int _macb_send(struct macb_device *macb, const char *name, void *packet,
 		barrier();
 		macb_invalidate_ring_desc(macb, TX);
 		ctrl = macb->tx_ring[tx_head].ctrl;
-		if (ctrl & TXBUF_USED)
+		if (ctrl & MACB_BIT(TX_USED))
 			break;
 		udelay(1);
 	}
@@ -348,9 +329,9 @@ static int _macb_send(struct macb_device *macb, const char *name, void *packet,
 	dma_unmap_single(packet, length, paddr);
 
 	if (i <= MACB_TX_TIMEOUT) {
-		if (ctrl & TXBUF_UNDERRUN)
+		if (ctrl & MACB_BIT(TX_UNDERRUN))
 			printf("%s: TX underrun\n", name);
-		if (ctrl & TXBUF_EXHAUSTED)
+		if (ctrl & MACB_BIT(TX_BUF_EXHAUSTED))
 			printf("%s: TX buffers exhausted in mid frame\n", name);
 	} else {
 		printf("%s: TX timeout\n", name);
@@ -369,14 +350,14 @@ static void reclaim_rx_buffers(struct macb_device *macb,
 
 	macb_invalidate_ring_desc(macb, RX);
 	while (i > new_tail) {
-		macb->rx_ring[i].addr &= ~RXADDR_USED;
+		macb->rx_ring[i].addr &= ~MACB_BIT(RX_USED);
 		i++;
 		if (i > MACB_RX_RING_SIZE)
 			i = 0;
 	}
 
 	while (i < new_tail) {
-		macb->rx_ring[i].addr &= ~RXADDR_USED;
+		macb->rx_ring[i].addr &= ~MACB_BIT(RX_USED);
 		i++;
 	}
 
@@ -396,17 +377,17 @@ static int _macb_recv(struct macb_device *macb, uchar **packetp)
 	for (;;) {
 		macb_invalidate_ring_desc(macb, RX);
 
-		if (!(macb->rx_ring[next_rx_tail].addr & RXADDR_USED))
+		if (!(macb->rx_ring[next_rx_tail].addr & MACB_BIT(RX_USED)))
 			return -EAGAIN;
 
 		status = macb->rx_ring[next_rx_tail].ctrl;
-		if (status & RXBUF_FRAME_START) {
+		if (status & MACB_BIT(RX_SOF)) {
 			if (next_rx_tail != macb->rx_tail)
 				reclaim_rx_buffers(macb, next_rx_tail);
 			macb->wrapped = false;
 		}
 
-		if (status & RXBUF_FRAME_END) {
+		if (status & MACB_BIT(RX_EOF)) {
 			buffer = macb->rx_buffer + 128 * macb->rx_tail;
 			length = status & RXBUF_FRMLEN_MASK;
 
@@ -699,7 +680,7 @@ static int gmac_init_multi_queues(struct macb_device *macb)
 		if (queue_mask & (1 << i))
 			num_queues++;
 
-	macb->dummy_desc->ctrl = TXBUF_USED;
+	macb->dummy_desc->ctrl = MACB_BIT(TX_USED);
 	macb->dummy_desc->addr = 0;
 	flush_dcache_range(macb->dummy_desc_dma, macb->dummy_desc_dma +
 			ALIGN(MACB_TX_DUMMY_DMA_DESC_SIZE, PKTALIGN));
@@ -732,7 +713,7 @@ static int _macb_init(struct macb_device *macb, const char *name)
 	paddr = macb->rx_buffer_dma;
 	for (i = 0; i < MACB_RX_RING_SIZE; i++) {
 		if (i == (MACB_RX_RING_SIZE - 1))
-			paddr |= RXADDR_WRAP;
+			paddr |= MACB_BIT(RX_WRAP);
 		macb->rx_ring[i].addr = paddr;
 		macb->rx_ring[i].ctrl = 0;
 		paddr += 128;
@@ -743,9 +724,10 @@ static int _macb_init(struct macb_device *macb, const char *name)
 	for (i = 0; i < MACB_TX_RING_SIZE; i++) {
 		macb->tx_ring[i].addr = 0;
 		if (i == (MACB_TX_RING_SIZE - 1))
-			macb->tx_ring[i].ctrl = TXBUF_USED | TXBUF_WRAP;
+			macb->tx_ring[i].ctrl = MACB_BIT(TX_USED) |
+				MACB_BIT(TX_WRAP);
 		else
-			macb->tx_ring[i].ctrl = TXBUF_USED;
+			macb->tx_ring[i].ctrl = MACB_BIT(TX_USED);
 	}
 	macb_flush_ring_desc(macb, TX);
 
Signature · 1 line
2.22.0
#3 lore raw

PATCH 4/6 net: macb: add support for SGMII phy interface

In reply to Ramon Fried

This patch adds support for the sgmii phy interface, available only to DM users, dictated by current driver design.

---
v2: nothing.

 drivers/net/macb.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/net/macb.c +7 -0
index a968a4bd06..cf76270ad8 100644
@@ -759,6 +759,13 @@ static int _macb_init(struct macb_device *macb, const char *name)
 			gem_writel(macb, USRIO, GEM_BIT(RGMII));
 		else
 			gem_writel(macb, USRIO, 0);
+
+		if (macb->phy_interface == PHY_INTERFACE_MODE_SGMII) {
+			unsigned int ncfgr = macb_readl(macb, NCFGR);
+
+			ncfgr |= GEM_BIT(SGMIIEN) | GEM_BIT(PCSSEL);
+			macb_writel(macb, NCFGR, ncfgr);
+		}
 #else
 #if defined(CONFIG_RGMII) || defined(CONFIG_RMII)
 		gem_writel(macb, USRIO, GEM_BIT(RGMII));
Signature · 1 line
2.22.0
#4 lore raw

PATCH 5/6 net: macb: add dma_burst_length config

In reply to Ramon Fried

GEM support higher DMA burst writes/reads than the default (4). add configuration structure with dma burst length so it could be applied later to DMA configuration.

---
v2: nothing.

 drivers/net/macb.c | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)
drivers/net/macb.c +21 -1
index cf76270ad8..dc6aa6deda 100644
@@ -82,6 +82,7 @@ struct macb_dma_desc {
 
 struct macb_device {
 	void			*regs;
+	unsigned int		dma_burst_length;
 
 	unsigned int		rx_tail;
 	unsigned int		tx_head;
@@ -118,6 +119,11 @@ struct macb_device {
 	phy_interface_t		phy_interface;
 #endif
 };
+
+struct macb_config {
+	unsigned int		dma_burst_length;
+};
+
 #ifndef CONFIG_DM_ETH
 #define to_macb(_nd) container_of(_nd, struct macb_device, netdev)
 #endif
@@ -1135,8 +1141,13 @@ static int macb_enable_clk(struct udevice *dev)
 }
 #endif
 
+static const struct macb_config default_gem_config = {
+	.dma_burst_length = 16,
+};
+
 static int macb_eth_probe(struct udevice *dev)
 {
+	const struct macb_config *macb_config;
 	struct eth_pdata *pdata = dev_get_platdata(dev);
 	struct macb_device *macb = dev_get_priv(dev);
 	const char *phy_mode;
@@ -1153,6 +1164,11 @@ static int macb_eth_probe(struct udevice *dev)
 
 	macb->regs = (void *)pdata->iobase;
 
+	macb_config = (struct macb_config *)dev_get_driver_data(dev);
+	if (!macb_config)
+		macb_config = &default_gem_config;
+
+	macb->dma_burst_length = macb_config->dma_burst_length;
 #ifdef CONFIG_CLK
 	ret = macb_enable_clk(dev);
 	if (ret)
@@ -1213,12 +1229,16 @@ static int macb_eth_ofdata_to_platdata(struct udevice *dev)
 	return macb_late_eth_ofdata_to_platdata(dev);
 }
 
+static const struct macb_config sama5d4_config = {
+	.dma_burst_length = 4,
+};
+
 static const struct udevice_id macb_eth_ids[] = {
 	{ .compatible = "cdns,macb" },
 	{ .compatible = "cdns,at91sam9260-macb" },
 	{ .compatible = "atmel,sama5d2-gem" },
 	{ .compatible = "atmel,sama5d3-gem" },
-	{ .compatible = "atmel,sama5d4-gem" },
+	{ .compatible = "atmel,sama5d4-gem", .data = (ulong)&sama5d4_config },
 	{ .compatible = "cdns,zynq-gem" },
 	{ }
 };
Signature · 1 line
2.22.0
#5 lore raw

PATCH 6/6 net: macb: apply sane DMA configuration

In reply to Ramon Fried

DMA configuration was heavily dependent on the HW defaults, add function to properly set the required fields, including the new dma_burst_length.

---
v2: nothing.

 drivers/net/macb.c | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)
drivers/net/macb.c +28 -0
index dc6aa6deda..035109dc43 100644
@@ -47,6 +47,7 @@ DECLARE_GLOBAL_DATA_PTR;
 
 #define MACB_RX_BUFFER_SIZE		4096
 #define MACB_RX_RING_SIZE		(MACB_RX_BUFFER_SIZE / 128)
+#define RX_BUFFER_MULTIPLE		64
 #define MACB_TX_RING_SIZE		16
 #define MACB_TX_TIMEOUT		1000
 #define MACB_AUTONEG_TIMEOUT	5000000
@@ -697,6 +698,31 @@ static int gmac_init_multi_queues(struct macb_device *macb)
 	return 0;
 }
 
+static void gmac_configure_dma(struct macb_device *macb)
+{
+	u32 buffer_size;
+	u32 dmacfg;
+
+	buffer_size = 128 / RX_BUFFER_MULTIPLE;
+	dmacfg = gem_readl(macb, DMACFG) & ~GEM_BF(RXBS, -1L);
+	dmacfg |= GEM_BF(RXBS, buffer_size);
+
+	if (macb->dma_burst_length)
+		dmacfg = GEM_BFINS(FBLDO, macb->dma_burst_length, dmacfg);
+
+	dmacfg |= GEM_BIT(TXPBMS) | GEM_BF(RXBMS, -1L);
+	dmacfg &= ~GEM_BIT(ENDIA_PKT);
+
+#ifdef CONFIG_SYS_LITTLE_ENDIAN
+		dmacfg &= ~GEM_BIT(ENDIA_DESC);
+#else
+		dmacfg |= GEM_BIT(ENDIA_DESC); /* CPU in big endian */
+#endif
+
+	dmacfg &= ~GEM_BIT(ADDR64);
+	gem_writel(macb, DMACFG, dmacfg);
+}
+
 #ifdef CONFIG_DM_ETH
 static int _macb_init(struct udevice *dev, const char *name)
 #else
@@ -750,6 +776,8 @@ static int _macb_init(struct macb_device *macb, const char *name)
 	macb_writel(macb, TBQP, macb->tx_ring_dma);
 
 	if (macb_is_gem(macb)) {
+		/* Initialize DMA properties */
+		gmac_configure_dma(macb);
 		/* Check the multi queue and initialize the queue for tx */
 		gmac_init_multi_queues(macb);
 
Signature · 1 line
2.22.0