Skip to contentSkip to conversation

net: ftgmac100: Add Aspeed AST2700 support

PATCH In review Jacky Chou 3 participants 4 messages Jul 8, 2024 – Sep 11, 2024 Network drivers

lore
Share & tools
lore

Jacky Chou

author
#0 lore raw

PATCH 1/1 net: ftgmac100: Add Aspeed AST2700 support

Add support of Aspeed AST2700 SoC. AST2700 is based on ARM64 so modify the DMA address related code to fit both ARM and ARM64. Besides, the RMII/RGMII mode control register is moved from SCU500 to MAC50 so initialize the register in ftgmac100_start correspondingly.

---
 drivers/net/ftgmac100.c | 66 +++++++++++++++++++++++++++++++++--------
 drivers/net/ftgmac100.h | 12 ++++++++
 2 files changed, 65 insertions(+), 13 deletions(-)
drivers/net/ftgmac100.c +53 -13
index 9fb8c12838..a909a0b309 100644
@@ -27,6 +27,7 @@
 #include <linux/io.h>
 #include <linux/iopoll.h>
 #include <linux/printk.h>
+#include <linux/bitfield.h>
 
 #include "ftgmac100.h"
 
@@ -58,6 +59,15 @@
 enum ftgmac100_model {
 	FTGMAC100_MODEL_FARADAY,
 	FTGMAC100_MODEL_ASPEED,
+	FTGMAC100_MODEL_ASPEED_AST2700,
+};
+
+union ftgmac100_dma_addr {
+	dma_addr_t addr;
+	struct {
+		u32 lo;
+		u32 hi;
+	};
 };
 
 /**
@@ -97,6 +107,8 @@ struct ftgmac100_data {
 	/* End of RX/TX ring buffer bits. Depend on model */
 	u32 rxdes0_edorr_mask;
 	u32 txdes0_edotr_mask;
+
+	bool is_ast2700;
 };
 
 /*
@@ -321,6 +333,7 @@ static int ftgmac100_start(struct udevice *dev)
 	struct eth_pdata *plat = dev_get_plat(dev);
 	struct ftgmac100_data *priv = dev_get_priv(dev);
 	struct ftgmac100 *ftgmac100 = priv->iobase;
+	union ftgmac100_dma_addr dma_addr = {.hi = 0, .lo = 0};
 	struct phy_device *phydev = priv->phydev;
 	unsigned int maccr, dblac, desc_size;
 	ulong start, end;
@@ -342,6 +355,7 @@ static int ftgmac100_start(struct udevice *dev)
 	priv->rx_index = 0;
 
 	for (i = 0; i < PKTBUFSTX; i++) {
+		priv->txdes[i].txdes2 = 0;
 		priv->txdes[i].txdes3 = 0;
 		priv->txdes[i].txdes0 = 0;
 	}
@@ -352,7 +366,14 @@ static int ftgmac100_start(struct udevice *dev)
 	flush_dcache_range(start, end);
 
 	for (i = 0; i < PKTBUFSRX; i++) {
-		priv->rxdes[i].rxdes3 = (unsigned int)net_rx_packets[i];
+		unsigned int ip_align = 0;
+
+		dma_addr.addr = (dma_addr_t)net_rx_packets[i];
+		priv->rxdes[i].rxdes2 = FIELD_PREP(FTGMAC100_RXDES2_RXBUF_BADR_HI, dma_addr.hi);
+		/* For IP alignment */
+		if ((dma_addr.lo & (PKTALIGN - 1)) == 0)
+			ip_align = 2;
+		priv->rxdes[i].rxdes3 = dma_addr.lo + ip_align;
 		priv->rxdes[i].rxdes0 = 0;
 	}
 	priv->rxdes[PKTBUFSRX - 1].rxdes0 = priv->rxdes0_edorr_mask;
@@ -362,10 +383,14 @@ static int ftgmac100_start(struct udevice *dev)
 	flush_dcache_range(start, end);
 
 	/* transmit ring */
-	writel((u32)priv->txdes, &ftgmac100->txr_badr);
+	dma_addr.addr = (dma_addr_t)priv->txdes;
+	writel(dma_addr.lo, &ftgmac100->txr_badr);
+	writel(dma_addr.hi, &ftgmac100->txr_badr_hi);
 
 	/* receive ring */
-	writel((u32)priv->rxdes, &ftgmac100->rxr_badr);
+	dma_addr.addr = (dma_addr_t)priv->rxdes;
+	writel(dma_addr.lo, &ftgmac100->rxr_badr);
+	writel(dma_addr.hi, &ftgmac100->rxr_badr_hi);
 
 	/* Configure TX/RX decsriptor size
 	 * This size is calculated based on cache line.
@@ -394,6 +419,10 @@ static int ftgmac100_start(struct udevice *dev)
 		FTGMAC100_MACCR_RX_RUNT |
 		FTGMAC100_MACCR_RX_BROADPKT;
 
+	if (priv->is_ast2700 && (priv->phydev->interface == PHY_INTERFACE_MODE_RMII ||
+				 priv->phydev->interface == PHY_INTERFACE_MODE_NCSI))
+		maccr |= FTGMAC100_MACCR_RMII_ENABLE;
+
 	writel(maccr, &ftgmac100->maccr);
 
 	ret = phy_startup(phydev);
@@ -443,9 +472,11 @@ static int ftgmac100_recv(struct udevice *dev, int flags, uchar **packetp)
 	ulong des_start = ((ulong)curr_des) & ~(ARCH_DMA_MINALIGN - 1);
 	ulong des_end = des_start +
 		roundup(sizeof(*curr_des), ARCH_DMA_MINALIGN);
-	ulong data_start = curr_des->rxdes3;
+	union ftgmac100_dma_addr data_start = { .lo = 0, .hi = 0 };
 	ulong data_end;
 
+	data_start.hi = FIELD_GET(FTGMAC100_RXDES2_RXBUF_BADR_HI, curr_des->rxdes2);
+	data_start.lo = curr_des->rxdes3;
 	invalidate_dcache_range(des_start, des_end);
 
 	if (!(curr_des->rxdes0 & FTGMAC100_RXDES0_RXPKT_RDY))
@@ -465,9 +496,9 @@ static int ftgmac100_recv(struct udevice *dev, int flags, uchar **packetp)
 	       __func__, priv->rx_index, rxlen);
 
 	/* Invalidate received data */
-	data_end = data_start + roundup(rxlen, ARCH_DMA_MINALIGN);
-	invalidate_dcache_range(data_start, data_end);
-	*packetp = (uchar *)data_start;
+	data_end = data_start.addr + roundup(rxlen, ARCH_DMA_MINALIGN);
+	invalidate_dcache_range(data_start.addr, data_end);
+	*packetp = (uchar *)data_start.addr;
 
 	return rxlen;
 }
@@ -493,6 +524,7 @@ static int ftgmac100_send(struct udevice *dev, void *packet, int length)
 	struct ftgmac100_data *priv = dev_get_priv(dev);
 	struct ftgmac100 *ftgmac100 = priv->iobase;
 	struct ftgmac100_txdes *curr_des = &priv->txdes[priv->tx_index];
+	union ftgmac100_dma_addr dma_addr;
 	ulong des_start = ((ulong)curr_des) & ~(ARCH_DMA_MINALIGN - 1);
 	ulong des_end = des_start +
 		roundup(sizeof(*curr_des), ARCH_DMA_MINALIGN);
@@ -511,10 +543,12 @@ static int ftgmac100_send(struct udevice *dev, void *packet, int length)
 
 	length = (length < ETH_ZLEN) ? ETH_ZLEN : length;
 
-	curr_des->txdes3 = (unsigned int)packet;
+	dma_addr.addr = (dma_addr_t)packet;
+	curr_des->txdes2 = FIELD_PREP(FTGMAC100_TXDES2_TXBUF_BADR_HI, dma_addr.hi);
+	curr_des->txdes3 = dma_addr.lo;
 
 	/* Flush data to be sent */
-	data_start = curr_des->txdes3;
+	data_start = (ulong)dma_addr.addr;
 	data_end = data_start + roundup(length, ARCH_DMA_MINALIGN);
 	flush_dcache_range(data_start, data_end);
 
@@ -577,6 +611,11 @@ static int ftgmac100_of_to_plat(struct udevice *dev)
 	if (dev_get_driver_data(dev) == FTGMAC100_MODEL_ASPEED) {
 		priv->rxdes0_edorr_mask = BIT(30);
 		priv->txdes0_edotr_mask = BIT(30);
+		priv->is_ast2700 = false;
+	} else if (dev_get_driver_data(dev) == FTGMAC100_MODEL_ASPEED_AST2700) {
+		priv->rxdes0_edorr_mask = BIT(30);
+		priv->txdes0_edotr_mask = BIT(30);
+		priv->is_ast2700 = true;
 	} else {
 		priv->rxdes0_edorr_mask = BIT(15);
 		priv->txdes0_edotr_mask = BIT(15);
@@ -667,10 +706,11 @@ static const struct eth_ops ftgmac100_ops = {
 };
 
 static const struct udevice_id ftgmac100_ids[] = {
-	{ .compatible = "faraday,ftgmac100",  .data = FTGMAC100_MODEL_FARADAY },
-	{ .compatible = "aspeed,ast2500-mac", .data = FTGMAC100_MODEL_ASPEED  },
-	{ .compatible = "aspeed,ast2600-mac", .data = FTGMAC100_MODEL_ASPEED  },
-	{ }
+	{ .compatible = "faraday,ftgmac100", .data = FTGMAC100_MODEL_FARADAY },
+	{ .compatible = "aspeed,ast2500-mac", .data = FTGMAC100_MODEL_ASPEED },
+	{ .compatible = "aspeed,ast2600-mac", .data = FTGMAC100_MODEL_ASPEED },
+	{ .compatible = "aspeed,ast2700-mac", .data = FTGMAC100_MODEL_ASPEED_AST2700 },
+	{}
 };
 
 U_BOOT_DRIVER(ftgmac100) = {
drivers/net/ftgmac100.h +12 -0
index 37c029aded..c38b57c954 100644
@@ -66,6 +66,13 @@ struct ftgmac100 {
 	unsigned int	rx_runt;	/* 0xc0 */
 	unsigned int	rx_crcer_ftl;	/* 0xc4 */
 	unsigned int	rx_col_lost;	/* 0xc8 */
+	unsigned int	reserved[43];	/* 0xcc - 0x174 */
+	unsigned int	txr_badr_lo;	/* 0x178, defined in ast2700 */
+	unsigned int	txr_badr_hi;	/* 0x17c, defined in ast2700 */
+	unsigned int	hptxr_badr_lo;	/* 0x180, defined in ast2700 */
+	unsigned int	hptxr_badr_hi;	/* 0x184, defined in ast2700 */
+	unsigned int	rxr_badr_lo;	/* 0x188, defined in ast2700 */
+	unsigned int	rxr_badr_hi;	/* 0x18c, defined in ast2700 */
 };
 
 /*
@@ -158,6 +165,7 @@ struct ftgmac100 {
 #define FTGMAC100_MACCR_RX_BROADPKT	BIT(17)
 #define FTGMAC100_MACCR_DISCARD_CRCERR	BIT(18)
 #define FTGMAC100_MACCR_FAST_MODE	BIT(19)
+#define FTGMAC100_MACCR_RMII_ENABLE	BIT(20)	/* defined in ast2700 */
 #define FTGMAC100_MACCR_SW_RST		BIT(31)
 
 /*
@@ -202,6 +210,8 @@ struct ftgmac100_txdes {
 #define FTGMAC100_TXDES1_TX2FIC		BIT(30)
 #define FTGMAC100_TXDES1_TXIC		BIT(31)
 
+#define FTGMAC100_TXDES2_TXBUF_BADR_HI	GENMASK(18, 16)
+
 /*
  * Receive descriptor, aligned to 16 bytes
  */
@@ -241,4 +251,6 @@ struct ftgmac100_rxdes {
 #define FTGMAC100_RXDES1_UDP_CHKSUM_ERR	BIT(26)
 #define FTGMAC100_RXDES1_IP_CHKSUM_ERR	BIT(27)
 
+#define FTGMAC100_RXDES2_RXBUF_BADR_HI	GENMASK(18, 16)
+
 #endif /* __FTGMAC100_H */
Signature · 1 line
2.25.1
Acked-by on v1 1/1
#1 lore raw
Quoted 10 lines · Jacky Chou

Add support of Aspeed AST2700 SoC. AST2700 is based on ARM64 so modify the DMA address related code to fit both ARM and ARM64. Besides, the RMII/RGMII mode control register is moved from SCU500 to MAC50 so initialize the register in ftgmac100_start correspondingly.

---
 drivers/net/ftgmac100.c | 66 +++++++++++++++++++++++++++++++++--------
 drivers/net/ftgmac100.h | 12 ++++++++
 2 files changed, 65 insertions(+), 13 deletions(-)
#2 lore raw
In reply to Jacky Chou

Hi Jacky,

Quoted 5 lines · Jacky Chou

Add support of Aspeed AST2700 SoC. AST2700 is based on ARM64 so modify the DMA address related code to fit both ARM and ARM64. Besides, the RMII/RGMII mode control register is moved from SCU500 to MAC50 so initialize the register in ftgmac100_start correspondingly.

It looks like these changes will affect the older platforms. Have you tested on an ast2600?

Is it okay to be writing to the new memory locations on the old platforms? If this is the case, please mention it in the commit message.

drivers/net/ftgmac100.c static int ftgmac100_start(struct udevice *dev) · line 336

Quoted 10 lines
drivers/net/ftgmac100.c +1 -0
index 9fb8c12838..a909a0b309 100644
@@ -321,6 +333,7 @@ static int ftgmac100_start(struct udevice *dev)
        struct eth_pdata *plat = dev_get_plat(dev);
        struct ftgmac100_data *priv = dev_get_priv(dev);
        struct ftgmac100 *ftgmac100 = priv->iobase;
+       union ftgmac100_dma_addr dma_addr = {.hi = 0, .lo = 0};

You always set dma_addr before using it, so this zero-init is unnecessary.

drivers/net/ftgmac100.c static int ftgmac100_start(struct udevice *dev) · line 376

Quoted 13 lines
drivers/net/ftgmac100.c +8 -1
@@ -352,7 +366,14 @@ static int ftgmac100_start(struct udevice *dev)
        flush_dcache_range(start, end);
 
        for (i = 0; i < PKTBUFSRX; i++) {
-               priv->rxdes[i].rxdes3 = (unsigned int)net_rx_packets[i];
+               unsigned int ip_align = 0;
+
+               dma_addr.addr = (dma_addr_t)net_rx_packets[i];
+               priv->rxdes[i].rxdes2 = FIELD_PREP(FTGMAC100_RXDES2_RXBUF_BADR_HI, dma_addr.hi);
+               /* For IP alignment */
+               if ((dma_addr.lo & (PKTALIGN - 1)) == 0)
+                       ip_align = 2;
+               priv->rxdes[i].rxdes3 = dma_addr.lo + ip_align;

Please explain why the old code didn't need alignment added, and the new version does.

drivers/net/ftgmac100.c static int ftgmac100_start(struct udevice *dev) · line 423

Quoted 6 lines
drivers/net/ftgmac100.c +2 -0
@@ -394,6 +419,10 @@ static int ftgmac100_start(struct udevice *dev)
                FTGMAC100_MACCR_RX_RUNT |
                FTGMAC100_MACCR_RX_BROADPKT;
 
+       if (priv->is_ast2700 && (priv->phydev->interface == PHY_INTERFACE_MODE_RMII ||
+                                priv->phydev->interface == PHY_INTERFACE_MODE_NCSI))

Use device_is_compatible(dev, "aspeed,ast2700-mac") instead of adding is_ast2700.

drivers/net/ftgmac100.c static int ftgmac100_recv(struct udevice *dev, int flags, uchar **packetp) · line 475

Quoted 11 lines
drivers/net/ftgmac100.c +3 -1
+               maccr |= FTGMAC100_MACCR_RMII_ENABLE;
+
        writel(maccr, &ftgmac100->maccr);
 
        ret = phy_startup(phydev);
@@ -443,9 +472,11 @@ static int ftgmac100_recv(struct udevice *dev, int flags, uchar **packetp)
        ulong des_start = ((ulong)curr_des) & ~(ARCH_DMA_MINALIGN - 1);
        ulong des_end = des_start +
                roundup(sizeof(*curr_des), ARCH_DMA_MINALIGN);
-       ulong data_start = curr_des->rxdes3;
+       union ftgmac100_dma_addr data_start = { .lo = 0, .hi = 0 };

Same here.

Quoted 5 lines
drivers/net/ftgmac100.c +2 -0
        ulong data_end;
 
+       data_start.hi = FIELD_GET(FTGMAC100_RXDES2_RXBUF_BADR_HI, curr_des->rxdes2);
+       data_start.lo = curr_des->rxdes3;
        invalidate_dcache_range(des_start, des_end);
author
#3 lore raw

Hello Joel,

Thanks for your reply.

Quoted 8 lines
Quoted 5 lines

Add support of Aspeed AST2700 SoC. AST2700 is based on ARM64 so modify the DMA address related code to fit both ARM and ARM64. Besides, the RMII/RGMII mode control register is moved from SCU500 to MAC50 so initialize the register in ftgmac100_start correspondingly.

It looks like these changes will affect the older platforms. Have you tested on an ast2600?

Yes. We have verified on AST2600 and AST2700. These changes do not affect.

Quoted 3 lines

Is it okay to be writing to the new memory locations on the old platforms? If this is the case, please mention it in the commit message.

Yes. I will refine the commit message to add more information in the next version.

Quoted 6 lines
Quoted 5 lines
drivers/net/ftgmac100.c index renamed from drivers/net/ftgmac100.c +0 -0

9fb8c12838..a909a0b309 100644

drivers/net/ftgmac100.c +0 -0
Quoted 7 lines

drivers/net/ftgmac100.c static int ftgmac100_start(struct udevice *dev) · line 336

Quoted 5 lines
drivers/net/ftgmac100.c +1 -0
@@ -321,6 +333,7 @@ static int ftgmac100_start(struct udevice *dev)
        struct eth_pdata *plat = dev_get_plat(dev);
        struct ftgmac100_data *priv = dev_get_priv(dev);
        struct ftgmac100 *ftgmac100 = priv->iobase;
+       union ftgmac100_dma_addr dma_addr = {.hi = 0, .lo = 0};

You always set dma_addr before using it, so this zero-init is unnecessary.

Agree. I checked this part again. It does not need to initialize the variable to zero. I will remove it in the next version. Thanks for your kindly reminder.

Quoted 11 lines

drivers/net/ftgmac100.c static int ftgmac100_start(struct udevice *dev) · line 372

Quoted 10 lines
drivers/net/ftgmac100.c +4 -1
@@ -352,7 +366,14 @@ static int ftgmac100_start(struct udevice *dev)
        flush_dcache_range(start, end);
 
        for (i = 0; i < PKTBUFSRX; i++) {
-               priv->rxdes[i].rxdes3 = (unsigned int)net_rx_packets[i];
+               unsigned int ip_align = 0;
+
+               dma_addr.addr = (dma_addr_t)net_rx_packets[i];
+               priv->rxdes[i].rxdes2 =

FIELD_PREP(FTGMAC100_RXDES2_RXBUF_BADR_HI, dma_addr.hi);

Quoted 7 lines

drivers/net/ftgmac100.c static int ftgmac100_start(struct udevice *dev) · line 376

Quoted 4 lines
drivers/net/ftgmac100.c +4 -0
+               /* For IP alignment */
+               if ((dma_addr.lo & (PKTALIGN - 1)) == 0)
+                       ip_align = 2;
+               priv->rxdes[i].rxdes3 = dma_addr.lo + ip_align;

Please explain why the old code didn't need alignment added, and the new version does.

Sorry. I forgot the driver no longer need to support IP alignmen. IP alignment was originally supported because the NCSI PHY driver would crash. I have fixed the NCSI PHY driver and have submitted fixed patch to U-boot. And it has accepted. Therefore, I will remove this part in the next version.

Quoted 5 lines
Quoted 5 lines
drivers/net/ftgmac100.c +0 -0
@@ -394,6 +419,10 @@ static int ftgmac100_start(struct udevice *dev)
                FTGMAC100_MACCR_RX_RUNT |
                FTGMAC100_MACCR_RX_BROADPKT;
 
Quoted 7 lines

drivers/net/ftgmac100.c static int ftgmac100_start(struct udevice *dev) · line 422

Quoted 1 line
drivers/net/ftgmac100.c +1 -0
+       if (priv->is_ast2700 && (priv->phydev->interface ==

PHY_INTERFACE_MODE_RMII ||

drivers/net/ftgmac100.c static int ftgmac100_start(struct udevice *dev) · line 424

Quoted 2 lines
drivers/net/ftgmac100.c +2 -0
+                                priv->phydev->interface ==
+ PHY_INTERFACE_MODE_NCSI))

Use device_is_compatible(dev, "aspeed,ast2700-mac") instead of adding is_ast2700.

Agree. I will adjust this code using device_is_compatible() in the next version.

Quoted 8 lines

drivers/net/ftgmac100.c static int ftgmac100_recv(struct udevice *dev, int

Quoted 7 lines
drivers/net/ftgmac100.c +2 -0
+               maccr |= FTGMAC100_MACCR_RMII_ENABLE;
+
        writel(maccr, &ftgmac100->maccr);
 
        ret = phy_startup(phydev);
@@ -443,9 +472,11 @@ static int ftgmac100_recv(struct udevice *dev, int

flags, uchar **packetp)

Quoted 8 lines

drivers/net/ftgmac100.c static int ftgmac100_recv(struct udevice *dev, int · line 472

Quoted 1 line
drivers/net/ftgmac100.c +0 -0
        ulong des_start = ((ulong)curr_des) & ~(ARCH_DMA_MINALIGN -

1);

drivers/net/ftgmac100.c static int ftgmac100_recv(struct udevice *dev, int flags, uchar **packetp) · line 475

Quoted 4 lines
drivers/net/ftgmac100.c +1 -1
        ulong des_end = des_start +
                roundup(sizeof(*curr_des), ARCH_DMA_MINALIGN);
-       ulong data_start = curr_des->rxdes3;
+       union ftgmac100_dma_addr data_start = { .lo = 0, .hi = 0 };

Same here.

I will remove it in the next version. Thanks for your kindly reminder.

Quoted 7 lines

drivers/net/ftgmac100.c static int ftgmac100_recv(struct udevice *dev, int flags, uchar **packetp)

Quoted 4 lines
drivers/net/ftgmac100.c +1 -0
        ulong data_end;
 
+       data_start.hi = FIELD_GET(FTGMAC100_RXDES2_RXBUF_BADR_HI,

curr_des->rxdes2);

Quoted 2 lines
drivers/net/ftgmac100.c +1 -0
+       data_start.lo = curr_des->rxdes3;
        invalidate_dcache_range(des_start, des_end);

Thanks,
Jacky