Skip to contentSkip to conversation

stmmac: Add Loongson platform support

PATCH Superseded Yanteng Si 6 participants 97 messages Jan 30, 2024 – Apr 5, 2024 4 messages not in the archive Page 1 of 2

Subsystems (5)

v8 of 17 Superseded Latest is v17 →

lore
Share & tools
lore

Yanteng Si

author
#0 lore raw

v8 cover stmmac: Add Loongson platform support

v8:
* The biggest change is according to Serge's comment in the previous edition:
Seeing the patch in the current state would overcomplicate the generic code and the only functions you need to update are dwmac_dma_interrupt()
dwmac1000_dma_init_channel()
you can have these methods re-defined with all the Loongson GNET specifics in the low-level platform driver (dwmac-loongson.c). After that you can just override the mac_device_info.dma pointer with a fixed stmmac_dma_ops descriptor. Here is what should be done for that:

1. Keep the Patch 4/9 with my comments fixed. First it will be partly useful for your GNET device. Second in general it's a correct implementation of the normal DW GMAC v3.x multi-channels feature and will be useful for the DW GMACs with that feature enabled.

2. Create the Loongson GNET-specific stmmac_dma_ops.dma_interrupt()
stmmac_dma_ops.init_chan()
methods in the dwmac-loongson.c driver. Don't forget to move all the Loongson-specific macros from dwmac_dma.h to dwmac-loongson.c.

3. Create a Loongson GNET-specific platform setup method with the next semantics:
+ allocate stmmac_dma_ops instance and initialize it with dwmac1000_dma_ops.
+ override the stmmac_dma_ops.{dma_interrupt, init_chan} with the pointers to the methods defined in 2.
+ allocate mac_device_info instance and initialize the mac_device_info.dma field with a pointer to the new stmmac_dma_ops instance.
+ call dwmac1000_setup() or initialize mac_device_info in a way it's done in dwmac1000_setup() (the later might be better so you wouldn't need to export the dwmac1000_setup() function).
+ override stmmac_priv.synopsys_id with a correct value.

4. Initialize plat_stmmacenet_data.setup() with the pointer to the method created in 3.

* Others:
Re-split the patch.
Passed checkpatch.pl test.

v7:
* Refer to andrew's suggestion:
- Add DMA_INTR_ENA_NIE_RX and DMA_INTR_ENA_NIE_TX #define's, etc.

* Others:
- Using --subject-prefix="PATCH net-next vN" to indicate that the patches are for the networking tree.
- Rebase to the latest networking tree:
<git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next.git>

v6:

* Refer to Serge's suggestion:
- Add new platform feature flag:

    include/linux/stmmac.h:
    +#define STMMAC_FLAG_HAS_LGMAC			BIT(13)

- Add the IRQs macros specific to the Loongson Multi-channels GMAC:

     drivers/net/ethernet/stmicro/stmmac/dwmac_dma.h:
     +#define DMA_INTR_ENA_NIE_LOONGSON 0x00060000      /* ...*/
     #define DMA_INTR_ENA_NIE 0x00010000	/* Normal Summary */
     ...

- Drop all of redundant changes that don't require the prototypes being converted to accepting the stmmac_priv pointer.

* Refer to andrew's suggestion:
- Drop white space changes.
- break patch up into lots of smaller parts.
Some small patches have been put into another series as a preparation see <https://lore.kernel.org/loongarch/[email protected]/T/#t>

*note* : This series of patches relies on the three small patches above.
* others
- Drop irq_flags changes.
- Changed patch order.

v4 -> v5:

* Remove an ugly and useless patch (fix channel number).
* Remove the non-standard dma64 driver code, and also remove the HWIF entries, since the associated custom callbacks no longer exist.
* Refer to Serge's suggestion: Update the dwmac1000_dma.c to support the multi-DMA-channels controller setup.

See:
v4: <https://lore.kernel.org/loongarch/[email protected]/>
v3: <https://lore.kernel.org/loongarch/[email protected]/>
v2: <https://lore.kernel.org/loongarch/[email protected]/>
v1: <https://lore.kernel.org/loongarch/[email protected]/>

Yanteng Si (11):
net: stmmac: Add multi-channel support
net: stmmac: dwmac-loongson: Refactor code for loongson_dwmac_probe()
net: stmmac: dwmac-loongson: Add full PCI support
net: stmmac: dwmac-loongson: Move irq config to loongson_gmac_config
net: stmmac: dwmac-loongson: Add Loongson-specific register
definitions
net: stmmac: dwmac-loongson: Add GNET support
net: stmmac: dwmac-loongson: Add multi-channel supports for loongson
net: stmmac: dwmac-loongson: Fix MAC speed for GNET
net: stmmac: dwmac-loongson: Fix half duplex
net: stmmac: dwmac-loongson: Disable flow control for GMAC
net: stmmac: dwmac-loongson: Disable coe for some Loongson GNET

 .../ethernet/stmicro/stmmac/dwmac-loongson.c  | 561 ++++++++++++++++--
 .../net/ethernet/stmicro/stmmac/dwmac-sun8i.c |   2 +-
 .../ethernet/stmicro/stmmac/dwmac1000_dma.c   |  36 +-
 .../net/ethernet/stmicro/stmmac/dwmac_dma.h   |  19 +-
 .../net/ethernet/stmicro/stmmac/dwmac_lib.c   |  32 +-
 drivers/net/ethernet/stmicro/stmmac/hwif.h    |   2 +-
 .../ethernet/stmicro/stmmac/stmmac_ethtool.c  |   6 +
 .../net/ethernet/stmicro/stmmac/stmmac_main.c |  15 +-
 include/linux/stmmac.h                        |   3 +
 9 files changed, 582 insertions(+), 94 deletions(-)
Signature · 1 line
2.31.4
author
#1 lore raw

PATCH v8 1/11 net: stmmac: Add multi-channel support

DW GMAC v3.x multi-channels feature is implemented as multiple sets of the same CSRs. Here is only preliminary support, it will be useful for the driver further evolution and for the users having multi-channel DWGMAC v3.x devices.

---
 .../net/ethernet/stmicro/stmmac/dwmac-sun8i.c |  2 +-
 .../ethernet/stmicro/stmmac/dwmac1000_dma.c   | 36 ++++++++++---------
 .../net/ethernet/stmicro/stmmac/dwmac_dma.h   | 19 +++++++++-
 .../net/ethernet/stmicro/stmmac/dwmac_lib.c   | 32 ++++++++---------
 drivers/net/ethernet/stmicro/stmmac/hwif.h    |  2 +-
 .../net/ethernet/stmicro/stmmac/stmmac_main.c |  6 ++--
 6 files changed, 58 insertions(+), 39 deletions(-)
drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c +1 -1
index 137741b94122..7cdfa0bdb93a 100644
@@ -395,7 +395,7 @@ static void sun8i_dwmac_dma_start_tx(struct stmmac_priv *priv,
 	writel(v, ioaddr + EMAC_TX_CTL1);
 }
 
-static void sun8i_dwmac_enable_dma_transmission(void __iomem *ioaddr)
+static void sun8i_dwmac_enable_dma_transmission(void __iomem *ioaddr, u32 chan)
 {
 	u32 v;
 
drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c +19 -17
index daf79cdbd3ec..5f7b82ad3ec2 100644
@@ -70,15 +70,18 @@ static void dwmac1000_dma_axi(void __iomem *ioaddr, struct stmmac_axi *axi)
 	writel(value, ioaddr + DMA_AXI_BUS_MODE);
 }
 
-static void dwmac1000_dma_init(void __iomem *ioaddr,
-			       struct stmmac_dma_cfg *dma_cfg, int atds)
+static void dwmac1000_dma_init_channel(struct stmmac_priv *priv,
+				       void __iomem *ioaddr,
+				       struct stmmac_dma_cfg *dma_cfg, u32 chan)
 {
-	u32 value = readl(ioaddr + DMA_BUS_MODE);
+	u32 value;
 	int txpbl = dma_cfg->txpbl ?: dma_cfg->pbl;
 	int rxpbl = dma_cfg->rxpbl ?: dma_cfg->pbl;
 
-	/*
-	 * Set the DMA PBL (Programmable Burst Length) mode.
+	/* common channel control register config */
+	value = readl(ioaddr + DMA_CHAN_BUS_MODE(chan));
+
+	/* Set the DMA PBL (Programmable Burst Length) mode.
 	 *
 	 * Note: before stmmac core 3.50 this mode bit was 4xPBL, and
 	 * post 3.5 mode bit acts as 8*PBL.
@@ -98,16 +101,15 @@ static void dwmac1000_dma_init(void __iomem *ioaddr,
 	if (dma_cfg->mixed_burst)
 		value |= DMA_BUS_MODE_MB;
 
-	if (atds)
-		value |= DMA_BUS_MODE_ATDS;
+	value |= DMA_BUS_MODE_ATDS;
 
 	if (dma_cfg->aal)
 		value |= DMA_BUS_MODE_AAL;
 
-	writel(value, ioaddr + DMA_BUS_MODE);
+	writel(value, ioaddr + DMA_CHAN_BUS_MODE(chan));
 
 	/* Mask interrupts by writing to CSR7 */
-	writel(DMA_INTR_DEFAULT_MASK, ioaddr + DMA_INTR_ENA);
+	writel(DMA_INTR_DEFAULT_MASK, ioaddr + DMA_CHAN_INTR_ENA(chan));
 }
 
 static void dwmac1000_dma_init_rx(struct stmmac_priv *priv,
@@ -116,7 +118,7 @@ static void dwmac1000_dma_init_rx(struct stmmac_priv *priv,
 				  dma_addr_t dma_rx_phy, u32 chan)
 {
 	/* RX descriptor base address list must be written into DMA CSR3 */
-	writel(lower_32_bits(dma_rx_phy), ioaddr + DMA_RCV_BASE_ADDR);
+	writel(lower_32_bits(dma_rx_phy), ioaddr + DMA_CHAN_RCV_BASE_ADDR(chan));
 }
 
 static void dwmac1000_dma_init_tx(struct stmmac_priv *priv,
@@ -125,7 +127,7 @@ static void dwmac1000_dma_init_tx(struct stmmac_priv *priv,
 				  dma_addr_t dma_tx_phy, u32 chan)
 {
 	/* TX descriptor base address list must be written into DMA CSR4 */
-	writel(lower_32_bits(dma_tx_phy), ioaddr + DMA_TX_BASE_ADDR);
+	writel(lower_32_bits(dma_tx_phy), ioaddr + DMA_CHAN_TX_BASE_ADDR(chan));
 }
 
 static u32 dwmac1000_configure_fc(u32 csr6, int rxfifosz)
@@ -153,7 +155,7 @@ static void dwmac1000_dma_operation_mode_rx(struct stmmac_priv *priv,
 					    void __iomem *ioaddr, int mode,
 					    u32 channel, int fifosz, u8 qmode)
 {
-	u32 csr6 = readl(ioaddr + DMA_CONTROL);
+	u32 csr6 = readl(ioaddr + DMA_CHAN_CONTROL(channel));
 
 	if (mode == SF_DMA_MODE) {
 		pr_debug("GMAC: enable RX store and forward mode\n");
@@ -175,14 +177,14 @@ static void dwmac1000_dma_operation_mode_rx(struct stmmac_priv *priv,
 	/* Configure flow control based on rx fifo size */
 	csr6 = dwmac1000_configure_fc(csr6, fifosz);
 
-	writel(csr6, ioaddr + DMA_CONTROL);
+	writel(csr6, ioaddr + DMA_CHAN_CONTROL(channel));
 }
 
 static void dwmac1000_dma_operation_mode_tx(struct stmmac_priv *priv,
 					    void __iomem *ioaddr, int mode,
 					    u32 channel, int fifosz, u8 qmode)
 {
-	u32 csr6 = readl(ioaddr + DMA_CONTROL);
+	u32 csr6 = readl(ioaddr + DMA_CHAN_CONTROL(channel));
 
 	if (mode == SF_DMA_MODE) {
 		pr_debug("GMAC: enable TX store and forward mode\n");
@@ -209,7 +211,7 @@ static void dwmac1000_dma_operation_mode_tx(struct stmmac_priv *priv,
 			csr6 |= DMA_CONTROL_TTC_256;
 	}
 
-	writel(csr6, ioaddr + DMA_CONTROL);
+	writel(csr6, ioaddr + DMA_CHAN_CONTROL(channel));
 }
 
 static void dwmac1000_dump_dma_regs(struct stmmac_priv *priv,
@@ -271,12 +273,12 @@ static int dwmac1000_get_hw_feature(void __iomem *ioaddr,
 static void dwmac1000_rx_watchdog(struct stmmac_priv *priv,
 				  void __iomem *ioaddr, u32 riwt, u32 queue)
 {
-	writel(riwt, ioaddr + DMA_RX_WATCHDOG);
+	writel(riwt, ioaddr + DMA_CHAN_RX_WATCHDOG(queue));
 }
 
 const struct stmmac_dma_ops dwmac1000_dma_ops = {
 	.reset = dwmac_dma_reset,
-	.init = dwmac1000_dma_init,
+	.init_chan = dwmac1000_dma_init_channel,
 	.init_rx_chan = dwmac1000_dma_init_rx,
 	.init_tx_chan = dwmac1000_dma_init_tx,
 	.axi = dwmac1000_dma_axi,
drivers/net/ethernet/stmicro/stmmac/dwmac_dma.h +18 -1
index 72672391675f..593be79c46e1 100644
@@ -148,11 +148,14 @@
 					 DMA_STATUS_TI | \
 					 DMA_STATUS_MSK_COMMON)
 
+/* Following DMA defines are chanels oriented */
+#define DMA_CHAN_OFFSET			0x100
+
 #define NUM_DWMAC100_DMA_REGS	9
 #define NUM_DWMAC1000_DMA_REGS	23
 #define NUM_DWMAC4_DMA_REGS	27
 
-void dwmac_enable_dma_transmission(void __iomem *ioaddr);
+void dwmac_enable_dma_transmission(void __iomem *ioaddr, u32 chan);
 void dwmac_enable_dma_irq(struct stmmac_priv *priv, void __iomem *ioaddr,
 			  u32 chan, bool rx, bool tx);
 void dwmac_disable_dma_irq(struct stmmac_priv *priv, void __iomem *ioaddr,
@@ -169,4 +172,18 @@ int dwmac_dma_interrupt(struct stmmac_priv *priv, void __iomem *ioaddr,
 			struct stmmac_extra_stats *x, u32 chan, u32 dir);
 int dwmac_dma_reset(void __iomem *ioaddr);
 
+static inline u32 dma_chan_base_addr(u32 base, u32 chan)
+{
+	return base + chan * DMA_CHAN_OFFSET;
+}
+
+#define DMA_CHAN_XMT_POLL_DEMAND(chan)	dma_chan_base_addr(DMA_XMT_POLL_DEMAND, chan)
+#define DMA_CHAN_INTR_ENA(chan)		dma_chan_base_addr(DMA_INTR_ENA, chan)
+#define DMA_CHAN_CONTROL(chan)		dma_chan_base_addr(DMA_CONTROL, chan)
+#define DMA_CHAN_STATUS(chan)		dma_chan_base_addr(DMA_STATUS, chan)
+#define DMA_CHAN_BUS_MODE(chan)		dma_chan_base_addr(DMA_BUS_MODE, chan)
+#define DMA_CHAN_RCV_BASE_ADDR(chan)	dma_chan_base_addr(DMA_RCV_BASE_ADDR, chan)
+#define DMA_CHAN_TX_BASE_ADDR(chan)	dma_chan_base_addr(DMA_TX_BASE_ADDR, chan)
+#define DMA_CHAN_RX_WATCHDOG(chan)	dma_chan_base_addr(DMA_RX_WATCHDOG, chan)
+
 #endif /* __DWMAC_DMA_H__ */
drivers/net/ethernet/stmicro/stmmac/dwmac_lib.c +16 -16
index 7907d62d3437..b37368137810 100644
@@ -28,65 +28,65 @@ int dwmac_dma_reset(void __iomem *ioaddr)
 }
 
 /* CSR1 enables the transmit DMA to check for new descriptor */
-void dwmac_enable_dma_transmission(void __iomem *ioaddr)
+void dwmac_enable_dma_transmission(void __iomem *ioaddr, u32 chan)
 {
-	writel(1, ioaddr + DMA_XMT_POLL_DEMAND);
+	writel(1, ioaddr + DMA_CHAN_XMT_POLL_DEMAND(chan));
 }
 
 void dwmac_enable_dma_irq(struct stmmac_priv *priv, void __iomem *ioaddr,
 			  u32 chan, bool rx, bool tx)
 {
-	u32 value = readl(ioaddr + DMA_INTR_ENA);
+	u32 value = readl(ioaddr + DMA_CHAN_INTR_ENA(chan));
 
 	if (rx)
 		value |= DMA_INTR_DEFAULT_RX;
 	if (tx)
 		value |= DMA_INTR_DEFAULT_TX;
 
-	writel(value, ioaddr + DMA_INTR_ENA);
+	writel(value, ioaddr + DMA_CHAN_INTR_ENA(chan));
 }
 
 void dwmac_disable_dma_irq(struct stmmac_priv *priv, void __iomem *ioaddr,
 			   u32 chan, bool rx, bool tx)
 {
-	u32 value = readl(ioaddr + DMA_INTR_ENA);
+	u32 value = readl(ioaddr + DMA_CHAN_INTR_ENA(chan));
 
 	if (rx)
 		value &= ~DMA_INTR_DEFAULT_RX;
 	if (tx)
 		value &= ~DMA_INTR_DEFAULT_TX;
 
-	writel(value, ioaddr + DMA_INTR_ENA);
+	writel(value, ioaddr + DMA_CHAN_INTR_ENA(chan));
 }
 
 void dwmac_dma_start_tx(struct stmmac_priv *priv, void __iomem *ioaddr,
 			u32 chan)
 {
-	u32 value = readl(ioaddr + DMA_CONTROL);
+	u32 value = readl(ioaddr + DMA_CHAN_CONTROL(chan));
 	value |= DMA_CONTROL_ST;
-	writel(value, ioaddr + DMA_CONTROL);
+	writel(value, ioaddr + DMA_CHAN_CONTROL(chan));
 }
 
 void dwmac_dma_stop_tx(struct stmmac_priv *priv, void __iomem *ioaddr, u32 chan)
 {
-	u32 value = readl(ioaddr + DMA_CONTROL);
+	u32 value = readl(ioaddr + DMA_CHAN_CONTROL(chan));
 	value &= ~DMA_CONTROL_ST;
-	writel(value, ioaddr + DMA_CONTROL);
+	writel(value, ioaddr + DMA_CHAN_CONTROL(chan));
 }
 
 void dwmac_dma_start_rx(struct stmmac_priv *priv, void __iomem *ioaddr,
 			u32 chan)
 {
-	u32 value = readl(ioaddr + DMA_CONTROL);
+	u32 value = readl(ioaddr + DMA_CHAN_CONTROL(chan));
 	value |= DMA_CONTROL_SR;
-	writel(value, ioaddr + DMA_CONTROL);
+	writel(value, ioaddr + DMA_CHAN_CONTROL(chan));
 }
 
 void dwmac_dma_stop_rx(struct stmmac_priv *priv, void __iomem *ioaddr, u32 chan)
 {
-	u32 value = readl(ioaddr + DMA_CONTROL);
+	u32 value = readl(ioaddr + DMA_CHAN_CONTROL(chan));
 	value &= ~DMA_CONTROL_SR;
-	writel(value, ioaddr + DMA_CONTROL);
+	writel(value, ioaddr + DMA_CHAN_CONTROL(chan));
 }
 
 #ifdef DWMAC_DMA_DEBUG
@@ -166,7 +166,7 @@ int dwmac_dma_interrupt(struct stmmac_priv *priv, void __iomem *ioaddr,
 	struct stmmac_txq_stats *txq_stats = &priv->xstats.txq_stats[chan];
 	int ret = 0;
 	/* read the status register (CSR5) */
-	u32 intr_status = readl(ioaddr + DMA_STATUS);
+	u32 intr_status = readl(ioaddr + DMA_CHAN_STATUS(chan));
 
 #ifdef DWMAC_DMA_DEBUG
 	/* Enable it to monitor DMA rx/tx status in case of critical problems */
@@ -236,7 +236,7 @@ int dwmac_dma_interrupt(struct stmmac_priv *priv, void __iomem *ioaddr,
 		pr_warn("%s: unexpected status %08x\n", __func__, intr_status);
 
 	/* Clear the interrupt by writing a logic 1 to the CSR5[15-0] */
-	writel((intr_status & 0x1ffff), ioaddr + DMA_STATUS);
+	writel((intr_status & 0x7ffff), ioaddr + DMA_CHAN_STATUS(chan));
 
 	return ret;
 }
drivers/net/ethernet/stmicro/stmmac/hwif.h +1 -1
index 7be04b54738b..b0db38396171 100644
@@ -198,7 +198,7 @@ struct stmmac_dma_ops {
 	/* To track extra statistic (if supported) */
 	void (*dma_diagnostic_fr)(struct stmmac_extra_stats *x,
 				  void __iomem *ioaddr);
-	void (*enable_dma_transmission) (void __iomem *ioaddr);
+	void (*enable_dma_transmission)(void __iomem *ioaddr, u32 chan);
 	void (*enable_dma_irq)(struct stmmac_priv *priv, void __iomem *ioaddr,
 			       u32 chan, bool rx, bool tx);
 	void (*disable_dma_irq)(struct stmmac_priv *priv, void __iomem *ioaddr,
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +3 -3
index b334eb16da23..5617b40abbe4 100644
@@ -2558,7 +2558,7 @@ static bool stmmac_xdp_xmit_zc(struct stmmac_priv *priv, u32 queue, u32 budget)
 				       true, priv->mode, true, true,
 				       xdp_desc.len);
 
-		stmmac_enable_dma_transmission(priv, priv->ioaddr);
+		stmmac_enable_dma_transmission(priv, priv->ioaddr, queue);
 
 		xsk_tx_metadata_to_compl(meta,
 					 &tx_q->tx_skbuff_dma[entry].xsk_meta);
@@ -4706,7 +4706,7 @@ static netdev_tx_t stmmac_xmit(struct sk_buff *skb, struct net_device *dev)
 
 	netdev_tx_sent_queue(netdev_get_tx_queue(dev, queue), skb->len);
 
-	stmmac_enable_dma_transmission(priv, priv->ioaddr);
+	stmmac_enable_dma_transmission(priv, priv->ioaddr, queue);
 
 	stmmac_flush_tx_descriptors(priv, queue);
 	stmmac_tx_timer_arm(priv, queue);
@@ -4926,7 +4926,7 @@ static int stmmac_xdp_xmit_xdpf(struct stmmac_priv *priv, int queue,
 		u64_stats_update_end_irqrestore(&txq_stats->syncp, flags);
 	}
 
-	stmmac_enable_dma_transmission(priv, priv->ioaddr);
+	stmmac_enable_dma_transmission(priv, priv->ioaddr, queue);
 
 	entry = STMMAC_GET_ENTRY(entry, priv->dma_conf.dma_tx_size);
 	tx_q->cur_tx = entry;
Signature · 1 line
2.31.4
author
#16 lore raw

PATCH v8 2/11 net: stmmac: dwmac-loongson: Refactor code for loongson_dwmac_probe()

In reply to Yanteng Si

The driver function is not changed, but the code location is adjusted to prepare for adding more loongson drivers.

---
 .../ethernet/stmicro/stmmac/dwmac-loongson.c  | 61 +++++++++++++------
 1 file changed, 42 insertions(+), 19 deletions(-)
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +42 -19
index 9e40c28d453a..e2dcb339b8b0 100644
@@ -9,7 +9,12 @@
 #include <linux/of_irq.h>
 #include "stmmac.h"
 
-static int loongson_default_data(struct plat_stmmacenet_data *plat)
+struct stmmac_pci_info {
+	int (*setup)(struct pci_dev *pdev, struct plat_stmmacenet_data *plat);
+};
+
+static void loongson_default_data(struct pci_dev *pdev,
+				  struct plat_stmmacenet_data *plat)
 {
 	plat->clk_csr = 2;	/* clk_csr_i = 20-35MHz & MDC = clk_csr_i/16 */
 	plat->has_gmac = 1;
@@ -34,23 +39,37 @@ static int loongson_default_data(struct plat_stmmacenet_data *plat)
 
 	/* Disable RX queues routing by default */
 	plat->rx_queues_cfg[0].pkt_route = 0x0;
+}
+
+static int loongson_gmac_data(struct pci_dev *pdev,
+			      struct plat_stmmacenet_data *plat)
+{
+	loongson_default_data(pdev, plat);
+
+	plat->multicast_filter_bins = 256;
+
+	plat->mdio_bus_data->phy_mask = 0;
 
-	/* Default to phy auto-detection */
 	plat->phy_addr = -1;
 
 	plat->dma_cfg->pbl = 32;
 	plat->dma_cfg->pblx8 = true;
 
-	plat->multicast_filter_bins = 256;
 	return 0;
 }
 
-static int loongson_dwmac_probe(struct pci_dev *pdev, const struct pci_device_id *id)
+static struct stmmac_pci_info loongson_gmac_pci_info = {
+	.setup = loongson_gmac_data,
+};
+
+static int loongson_dwmac_probe(struct pci_dev *pdev,
+				const struct pci_device_id *id)
 {
+	int ret, i, bus_id, phy_mode;
 	struct plat_stmmacenet_data *plat;
+	struct stmmac_pci_info *info;
 	struct stmmac_resources res;
 	struct device_node *np;
-	int ret, i, phy_mode;
 
 	np = dev_of_node(&pdev->dev);
 
@@ -69,18 +88,17 @@ static int loongson_dwmac_probe(struct pci_dev *pdev, const struct pci_device_id
 	if (!plat->mdio_bus_data)
 		return -ENOMEM;
 
+	plat->dma_cfg = devm_kzalloc(&pdev->dev, sizeof(*plat->dma_cfg),
+				     GFP_KERNEL);
+	if (!plat->dma_cfg)
+		return -ENOMEM;
+
 	plat->mdio_node = of_get_child_by_name(np, "mdio");
 	if (plat->mdio_node) {
 		dev_info(&pdev->dev, "Found MDIO subnode\n");
 		plat->mdio_bus_data->needs_reset = true;
 	}
 
-	plat->dma_cfg = devm_kzalloc(&pdev->dev, sizeof(*plat->dma_cfg), GFP_KERNEL);
-	if (!plat->dma_cfg) {
-		ret = -ENOMEM;
-		goto err_put_node;
-	}
-
 	/* Enable pci device */
 	ret = pci_enable_device(pdev);
 	if (ret) {
@@ -98,9 +116,16 @@ static int loongson_dwmac_probe(struct pci_dev *pdev, const struct pci_device_id
 		break;
 	}
 
-	plat->bus_id = of_alias_get_id(np, "ethernet");
-	if (plat->bus_id < 0)
-		plat->bus_id = pci_dev_id(pdev);
+	pci_set_master(pdev);
+
+	info = (struct stmmac_pci_info *)id->driver_data;
+	ret = info->setup(pdev, plat);
+	if (ret)
+		goto err_disable_device;
+
+	bus_id = of_alias_get_id(np, "ethernet");
+	if (bus_id >= 0)
+		plat->bus_id = bus_id;
 
 	phy_mode = device_get_phy_mode(&pdev->dev);
 	if (phy_mode < 0) {
@@ -110,11 +135,7 @@ static int loongson_dwmac_probe(struct pci_dev *pdev, const struct pci_device_id
 	}
 
 	plat->phy_interface = phy_mode;
-	plat->mac_interface = PHY_INTERFACE_MODE_GMII;
 
-	pci_set_master(pdev);
-
-	loongson_default_data(plat);
 	pci_enable_msi(pdev);
 	memset(&res, 0, sizeof(res));
 	res.addr = pcim_iomap_table(pdev)[0];
@@ -212,8 +233,10 @@ static int __maybe_unused loongson_dwmac_resume(struct device *dev)
 static SIMPLE_DEV_PM_OPS(loongson_dwmac_pm_ops, loongson_dwmac_suspend,
 			 loongson_dwmac_resume);
 
+#define PCI_DEVICE_ID_LOONGSON_GMAC	0x7a03
+
 static const struct pci_device_id loongson_dwmac_id_table[] = {
-	{ PCI_VDEVICE(LOONGSON, 0x7a03) },
+	{ PCI_DEVICE_DATA(LOONGSON, GMAC, &loongson_gmac_pci_info) },
 	{}
 };
 MODULE_DEVICE_TABLE(pci, loongson_dwmac_id_table);
Signature · 1 line
2.31.4
author
#21 lore raw

PATCH v8 3/11 net: stmmac: dwmac-loongson: Add full PCI support

In reply to Yanteng Si

Current dwmac-loongson only support LS2K in the "probed with PCI and configured with DT" manner. Add LS7A support on which the devices are fully PCI (non-DT).

---
 .../ethernet/stmicro/stmmac/dwmac-loongson.c  | 79 +++++++++++--------
 1 file changed, 44 insertions(+), 35 deletions(-)
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +44 -35
index e2dcb339b8b0..979c9b6dab3f 100644
@@ -16,6 +16,10 @@ struct stmmac_pci_info {
 static void loongson_default_data(struct pci_dev *pdev,
 				  struct plat_stmmacenet_data *plat)
 {
+	/* Get bus_id, this can be overloaded later */
+	plat->bus_id = (pci_domain_nr(pdev->bus) << 16) |
+		       PCI_DEVID(pdev->bus->number, pdev->devfn);
+
 	plat->clk_csr = 2;	/* clk_csr_i = 20-35MHz & MDC = clk_csr_i/16 */
 	plat->has_gmac = 1;
 	plat->force_sf_dma_mode = 1;
@@ -51,10 +55,14 @@ static int loongson_gmac_data(struct pci_dev *pdev,
 	plat->mdio_bus_data->phy_mask = 0;
 
 	plat->phy_addr = -1;
+	plat->phy_interface = PHY_INTERFACE_MODE_RGMII_ID;
 
 	plat->dma_cfg->pbl = 32;
 	plat->dma_cfg->pblx8 = true;
 
+	plat->clk_ref_rate = 125000000;
+	plat->clk_ptp_rate = 125000000;
+
 	return 0;
 }
 
@@ -71,13 +79,6 @@ static int loongson_dwmac_probe(struct pci_dev *pdev,
 	struct stmmac_resources res;
 	struct device_node *np;
 
-	np = dev_of_node(&pdev->dev);
-
-	if (!np) {
-		pr_info("dwmac_loongson_pci: No OF node\n");
-		return -ENODEV;
-	}
-
 	plat = devm_kzalloc(&pdev->dev, sizeof(*plat), GFP_KERNEL);
 	if (!plat)
 		return -ENOMEM;
@@ -93,6 +94,7 @@ static int loongson_dwmac_probe(struct pci_dev *pdev,
 	if (!plat->dma_cfg)
 		return -ENOMEM;
 
+	np = dev_of_node(&pdev->dev);
 	plat->mdio_node = of_get_child_by_name(np, "mdio");
 	if (plat->mdio_node) {
 		dev_info(&pdev->dev, "Found MDIO subnode\n");
@@ -123,41 +125,48 @@ static int loongson_dwmac_probe(struct pci_dev *pdev,
 	if (ret)
 		goto err_disable_device;
 
-	bus_id = of_alias_get_id(np, "ethernet");
-	if (bus_id >= 0)
-		plat->bus_id = bus_id;
+	if (np) {
+		bus_id = of_alias_get_id(np, "ethernet");
+		if (bus_id >= 0)
+			plat->bus_id = bus_id;
 
-	phy_mode = device_get_phy_mode(&pdev->dev);
-	if (phy_mode < 0) {
-		dev_err(&pdev->dev, "phy_mode not found\n");
-		ret = phy_mode;
-		goto err_disable_device;
+		phy_mode = device_get_phy_mode(&pdev->dev);
+		if (phy_mode < 0) {
+			dev_err(&pdev->dev, "phy_mode not found\n");
+			ret = phy_mode;
+			goto err_disable_device;
+		}
+		plat->phy_interface = phy_mode;
 	}
 
-	plat->phy_interface = phy_mode;
-
 	pci_enable_msi(pdev);
 	memset(&res, 0, sizeof(res));
 	res.addr = pcim_iomap_table(pdev)[0];
 
-	res.irq = of_irq_get_byname(np, "macirq");
-	if (res.irq < 0) {
-		dev_err(&pdev->dev, "IRQ macirq not found\n");
-		ret = -ENODEV;
-		goto err_disable_msi;
-	}
-
-	res.wol_irq = of_irq_get_byname(np, "eth_wake_irq");
-	if (res.wol_irq < 0) {
-		dev_info(&pdev->dev, "IRQ eth_wake_irq not found, using macirq\n");
-		res.wol_irq = res.irq;
-	}
-
-	res.lpi_irq = of_irq_get_byname(np, "eth_lpi");
-	if (res.lpi_irq < 0) {
-		dev_err(&pdev->dev, "IRQ eth_lpi not found\n");
-		ret = -ENODEV;
-		goto err_disable_msi;
+	if (np) {
+		res.irq = of_irq_get_byname(np, "macirq");
+		if (res.irq < 0) {
+			dev_err(&pdev->dev, "IRQ macirq not found\n");
+			ret = -ENODEV;
+			goto err_disable_msi;
+		}
+
+		res.wol_irq = of_irq_get_byname(np, "eth_wake_irq");
+		if (res.wol_irq < 0) {
+			dev_info(&pdev->dev,
+				 "IRQ eth_wake_irq not found, using macirq\n");
+			res.wol_irq = res.irq;
+		}
+
+		res.lpi_irq = of_irq_get_byname(np, "eth_lpi");
+		if (res.lpi_irq < 0) {
+			dev_err(&pdev->dev, "IRQ eth_lpi not found\n");
+			ret = -ENODEV;
+			goto err_disable_msi;
+		}
+	} else {
+		res.irq = pdev->irq;
+		res.wol_irq = pdev->irq;
 	}
 
 	ret = stmmac_dvr_probe(&pdev->dev, plat, &res);
Signature · 1 line
2.31.4
author
#24 lore raw

PATCH v8 4/11 net: stmmac: dwmac-loongson: Move irq config to loongson_gmac_config

In reply to Yanteng Si

Add loongson_dwmac_config and moving irq config related code to loongson_dwmac_config.

Removing MSI to prepare for adding loongson multi-channel support later.

---
 .../ethernet/stmicro/stmmac/dwmac-loongson.c  | 85 ++++++++++++-------
 1 file changed, 55 insertions(+), 30 deletions(-)
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +55 -30
index 979c9b6dab3f..e7ce027cc14e 100644
@@ -11,8 +11,46 @@
 
 struct stmmac_pci_info {
 	int (*setup)(struct pci_dev *pdev, struct plat_stmmacenet_data *plat);
+	int (*config)(struct pci_dev *pdev, struct plat_stmmacenet_data *plat,
+		      struct stmmac_resources *res, struct device_node *np);
 };
 
+static int loongson_dwmac_config_legacy(struct pci_dev *pdev,
+					struct plat_stmmacenet_data *plat,
+					struct stmmac_resources *res,
+					struct device_node *np)
+{
+	if (np) {
+		res->irq = of_irq_get_byname(np, "macirq");
+		if (res->irq < 0) {
+			dev_err(&pdev->dev, "IRQ macirq not found\n");
+			return -ENODEV;
+		}
+
+		res->wol_irq = of_irq_get_byname(np, "eth_wake_irq");
+		if (res->wol_irq < 0) {
+			dev_info(&pdev->dev,
+				 "IRQ eth_wake_irq not found, using macirq\n");
+			res->wol_irq = res->irq;
+		}
+
+		res->lpi_irq = of_irq_get_byname(np, "eth_lpi");
+		if (res->lpi_irq < 0) {
+			dev_err(&pdev->dev, "IRQ eth_lpi not found\n");
+			return -ENODEV;
+		}
+	} else {
+		res->irq = pdev->irq;
+		res->wol_irq = res->irq;
+	}
+
+	plat->flags &= ~STMMAC_FLAG_MULTI_MSI_EN;
+	dev_info(&pdev->dev, "%s: Single IRQ enablement successful\n",
+		 __func__);
+
+	return 0;
+}
+
 static void loongson_default_data(struct pci_dev *pdev,
 				  struct plat_stmmacenet_data *plat)
 {
@@ -66,8 +104,21 @@ static int loongson_gmac_data(struct pci_dev *pdev,
 	return 0;
 }
 
+static int loongson_gmac_config(struct pci_dev *pdev,
+				struct plat_stmmacenet_data *plat,
+				struct stmmac_resources *res,
+				struct device_node *np)
+{
+	int ret;
+
+	ret = loongson_dwmac_config_legacy(pdev, plat, res, np);
+
+	return ret;
+}
+
 static struct stmmac_pci_info loongson_gmac_pci_info = {
 	.setup = loongson_gmac_data,
+	.config = loongson_gmac_config,
 };
 
 static int loongson_dwmac_probe(struct pci_dev *pdev,
@@ -139,44 +190,19 @@ static int loongson_dwmac_probe(struct pci_dev *pdev,
 		plat->phy_interface = phy_mode;
 	}
 
-	pci_enable_msi(pdev);
 	memset(&res, 0, sizeof(res));
 	res.addr = pcim_iomap_table(pdev)[0];
 
-	if (np) {
-		res.irq = of_irq_get_byname(np, "macirq");
-		if (res.irq < 0) {
-			dev_err(&pdev->dev, "IRQ macirq not found\n");
-			ret = -ENODEV;
-			goto err_disable_msi;
-		}
-
-		res.wol_irq = of_irq_get_byname(np, "eth_wake_irq");
-		if (res.wol_irq < 0) {
-			dev_info(&pdev->dev,
-				 "IRQ eth_wake_irq not found, using macirq\n");
-			res.wol_irq = res.irq;
-		}
-
-		res.lpi_irq = of_irq_get_byname(np, "eth_lpi");
-		if (res.lpi_irq < 0) {
-			dev_err(&pdev->dev, "IRQ eth_lpi not found\n");
-			ret = -ENODEV;
-			goto err_disable_msi;
-		}
-	} else {
-		res.irq = pdev->irq;
-		res.wol_irq = pdev->irq;
-	}
+	ret = info->config(pdev, plat, &res, np);
+	if (ret)
+		goto err_disable_device;
 
 	ret = stmmac_dvr_probe(&pdev->dev, plat, &res);
 	if (ret)
-		goto err_disable_msi;
+		goto err_disable_device;
 
 	return ret;
 
-err_disable_msi:
-	pci_disable_msi(pdev);
 err_disable_device:
 	pci_disable_device(pdev);
 err_put_node:
@@ -200,7 +226,6 @@ static void loongson_dwmac_remove(struct pci_dev *pdev)
 		break;
 	}
 
-	pci_disable_msi(pdev);
 	pci_disable_device(pdev);
 }
 
Signature · 1 line
2.31.4
author
#29 lore raw

PATCH v8 5/11 net: stmmac: dwmac-loongson: Add Loongson-specific register definitions

In reply to Yanteng Si

There are two types of Loongson DWGMAC. The first type shares the same register definitions and has similar logic as dwmac1000. The second type uses several different register definitions, we think it is necessary to distinguish rx and tx, so we split these bits into two.

Simply put, we split some single bit fields into double bits fileds:

Name Tx Rx

DMA_INTR_ENA_NIE = 0x00040000 | 0x00020000;
DMA_INTR_ENA_AIE = 0x00010000 | 0x00008000;
DMA_STATUS_NIS   = 0x00040000 | 0x00020000;
DMA_STATUS_AIS   = 0x00010000 | 0x00008000;
DMA_STATUS_FBI   = 0x00002000 | 0x00001000;

Therefore, when using, TX and RX must be set at the same time.

How to use them:
1. Create the Loongson GNET-specific stmmac_dma_ops.dma_interrupt() stmmac_dma_ops.init_chan()
methods in the dwmac-loongson.c driver. Adding all the Loongson-specific macros

2. Create a Loongson GNET-specific platform setup method with the next semantics:
+ allocate stmmac_dma_ops instance and initialize it with

     dwmac1000_dma_ops.
   + override the stmmac_dma_ops.{dma_interrupt, init_chan} with
     the pointers to the methods defined in 2.
   + allocate mac_device_info instance and initialize the
     mac_device_info.dma field with a pointer to the new
     stmmac_dma_ops instance.
   + initialize mac_device_info in a way it's done in
     dwmac1000_setup().

3. Initialize plat_stmmacenet_data.setup() with the pointer to the method created in 2.

---
 .../ethernet/stmicro/stmmac/dwmac-loongson.c  | 248 ++++++++++++++++++
 1 file changed, 248 insertions(+)
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +248 -0
index e7ce027cc14e..3b3578318cc1 100644
@@ -8,6 +8,193 @@
 #include <linux/device.h>
 #include <linux/of_irq.h>
 #include "stmmac.h"
+#include "dwmac_dma.h"
+#include "dwmac1000.h"
+
+#define DMA_INTR_ENA_NIE_TX_LOONGSON 0x00040000	/* Normal Loongson Tx Summary */
+#define DMA_INTR_ENA_NIE_RX_LOONGSON 0x00020000	/* Normal Loongson Rx Summary */
+#define DMA_INTR_NORMAL_LOONGSON	(DMA_INTR_ENA_NIE_TX_LOONGSON | \
+			 DMA_INTR_ENA_NIE_RX_LOONGSON | DMA_INTR_ENA_RIE | \
+			 DMA_INTR_ENA_TIE)
+
+#define DMA_INTR_ENA_AIE_TX_LOONGSON 0x00010000	/* Abnormal Loongson Tx Summary */
+#define DMA_INTR_ENA_AIE_RX_LOONGSON 0x00008000	/* Abnormal Loongson Rx Summary */
+
+#define DMA_INTR_ABNORMAL_LOONGSON	(DMA_INTR_ENA_AIE_TX_LOONGSON | \
+				DMA_INTR_ENA_AIE_RX_LOONGSON | DMA_INTR_ENA_FBE | \
+				DMA_INTR_ENA_UNE)
+
+#define DMA_INTR_DEFAULT_MASK_LOONGSON	(DMA_INTR_NORMAL_LOONGSON | DMA_INTR_ABNORMAL_LOONGSON)
+
+#define DMA_STATUS_NIS_TX_LOONGSON	0x00040000	/* Normal Loongson Tx Interrupt Summary */
+#define DMA_STATUS_NIS_RX_LOONGSON	0x00020000	/* Normal Loongson Rx Interrupt Summary */
+
+#define DMA_STATUS_AIS_TX_LOONGSON	0x00010000	/* Abnormal Loongson Tx Interrupt Summary */
+#define DMA_STATUS_AIS_RX_LOONGSON	0x00008000	/* Abnormal Loongson Rx Interrupt Summary */
+
+#define DMA_STATUS_FBI_TX_LOONGSON	0x00002000	/* Fatal Loongson Tx Bus Error Interrupt */
+#define DMA_STATUS_FBI_RX_LOONGSON	0x00001000	/* Fatal Loongson Rx Bus Error Interrupt */
+
+#define DMA_STATUS_MSK_COMMON_LOONGSON		(DMA_STATUS_NIS_TX_LOONGSON | \
+					 DMA_STATUS_NIS_RX_LOONGSON | DMA_STATUS_AIS_TX_LOONGSON | \
+					 DMA_STATUS_AIS_RX_LOONGSON | DMA_STATUS_FBI_TX_LOONGSON | \
+					 DMA_STATUS_FBI_RX_LOONGSON)
+
+#define DMA_STATUS_MSK_RX_LOONGSON		(DMA_STATUS_ERI | \
+					 DMA_STATUS_RWT | \
+					 DMA_STATUS_RPS | \
+					 DMA_STATUS_RU | \
+					 DMA_STATUS_RI | \
+					 DMA_STATUS_OVF | \
+					 DMA_STATUS_MSK_COMMON_LOONGSON)
+
+#define DMA_STATUS_MSK_TX_LOONGSON		(DMA_STATUS_ETI | \
+					 DMA_STATUS_UNF | \
+					 DMA_STATUS_TJT | \
+					 DMA_STATUS_TU | \
+					 DMA_STATUS_TPS | \
+					 DMA_STATUS_TI | \
+					 DMA_STATUS_MSK_COMMON_LOONGSON)
+
+struct loongson_data {
+	struct device *dev;
+	u32 lgmac_version;
+	struct stmmac_dma_ops dwlgmac_dma_ops;
+};
+
+static void dwlgmac_dma_init_channel(struct stmmac_priv *priv,
+				     void __iomem *ioaddr,
+				     struct stmmac_dma_cfg *dma_cfg, u32 chan)
+{
+	u32 value;
+	int txpbl = dma_cfg->txpbl ?: dma_cfg->pbl;
+	int rxpbl = dma_cfg->rxpbl ?: dma_cfg->pbl;
+
+	/* common channel control register config */
+	value = readl(ioaddr + DMA_CHAN_BUS_MODE(chan));
+
+	/* Set the DMA PBL (Programmable Burst Length) mode.
+	 *
+	 * Note: before stmmac core 3.50 this mode bit was 4xPBL, and
+	 * post 3.5 mode bit acts as 8*PBL.
+	 */
+	if (dma_cfg->pblx8)
+		value |= DMA_BUS_MODE_MAXPBL;
+	value |= DMA_BUS_MODE_USP;
+	value &= ~(DMA_BUS_MODE_PBL_MASK | DMA_BUS_MODE_RPBL_MASK);
+	value |= (txpbl << DMA_BUS_MODE_PBL_SHIFT);
+	value |= (rxpbl << DMA_BUS_MODE_RPBL_SHIFT);
+
+	/* Set the Fixed burst mode */
+	if (dma_cfg->fixed_burst)
+		value |= DMA_BUS_MODE_FB;
+
+	/* Mixed Burst has no effect when fb is set */
+	if (dma_cfg->mixed_burst)
+		value |= DMA_BUS_MODE_MB;
+
+	value |= DMA_BUS_MODE_ATDS;
+
+	if (dma_cfg->aal)
+		value |= DMA_BUS_MODE_AAL;
+
+	writel(value, ioaddr + DMA_BUS_MODE);
+
+	/* Mask interrupts by writing to CSR7 */
+	writel(DMA_INTR_DEFAULT_MASK_LOONGSON, ioaddr + DMA_INTR_ENA);
+}
+
+static int dwlgmac_dma_interrupt(struct stmmac_priv *priv, void __iomem *ioaddr,
+				 struct stmmac_extra_stats *x, u32 chan, u32 dir)
+{
+	struct stmmac_rxq_stats *rxq_stats = &priv->xstats.rxq_stats[chan];
+	struct stmmac_txq_stats *txq_stats = &priv->xstats.txq_stats[chan];
+	int ret = 0;
+	/* read the status register (CSR5) */
+	u32 nor_intr_status;
+	u32 abnor_intr_status;
+	u32 fb_intr_status;
+	u32 intr_status = readl(ioaddr + DMA_CHAN_STATUS(chan));
+
+#ifdef DWMAC_DMA_DEBUG
+	/* Enable it to monitor DMA rx/tx status in case of critical problems */
+	pr_debug("%s: [CSR5: 0x%08x]\n", __func__, intr_status);
+	show_tx_process_state(intr_status);
+	show_rx_process_state(intr_status);
+#endif
+
+	if (dir == DMA_DIR_RX)
+		intr_status &= DMA_STATUS_MSK_RX_LOONGSON;
+	else if (dir == DMA_DIR_TX)
+		intr_status &= DMA_STATUS_MSK_TX_LOONGSON;
+
+	nor_intr_status = intr_status & (DMA_STATUS_NIS_TX_LOONGSON |
+		DMA_STATUS_NIS_RX_LOONGSON);
+	abnor_intr_status = intr_status & (DMA_STATUS_AIS_TX_LOONGSON |
+		DMA_STATUS_AIS_RX_LOONGSON);
+	fb_intr_status = intr_status & (DMA_STATUS_FBI_TX_LOONGSON |
+		DMA_STATUS_FBI_RX_LOONGSON);
+
+	/* ABNORMAL interrupts */
+	if (unlikely(abnor_intr_status)) {
+		if (unlikely(intr_status & DMA_STATUS_UNF)) {
+			ret = tx_hard_error_bump_tc;
+			x->tx_undeflow_irq++;
+		}
+		if (unlikely(intr_status & DMA_STATUS_TJT))
+			x->tx_jabber_irq++;
+
+		if (unlikely(intr_status & DMA_STATUS_OVF))
+			x->rx_overflow_irq++;
+
+		if (unlikely(intr_status & DMA_STATUS_RU))
+			x->rx_buf_unav_irq++;
+		if (unlikely(intr_status & DMA_STATUS_RPS))
+			x->rx_process_stopped_irq++;
+		if (unlikely(intr_status & DMA_STATUS_RWT))
+			x->rx_watchdog_irq++;
+		if (unlikely(intr_status & DMA_STATUS_ETI))
+			x->tx_early_irq++;
+		if (unlikely(intr_status & DMA_STATUS_TPS)) {
+			x->tx_process_stopped_irq++;
+			ret = tx_hard_error;
+		}
+		if (unlikely(intr_status & fb_intr_status)) {
+			x->fatal_bus_error_irq++;
+			ret = tx_hard_error;
+		}
+	}
+	/* TX/RX NORMAL interrupts */
+	if (likely(nor_intr_status)) {
+		if (likely(intr_status & DMA_STATUS_RI)) {
+			u32 value = readl(ioaddr + DMA_INTR_ENA);
+			/* to schedule NAPI on real RIE event. */
+			if (likely(value & DMA_INTR_ENA_RIE)) {
+				u64_stats_update_begin(&rxq_stats->syncp);
+				rxq_stats->rx_normal_irq_n++;
+				u64_stats_update_end(&rxq_stats->syncp);
+				ret |= handle_rx;
+			}
+		}
+		if (likely(intr_status & DMA_STATUS_TI)) {
+			u64_stats_update_begin(&txq_stats->syncp);
+			txq_stats->tx_normal_irq_n++;
+			u64_stats_update_end(&txq_stats->syncp);
+			ret |= handle_tx;
+		}
+		if (unlikely(intr_status & DMA_STATUS_ERI))
+			x->rx_early_irq++;
+	}
+	/* Optional hardware blocks, interrupts should be disabled */
+	if (unlikely(intr_status &
+		     (DMA_STATUS_GPI | DMA_STATUS_GMI | DMA_STATUS_GLI)))
+		pr_warn("%s: unexpected status %08x\n", __func__, intr_status);
+
+	/* Clear the interrupt by writing a logic 1 to the CSR5[15-0] */
+	writel((intr_status & 0x7ffff), ioaddr + DMA_CHAN_STATUS(chan));
+
+	return ret;
+}
 
 struct stmmac_pci_info {
 	int (*setup)(struct pci_dev *pdev, struct plat_stmmacenet_data *plat);
@@ -121,6 +308,48 @@ static struct stmmac_pci_info loongson_gmac_pci_info = {
 	.config = loongson_gmac_config,
 };
 
+static struct mac_device_info *loongson_setup(void *apriv)
+{
+	struct stmmac_priv *priv = apriv;
+	struct mac_device_info *mac;
+	struct loongson_data *ld;
+
+	mac = devm_kzalloc(priv->device, sizeof(*mac), GFP_KERNEL);
+	if (!mac)
+		return NULL;
+
+	ld = priv->plat->bsp_priv;
+	mac->dma = &ld->dwlgmac_dma_ops;
+
+	/* Pre-initialize the respective "mac" fields as it's done in
+	 * dwmac1000_setup()
+	 */
+	priv->dev->priv_flags |= IFF_UNICAST_FLT;
+	mac->pcsr = priv->ioaddr;
+	mac->multicast_filter_bins = priv->plat->multicast_filter_bins;
+	mac->unicast_filter_entries = priv->plat->unicast_filter_entries;
+	mac->mcast_bits_log2 = 0;
+
+	if (mac->multicast_filter_bins)
+		mac->mcast_bits_log2 = ilog2(mac->multicast_filter_bins);
+
+	mac->link.duplex = GMAC_CONTROL_DM;
+	mac->link.speed10 = GMAC_CONTROL_PS;
+	mac->link.speed100 = GMAC_CONTROL_PS | GMAC_CONTROL_FES;
+	mac->link.speed1000 = 0;
+	mac->link.speed_mask = GMAC_CONTROL_PS | GMAC_CONTROL_FES;
+	mac->mii.addr = GMAC_MII_ADDR;
+	mac->mii.data = GMAC_MII_DATA;
+	mac->mii.addr_shift = 11;
+	mac->mii.addr_mask = 0x0000F800;
+	mac->mii.reg_shift = 6;
+	mac->mii.reg_mask = 0x000007C0;
+	mac->mii.clk_csr_shift = 2;
+	mac->mii.clk_csr_mask = GENMASK(5, 2);
+
+	return mac;
+}
+
 static int loongson_dwmac_probe(struct pci_dev *pdev,
 				const struct pci_device_id *id)
 {
@@ -129,6 +358,7 @@ static int loongson_dwmac_probe(struct pci_dev *pdev,
 	struct stmmac_pci_info *info;
 	struct stmmac_resources res;
 	struct device_node *np;
+	struct loongson_data *ld;
 
 	plat = devm_kzalloc(&pdev->dev, sizeof(*plat), GFP_KERNEL);
 	if (!plat)
@@ -145,6 +375,10 @@ static int loongson_dwmac_probe(struct pci_dev *pdev,
 	if (!plat->dma_cfg)
 		return -ENOMEM;
 
+	ld = devm_kzalloc(&pdev->dev, sizeof(*ld), GFP_KERNEL);
+	if (!ld)
+		return -ENOMEM;
+
 	np = dev_of_node(&pdev->dev);
 	plat->mdio_node = of_get_child_by_name(np, "mdio");
 	if (plat->mdio_node) {
@@ -197,6 +431,20 @@ static int loongson_dwmac_probe(struct pci_dev *pdev,
 	if (ret)
 		goto err_disable_device;
 
+	ld->dev = &pdev->dev;
+	ld->lgmac_version = readl(res.addr + GMAC_VERSION) & 0xff;
+
+	/* Activate loongson custom ip */
+	if (ld->lgmac_version < DWMAC_CORE_3_50) {
+		ld->dwlgmac_dma_ops = dwmac1000_dma_ops;
+		ld->dwlgmac_dma_ops.init_chan = dwlgmac_dma_init_channel;
+		ld->dwlgmac_dma_ops.dma_interrupt = dwlgmac_dma_interrupt;
+
+		plat->setup = loongson_setup;
+	}
+
+	plat->bsp_priv = ld;
+
 	ret = stmmac_dvr_probe(&pdev->dev, plat, &res);
 	if (ret)
 		goto err_disable_device;
Signature · 1 line
2.31.4
author
#38 lore raw

PATCH v8 6/11 net: stmmac: dwmac-loongson: Add GNET support

In reply to Yanteng Si

Add Loongson GNET (GMAC with PHY) support, override stmmac_priv.synopsys_id with 0x37.

---
 .../ethernet/stmicro/stmmac/dwmac-loongson.c  | 44 +++++++++++++++++++
 1 file changed, 44 insertions(+)
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +44 -0
index 3b3578318cc1..584f7322bd3e 100644
@@ -318,6 +318,8 @@ static struct mac_device_info *loongson_setup(void *apriv)
 	if (!mac)
 		return NULL;
 
+	priv->synopsys_id = 0x37;	/*Overwrite custom IP*/
+
 	ld = priv->plat->bsp_priv;
 	mac->dma = &ld->dwlgmac_dma_ops;
 
@@ -350,6 +352,46 @@ static struct mac_device_info *loongson_setup(void *apriv)
 	return mac;
 }
 
+static int loongson_gnet_data(struct pci_dev *pdev,
+			      struct plat_stmmacenet_data *plat)
+{
+	loongson_default_data(pdev, plat);
+
+	plat->multicast_filter_bins = 256;
+
+	plat->mdio_bus_data->phy_mask =  ~(u32)BIT(2);
+
+	plat->phy_addr = 2;
+	plat->phy_interface = PHY_INTERFACE_MODE_INTERNAL;
+
+	plat->bsp_priv = &pdev->dev;
+
+	plat->dma_cfg->pbl = 32;
+	plat->dma_cfg->pblx8 = true;
+
+	plat->clk_ref_rate = 125000000;
+	plat->clk_ptp_rate = 125000000;
+
+	return 0;
+}
+
+static int loongson_gnet_config(struct pci_dev *pdev,
+				struct plat_stmmacenet_data *plat,
+				struct stmmac_resources *res,
+				struct device_node *np)
+{
+	int ret;
+
+	ret = loongson_dwmac_config_legacy(pdev, plat, res, np);
+
+	return ret;
+}
+
+static struct stmmac_pci_info loongson_gnet_pci_info = {
+	.setup = loongson_gnet_data,
+	.config = loongson_gnet_config,
+};
+
 static int loongson_dwmac_probe(struct pci_dev *pdev,
 				const struct pci_device_id *id)
 {
@@ -516,9 +558,11 @@ static SIMPLE_DEV_PM_OPS(loongson_dwmac_pm_ops, loongson_dwmac_suspend,
 			 loongson_dwmac_resume);
 
 #define PCI_DEVICE_ID_LOONGSON_GMAC	0x7a03
+#define PCI_DEVICE_ID_LOONGSON_GNET	0x7a13
 
 static const struct pci_device_id loongson_dwmac_id_table[] = {
 	{ PCI_DEVICE_DATA(LOONGSON, GMAC, &loongson_gmac_pci_info) },
+	{ PCI_DEVICE_DATA(LOONGSON, GNET, &loongson_gnet_pci_info) },
 	{}
 };
 MODULE_DEVICE_TABLE(pci, loongson_dwmac_id_table);
Signature · 1 line
2.31.4
author
#49 lore raw

PATCH v8 7/11 net: stmmac: dwmac-loongson: Add multi-channel supports for loongson

In reply to Yanteng Si

Request allocation for MSI for specific versions.

Some features of Loongson platforms are bound to the GMAC_VERSION register. We have to read its value in order to get the correct channel number.

---
 .../ethernet/stmicro/stmmac/dwmac-loongson.c  | 57 +++++++++++++++----
 1 file changed, 46 insertions(+), 11 deletions(-)
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +46 -11
index 584f7322bd3e..60d0a122d7c9 100644
@@ -98,10 +98,10 @@ static void dwlgmac_dma_init_channel(struct stmmac_priv *priv,
 	if (dma_cfg->aal)
 		value |= DMA_BUS_MODE_AAL;
 
-	writel(value, ioaddr + DMA_BUS_MODE);
+	writel(value, ioaddr + DMA_CHAN_BUS_MODE(chan));
 
 	/* Mask interrupts by writing to CSR7 */
-	writel(DMA_INTR_DEFAULT_MASK_LOONGSON, ioaddr + DMA_INTR_ENA);
+	writel(DMA_INTR_DEFAULT_MASK_LOONGSON, ioaddr + DMA_CHAN_INTR_ENA(chan));
 }
 
 static int dwlgmac_dma_interrupt(struct stmmac_priv *priv, void __iomem *ioaddr,
@@ -238,6 +238,45 @@ static int loongson_dwmac_config_legacy(struct pci_dev *pdev,
 	return 0;
 }
 
+static int loongson_dwmac_config_multi_msi(struct pci_dev *pdev,
+					   struct plat_stmmacenet_data *plat,
+					   struct stmmac_resources *res,
+					   struct device_node *np,
+					   int channel_num)
+{
+	int i, ret, vecs;
+
+	vecs = roundup_pow_of_two(channel_num * 2 + 1);
+	ret = pci_alloc_irq_vectors(pdev, vecs, vecs, PCI_IRQ_MSI);
+	if (ret < 0) {
+		dev_info(&pdev->dev,
+			 "MSI enable failed, Fallback to legacy interrupt\n");
+		return loongson_dwmac_config_legacy(pdev, plat, res, np);
+	}
+
+	plat->rx_queues_to_use = channel_num;
+	plat->tx_queues_to_use = channel_num;
+
+	res->irq = pci_irq_vector(pdev, 0);
+	res->wol_irq = res->irq;
+
+	/* INT NAME | MAC | CH7 rx | CH7 tx | ... | CH0 rx | CH0 tx |
+	 * --------- ----- -------- --------  ...  -------- --------
+	 * IRQ NUM  |  0  |   1    |   2    | ... |   15   |   16   |
+	 */
+	for (i = 0; i < channel_num; i++) {
+		res->rx_irq[channel_num - 1 - i] =
+			pci_irq_vector(pdev, 1 + i * 2);
+		res->tx_irq[channel_num - 1 - i] =
+			pci_irq_vector(pdev, 2 + i * 2);
+	}
+
+	plat->flags |= STMMAC_FLAG_MULTI_MSI_EN;
+	dev_info(&pdev->dev, "%s: multi MSI enablement successful\n", __func__);
+
+	return 0;
+}
+
 static void loongson_default_data(struct pci_dev *pdev,
 				  struct plat_stmmacenet_data *plat)
 {
@@ -296,11 +335,8 @@ static int loongson_gmac_config(struct pci_dev *pdev,
 				struct stmmac_resources *res,
 				struct device_node *np)
 {
-	int ret;
-
-	ret = loongson_dwmac_config_legacy(pdev, plat, res, np);
 
-	return ret;
+	return 0;
 }
 
 static struct stmmac_pci_info loongson_gmac_pci_info = {
@@ -380,11 +416,7 @@ static int loongson_gnet_config(struct pci_dev *pdev,
 				struct stmmac_resources *res,
 				struct device_node *np)
 {
-	int ret;
-
-	ret = loongson_dwmac_config_legacy(pdev, plat, res, np);
-
-	return ret;
+	return 0;
 }
 
 static struct stmmac_pci_info loongson_gnet_pci_info = {
@@ -483,6 +515,9 @@ static int loongson_dwmac_probe(struct pci_dev *pdev,
 		ld->dwlgmac_dma_ops.dma_interrupt = dwlgmac_dma_interrupt;
 
 		plat->setup = loongson_setup;
+		ret = loongson_dwmac_config_multi_msi(pdev, plat, &res, np, 8);
+	} else {
+		ret = loongson_dwmac_config_legacy(pdev, plat, &res, np);
 	}
 
 	plat->bsp_priv = ld;
Signature · 1 line
2.31.4
author
#60 lore raw

PATCH v8 8/11 net: stmmac: dwmac-loongson: Fix MAC speed for GNET

In reply to Yanteng Si

Current GNET on LS7A only supports ANE when speed is set to 1000M.

---
 .../ethernet/stmicro/stmmac/dwmac-loongson.c  | 19 +++++++++++++++++++
 .../ethernet/stmicro/stmmac/stmmac_ethtool.c  |  6 ++++++
 include/linux/stmmac.h                        |  1 +
 3 files changed, 26 insertions(+)
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +19 -0
index 60d0a122d7c9..264c4c198d5a 100644
@@ -344,6 +344,21 @@ static struct stmmac_pci_info loongson_gmac_pci_info = {
 	.config = loongson_gmac_config,
 };
 
+static void loongson_gnet_fix_speed(void *priv, unsigned int speed, unsigned int mode)
+{
+	struct loongson_data *ld = (struct loongson_data *)priv;
+	struct net_device *ndev = dev_get_drvdata(ld->dev);
+	struct stmmac_priv *ptr = netdev_priv(ndev);
+
+	/* The controller and PHY don't work well together.
+	 * We need to use the PS bit to check if the controller's status
+	 * is correct and reset PHY if necessary.
+	 */
+	if (speed == SPEED_1000)
+		if (readl(ptr->ioaddr + MAC_CTRL_REG) & (1 << 15) /* PS */)
+			phy_restart_aneg(ndev->phydev);
+}
+
 static struct mac_device_info *loongson_setup(void *apriv)
 {
 	struct stmmac_priv *priv = apriv;
@@ -401,6 +416,7 @@ static int loongson_gnet_data(struct pci_dev *pdev,
 	plat->phy_interface = PHY_INTERFACE_MODE_INTERNAL;
 
 	plat->bsp_priv = &pdev->dev;
+	plat->fix_mac_speed = loongson_gnet_fix_speed;
 
 	plat->dma_cfg->pbl = 32;
 	plat->dma_cfg->pblx8 = true;
@@ -416,6 +432,9 @@ static int loongson_gnet_config(struct pci_dev *pdev,
 				struct stmmac_resources *res,
 				struct device_node *np)
 {
+	if (pdev->revision == 0x00 || pdev->revision == 0x01)
+		plat->flags |= STMMAC_FLAG_DISABLE_FORCE_1000;
+
 	return 0;
 }
 
drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c +6 -0
index 42d27b97dd1d..31068fbc23c9 100644
@@ -422,6 +422,12 @@ stmmac_ethtool_set_link_ksettings(struct net_device *dev,
 		return 0;
 	}
 
+	if (FIELD_GET(STMMAC_FLAG_DISABLE_FORCE_1000, priv->plat->flags)) {
+		if (cmd->base.speed == SPEED_1000 &&
+		    cmd->base.autoneg != AUTONEG_ENABLE)
+			return -EOPNOTSUPP;
+	}
+
 	return phylink_ethtool_ksettings_set(priv->phylink, cmd);
 }
 
include/linux/stmmac.h +1 -0
index dee5ad6e48c5..2810361e4048 100644
@@ -221,6 +221,7 @@ struct dwmac4_addrs {
 #define STMMAC_FLAG_RX_CLK_RUNS_IN_LPI		BIT(10)
 #define STMMAC_FLAG_EN_TX_LPI_CLOCKGATING	BIT(11)
 #define STMMAC_FLAG_HWTSTAMP_CORRECT_LATENCY	BIT(12)
+#define STMMAC_FLAG_DISABLE_FORCE_1000	BIT(13)
 
 struct plat_stmmacenet_data {
 	int bus_id;
Signature · 1 line
2.31.4
author
#76 lore raw

PATCH v8 9/11 net: stmmac: dwmac-loongson: Fix half duplex

In reply to Yanteng Si

Current GNET does not support half duplex mode.

---
 drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c | 11 ++++++++++-
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c    |  3 ++-
 include/linux/stmmac.h                               |  1 +
 3 files changed, 13 insertions(+), 2 deletions(-)
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +10 -1
index 264c4c198d5a..1753a3c46b77 100644
@@ -432,8 +432,17 @@ static int loongson_gnet_config(struct pci_dev *pdev,
 				struct stmmac_resources *res,
 				struct device_node *np)
 {
-	if (pdev->revision == 0x00 || pdev->revision == 0x01)
+	switch (pdev->revision) {
+	case 0x00:
+		plat->flags |= STMMAC_FLAG_DISABLE_FORCE_1000 |
+			       STMMAC_FLAG_DISABLE_HALF_DUPLEX;
+		break;
+	case 0x01:
 		plat->flags |= STMMAC_FLAG_DISABLE_FORCE_1000;
+		break;
+	default:
+		break;
+	}
 
 	return 0;
 }
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +2 -1
index 5617b40abbe4..3aa862269eb0 100644
@@ -1201,7 +1201,8 @@ static int stmmac_init_phy(struct net_device *dev)
 static void stmmac_set_half_duplex(struct stmmac_priv *priv)
 {
 	/* Half-Duplex can only work with single tx queue */
-	if (priv->plat->tx_queues_to_use > 1)
+	if (priv->plat->tx_queues_to_use > 1 ||
+	    (STMMAC_FLAG_DISABLE_HALF_DUPLEX & priv->plat->flags))
 		priv->phylink_config.mac_capabilities &=
 			~(MAC_10HD | MAC_100HD | MAC_1000HD);
 	else
include/linux/stmmac.h +1 -0
index 2810361e4048..197f6f914104 100644
@@ -222,6 +222,7 @@ struct dwmac4_addrs {
 #define STMMAC_FLAG_EN_TX_LPI_CLOCKGATING	BIT(11)
 #define STMMAC_FLAG_HWTSTAMP_CORRECT_LATENCY	BIT(12)
 #define STMMAC_FLAG_DISABLE_FORCE_1000	BIT(13)
+#define STMMAC_FLAG_DISABLE_HALF_DUPLEX	BIT(14)
 
 struct plat_stmmacenet_data {
 	int bus_id;
Signature · 1 line
2.31.4
author
#90 lore raw

PATCH v8 10/11 net: stmmac: dwmac-loongson: Disable flow control for GMAC

In reply to Yanteng Si

Loongson GMAC does not support Flow Control feature. Set flags to disable it.

---
 drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c | 1 +
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c    | 6 +++---
 include/linux/stmmac.h                               | 1 +
 3 files changed, 5 insertions(+), 3 deletions(-)
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +1 -0
index 1753a3c46b77..b78a73ea748b 100644
@@ -335,6 +335,7 @@ static int loongson_gmac_config(struct pci_dev *pdev,
 				struct stmmac_resources *res,
 				struct device_node *np)
 {
+	plat->flags |= STMMAC_FLAG_DISABLE_FLOW_CONTROL;
 
 	return 0;
 }
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +3 -3
index 3aa862269eb0..8d676cbfba1e 100644
@@ -1237,9 +1237,9 @@ static int stmmac_phy_setup(struct stmmac_priv *priv)
 		xpcs_get_interfaces(priv->hw->xpcs,
 				    priv->phylink_config.supported_interfaces);
 
-	priv->phylink_config.mac_capabilities = MAC_ASYM_PAUSE | MAC_SYM_PAUSE |
-						MAC_10FD | MAC_100FD |
-						MAC_1000FD;
+	priv->phylink_config.mac_capabilities = MAC_10FD | MAC_100FD | MAC_1000FD;
+	if (!(priv->plat->flags & STMMAC_FLAG_DISABLE_FLOW_CONTROL))
+		priv->phylink_config.mac_capabilities |= MAC_ASYM_PAUSE | MAC_SYM_PAUSE;
 
 	stmmac_set_half_duplex(priv);
 
include/linux/stmmac.h +1 -0
index 197f6f914104..832cd8cd688f 100644
@@ -223,6 +223,7 @@ struct dwmac4_addrs {
 #define STMMAC_FLAG_HWTSTAMP_CORRECT_LATENCY	BIT(12)
 #define STMMAC_FLAG_DISABLE_FORCE_1000	BIT(13)
 #define STMMAC_FLAG_DISABLE_HALF_DUPLEX	BIT(14)
+#define STMMAC_FLAG_DISABLE_FLOW_CONTROL	BIT(15)
 
 struct plat_stmmacenet_data {
 	int bus_id;
Signature · 1 line
2.31.4
author
#93 lore raw

PATCH v8 11/11 net: stmmac: dwmac-loongson: Disable coe for some Loongson GNET

In reply to Yanteng Si

Some chips of Loongson GNET does not support coe, so disable them.

Set dma_cap->tx_coe to 0 and overwrite get_hw_feature.

---
 .../ethernet/stmicro/stmmac/dwmac-loongson.c  | 46 +++++++++++++++++++
 1 file changed, 46 insertions(+)
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +46 -0
index b78a73ea748b..8018d7d5f31b 100644
@@ -196,6 +196,51 @@ static int dwlgmac_dma_interrupt(struct stmmac_priv *priv, void __iomem *ioaddr,
 	return ret;
 }
 
+static int dwlgmac_get_hw_feature(void __iomem *ioaddr,
+				  struct dma_features *dma_cap)
+{
+	u32 hw_cap = readl(ioaddr + DMA_HW_FEATURE);
+
+	if (!hw_cap) {
+		/* 0x00000000 is the value read on old hardware that does not
+		 * implement this register
+		 */
+		return -EOPNOTSUPP;
+	}
+
+	dma_cap->mbps_10_100 = (hw_cap & DMA_HW_FEAT_MIISEL);
+	dma_cap->mbps_1000 = (hw_cap & DMA_HW_FEAT_GMIISEL) >> 1;
+	dma_cap->half_duplex = (hw_cap & DMA_HW_FEAT_HDSEL) >> 2;
+	dma_cap->hash_filter = (hw_cap & DMA_HW_FEAT_HASHSEL) >> 4;
+	dma_cap->multi_addr = (hw_cap & DMA_HW_FEAT_ADDMAC) >> 5;
+	dma_cap->pcs = (hw_cap & DMA_HW_FEAT_PCSSEL) >> 6;
+	dma_cap->sma_mdio = (hw_cap & DMA_HW_FEAT_SMASEL) >> 8;
+	dma_cap->pmt_remote_wake_up = (hw_cap & DMA_HW_FEAT_RWKSEL) >> 9;
+	dma_cap->pmt_magic_frame = (hw_cap & DMA_HW_FEAT_MGKSEL) >> 10;
+	/* MMC */
+	dma_cap->rmon = (hw_cap & DMA_HW_FEAT_MMCSEL) >> 11;
+	/* IEEE 1588-2002 */
+	dma_cap->time_stamp =
+	    (hw_cap & DMA_HW_FEAT_TSVER1SEL) >> 12;
+	/* IEEE 1588-2008 */
+	dma_cap->atime_stamp = (hw_cap & DMA_HW_FEAT_TSVER2SEL) >> 13;
+	/* 802.3az - Energy-Efficient Ethernet (EEE) */
+	dma_cap->eee = (hw_cap & DMA_HW_FEAT_EEESEL) >> 14;
+	dma_cap->av = (hw_cap & DMA_HW_FEAT_AVSEL) >> 15;
+	/* TX and RX csum */
+	dma_cap->tx_coe = 0;
+	dma_cap->rx_coe_type1 = (hw_cap & DMA_HW_FEAT_RXTYP1COE) >> 17;
+	dma_cap->rx_coe_type2 = (hw_cap & DMA_HW_FEAT_RXTYP2COE) >> 18;
+	dma_cap->rxfifo_over_2048 = (hw_cap & DMA_HW_FEAT_RXFIFOSIZE) >> 19;
+	/* TX and RX number of channels */
+	dma_cap->number_rx_channel = (hw_cap & DMA_HW_FEAT_RXCHCNT) >> 20;
+	dma_cap->number_tx_channel = (hw_cap & DMA_HW_FEAT_TXCHCNT) >> 22;
+	/* Alternate (enhanced) DESC mode */
+	dma_cap->enh_desc = (hw_cap & DMA_HW_FEAT_ENHDESSEL) >> 24;
+
+	return 0;
+}
+
 struct stmmac_pci_info {
 	int (*setup)(struct pci_dev *pdev, struct plat_stmmacenet_data *plat);
 	int (*config)(struct pci_dev *pdev, struct plat_stmmacenet_data *plat,
@@ -542,6 +587,7 @@ static int loongson_dwmac_probe(struct pci_dev *pdev,
 		ld->dwlgmac_dma_ops = dwmac1000_dma_ops;
 		ld->dwlgmac_dma_ops.init_chan = dwlgmac_dma_init_channel;
 		ld->dwlgmac_dma_ops.dma_interrupt = dwlgmac_dma_interrupt;
+		ld->dwlgmac_dma_ops.get_hw_feature = dwlgmac_get_hw_feature;
 
 		plat->setup = loongson_setup;
 		ret = loongson_dwmac_config_multi_msi(pdev, plat, &res, np, 8);
Signature · 1 line
2.31.4
#98 lore raw
In reply to Yanteng Si

Hi Yanteng

Quoted 37 lines · Yanteng Si

v8:
* The biggest change is according to Serge's comment in the previous edition:
Seeing the patch in the current state would overcomplicate the generic code and the only functions you need to update are dwmac_dma_interrupt()
dwmac1000_dma_init_channel()
you can have these methods re-defined with all the Loongson GNET specifics in the low-level platform driver (dwmac-loongson.c). After that you can just override the mac_device_info.dma pointer with a fixed stmmac_dma_ops descriptor. Here is what should be done for that:

1. Keep the Patch 4/9 with my comments fixed. First it will be partly useful for your GNET device. Second in general it's a correct implementation of the normal DW GMAC v3.x multi-channels feature and will be useful for the DW GMACs with that feature enabled.

2. Create the Loongson GNET-specific stmmac_dma_ops.dma_interrupt()
stmmac_dma_ops.init_chan()
methods in the dwmac-loongson.c driver. Don't forget to move all the Loongson-specific macros from dwmac_dma.h to dwmac-loongson.c.

3. Create a Loongson GNET-specific platform setup method with the next semantics:
+ allocate stmmac_dma_ops instance and initialize it with dwmac1000_dma_ops.
+ override the stmmac_dma_ops.{dma_interrupt, init_chan} with the pointers to the methods defined in 2.
+ allocate mac_device_info instance and initialize the mac_device_info.dma field with a pointer to the new stmmac_dma_ops instance.
+ call dwmac1000_setup() or initialize mac_device_info in a way it's done in dwmac1000_setup() (the later might be better so you wouldn't need to export the dwmac1000_setup() function).
+ override stmmac_priv.synopsys_id with a correct value.

Quoted 6 lines

4. Initialize plat_stmmacenet_data.setup() with the pointer to the method created in 3.

* Others:
Re-split the patch.
Passed checkpatch.pl test.

Thanks for the updated series. I'll have a look at it later on this week or early on the next one.

-Serge(y)

Quoted 85 lines

v7:
* Refer to andrew's suggestion:
- Add DMA_INTR_ENA_NIE_RX and DMA_INTR_ENA_NIE_TX #define's, etc.

* Others:
- Using --subject-prefix="PATCH net-next vN" to indicate that the patches are for the networking tree.
- Rebase to the latest networking tree:
<git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next.git>

v6:

* Refer to Serge's suggestion:
- Add new platform feature flag:

    include/linux/stmmac.h:
    +#define STMMAC_FLAG_HAS_LGMAC			BIT(13)

- Add the IRQs macros specific to the Loongson Multi-channels GMAC:

     drivers/net/ethernet/stmicro/stmmac/dwmac_dma.h:
     +#define DMA_INTR_ENA_NIE_LOONGSON 0x00060000      /* ...*/
     #define DMA_INTR_ENA_NIE 0x00010000	/* Normal Summary */
     ...

- Drop all of redundant changes that don't require the prototypes being converted to accepting the stmmac_priv pointer.

* Refer to andrew's suggestion:
- Drop white space changes.
- break patch up into lots of smaller parts.
Some small patches have been put into another series as a preparation see <https://lore.kernel.org/loongarch/[email protected]/T/#t>

*note* : This series of patches relies on the three small patches above.
* others
- Drop irq_flags changes.
- Changed patch order.

v4 -> v5:

* Remove an ugly and useless patch (fix channel number).
* Remove the non-standard dma64 driver code, and also remove the HWIF entries, since the associated custom callbacks no longer exist.
* Refer to Serge's suggestion: Update the dwmac1000_dma.c to support the multi-DMA-channels controller setup.

See:
v4: <https://lore.kernel.org/loongarch/[email protected]/>
v3: <https://lore.kernel.org/loongarch/[email protected]/>
v2: <https://lore.kernel.org/loongarch/[email protected]/>
v1: <https://lore.kernel.org/loongarch/[email protected]/>

Yanteng Si (11):
net: stmmac: Add multi-channel support
net: stmmac: dwmac-loongson: Refactor code for loongson_dwmac_probe()
net: stmmac: dwmac-loongson: Add full PCI support
net: stmmac: dwmac-loongson: Move irq config to loongson_gmac_config
net: stmmac: dwmac-loongson: Add Loongson-specific register
definitions
net: stmmac: dwmac-loongson: Add GNET support
net: stmmac: dwmac-loongson: Add multi-channel supports for loongson
net: stmmac: dwmac-loongson: Fix MAC speed for GNET
net: stmmac: dwmac-loongson: Fix half duplex
net: stmmac: dwmac-loongson: Disable flow control for GMAC
net: stmmac: dwmac-loongson: Disable coe for some Loongson GNET

 .../ethernet/stmicro/stmmac/dwmac-loongson.c  | 561 ++++++++++++++++--
 .../net/ethernet/stmicro/stmmac/dwmac-sun8i.c |   2 +-
 .../ethernet/stmicro/stmmac/dwmac1000_dma.c   |  36 +-
 .../net/ethernet/stmicro/stmmac/dwmac_dma.h   |  19 +-
 .../net/ethernet/stmicro/stmmac/dwmac_lib.c   |  32 +-
 drivers/net/ethernet/stmicro/stmmac/hwif.h    |   2 +-
 .../ethernet/stmicro/stmmac/stmmac_ethtool.c  |   6 +
 .../net/ethernet/stmicro/stmmac/stmmac_main.c |  15 +-
 include/linux/stmmac.h                        |   3 +
 9 files changed, 582 insertions(+), 94 deletions(-)
Signature · 1 line
2.31.4
maintainer
#99 lore raw
In reply to Yanteng Si
Quoted 2 lines · On Tue, 30 Jan 2024 16:43:20 +0800 Yanteng Si wrote:

* The biggest change is according to Serge's comment in the previous edition:

Looks like there's a trivial build issue here:

ERROR: modpost: "dwmac1000_dma_ops" [drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.ko] undefined!

Please wait for Serge's review before posting v9.

Signature · 1 line
pw-bot: cr
author
#100 lore raw
Quoted 9 lines · Jakub Kicinski
Quoted 2 lines · On Tue, 30 Jan 2024 16:43:20 +0800 Yanteng Si wrote:

* The biggest change is according to Serge's comment in the previous edition:

Looks like there's a trivial build issue here:

ERROR: modpost: "dwmac1000_dma_ops" [drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.ko] undefined!

Please wait for Serge's review before posting v9.

OK!  Will fix with:

drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c +0 -0
index 5f7b82ad3ec2..0323f0a5049c 100644
@@ -296,3 +296,4 @@ const struct stmmac_dma_ops dwmac1000_dma_ops = {

        .get_hw_feature = dwmac1000_get_hw_feature, .rx_watchdog = dwmac1000_rx_watchdog, };
+EXPORT_SYMBOL_GPL(dwmac1000_dma_ops);

Thanks,

Yanteng

reviewer
#2 lore raw

Re: [PATCH net-next v8 01/11] net: stmmac: Add multi-channel support

In reply to Yanteng Si
Quoted 8 lines · Yanteng Si

DW GMAC v3.x multi-channels feature is implemented as multiple sets of the same CSRs. Here is only preliminary support, it will be useful for the driver further evolution and for the users having multi-channel DWGMAC v3.x devices.

...

drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c static void dwmac1000_dma_init_rx(struct stmmac_priv *priv, · line 121

Quoted 6 lines
drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c +1 -1
@@ -116,7 +118,7 @@ static void dwmac1000_dma_init_rx(struct stmmac_priv *priv,
 				  dma_addr_t dma_rx_phy, u32 chan)
 {
 	/* RX descriptor base address list must be written into DMA CSR3 */
-	writel(lower_32_bits(dma_rx_phy), ioaddr + DMA_RCV_BASE_ADDR);
+	writel(lower_32_bits(dma_rx_phy), ioaddr + DMA_CHAN_RCV_BASE_ADDR(chan));

nit: Networking code (still) prefers code to be 80 columns wide or less.

Please consider running checkpatch as it is run by the CI.

https://github.com/linux-netdev/nipa/blob/main/tests/patch/checkpatch/checkpatch.sh

Quoted 3 lines
drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c +0 -0
 }
 
 static void dwmac1000_dma_init_tx(struct stmmac_priv *priv,

...

drivers/net/ethernet/stmicro/stmmac/dwmac_dma.h line 151

Quoted 9 lines
drivers/net/ethernet/stmicro/stmmac/dwmac_dma.h +1 -0
index 72672391675f..593be79c46e1 100644
@@ -148,11 +148,14 @@
 					 DMA_STATUS_TI | \
 					 DMA_STATUS_MSK_COMMON)
 
+/* Following DMA defines are chanels oriented */

nit: channels

FWIIW, checkpatch also has a --codespell option which can be used to flag spelling errors.

...

reviewer
#17 lore raw

Re: [PATCH net-next v8 02/11] net: stmmac: dwmac-loongson: Refactor code for loongson_dwmac_probe()

In reply to Yanteng Si
Quoted 6 lines · Yanteng Si

The driver function is not changed, but the code location is adjusted to prepare for adding more loongson drivers.

...

Quoted 4 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +3 -1
-static int loongson_dwmac_probe(struct pci_dev *pdev, const struct pci_device_id *id)
+static struct stmmac_pci_info loongson_gmac_pci_info = {
+	.setup = loongson_gmac_data,
+};

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int loongson_default_data(struct plat_stmmacenet_data *plat) · line 53

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +5 -1
+
+static int loongson_dwmac_probe(struct pci_dev *pdev,
+				const struct pci_device_id *id)
 {
+	int ret, i, bus_id, phy_mode;
 	struct plat_stmmacenet_data *plat;
+	struct stmmac_pci_info *info;
 	struct stmmac_resources res;
 	struct device_node *np;
-	int ret, i, phy_mode;

nit: Please consider preserving reverse xmas tree order - longest line
to shortest - for local variable declarations in Networking code.

This tool can be helpful here:
https://github.com/ecree-solarflare/xmastree

...

author
#3 lore raw

Re: [PATCH net-next v8 01/11] net: stmmac: Add multi-channel support

In reply to Simon Horman
Quoted 20 lines · Simon Horman
Quoted 8 lines · Yanteng Si

DW GMAC v3.x multi-channels feature is implemented as multiple sets of the same CSRs. Here is only preliminary support, it will be useful for the driver further evolution and for the users having multi-channel DWGMAC v3.x devices.

...

drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c static void dwmac1000_dma_init_rx(struct stmmac_priv *priv, · line 121

Quoted 6 lines
drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c +1 -1
@@ -116,7 +118,7 @@ static void dwmac1000_dma_init_rx(struct stmmac_priv *priv,
  				  dma_addr_t dma_rx_phy, u32 chan)
  {
  	/* RX descriptor base address list must be written into DMA CSR3 */
-	writel(lower_32_bits(dma_rx_phy), ioaddr + DMA_RCV_BASE_ADDR);
+	writel(lower_32_bits(dma_rx_phy), ioaddr + DMA_CHAN_RCV_BASE_ADDR(chan));

nit: Networking code (still) prefers code to be 80 columns wide or less.

Quoted 3 lines

Please consider running checkpatch as it is run by the CI.

https://github.com/linux-netdev/nipa/blob/main/tests/patch/checkpatch/checkpatch.sh

OK!

Quoted 15 lines
Quoted 4 lines
drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c +0 -0
  }
 
  static void dwmac1000_dma_init_tx(struct stmmac_priv *priv,

...

Quoted 8 lines
drivers/net/ethernet/stmicro/stmmac/dwmac_dma.h +0 -0
index 72672391675f..593be79c46e1 100644
@@ -148,11 +148,14 @@
  					 DMA_STATUS_TI | \
  					 DMA_STATUS_MSK_COMMON)
 
Quoted 5 lines

drivers/net/ethernet/stmicro/stmmac/dwmac_dma.h line 151

Quoted 1 line
drivers/net/ethernet/stmicro/stmmac/dwmac_dma.h +1 -0
+/* Following DMA defines are chanels oriented */

nit: channels

FWIIW, checkpatch also has a --codespell option which can be used to flag spelling errors.

Sorry, I forgot to change it. This typo has already been commented in v7.

Thanks,

Yanteng

Quoted 2 lines

...

author
#18 lore raw

Re: [PATCH net-next v8 02/11] net: stmmac: dwmac-loongson: Refactor code for loongson_dwmac_probe()

In reply to Simon Horman
Quoted 26 lines · Simon Horman
Quoted 6 lines · Yanteng Si

The driver function is not changed, but the code location is adjusted to prepare for adding more loongson drivers.

...

Quoted 4 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +3 -1
-static int loongson_dwmac_probe(struct pci_dev *pdev, const struct pci_device_id *id)
+static struct stmmac_pci_info loongson_gmac_pci_info = {
+	.setup = loongson_gmac_data,
+};

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int loongson_default_data(struct plat_stmmacenet_data *plat) · line 53

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +5 -1
+
+static int loongson_dwmac_probe(struct pci_dev *pdev,
+				const struct pci_device_id *id)
  {
+	int ret, i, bus_id, phy_mode;
  	struct plat_stmmacenet_data *plat;
+	struct stmmac_pci_info *info;
  	struct stmmac_resources res;
  	struct device_node *np;
-	int ret, i, phy_mode;

nit: Please consider preserving reverse xmas tree order - longest line
to shortest - for local variable declarations in Networking code.

Quoted 2 lines

This tool can be helpful here:
https://github.com/ecree-solarflare/xmastree

Okey, thank you!

Thanks,

Yanteng

Quoted 2 lines

...

#4 lore raw

Re: [PATCH net-next v8 01/11] net: stmmac: Add multi-channel support

In reply to Yanteng Si
Quoted 39 lines · Yanteng Si

DW GMAC v3.x multi-channels feature is implemented as multiple sets of the same CSRs. Here is only preliminary support, it will be useful for the driver further evolution and for the users having multi-channel DWGMAC v3.x devices.

---
 .../net/ethernet/stmicro/stmmac/dwmac-sun8i.c |  2 +-
 .../ethernet/stmicro/stmmac/dwmac1000_dma.c   | 36 ++++++++++---------
 .../net/ethernet/stmicro/stmmac/dwmac_dma.h   | 19 +++++++++-
 .../net/ethernet/stmicro/stmmac/dwmac_lib.c   | 32 ++++++++---------
 drivers/net/ethernet/stmicro/stmmac/hwif.h    |  2 +-
 .../net/ethernet/stmicro/stmmac/stmmac_main.c |  6 ++--
 6 files changed, 58 insertions(+), 39 deletions(-)
drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c +1 -1
index 137741b94122..7cdfa0bdb93a 100644
@@ -395,7 +395,7 @@ static void sun8i_dwmac_dma_start_tx(struct stmmac_priv *priv,
 	writel(v, ioaddr + EMAC_TX_CTL1);
 }
 
-static void sun8i_dwmac_enable_dma_transmission(void __iomem *ioaddr)
+static void sun8i_dwmac_enable_dma_transmission(void __iomem *ioaddr, u32 chan)
 {
 	u32 v;
 
drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c +0 -1
index daf79cdbd3ec..5f7b82ad3ec2 100644
@@ -70,15 +70,18 @@ static void dwmac1000_dma_axi(void __iomem *ioaddr, struct stmmac_axi *axi)
 	writel(value, ioaddr + DMA_AXI_BUS_MODE);
 }
 
-static void dwmac1000_dma_init(void __iomem *ioaddr,

drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c static void dwmac1000_dma_axi(void __iomem *ioaddr, struct stmmac_axi *axi) · line 80

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c +4 -2
-			       struct stmmac_dma_cfg *dma_cfg, int atds)
+static void dwmac1000_dma_init_channel(struct stmmac_priv *priv,
+				       void __iomem *ioaddr,
+				       struct stmmac_dma_cfg *dma_cfg, u32 chan)
 {
 
-	u32 value = readl(ioaddr + DMA_BUS_MODE);
+	u32 value;
 	int txpbl = dma_cfg->txpbl ?: dma_cfg->pbl;
 	int rxpbl = dma_cfg->rxpbl ?: dma_cfg->pbl;

Reverse xmas tree please.

drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c static void dwmac1000_dma_axi(void __iomem *ioaddr, struct stmmac_axi *axi) · line 81

Quoted 5 lines
drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c +1 -2
-	/*
-	 * Set the DMA PBL (Programmable Burst Length) mode.
 
+	/* common channel control register config */

Redundant comment. Please drop.

Quoted 7 lines
drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c +3 -0
+	value = readl(ioaddr + DMA_CHAN_BUS_MODE(chan));
+
+	/* Set the DMA PBL (Programmable Burst Length) mode.
 	 *
 	 * Note: before stmmac core 3.50 this mode bit was 4xPBL, and
drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c +0 -0
 	 * post 3.5 mode bit acts as 8*PBL.

drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c static void dwmac1000_dma_init(void __iomem *ioaddr, · line 105

Quoted 7 lines
drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c +1 -2
@@ -98,16 +101,15 @@ static void dwmac1000_dma_init(void __iomem *ioaddr,
 	if (dma_cfg->mixed_burst)
 		value |= DMA_BUS_MODE_MB;
 
 
-	if (atds)
-		value |= DMA_BUS_MODE_ATDS;
+	value |= DMA_BUS_MODE_ATDS;

No, just convert the stmmac_dma_ops.dma_init_channel() to accepting the atds flag as I suggested in v7:
https://lore.kernel.org/netdev/vxcfrxtbfu4pya56m22icnizsyjzqqha5blzb7zpexqcur56uh@uv6vsjf77npa/

In order to simplify this patch you can provide the stmmac_dma_ops.dma_init_channel() and stmmac_dma_ops.enable_dma_transmission() prototype updates in a pre-requisite/preparation patch.

Quoted 86 lines
drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c +10 -10
 	if (dma_cfg->aal)
 		value |= DMA_BUS_MODE_AAL;
 
-	writel(value, ioaddr + DMA_BUS_MODE);
+	writel(value, ioaddr + DMA_CHAN_BUS_MODE(chan));
 
 	/* Mask interrupts by writing to CSR7 */
-	writel(DMA_INTR_DEFAULT_MASK, ioaddr + DMA_INTR_ENA);
+	writel(DMA_INTR_DEFAULT_MASK, ioaddr + DMA_CHAN_INTR_ENA(chan));
 }
 
 static void dwmac1000_dma_init_rx(struct stmmac_priv *priv,
@@ -116,7 +118,7 @@ static void dwmac1000_dma_init_rx(struct stmmac_priv *priv,
 				  dma_addr_t dma_rx_phy, u32 chan)
 {
 	/* RX descriptor base address list must be written into DMA CSR3 */
-	writel(lower_32_bits(dma_rx_phy), ioaddr + DMA_RCV_BASE_ADDR);
+	writel(lower_32_bits(dma_rx_phy), ioaddr + DMA_CHAN_RCV_BASE_ADDR(chan));
 }
 
 static void dwmac1000_dma_init_tx(struct stmmac_priv *priv,
@@ -125,7 +127,7 @@ static void dwmac1000_dma_init_tx(struct stmmac_priv *priv,
 				  dma_addr_t dma_tx_phy, u32 chan)
 {
 	/* TX descriptor base address list must be written into DMA CSR4 */
-	writel(lower_32_bits(dma_tx_phy), ioaddr + DMA_TX_BASE_ADDR);
+	writel(lower_32_bits(dma_tx_phy), ioaddr + DMA_CHAN_TX_BASE_ADDR(chan));
 }
 
 static u32 dwmac1000_configure_fc(u32 csr6, int rxfifosz)
@@ -153,7 +155,7 @@ static void dwmac1000_dma_operation_mode_rx(struct stmmac_priv *priv,
 					    void __iomem *ioaddr, int mode,
 					    u32 channel, int fifosz, u8 qmode)
 {
-	u32 csr6 = readl(ioaddr + DMA_CONTROL);
+	u32 csr6 = readl(ioaddr + DMA_CHAN_CONTROL(channel));
 
 	if (mode == SF_DMA_MODE) {
 		pr_debug("GMAC: enable RX store and forward mode\n");
@@ -175,14 +177,14 @@ static void dwmac1000_dma_operation_mode_rx(struct stmmac_priv *priv,
 	/* Configure flow control based on rx fifo size */
 	csr6 = dwmac1000_configure_fc(csr6, fifosz);
 
-	writel(csr6, ioaddr + DMA_CONTROL);
+	writel(csr6, ioaddr + DMA_CHAN_CONTROL(channel));
 }
 
 static void dwmac1000_dma_operation_mode_tx(struct stmmac_priv *priv,
 					    void __iomem *ioaddr, int mode,
 					    u32 channel, int fifosz, u8 qmode)
 {
-	u32 csr6 = readl(ioaddr + DMA_CONTROL);
+	u32 csr6 = readl(ioaddr + DMA_CHAN_CONTROL(channel));
 
 	if (mode == SF_DMA_MODE) {
 		pr_debug("GMAC: enable TX store and forward mode\n");
@@ -209,7 +211,7 @@ static void dwmac1000_dma_operation_mode_tx(struct stmmac_priv *priv,
 			csr6 |= DMA_CONTROL_TTC_256;
 	}
 
-	writel(csr6, ioaddr + DMA_CONTROL);
+	writel(csr6, ioaddr + DMA_CHAN_CONTROL(channel));
 }
 
 static void dwmac1000_dump_dma_regs(struct stmmac_priv *priv,
@@ -271,12 +273,12 @@ static int dwmac1000_get_hw_feature(void __iomem *ioaddr,
 static void dwmac1000_rx_watchdog(struct stmmac_priv *priv,
 				  void __iomem *ioaddr, u32 riwt, u32 queue)
 {
-	writel(riwt, ioaddr + DMA_RX_WATCHDOG);
+	writel(riwt, ioaddr + DMA_CHAN_RX_WATCHDOG(queue));
 }
 
 const struct stmmac_dma_ops dwmac1000_dma_ops = {
 	.reset = dwmac_dma_reset,
-	.init = dwmac1000_dma_init,
+	.init_chan = dwmac1000_dma_init_channel,
 	.init_rx_chan = dwmac1000_dma_init_rx,
 	.init_tx_chan = dwmac1000_dma_init_tx,
 	.axi = dwmac1000_dma_axi,
drivers/net/ethernet/stmicro/stmmac/dwmac_dma.h +0 -0
index 72672391675f..593be79c46e1 100644

drivers/net/ethernet/stmicro/stmmac/dwmac_dma.h line 154

Quoted 7 lines
drivers/net/ethernet/stmicro/stmmac/dwmac_dma.h +3 -0
@@ -148,11 +148,14 @@
 					 DMA_STATUS_TI | \
 					 DMA_STATUS_MSK_COMMON)
 
 
+/* Following DMA defines are chanels oriented */    \
+#define DMA_CHAN_OFFSET			0x100   |-------------+
+                                                    /              |
                                                                      |
Please move all of these ---------------------------------------------+-------------------------+
to being defined just below the DMA_MISSED_FRAME_CTR macros definition.                         |
The point is to keep a coherency between dwmac_dma.h and dwmac4_dma.h.                          |
The later header file has first generic DMA-related macros defined                              |
(CSR addresses and flags) and then the channel-specific ones (CSR                               |
addresses and flags). Since in case of the DW GMAC v3.x the                                     |
multi-channels are implemented as a copy of all the DMA CSRs let's                              |
preserve the logic of having all CSR address defined first, then the                            |
CSR flags.                                                                                      |
                                                                                                |

drivers/net/ethernet/stmicro/stmmac/dwmac_dma.h int dwmac_dma_interrupt(struct stmmac_priv *priv, void __iomem *ioaddr, | · line 174

Quoted 13 lines
drivers/net/ethernet/stmicro/stmmac/dwmac_dma.h +1 -1
 #define NUM_DWMAC100_DMA_REGS	9                                                       |
 #define NUM_DWMAC1000_DMA_REGS	23                                                      |
 #define NUM_DWMAC4_DMA_REGS	27                                                              |
                                                                                              |
-void dwmac_enable_dma_transmission(void __iomem *ioaddr);                                    |
+void dwmac_enable_dma_transmission(void __iomem *ioaddr, u32 chan);                          |
 void dwmac_enable_dma_irq(struct stmmac_priv *priv, void __iomem *ioaddr,                    |
 			  u32 chan, bool rx, bool tx);                                          |

void dwmac_disable_dma_irq(struct stmmac_priv *priv, void __iomem *ioaddr, |

drivers/net/ethernet/stmicro/stmmac/dwmac_dma.h +0 -0
@@ -169,4 +172,18 @@ int dwmac_dma_interrupt(struct stmmac_priv *priv, void __iomem *ioaddr,  |
 			struct stmmac_extra_stats *x, u32 chan, u32 dir);                       |
 int dwmac_dma_reset(void __iomem *ioaddr);                                                   |
                                                                                              |
                                                                                                |
> +static inline u32 dma_chan_base_addr(u32 base, u32 chan)                                  \  |
> +{                                                                                          | |
Quoted 108 lines
drivers/net/ethernet/stmicro/stmmac/dwmac_dma.h +12 -0
+	return base + chan * DMA_CHAN_OFFSET;                                                 | |
+}                                                                                          | |
+                                                                                           | |
+#define DMA_CHAN_XMT_POLL_DEMAND(chan)	dma_chan_base_addr(DMA_XMT_POLL_DEMAND, chan) | |
+#define DMA_CHAN_INTR_ENA(chan)		dma_chan_base_addr(DMA_INTR_ENA, chan)        | |
+#define DMA_CHAN_CONTROL(chan)		dma_chan_base_addr(DMA_CONTROL, chan)         | |
+#define DMA_CHAN_STATUS(chan)		dma_chan_base_addr(DMA_STATUS, chan)          |-+
+#define DMA_CHAN_BUS_MODE(chan)		dma_chan_base_addr(DMA_BUS_MODE, chan)        |
+#define DMA_CHAN_RCV_BASE_ADDR(chan)	dma_chan_base_addr(DMA_RCV_BASE_ADDR, chan)           |
+#define DMA_CHAN_TX_BASE_ADDR(chan)	dma_chan_base_addr(DMA_TX_BASE_ADDR, chan)            |
+#define DMA_CHAN_RX_WATCHDOG(chan)	dma_chan_base_addr(DMA_RX_WATCHDOG, chan)             |
+                                                                                           /
 
 #endif /* __DWMAC_DMA_H__ */
drivers/net/ethernet/stmicro/stmmac/dwmac_lib.c +15 -15
index 7907d62d3437..b37368137810 100644
@@ -28,65 +28,65 @@ int dwmac_dma_reset(void __iomem *ioaddr)
 }
 
 /* CSR1 enables the transmit DMA to check for new descriptor */
-void dwmac_enable_dma_transmission(void __iomem *ioaddr)
+void dwmac_enable_dma_transmission(void __iomem *ioaddr, u32 chan)
 {
-	writel(1, ioaddr + DMA_XMT_POLL_DEMAND);
+	writel(1, ioaddr + DMA_CHAN_XMT_POLL_DEMAND(chan));
 }
 
 void dwmac_enable_dma_irq(struct stmmac_priv *priv, void __iomem *ioaddr,
 			  u32 chan, bool rx, bool tx)
 {
-	u32 value = readl(ioaddr + DMA_INTR_ENA);
+	u32 value = readl(ioaddr + DMA_CHAN_INTR_ENA(chan));
 
 	if (rx)
 		value |= DMA_INTR_DEFAULT_RX;
 	if (tx)
 		value |= DMA_INTR_DEFAULT_TX;
 
-	writel(value, ioaddr + DMA_INTR_ENA);
+	writel(value, ioaddr + DMA_CHAN_INTR_ENA(chan));
 }
 
 void dwmac_disable_dma_irq(struct stmmac_priv *priv, void __iomem *ioaddr,
 			   u32 chan, bool rx, bool tx)
 {
-	u32 value = readl(ioaddr + DMA_INTR_ENA);
+	u32 value = readl(ioaddr + DMA_CHAN_INTR_ENA(chan));
 
 	if (rx)
 		value &= ~DMA_INTR_DEFAULT_RX;
 	if (tx)
 		value &= ~DMA_INTR_DEFAULT_TX;
 
-	writel(value, ioaddr + DMA_INTR_ENA);
+	writel(value, ioaddr + DMA_CHAN_INTR_ENA(chan));
 }
 
 void dwmac_dma_start_tx(struct stmmac_priv *priv, void __iomem *ioaddr,
 			u32 chan)
 {
-	u32 value = readl(ioaddr + DMA_CONTROL);
+	u32 value = readl(ioaddr + DMA_CHAN_CONTROL(chan));
 	value |= DMA_CONTROL_ST;
-	writel(value, ioaddr + DMA_CONTROL);
+	writel(value, ioaddr + DMA_CHAN_CONTROL(chan));
 }
 
 void dwmac_dma_stop_tx(struct stmmac_priv *priv, void __iomem *ioaddr, u32 chan)
 {
-	u32 value = readl(ioaddr + DMA_CONTROL);
+	u32 value = readl(ioaddr + DMA_CHAN_CONTROL(chan));
 	value &= ~DMA_CONTROL_ST;
-	writel(value, ioaddr + DMA_CONTROL);
+	writel(value, ioaddr + DMA_CHAN_CONTROL(chan));
 }
 
 void dwmac_dma_start_rx(struct stmmac_priv *priv, void __iomem *ioaddr,
 			u32 chan)
 {
-	u32 value = readl(ioaddr + DMA_CONTROL);
+	u32 value = readl(ioaddr + DMA_CHAN_CONTROL(chan));
 	value |= DMA_CONTROL_SR;
-	writel(value, ioaddr + DMA_CONTROL);
+	writel(value, ioaddr + DMA_CHAN_CONTROL(chan));
 }
 
 void dwmac_dma_stop_rx(struct stmmac_priv *priv, void __iomem *ioaddr, u32 chan)
 {
-	u32 value = readl(ioaddr + DMA_CONTROL);
+	u32 value = readl(ioaddr + DMA_CHAN_CONTROL(chan));
 	value &= ~DMA_CONTROL_SR;
-	writel(value, ioaddr + DMA_CONTROL);
+	writel(value, ioaddr + DMA_CHAN_CONTROL(chan));
 }
 
 #ifdef DWMAC_DMA_DEBUG
@@ -166,7 +166,7 @@ int dwmac_dma_interrupt(struct stmmac_priv *priv, void __iomem *ioaddr,
 	struct stmmac_txq_stats *txq_stats = &priv->xstats.txq_stats[chan];
 	int ret = 0;
 	/* read the status register (CSR5) */
-	u32 intr_status = readl(ioaddr + DMA_STATUS);
+	u32 intr_status = readl(ioaddr + DMA_CHAN_STATUS(chan));
 
 #ifdef DWMAC_DMA_DEBUG
 	/* Enable it to monitor DMA rx/tx status in case of critical problems */

drivers/net/ethernet/stmicro/stmmac/dwmac_lib.c int dwmac_dma_interrupt(struct stmmac_priv *priv, void __iomem *ioaddr, · line 240

Quoted 6 lines
drivers/net/ethernet/stmicro/stmmac/dwmac_lib.c +1 -1
@@ -236,7 +236,7 @@ int dwmac_dma_interrupt(struct stmmac_priv *priv, void __iomem *ioaddr,
 		pr_warn("%s: unexpected status %08x\n", __func__, intr_status);
 
 	/* Clear the interrupt by writing a logic 1 to the CSR5[15-0] */
 
-	writel((intr_status & 0x1ffff), ioaddr + DMA_STATUS);
+	writel((intr_status & 0x7ffff), ioaddr + DMA_CHAN_STATUS(chan));

Isn't the mask change going to be implemented in the framework of the Loongson-specific DMA-interrupt handler in some of the further patches?

I'll get back to reviewing the series tomorrow (later today)...

-Serge(y)

Quoted 50 lines
drivers/net/ethernet/stmicro/stmmac/dwmac_lib.c +0 -0
 	return ret;
 }
drivers/net/ethernet/stmicro/stmmac/hwif.h +1 -1
index 7be04b54738b..b0db38396171 100644
@@ -198,7 +198,7 @@ struct stmmac_dma_ops {
 	/* To track extra statistic (if supported) */
 	void (*dma_diagnostic_fr)(struct stmmac_extra_stats *x,
 				  void __iomem *ioaddr);
-	void (*enable_dma_transmission) (void __iomem *ioaddr);
+	void (*enable_dma_transmission)(void __iomem *ioaddr, u32 chan);
 	void (*enable_dma_irq)(struct stmmac_priv *priv, void __iomem *ioaddr,
 			       u32 chan, bool rx, bool tx);
 	void (*disable_dma_irq)(struct stmmac_priv *priv, void __iomem *ioaddr,
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +3 -3
index b334eb16da23..5617b40abbe4 100644
@@ -2558,7 +2558,7 @@ static bool stmmac_xdp_xmit_zc(struct stmmac_priv *priv, u32 queue, u32 budget)
 				       true, priv->mode, true, true,
 				       xdp_desc.len);
 
-		stmmac_enable_dma_transmission(priv, priv->ioaddr);
+		stmmac_enable_dma_transmission(priv, priv->ioaddr, queue);
 
 		xsk_tx_metadata_to_compl(meta,
 					 &tx_q->tx_skbuff_dma[entry].xsk_meta);
@@ -4706,7 +4706,7 @@ static netdev_tx_t stmmac_xmit(struct sk_buff *skb, struct net_device *dev)
 
 	netdev_tx_sent_queue(netdev_get_tx_queue(dev, queue), skb->len);
 
-	stmmac_enable_dma_transmission(priv, priv->ioaddr);
+	stmmac_enable_dma_transmission(priv, priv->ioaddr, queue);
 
 	stmmac_flush_tx_descriptors(priv, queue);
 	stmmac_tx_timer_arm(priv, queue);
@@ -4926,7 +4926,7 @@ static int stmmac_xdp_xmit_xdpf(struct stmmac_priv *priv, int queue,
 		u64_stats_update_end_irqrestore(&txq_stats->syncp, flags);
 	}
 
-	stmmac_enable_dma_transmission(priv, priv->ioaddr);
+	stmmac_enable_dma_transmission(priv, priv->ioaddr, queue);
 
 	entry = STMMAC_GET_ENTRY(entry, priv->dma_conf.dma_tx_size);
 	tx_q->cur_tx = entry;
Signature · 1 line
2.31.4
#15 lore raw

Re: [PATCH net-next v8 01/11] net: stmmac: Add multi-channel support

In reply to Yanteng Si
Quoted 151 lines · Yanteng Si

DW GMAC v3.x multi-channels feature is implemented as multiple sets of the same CSRs. Here is only preliminary support, it will be useful for the driver further evolution and for the users having multi-channel DWGMAC v3.x devices.

---
 .../net/ethernet/stmicro/stmmac/dwmac-sun8i.c |  2 +-
 .../ethernet/stmicro/stmmac/dwmac1000_dma.c   | 36 ++++++++++---------
 .../net/ethernet/stmicro/stmmac/dwmac_dma.h   | 19 +++++++++-
 .../net/ethernet/stmicro/stmmac/dwmac_lib.c   | 32 ++++++++---------
 drivers/net/ethernet/stmicro/stmmac/hwif.h    |  2 +-
 .../net/ethernet/stmicro/stmmac/stmmac_main.c |  6 ++--
 6 files changed, 58 insertions(+), 39 deletions(-)
drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c +1 -1
index 137741b94122..7cdfa0bdb93a 100644
@@ -395,7 +395,7 @@ static void sun8i_dwmac_dma_start_tx(struct stmmac_priv *priv,
 	writel(v, ioaddr + EMAC_TX_CTL1);
 }
 
-static void sun8i_dwmac_enable_dma_transmission(void __iomem *ioaddr)
+static void sun8i_dwmac_enable_dma_transmission(void __iomem *ioaddr, u32 chan)
 {
 	u32 v;
 
drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c +19 -17
index daf79cdbd3ec..5f7b82ad3ec2 100644
@@ -70,15 +70,18 @@ static void dwmac1000_dma_axi(void __iomem *ioaddr, struct stmmac_axi *axi)
 	writel(value, ioaddr + DMA_AXI_BUS_MODE);
 }
 
-static void dwmac1000_dma_init(void __iomem *ioaddr,
-			       struct stmmac_dma_cfg *dma_cfg, int atds)
+static void dwmac1000_dma_init_channel(struct stmmac_priv *priv,
+				       void __iomem *ioaddr,
+				       struct stmmac_dma_cfg *dma_cfg, u32 chan)
 {
-	u32 value = readl(ioaddr + DMA_BUS_MODE);
+	u32 value;
 	int txpbl = dma_cfg->txpbl ?: dma_cfg->pbl;
 	int rxpbl = dma_cfg->rxpbl ?: dma_cfg->pbl;
 
-	/*
-	 * Set the DMA PBL (Programmable Burst Length) mode.
+	/* common channel control register config */
+	value = readl(ioaddr + DMA_CHAN_BUS_MODE(chan));
+
+	/* Set the DMA PBL (Programmable Burst Length) mode.
 	 *
 	 * Note: before stmmac core 3.50 this mode bit was 4xPBL, and
 	 * post 3.5 mode bit acts as 8*PBL.
@@ -98,16 +101,15 @@ static void dwmac1000_dma_init(void __iomem *ioaddr,
 	if (dma_cfg->mixed_burst)
 		value |= DMA_BUS_MODE_MB;
 
-	if (atds)
-		value |= DMA_BUS_MODE_ATDS;
+	value |= DMA_BUS_MODE_ATDS;
 
 	if (dma_cfg->aal)
 		value |= DMA_BUS_MODE_AAL;
 
-	writel(value, ioaddr + DMA_BUS_MODE);
+	writel(value, ioaddr + DMA_CHAN_BUS_MODE(chan));
 
 	/* Mask interrupts by writing to CSR7 */
-	writel(DMA_INTR_DEFAULT_MASK, ioaddr + DMA_INTR_ENA);
+	writel(DMA_INTR_DEFAULT_MASK, ioaddr + DMA_CHAN_INTR_ENA(chan));
 }
 
 static void dwmac1000_dma_init_rx(struct stmmac_priv *priv,
@@ -116,7 +118,7 @@ static void dwmac1000_dma_init_rx(struct stmmac_priv *priv,
 				  dma_addr_t dma_rx_phy, u32 chan)
 {
 	/* RX descriptor base address list must be written into DMA CSR3 */
-	writel(lower_32_bits(dma_rx_phy), ioaddr + DMA_RCV_BASE_ADDR);
+	writel(lower_32_bits(dma_rx_phy), ioaddr + DMA_CHAN_RCV_BASE_ADDR(chan));
 }
 
 static void dwmac1000_dma_init_tx(struct stmmac_priv *priv,
@@ -125,7 +127,7 @@ static void dwmac1000_dma_init_tx(struct stmmac_priv *priv,
 				  dma_addr_t dma_tx_phy, u32 chan)
 {
 	/* TX descriptor base address list must be written into DMA CSR4 */
-	writel(lower_32_bits(dma_tx_phy), ioaddr + DMA_TX_BASE_ADDR);
+	writel(lower_32_bits(dma_tx_phy), ioaddr + DMA_CHAN_TX_BASE_ADDR(chan));
 }
 
 static u32 dwmac1000_configure_fc(u32 csr6, int rxfifosz)
@@ -153,7 +155,7 @@ static void dwmac1000_dma_operation_mode_rx(struct stmmac_priv *priv,
 					    void __iomem *ioaddr, int mode,
 					    u32 channel, int fifosz, u8 qmode)
 {
-	u32 csr6 = readl(ioaddr + DMA_CONTROL);
+	u32 csr6 = readl(ioaddr + DMA_CHAN_CONTROL(channel));
 
 	if (mode == SF_DMA_MODE) {
 		pr_debug("GMAC: enable RX store and forward mode\n");
@@ -175,14 +177,14 @@ static void dwmac1000_dma_operation_mode_rx(struct stmmac_priv *priv,
 	/* Configure flow control based on rx fifo size */
 	csr6 = dwmac1000_configure_fc(csr6, fifosz);
 
-	writel(csr6, ioaddr + DMA_CONTROL);
+	writel(csr6, ioaddr + DMA_CHAN_CONTROL(channel));
 }
 
 static void dwmac1000_dma_operation_mode_tx(struct stmmac_priv *priv,
 					    void __iomem *ioaddr, int mode,
 					    u32 channel, int fifosz, u8 qmode)
 {
-	u32 csr6 = readl(ioaddr + DMA_CONTROL);
+	u32 csr6 = readl(ioaddr + DMA_CHAN_CONTROL(channel));
 
 	if (mode == SF_DMA_MODE) {
 		pr_debug("GMAC: enable TX store and forward mode\n");
@@ -209,7 +211,7 @@ static void dwmac1000_dma_operation_mode_tx(struct stmmac_priv *priv,
 			csr6 |= DMA_CONTROL_TTC_256;
 	}
 
-	writel(csr6, ioaddr + DMA_CONTROL);
+	writel(csr6, ioaddr + DMA_CHAN_CONTROL(channel));
 }
 
 static void dwmac1000_dump_dma_regs(struct stmmac_priv *priv,
@@ -271,12 +273,12 @@ static int dwmac1000_get_hw_feature(void __iomem *ioaddr,
 static void dwmac1000_rx_watchdog(struct stmmac_priv *priv,
 				  void __iomem *ioaddr, u32 riwt, u32 queue)
 {
-	writel(riwt, ioaddr + DMA_RX_WATCHDOG);
+	writel(riwt, ioaddr + DMA_CHAN_RX_WATCHDOG(queue));
 }
 
 const struct stmmac_dma_ops dwmac1000_dma_ops = {
 	.reset = dwmac_dma_reset,
-	.init = dwmac1000_dma_init,
+	.init_chan = dwmac1000_dma_init_channel,
 	.init_rx_chan = dwmac1000_dma_init_rx,
 	.init_tx_chan = dwmac1000_dma_init_tx,
 	.axi = dwmac1000_dma_axi,
drivers/net/ethernet/stmicro/stmmac/dwmac_dma.h +0 -0
index 72672391675f..593be79c46e1 100644

drivers/net/ethernet/stmicro/stmmac/dwmac_dma.h line 152

Quoted 5 lines
drivers/net/ethernet/stmicro/stmmac/dwmac_dma.h +1 -0
@@ -148,11 +148,14 @@
 					 DMA_STATUS_TI | \
 					 DMA_STATUS_MSK_COMMON)
 
 
+/* Following DMA defines are chanels oriented */

One more time:
s/chanels/channels

drivers/net/ethernet/stmicro/stmmac/dwmac_dma.h line 152

Quoted 1 line
drivers/net/ethernet/stmicro/stmmac/dwmac_dma.h +1 -0
+#define DMA_CHAN_OFFSET			0x100

Once again:
DMA_CHAN_BASE_OFFSET? to be looking the same as in DW QoS Eth GMAC v4.x/v5.x (dwmac4_dma.h).

Please be more attentive to the review notes.

-Serge(y)

Quoted 178 lines
drivers/net/ethernet/stmicro/stmmac/dwmac_dma.h +2 -1
+
 #define NUM_DWMAC100_DMA_REGS	9
 #define NUM_DWMAC1000_DMA_REGS	23
 #define NUM_DWMAC4_DMA_REGS	27
 
-void dwmac_enable_dma_transmission(void __iomem *ioaddr);
+void dwmac_enable_dma_transmission(void __iomem *ioaddr, u32 chan);
 void dwmac_enable_dma_irq(struct stmmac_priv *priv, void __iomem *ioaddr,
 			  u32 chan, bool rx, bool tx);

void dwmac_disable_dma_irq(struct stmmac_priv *priv, void __iomem *ioaddr,

drivers/net/ethernet/stmicro/stmmac/dwmac_dma.h +14 -0
@@ -169,4 +172,18 @@ int dwmac_dma_interrupt(struct stmmac_priv *priv, void __iomem *ioaddr,
 			struct stmmac_extra_stats *x, u32 chan, u32 dir);
 int dwmac_dma_reset(void __iomem *ioaddr);
 
+static inline u32 dma_chan_base_addr(u32 base, u32 chan)
+{
+	return base + chan * DMA_CHAN_OFFSET;
+}
+
+#define DMA_CHAN_XMT_POLL_DEMAND(chan)	dma_chan_base_addr(DMA_XMT_POLL_DEMAND, chan)
+#define DMA_CHAN_INTR_ENA(chan)		dma_chan_base_addr(DMA_INTR_ENA, chan)
+#define DMA_CHAN_CONTROL(chan)		dma_chan_base_addr(DMA_CONTROL, chan)
+#define DMA_CHAN_STATUS(chan)		dma_chan_base_addr(DMA_STATUS, chan)
+#define DMA_CHAN_BUS_MODE(chan)		dma_chan_base_addr(DMA_BUS_MODE, chan)
+#define DMA_CHAN_RCV_BASE_ADDR(chan)	dma_chan_base_addr(DMA_RCV_BASE_ADDR, chan)
+#define DMA_CHAN_TX_BASE_ADDR(chan)	dma_chan_base_addr(DMA_TX_BASE_ADDR, chan)
+#define DMA_CHAN_RX_WATCHDOG(chan)	dma_chan_base_addr(DMA_RX_WATCHDOG, chan)
+
 #endif /* __DWMAC_DMA_H__ */
drivers/net/ethernet/stmicro/stmmac/dwmac_lib.c +16 -16
index 7907d62d3437..b37368137810 100644
@@ -28,65 +28,65 @@ int dwmac_dma_reset(void __iomem *ioaddr)
 }
 
 /* CSR1 enables the transmit DMA to check for new descriptor */
-void dwmac_enable_dma_transmission(void __iomem *ioaddr)
+void dwmac_enable_dma_transmission(void __iomem *ioaddr, u32 chan)
 {
-	writel(1, ioaddr + DMA_XMT_POLL_DEMAND);
+	writel(1, ioaddr + DMA_CHAN_XMT_POLL_DEMAND(chan));
 }
 
 void dwmac_enable_dma_irq(struct stmmac_priv *priv, void __iomem *ioaddr,
 			  u32 chan, bool rx, bool tx)
 {
-	u32 value = readl(ioaddr + DMA_INTR_ENA);
+	u32 value = readl(ioaddr + DMA_CHAN_INTR_ENA(chan));
 
 	if (rx)
 		value |= DMA_INTR_DEFAULT_RX;
 	if (tx)
 		value |= DMA_INTR_DEFAULT_TX;
 
-	writel(value, ioaddr + DMA_INTR_ENA);
+	writel(value, ioaddr + DMA_CHAN_INTR_ENA(chan));
 }
 
 void dwmac_disable_dma_irq(struct stmmac_priv *priv, void __iomem *ioaddr,
 			   u32 chan, bool rx, bool tx)
 {
-	u32 value = readl(ioaddr + DMA_INTR_ENA);
+	u32 value = readl(ioaddr + DMA_CHAN_INTR_ENA(chan));
 
 	if (rx)
 		value &= ~DMA_INTR_DEFAULT_RX;
 	if (tx)
 		value &= ~DMA_INTR_DEFAULT_TX;
 
-	writel(value, ioaddr + DMA_INTR_ENA);
+	writel(value, ioaddr + DMA_CHAN_INTR_ENA(chan));
 }
 
 void dwmac_dma_start_tx(struct stmmac_priv *priv, void __iomem *ioaddr,
 			u32 chan)
 {
-	u32 value = readl(ioaddr + DMA_CONTROL);
+	u32 value = readl(ioaddr + DMA_CHAN_CONTROL(chan));
 	value |= DMA_CONTROL_ST;
-	writel(value, ioaddr + DMA_CONTROL);
+	writel(value, ioaddr + DMA_CHAN_CONTROL(chan));
 }
 
 void dwmac_dma_stop_tx(struct stmmac_priv *priv, void __iomem *ioaddr, u32 chan)
 {
-	u32 value = readl(ioaddr + DMA_CONTROL);
+	u32 value = readl(ioaddr + DMA_CHAN_CONTROL(chan));
 	value &= ~DMA_CONTROL_ST;
-	writel(value, ioaddr + DMA_CONTROL);
+	writel(value, ioaddr + DMA_CHAN_CONTROL(chan));
 }
 
 void dwmac_dma_start_rx(struct stmmac_priv *priv, void __iomem *ioaddr,
 			u32 chan)
 {
-	u32 value = readl(ioaddr + DMA_CONTROL);
+	u32 value = readl(ioaddr + DMA_CHAN_CONTROL(chan));
 	value |= DMA_CONTROL_SR;
-	writel(value, ioaddr + DMA_CONTROL);
+	writel(value, ioaddr + DMA_CHAN_CONTROL(chan));
 }
 
 void dwmac_dma_stop_rx(struct stmmac_priv *priv, void __iomem *ioaddr, u32 chan)
 {
-	u32 value = readl(ioaddr + DMA_CONTROL);
+	u32 value = readl(ioaddr + DMA_CHAN_CONTROL(chan));
 	value &= ~DMA_CONTROL_SR;
-	writel(value, ioaddr + DMA_CONTROL);
+	writel(value, ioaddr + DMA_CHAN_CONTROL(chan));
 }
 
 #ifdef DWMAC_DMA_DEBUG
@@ -166,7 +166,7 @@ int dwmac_dma_interrupt(struct stmmac_priv *priv, void __iomem *ioaddr,
 	struct stmmac_txq_stats *txq_stats = &priv->xstats.txq_stats[chan];
 	int ret = 0;
 	/* read the status register (CSR5) */
-	u32 intr_status = readl(ioaddr + DMA_STATUS);
+	u32 intr_status = readl(ioaddr + DMA_CHAN_STATUS(chan));
 
 #ifdef DWMAC_DMA_DEBUG
 	/* Enable it to monitor DMA rx/tx status in case of critical problems */
@@ -236,7 +236,7 @@ int dwmac_dma_interrupt(struct stmmac_priv *priv, void __iomem *ioaddr,
 		pr_warn("%s: unexpected status %08x\n", __func__, intr_status);
 
 	/* Clear the interrupt by writing a logic 1 to the CSR5[15-0] */
-	writel((intr_status & 0x1ffff), ioaddr + DMA_STATUS);
+	writel((intr_status & 0x7ffff), ioaddr + DMA_CHAN_STATUS(chan));
 
 	return ret;
 }
drivers/net/ethernet/stmicro/stmmac/hwif.h +1 -1
index 7be04b54738b..b0db38396171 100644
@@ -198,7 +198,7 @@ struct stmmac_dma_ops {
 	/* To track extra statistic (if supported) */
 	void (*dma_diagnostic_fr)(struct stmmac_extra_stats *x,
 				  void __iomem *ioaddr);
-	void (*enable_dma_transmission) (void __iomem *ioaddr);
+	void (*enable_dma_transmission)(void __iomem *ioaddr, u32 chan);
 	void (*enable_dma_irq)(struct stmmac_priv *priv, void __iomem *ioaddr,
 			       u32 chan, bool rx, bool tx);
 	void (*disable_dma_irq)(struct stmmac_priv *priv, void __iomem *ioaddr,
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +3 -3
index b334eb16da23..5617b40abbe4 100644
@@ -2558,7 +2558,7 @@ static bool stmmac_xdp_xmit_zc(struct stmmac_priv *priv, u32 queue, u32 budget)
 				       true, priv->mode, true, true,
 				       xdp_desc.len);
 
-		stmmac_enable_dma_transmission(priv, priv->ioaddr);
+		stmmac_enable_dma_transmission(priv, priv->ioaddr, queue);
 
 		xsk_tx_metadata_to_compl(meta,
 					 &tx_q->tx_skbuff_dma[entry].xsk_meta);
@@ -4706,7 +4706,7 @@ static netdev_tx_t stmmac_xmit(struct sk_buff *skb, struct net_device *dev)
 
 	netdev_tx_sent_queue(netdev_get_tx_queue(dev, queue), skb->len);
 
-	stmmac_enable_dma_transmission(priv, priv->ioaddr);
+	stmmac_enable_dma_transmission(priv, priv->ioaddr, queue);
 
 	stmmac_flush_tx_descriptors(priv, queue);
 	stmmac_tx_timer_arm(priv, queue);
@@ -4926,7 +4926,7 @@ static int stmmac_xdp_xmit_xdpf(struct stmmac_priv *priv, int queue,
 		u64_stats_update_end_irqrestore(&txq_stats->syncp, flags);
 	}
 
-	stmmac_enable_dma_transmission(priv, priv->ioaddr);
+	stmmac_enable_dma_transmission(priv, priv->ioaddr, queue);
 
 	entry = STMMAC_GET_ENTRY(entry, priv->dma_conf.dma_tx_size);
 	tx_q->cur_tx = entry;
Signature · 1 line
2.31.4
#19 lore raw

Re: [PATCH net-next v8 02/11] net: stmmac: dwmac-loongson: Refactor code for loongson_dwmac_probe()

In reply to Yanteng Si
Quoted 2 lines · Yanteng Si

The driver function is not changed, but the code location is adjusted to prepare for adding more loongson drivers.

Having the word "refactoring" in the subject is always suspicious because submitters very often try to hind behind it many small changes they didn't want to/didn't know how to unpin from a more bulky change. Moreover if there is no detailed explanation what is done and why, it raises too many review questions and makes the reviewers life much harder. So it would have been much better for us if you split up this change into the smaller patches (see my last comment for a presumable subset of the patches) to simplify the review process and improve the driver bisectability especially seeing there actually are functional changes introduced here despite of what is said in the commit log.

Quoted 29 lines
---
 .../ethernet/stmicro/stmmac/dwmac-loongson.c  | 61 +++++++++++++------
 1 file changed, 42 insertions(+), 19 deletions(-)
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +6 -1
index 9e40c28d453a..e2dcb339b8b0 100644
@@ -9,7 +9,12 @@
 #include <linux/of_irq.h>
 #include "stmmac.h"
 
-static int loongson_default_data(struct plat_stmmacenet_data *plat)
+struct stmmac_pci_info {
+	int (*setup)(struct pci_dev *pdev, struct plat_stmmacenet_data *plat);
+};
+
+static void loongson_default_data(struct pci_dev *pdev,
+				  struct plat_stmmacenet_data *plat)
 {
 	plat->clk_csr = 2;	/* clk_csr_i = 20-35MHz & MDC = clk_csr_i/16 */
 	plat->has_gmac = 1;
@@ -34,23 +39,37 @@ static int loongson_default_data(struct plat_stmmacenet_data *plat)
 
 	/* Disable RX queues routing by default */

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int loongson_default_data(struct plat_stmmacenet_data *plat) · line 50

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +8 -0
 	plat->rx_queues_cfg[0].pkt_route = 0x0;
+}
+
+static int loongson_gmac_data(struct pci_dev *pdev,
+			      struct plat_stmmacenet_data *plat)
+{
+	loongson_default_data(pdev, plat);
+
 
+	plat->multicast_filter_bins = 256;

Why do you need to move this here from the function tail?

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int loongson_default_data(struct plat_stmmacenet_data *plat) · line 51

Quoted 3 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +2 -0
+
 
+	plat->mdio_bus_data->phy_mask = 0;

This is already zero. Why do you need this?

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int loongson_default_data(struct plat_stmmacenet_data *plat) · line 38

Quoted 3 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +0 -1
-	/* Default to phy auto-detection */

What is wrong with this comment?

Quoted 14 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +4 -2
 	plat->phy_addr = -1;
 
 	plat->dma_cfg->pbl = 32;
 	plat->dma_cfg->pblx8 = true;
 
-	plat->multicast_filter_bins = 256;
 	return 0;
 }
 
-static int loongson_dwmac_probe(struct pci_dev *pdev, const struct pci_device_id *id)
+static struct stmmac_pci_info loongson_gmac_pci_info = {
+	.setup = loongson_gmac_data,
+};
+

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int loongson_default_data(struct plat_stmmacenet_data *plat)

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +4 -1
+static int loongson_dwmac_probe(struct pci_dev *pdev,
+				const struct pci_device_id *id)
 {
 
+	int ret, i, bus_id, phy_mode;
 	struct plat_stmmacenet_data *plat;
+	struct stmmac_pci_info *info;
 	struct stmmac_resources res;
 	struct device_node *np;
-	int ret, i, phy_mode;

Reverse xmas tree order please.

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int loongson_dwmac_probe(struct pci_dev *pdev, const struct pci_device_id · line 96

Quoted 13 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +5 -0
 	np = dev_of_node(&pdev->dev);
@@ -69,18 +88,17 @@ static int loongson_dwmac_probe(struct pci_dev *pdev, const struct pci_device_id
 	if (!plat->mdio_bus_data)
 		return -ENOMEM;
 
 
+	plat->dma_cfg = devm_kzalloc(&pdev->dev, sizeof(*plat->dma_cfg),
+				     GFP_KERNEL);
+	if (!plat->dma_cfg)
+		return -ENOMEM;
+

Why do you need this moved above the mdio_node getting procedure? They seem independent.

Quoted 16 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +0 -6
 	plat->mdio_node = of_get_child_by_name(np, "mdio");
 	if (plat->mdio_node) {
 		dev_info(&pdev->dev, "Found MDIO subnode\n");
 		plat->mdio_bus_data->needs_reset = true;
 	}
 
-	plat->dma_cfg = devm_kzalloc(&pdev->dev, sizeof(*plat->dma_cfg), GFP_KERNEL);
-	if (!plat->dma_cfg) {
-		ret = -ENOMEM;
-		goto err_put_node;
-	}
-
 	/* Enable pci device */
 	ret = pci_enable_device(pdev);
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +0 -0
 	if (ret) {

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int loongson_dwmac_probe(struct pci_dev *pdev, const struct pci_device_id · line 104

Quoted 7 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +0 -3
@@ -98,9 +116,16 @@ static int loongson_dwmac_probe(struct pci_dev *pdev, const struct pci_device_id
 		break;
 	}
 
 
-	plat->bus_id = of_alias_get_id(np, "ethernet");
-	if (plat->bus_id < 0)
-		plat->bus_id = pci_dev_id(pdev);

This is a functional change because further bus_id is no longer initialized by the pci_dev_id() method as a fallback case. If you are sure this is required please unpin to a separate patch and explain.

Quoted 14 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +10 -0
+	pci_set_master(pdev);
+
+	info = (struct stmmac_pci_info *)id->driver_data;
+	ret = info->setup(pdev, plat);
+	if (ret)
+		goto err_disable_device;
+
+	bus_id = of_alias_get_id(np, "ethernet");
+	if (bus_id >= 0)
+		plat->bus_id = bus_id;
 
 	phy_mode = device_get_phy_mode(&pdev->dev);
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +0 -0
 	if (phy_mode < 0) {

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int loongson_dwmac_probe(struct pci_dev *pdev, const struct pci_device_id · line 114

Quoted 5 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +0 -1
@@ -110,11 +135,7 @@ static int loongson_dwmac_probe(struct pci_dev *pdev, const struct pci_device_id
 	}
 
 	plat->phy_interface = phy_mode;
 
-	plat->mac_interface = PHY_INTERFACE_MODE_GMII;

This is just dropped. Are you sure that the driver will work correctly after this change is applied? Russell already asked you about this change here:
https://lore.kernel.org/netdev/[email protected]/

Anyway please unpin it to a separate patch and explain.

Quoted 8 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +0 -3
-	pci_set_master(pdev);
-
-	loongson_default_data(plat);
 	pci_enable_msi(pdev);
 	memset(&res, 0, sizeof(res));
 	res.addr = pcim_iomap_table(pdev)[0];

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int __maybe_unused loongson_dwmac_resume(struct device *dev) · line 239

Quoted 8 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +3 -1
@@ -212,8 +233,10 @@ static int __maybe_unused loongson_dwmac_resume(struct device *dev)
 static SIMPLE_DEV_PM_OPS(loongson_dwmac_pm_ops, loongson_dwmac_suspend,
 			 loongson_dwmac_resume);
 
+#define PCI_DEVICE_ID_LOONGSON_GMAC	0x7a03
+
 static const struct pci_device_id loongson_dwmac_id_table[] = {
-	{ PCI_VDEVICE(LOONGSON, 0x7a03) },
+	{ PCI_DEVICE_DATA(LOONGSON, GMAC, &loongson_gmac_pci_info) },

If I were you and needed to preserve all the changes I would have split the patch up into the next patches:
1. Use PCI_DEVICE_DATA() macro for device identification
2. Drop mac-interface initialization
3. Don't initialize MDIO bus ID with PCIe device ID
4. Introduce device-specific setup callback

-Serge(y)

Quoted 6 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +0 -0
 	{}
 };
 MODULE_DEVICE_TABLE(pci, loongson_dwmac_id_table);
Signature · 1 line
2.31.4
#22 lore raw

Re: [PATCH net-next v8 03/11] net: stmmac: dwmac-loongson: Add full PCI support

In reply to Yanteng Si
Quoted 3 lines · Yanteng Si

Current dwmac-loongson only support LS2K in the "probed with PCI and configured with DT" manner. Add LS7A support on which the devices are fully PCI (non-DT).

Please add to the commit log more details of what LS7A is like and bind that description to the changes below like the interface settings, ref and PTP clock settings, etc. What is the difference between LS2K and LS7A?

Quoted 26 lines
---
 .../ethernet/stmicro/stmmac/dwmac-loongson.c  | 79 +++++++++++--------
 1 file changed, 44 insertions(+), 35 deletions(-)
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +4 -0
index e2dcb339b8b0..979c9b6dab3f 100644
@@ -16,6 +16,10 @@ struct stmmac_pci_info {
 static void loongson_default_data(struct pci_dev *pdev,
 				  struct plat_stmmacenet_data *plat)
 {
+	/* Get bus_id, this can be overloaded later */
+	plat->bus_id = (pci_domain_nr(pdev->bus) << 16) |
+		       PCI_DEVID(pdev->bus->number, pdev->devfn);
+
 	plat->clk_csr = 2;	/* clk_csr_i = 20-35MHz & MDC = clk_csr_i/16 */
 	plat->has_gmac = 1;
 	plat->force_sf_dma_mode = 1;
@@ -51,10 +55,14 @@ static int loongson_gmac_data(struct pci_dev *pdev,
 	plat->mdio_bus_data->phy_mask = 0;
 

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int loongson_gmac_data(struct pci_dev *pdev, · line 66

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +4 -0
 	plat->phy_addr = -1;
+	plat->phy_interface = PHY_INTERFACE_MODE_RGMII_ID;
 
 	plat->dma_cfg->pbl = 32;
 	plat->dma_cfg->pblx8 = true;
 
 
+	plat->clk_ref_rate = 125000000;
+	plat->clk_ptp_rate = 125000000;
+

Is this compatible with the LS2K GMAC?

Quoted 25 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +1 -7
 	return 0;
 }
@@ -71,13 +79,6 @@ static int loongson_dwmac_probe(struct pci_dev *pdev,
 	struct stmmac_resources res;
 	struct device_node *np;
 
-	np = dev_of_node(&pdev->dev);
-
-	if (!np) {
-		pr_info("dwmac_loongson_pci: No OF node\n");
-		return -ENODEV;
-	}
-
 	plat = devm_kzalloc(&pdev->dev, sizeof(*plat), GFP_KERNEL);
 	if (!plat)
 		return -ENOMEM;
@@ -93,6 +94,7 @@ static int loongson_dwmac_probe(struct pci_dev *pdev,
 	if (!plat->dma_cfg)
 		return -ENOMEM;
 
+	np = dev_of_node(&pdev->dev);
 
 	plat->mdio_node = of_get_child_by_name(np, "mdio");
 	if (plat->mdio_node) {
Quoted 1 line

dev_info(&pdev->dev, "Found MDIO subnode\n");

Shouldn't mdio_node setup being done under the "if (np)" clause?

Quoted 16 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +4 -6
@@ -123,41 +125,48 @@ static int loongson_dwmac_probe(struct pci_dev *pdev,
 	if (ret)
 		goto err_disable_device;
 
-	bus_id = of_alias_get_id(np, "ethernet");
-	if (bus_id >= 0)
-		plat->bus_id = bus_id;
 
+	if (np) {
+		bus_id = of_alias_get_id(np, "ethernet");
+		if (bus_id >= 0)
+			plat->bus_id = bus_id;
 
-	phy_mode = device_get_phy_mode(&pdev->dev);
-	if (phy_mode < 0) {
-		dev_err(&pdev->dev, "phy_mode not found\n");

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int loongson_dwmac_probe(struct pci_dev *pdev, · line 141

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +7 -2
-		ret = phy_mode;
-		goto err_disable_device;
+		phy_mode = device_get_phy_mode(&pdev->dev);
+		if (phy_mode < 0) {
+			dev_err(&pdev->dev, "phy_mode not found\n");
+			ret = phy_mode;
+			goto err_disable_device;
+		}
+		plat->phy_interface = phy_mode;
 	}

Please collect all OF-specific code in the same "if (np)" clause if possible.

Quoted 40 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +15 -20
-	plat->phy_interface = phy_mode;
-
 	pci_enable_msi(pdev);
 	memset(&res, 0, sizeof(res));
 	res.addr = pcim_iomap_table(pdev)[0];
 
-	res.irq = of_irq_get_byname(np, "macirq");
-	if (res.irq < 0) {
-		dev_err(&pdev->dev, "IRQ macirq not found\n");
-		ret = -ENODEV;
-		goto err_disable_msi;
-	}
-
-	res.wol_irq = of_irq_get_byname(np, "eth_wake_irq");
-	if (res.wol_irq < 0) {
-		dev_info(&pdev->dev, "IRQ eth_wake_irq not found, using macirq\n");
-		res.wol_irq = res.irq;
-	}
-
-	res.lpi_irq = of_irq_get_byname(np, "eth_lpi");
-	if (res.lpi_irq < 0) {
-		dev_err(&pdev->dev, "IRQ eth_lpi not found\n");
-		ret = -ENODEV;
-		goto err_disable_msi;
+	if (np) {
+		res.irq = of_irq_get_byname(np, "macirq");
+		if (res.irq < 0) {
+			dev_err(&pdev->dev, "IRQ macirq not found\n");
+			ret = -ENODEV;
+			goto err_disable_msi;
+		}
+
+		res.wol_irq = of_irq_get_byname(np, "eth_wake_irq");
+		if (res.wol_irq < 0) {
+			dev_info(&pdev->dev,
+				 "IRQ eth_wake_irq not found, using macirq\n");
+			res.wol_irq = res.irq;
+		}
+

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int loongson_dwmac_probe(struct pci_dev *pdev,

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +9 -0
+		res.lpi_irq = of_irq_get_byname(np, "eth_lpi");
+		if (res.lpi_irq < 0) {
+			dev_err(&pdev->dev, "IRQ eth_lpi not found\n");
+			ret = -ENODEV;
+			goto err_disable_msi;
+		}
+	} else {
+		res.irq = pdev->irq;
 
+		res.wol_irq = pdev->irq;

This seems redundant. If res.wol_irq matches res_irq it won't be used (see stmmac_request_irq_multi_msi() and stmmac_request_irq_single()). What about dropping it?

-Serge(y)

Quoted 6 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +0 -0
 	}
 

ret = stmmac_dvr_probe(&pdev->dev, plat, &res);

Signature · 1 line
2.31.4
#25 lore raw

Re: [PATCH net-next v8 04/11] net: stmmac: dwmac-loongson: Move irq config to loongson_gmac_config

In reply to Yanteng Si
Quoted 6 lines · Yanteng Si

Add loongson_dwmac_config and moving irq config related code to loongson_dwmac_config.

Removing MSI to prepare for adding loongson multi-channel support later.

Please detach this change into a separate patch and thoroughly explain why it was necessary.

Quoted 43 lines
---
 .../ethernet/stmicro/stmmac/dwmac-loongson.c  | 85 ++++++++++++-------
 1 file changed, 55 insertions(+), 30 deletions(-)
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +25 -0
index 979c9b6dab3f..e7ce027cc14e 100644
@@ -11,8 +11,46 @@
 
 struct stmmac_pci_info {
 	int (*setup)(struct pci_dev *pdev, struct plat_stmmacenet_data *plat);
+	int (*config)(struct pci_dev *pdev, struct plat_stmmacenet_data *plat,
+		      struct stmmac_resources *res, struct device_node *np);
 };
 
+static int loongson_dwmac_config_legacy(struct pci_dev *pdev,
+					struct plat_stmmacenet_data *plat,
+					struct stmmac_resources *res,
+					struct device_node *np)
+{
+	if (np) {
+		res->irq = of_irq_get_byname(np, "macirq");
+		if (res->irq < 0) {
+			dev_err(&pdev->dev, "IRQ macirq not found\n");
+			return -ENODEV;
+		}
+
+		res->wol_irq = of_irq_get_byname(np, "eth_wake_irq");
+		if (res->wol_irq < 0) {
+			dev_info(&pdev->dev,
+				 "IRQ eth_wake_irq not found, using macirq\n");
+			res->wol_irq = res->irq;
+		}
+
+		res->lpi_irq = of_irq_get_byname(np, "eth_lpi");
+		if (res->lpi_irq < 0) {
+			dev_err(&pdev->dev, "IRQ eth_lpi not found\n");
+			return -ENODEV;

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c line 50

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +9 -0
+		}
+	} else {
+		res->irq = pdev->irq;
+		res->wol_irq = res->irq;
+	}
+
 
+	plat->flags &= ~STMMAC_FLAG_MULTI_MSI_EN;
+	dev_info(&pdev->dev, "%s: Single IRQ enablement successful\n",
+		 __func__);

Why is this here all of the sudden? I don't see this in the original code. Please move it to the patch which requires the flag setup/cleanup or drop if it isn't necessary.

Quoted 14 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +4 -0
+
+	return 0;
+}
+
 static void loongson_default_data(struct pci_dev *pdev,
 				  struct plat_stmmacenet_data *plat)

{

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +2 -0
@@ -66,8 +104,21 @@ static int loongson_gmac_data(struct pci_dev *pdev,
 	return 0;
 }
 
 
+static int loongson_gmac_config(struct pci_dev *pdev,
+				struct plat_stmmacenet_data *plat,

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int loongson_gmac_data(struct pci_dev *pdev, · line 119

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +10 -0
+				struct stmmac_resources *res,
+				struct device_node *np)
+{
+	int ret;
+
+	ret = loongson_dwmac_config_legacy(pdev, plat, res, np);
+
+	return ret;
+}
+

You introduce the config callback here and convert to a dummy method in
[PATCH 07/11] net: stmmac: dwmac-loongson: Add multi-channel supports for loongson It's just pointless. What about introducing the loongson_dwmac_config_legacy() method and call it directly?

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int loongson_dwmac_probe(struct pci_dev *pdev, · line 143

Quoted 12 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +1 -0
 static struct stmmac_pci_info loongson_gmac_pci_info = {
 	.setup = loongson_gmac_data,
+	.config = loongson_gmac_config,
 };
 

static int loongson_dwmac_probe(struct pci_dev *pdev,

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +0 -1
@@ -139,44 +190,19 @@ static int loongson_dwmac_probe(struct pci_dev *pdev,
 		plat->phy_interface = phy_mode;
 	}
 
 
-	pci_enable_msi(pdev);

See my first note in this message.

-Serge(y)

Quoted 55 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +4 -28
 	memset(&res, 0, sizeof(res));
 	res.addr = pcim_iomap_table(pdev)[0];
 
-	if (np) {
-		res.irq = of_irq_get_byname(np, "macirq");
-		if (res.irq < 0) {
-			dev_err(&pdev->dev, "IRQ macirq not found\n");
-			ret = -ENODEV;
-			goto err_disable_msi;
-		}
-
-		res.wol_irq = of_irq_get_byname(np, "eth_wake_irq");
-		if (res.wol_irq < 0) {
-			dev_info(&pdev->dev,
-				 "IRQ eth_wake_irq not found, using macirq\n");
-			res.wol_irq = res.irq;
-		}
-
-		res.lpi_irq = of_irq_get_byname(np, "eth_lpi");
-		if (res.lpi_irq < 0) {
-			dev_err(&pdev->dev, "IRQ eth_lpi not found\n");
-			ret = -ENODEV;
-			goto err_disable_msi;
-		}
-	} else {
-		res.irq = pdev->irq;
-		res.wol_irq = pdev->irq;
-	}
+	ret = info->config(pdev, plat, &res, np);
+	if (ret)
+		goto err_disable_device;
 
 	ret = stmmac_dvr_probe(&pdev->dev, plat, &res);
 	if (ret)
-		goto err_disable_msi;
+		goto err_disable_device;
 
 	return ret;
 
-err_disable_msi:
-	pci_disable_msi(pdev);
 err_disable_device:
 	pci_disable_device(pdev);

err_put_node:

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +0 -1
@@ -200,7 +226,6 @@ static void loongson_dwmac_remove(struct pci_dev *pdev)
 		break;
 	}
 
-	pci_disable_msi(pdev);
 	pci_disable_device(pdev);
 }
 
Signature · 1 line
2.31.4
#30 lore raw

Re: [PATCH net-next v8 05/11] net: stmmac: dwmac-loongson: Add Loongson-specific register definitions

In reply to Yanteng Si
Quoted 76 lines · Yanteng Si

There are two types of Loongson DWGMAC. The first type shares the same register definitions and has similar logic as dwmac1000. The second type uses several different register definitions, we think it is necessary to distinguish rx and tx, so we split these bits into two.

Simply put, we split some single bit fields into double bits fileds:

Name Tx Rx

DMA_INTR_ENA_NIE = 0x00040000 | 0x00020000;
DMA_INTR_ENA_AIE = 0x00010000 | 0x00008000;
DMA_STATUS_NIS   = 0x00040000 | 0x00020000;
DMA_STATUS_AIS   = 0x00010000 | 0x00008000;
DMA_STATUS_FBI   = 0x00002000 | 0x00001000;

Therefore, when using, TX and RX must be set at the same time.

How to use them:
1. Create the Loongson GNET-specific stmmac_dma_ops.dma_interrupt() stmmac_dma_ops.init_chan()
methods in the dwmac-loongson.c driver. Adding all the Loongson-specific macros

2. Create a Loongson GNET-specific platform setup method with the next semantics:
+ allocate stmmac_dma_ops instance and initialize it with

     dwmac1000_dma_ops.
   + override the stmmac_dma_ops.{dma_interrupt, init_chan} with
     the pointers to the methods defined in 2.
   + allocate mac_device_info instance and initialize the
     mac_device_info.dma field with a pointer to the new
     stmmac_dma_ops instance.
   + initialize mac_device_info in a way it's done in
     dwmac1000_setup().

3. Initialize plat_stmmacenet_data.setup() with the pointer to the method created in 2.

---
 .../ethernet/stmicro/stmmac/dwmac-loongson.c  | 248 ++++++++++++++++++
 1 file changed, 248 insertions(+)
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +21 -0
index e7ce027cc14e..3b3578318cc1 100644
@@ -8,6 +8,193 @@
 #include <linux/device.h>
 #include <linux/of_irq.h>
 #include "stmmac.h"
+#include "dwmac_dma.h"
+#include "dwmac1000.h"
+
 
+#define DMA_INTR_ENA_NIE_TX_LOONGSON 0x00040000	/* Normal Loongson Tx Summary */
+#define DMA_INTR_ENA_NIE_RX_LOONGSON 0x00020000	/* Normal Loongson Rx Summary */
+#define DMA_INTR_NORMAL_LOONGSON	(DMA_INTR_ENA_NIE_TX_LOONGSON | \
+			 DMA_INTR_ENA_NIE_RX_LOONGSON | DMA_INTR_ENA_RIE | \
+			 DMA_INTR_ENA_TIE)
+
+#define DMA_INTR_ENA_AIE_TX_LOONGSON 0x00010000	/* Abnormal Loongson Tx Summary */
+#define DMA_INTR_ENA_AIE_RX_LOONGSON 0x00008000	/* Abnormal Loongson Rx Summary */
+
+#define DMA_INTR_ABNORMAL_LOONGSON	(DMA_INTR_ENA_AIE_TX_LOONGSON | \
+				DMA_INTR_ENA_AIE_RX_LOONGSON | DMA_INTR_ENA_FBE | \
+				DMA_INTR_ENA_UNE)
+
+#define DMA_INTR_DEFAULT_MASK_LOONGSON	(DMA_INTR_NORMAL_LOONGSON | DMA_INTR_ABNORMAL_LOONGSON)
+
+#define DMA_STATUS_NIS_TX_LOONGSON	0x00040000	/* Normal Loongson Tx Interrupt Summary */
+#define DMA_STATUS_NIS_RX_LOONGSON	0x00020000	/* Normal Loongson Rx Interrupt Summary */
+

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c line 42

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +10 -0
+#define DMA_STATUS_AIS_TX_LOONGSON	0x00010000	/* Abnormal Loongson Tx Interrupt Summary */
+#define DMA_STATUS_AIS_RX_LOONGSON	0x00008000	/* Abnormal Loongson Rx Interrupt Summary */
+
+#define DMA_STATUS_FBI_TX_LOONGSON	0x00002000	/* Fatal Loongson Tx Bus Error Interrupt */
+#define DMA_STATUS_FBI_RX_LOONGSON	0x00001000	/* Fatal Loongson Rx Bus Error Interrupt */
+
+#define DMA_STATUS_MSK_COMMON_LOONGSON		(DMA_STATUS_NIS_TX_LOONGSON | \
+					 DMA_STATUS_NIS_RX_LOONGSON | DMA_STATUS_AIS_TX_LOONGSON | \
+					 DMA_STATUS_AIS_RX_LOONGSON | DMA_STATUS_FBI_TX_LOONGSON | \
+					 DMA_STATUS_FBI_RX_LOONGSON)

Max 80 chars per line please.

Quoted 13 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +13 -0
+
+#define DMA_STATUS_MSK_RX_LOONGSON		(DMA_STATUS_ERI | \
+					 DMA_STATUS_RWT | \
+					 DMA_STATUS_RPS | \
+					 DMA_STATUS_RU | \
+					 DMA_STATUS_RI | \
+					 DMA_STATUS_OVF | \
+					 DMA_STATUS_MSK_COMMON_LOONGSON)
+
+#define DMA_STATUS_MSK_TX_LOONGSON		(DMA_STATUS_ETI | \
+					 DMA_STATUS_UNF | \
+					 DMA_STATUS_TJT | \
+					 DMA_STATUS_TU | \

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c line 62

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +8 -0
+					 DMA_STATUS_TPS | \
+					 DMA_STATUS_TI | \
+					 DMA_STATUS_MSK_COMMON_LOONGSON)
+
 
+struct loongson_data {
+	struct device *dev;
+	u32 lgmac_version;
 
+	struct stmmac_dma_ops dwlgmac_dma_ops;

Just figured out we can do without this field being added to the private data. See my note in the loongson_setup() method.

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c line 65

Quoted 4 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +3 -0
+};
+
 
+static void dwlgmac_dma_init_channel(struct stmmac_priv *priv,

The "dwlgmac_" prefix is confusing. There is the DW XLGMAC IP-core for which the "dwxlgmac_" is more appropriate and "x" is easy to miss should your version of the prefix is met. Consider changing it to something like "loongson_gnet_".

Quoted 33 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +33 -0
+				     void __iomem *ioaddr,
+				     struct stmmac_dma_cfg *dma_cfg, u32 chan)
+{
+	u32 value;
+	int txpbl = dma_cfg->txpbl ?: dma_cfg->pbl;
+	int rxpbl = dma_cfg->rxpbl ?: dma_cfg->pbl;
+
+	/* common channel control register config */
+	value = readl(ioaddr + DMA_CHAN_BUS_MODE(chan));
+
+	/* Set the DMA PBL (Programmable Burst Length) mode.
+	 *
+	 * Note: before stmmac core 3.50 this mode bit was 4xPBL, and
+	 * post 3.5 mode bit acts as 8*PBL.
+	 */
+	if (dma_cfg->pblx8)
+		value |= DMA_BUS_MODE_MAXPBL;
+	value |= DMA_BUS_MODE_USP;
+	value &= ~(DMA_BUS_MODE_PBL_MASK | DMA_BUS_MODE_RPBL_MASK);
+	value |= (txpbl << DMA_BUS_MODE_PBL_SHIFT);
+	value |= (rxpbl << DMA_BUS_MODE_RPBL_SHIFT);
+
+	/* Set the Fixed burst mode */
+	if (dma_cfg->fixed_burst)
+		value |= DMA_BUS_MODE_FB;
+
+	/* Mixed Burst has no effect when fb is set */
+	if (dma_cfg->mixed_burst)
+		value |= DMA_BUS_MODE_MB;
+
+	value |= DMA_BUS_MODE_ATDS;
+
+	if (dma_cfg->aal)

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c line 107

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +9 -0
+		value |= DMA_BUS_MODE_AAL;
+
+	writel(value, ioaddr + DMA_BUS_MODE);
+
+	/* Mask interrupts by writing to CSR7 */
+	writel(DMA_INTR_DEFAULT_MASK_LOONGSON, ioaddr + DMA_INTR_ENA);
+}
+
 
+static int dwlgmac_dma_interrupt(struct stmmac_priv *priv, void __iomem *ioaddr,

The same note as above.

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c line 116

Quoted 9 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +9 -0
+				 struct stmmac_extra_stats *x, u32 chan, u32 dir)
+{
+	struct stmmac_rxq_stats *rxq_stats = &priv->xstats.rxq_stats[chan];
+	struct stmmac_txq_stats *txq_stats = &priv->xstats.txq_stats[chan];
+	int ret = 0;
+	/* read the status register (CSR5) */
+	u32 nor_intr_status;
+	u32 abnor_intr_status;
+	u32 fb_intr_status;

Reverse xmas tree please.

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c line 117

Quoted 1 line
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +1 -0
+	u32 intr_status = readl(ioaddr + DMA_CHAN_STATUS(chan));

Please move the initialization into a separate statement.

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c line 124

Quoted 7 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +7 -0
+
+#ifdef DWMAC_DMA_DEBUG
+	/* Enable it to monitor DMA rx/tx status in case of critical problems */
+	pr_debug("%s: [CSR5: 0x%08x]\n", __func__, intr_status);
+	show_tx_process_state(intr_status);
+	show_rx_process_state(intr_status);
+#endif

This will cause a build-error if DWMAC_DMA_DEBUG is defined. Just drop it.

Quoted 77 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +73 -0
+
+	if (dir == DMA_DIR_RX)
+		intr_status &= DMA_STATUS_MSK_RX_LOONGSON;
+	else if (dir == DMA_DIR_TX)
+		intr_status &= DMA_STATUS_MSK_TX_LOONGSON;
+
+	nor_intr_status = intr_status & (DMA_STATUS_NIS_TX_LOONGSON |
+		DMA_STATUS_NIS_RX_LOONGSON);
+	abnor_intr_status = intr_status & (DMA_STATUS_AIS_TX_LOONGSON |
+		DMA_STATUS_AIS_RX_LOONGSON);
+	fb_intr_status = intr_status & (DMA_STATUS_FBI_TX_LOONGSON |
+		DMA_STATUS_FBI_RX_LOONGSON);
+
+	/* ABNORMAL interrupts */
+	if (unlikely(abnor_intr_status)) {
+		if (unlikely(intr_status & DMA_STATUS_UNF)) {
+			ret = tx_hard_error_bump_tc;
+			x->tx_undeflow_irq++;
+		}
+		if (unlikely(intr_status & DMA_STATUS_TJT))
+			x->tx_jabber_irq++;
+
+		if (unlikely(intr_status & DMA_STATUS_OVF))
+			x->rx_overflow_irq++;
+
+		if (unlikely(intr_status & DMA_STATUS_RU))
+			x->rx_buf_unav_irq++;
+		if (unlikely(intr_status & DMA_STATUS_RPS))
+			x->rx_process_stopped_irq++;
+		if (unlikely(intr_status & DMA_STATUS_RWT))
+			x->rx_watchdog_irq++;
+		if (unlikely(intr_status & DMA_STATUS_ETI))
+			x->tx_early_irq++;
+		if (unlikely(intr_status & DMA_STATUS_TPS)) {
+			x->tx_process_stopped_irq++;
+			ret = tx_hard_error;
+		}
+		if (unlikely(intr_status & fb_intr_status)) {
+			x->fatal_bus_error_irq++;
+			ret = tx_hard_error;
+		}
+	}
+	/* TX/RX NORMAL interrupts */
+	if (likely(nor_intr_status)) {
+		if (likely(intr_status & DMA_STATUS_RI)) {
+			u32 value = readl(ioaddr + DMA_INTR_ENA);
+			/* to schedule NAPI on real RIE event. */
+			if (likely(value & DMA_INTR_ENA_RIE)) {
+				u64_stats_update_begin(&rxq_stats->syncp);
+				rxq_stats->rx_normal_irq_n++;
+				u64_stats_update_end(&rxq_stats->syncp);
+				ret |= handle_rx;
+			}
+		}
+		if (likely(intr_status & DMA_STATUS_TI)) {
+			u64_stats_update_begin(&txq_stats->syncp);
+			txq_stats->tx_normal_irq_n++;
+			u64_stats_update_end(&txq_stats->syncp);
+			ret |= handle_tx;
+		}
+		if (unlikely(intr_status & DMA_STATUS_ERI))
+			x->rx_early_irq++;
+	}
+	/* Optional hardware blocks, interrupts should be disabled */
+	if (unlikely(intr_status &
+		     (DMA_STATUS_GPI | DMA_STATUS_GMI | DMA_STATUS_GLI)))
+		pr_warn("%s: unexpected status %08x\n", __func__, intr_status);
+
+	/* Clear the interrupt by writing a logic 1 to the CSR5[15-0] */
+	writel((intr_status & 0x7ffff), ioaddr + DMA_CHAN_STATUS(chan));
+
+	return ret;
+}
 
 struct stmmac_pci_info {
 	int (*setup)(struct pci_dev *pdev, struct plat_stmmacenet_data *plat);

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static struct stmmac_pci_info loongson_gmac_pci_info = { · line 312

Quoted 5 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +1 -0
@@ -121,6 +308,48 @@ static struct stmmac_pci_info loongson_gmac_pci_info = {
 	.config = loongson_gmac_config,
 };
 
 
+static struct mac_device_info *loongson_setup(void *apriv)

Consider using the GNET-specific prefix, like "loongson_gnet_".

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static struct stmmac_pci_info loongson_gmac_pci_info = { · line 319

Quoted 8 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +8 -0
+{
+	struct stmmac_priv *priv = apriv;
+	struct mac_device_info *mac;
+	struct loongson_data *ld;
+
+	mac = devm_kzalloc(priv->device, sizeof(*mac), GFP_KERNEL);
+	if (!mac)
+		return NULL;

What about devm_kzalloc()-ing the stmmac_dma_ops instance here and initializing it as it's done in the probe method? Thus ...

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static struct stmmac_pci_info loongson_gmac_pci_info = { · line 322

Quoted 3 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +3 -0
+
+	ld = priv->plat->bsp_priv;
+	mac->dma = &ld->dwlgmac_dma_ops;

... this can be replaced with:

	mac->dma = devm_kzalloc(priv->device, sizeof(*mac->dma), GFP_KERNEL);
	if (!mac->dma)
		return -ENOMEM;

	*mac->dma = dwmac1000_dma_ops;
	mac->dma->init_chan = loongson_gnet_dma_init_channel;
	mac->dma->dma_interrupt = loongson_gnet_dma_interrupt;
Quoted 34 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +30 -0
+
+	/* Pre-initialize the respective "mac" fields as it's done in
+	 * dwmac1000_setup()
+	 */
+	priv->dev->priv_flags |= IFF_UNICAST_FLT;
+	mac->pcsr = priv->ioaddr;
+	mac->multicast_filter_bins = priv->plat->multicast_filter_bins;
+	mac->unicast_filter_entries = priv->plat->unicast_filter_entries;
+	mac->mcast_bits_log2 = 0;
+
+	if (mac->multicast_filter_bins)
+		mac->mcast_bits_log2 = ilog2(mac->multicast_filter_bins);
+
+	mac->link.duplex = GMAC_CONTROL_DM;
+	mac->link.speed10 = GMAC_CONTROL_PS;
+	mac->link.speed100 = GMAC_CONTROL_PS | GMAC_CONTROL_FES;
+	mac->link.speed1000 = 0;
+	mac->link.speed_mask = GMAC_CONTROL_PS | GMAC_CONTROL_FES;
+	mac->mii.addr = GMAC_MII_ADDR;
+	mac->mii.data = GMAC_MII_DATA;
+	mac->mii.addr_shift = 11;
+	mac->mii.addr_mask = 0x0000F800;
+	mac->mii.reg_shift = 6;
+	mac->mii.reg_mask = 0x000007C0;
+	mac->mii.clk_csr_shift = 2;
+	mac->mii.clk_csr_mask = GENMASK(5, 2);
+
+	return mac;
+}
+
 static int loongson_dwmac_probe(struct pci_dev *pdev,
 				const struct pci_device_id *id)

{

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int loongson_dwmac_probe(struct pci_dev *pdev, · line 361

Quoted 4 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +1 -0
@@ -129,6 +358,7 @@ static int loongson_dwmac_probe(struct pci_dev *pdev,
 	struct stmmac_pci_info *info;
 	struct stmmac_resources res;
 	struct device_node *np;
+	struct loongson_data *ld;

reverse xmas tree order please.

Quoted 15 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +4 -0
 	plat = devm_kzalloc(&pdev->dev, sizeof(*plat), GFP_KERNEL);
 	if (!plat)
@@ -145,6 +375,10 @@ static int loongson_dwmac_probe(struct pci_dev *pdev,
 	if (!plat->dma_cfg)
 		return -ENOMEM;
 
+	ld = devm_kzalloc(&pdev->dev, sizeof(*ld), GFP_KERNEL);
+	if (!ld)
+		return -ENOMEM;
+
 	np = dev_of_node(&pdev->dev);
 	plat->mdio_node = of_get_child_by_name(np, "mdio");
 	if (plat->mdio_node) {

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int loongson_dwmac_probe(struct pci_dev *pdev, · line 436

Quoted 6 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +2 -0
@@ -197,6 +431,20 @@ static int loongson_dwmac_probe(struct pci_dev *pdev,
 	if (ret)
 		goto err_disable_device;
 
+	ld->dev = &pdev->dev;
 
+	ld->lgmac_version = readl(res.addr + GMAC_VERSION) & 0xff;

AFAICS the lgmac_version is unused in out of the probe() method context. What about locally defining it?

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int loongson_dwmac_probe(struct pci_dev *pdev, · line 438

Quoted 4 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +3 -0
+
+	/* Activate loongson custom ip */
 
+	if (ld->lgmac_version < DWMAC_CORE_3_50) {

Please define a new macro for the GNET MAC.

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int loongson_dwmac_probe(struct pci_dev *pdev, · line 441

Quoted 3 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +3 -0
+		ld->dwlgmac_dma_ops = dwmac1000_dma_ops;
+		ld->dwlgmac_dma_ops.init_chan = dwlgmac_dma_init_channel;
+		ld->dwlgmac_dma_ops.dma_interrupt = dwlgmac_dma_interrupt;

See my comment in the loongson_setup() method.

-Serge(y)

Quoted 12 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +6 -0
+
+		plat->setup = loongson_setup;
+	}
+
+	plat->bsp_priv = ld;
+
 	ret = stmmac_dvr_probe(&pdev->dev, plat, &res);
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +0 -0
 	if (ret)
 		goto err_disable_device;
Signature · 1 line
2.31.4
#39 lore raw

Re: [PATCH net-next v8 06/11] net: stmmac: dwmac-loongson: Add GNET support

In reply to Yanteng Si
Quoted 2 lines · Yanteng Si

Add Loongson GNET (GMAC with PHY) support, override stmmac_priv.synopsys_id with 0x37.

Please add more details of all the device capabilities: supported speeds, duplexness, IP-core version, DMA-descriptors type (normal/enhanced), MTL Tx/Rx FIFO size, Perfect and Hash-based MAC Filter tables size, L3/L4 filters availability, VLAN hash table filter, PHY-interface (GMII, RGMII, etc), EEE support, AV-feature/Multi-channels support, IEEE 1588 Timestamp support, Magic Frame support, Remote Wake-up support, IP Checksum, Tx/Rx TCP/IP Checksum, Mac Management Counters (MMC), SMA/MDIO interface,

Quoted 13 lines
---
 .../ethernet/stmicro/stmmac/dwmac-loongson.c  | 44 +++++++++++++++++++
 1 file changed, 44 insertions(+)
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +0 -0
index 3b3578318cc1..584f7322bd3e 100644

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static struct mac_device_info *loongson_setup(void *apriv) · line 323

Quoted 6 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +2 -0
@@ -318,6 +318,8 @@ static struct mac_device_info *loongson_setup(void *apriv)
 	if (!mac)
 		return NULL;
 
 
+	priv->synopsys_id = 0x37;	/*Overwrite custom IP*/
+

Please add a more descriptive comment _above_ the subjected line. In particular note why the override is needed, what is the real DW GMAC IP-core version and what is the original value the statement above overrides.

Quoted 9 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +2 -0
 	ld = priv->plat->bsp_priv;
 	mac->dma = &ld->dwlgmac_dma_ops;
@@ -350,6 +352,46 @@ static struct mac_device_info *loongson_setup(void *apriv)
 	return mac;
 }
 
+static int loongson_gnet_data(struct pci_dev *pdev,
+			      struct plat_stmmacenet_data *plat)

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static struct mac_device_info *loongson_setup(void *apriv) · line 366

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +9 -0
+{
+	loongson_default_data(pdev, plat);
+
+	plat->multicast_filter_bins = 256;
+
+	plat->mdio_bus_data->phy_mask =  ~(u32)BIT(2);
+
+	plat->phy_addr = 2;
 
+	plat->phy_interface = PHY_INTERFACE_MODE_INTERNAL;

Are you sure PHY-interface is supposed to be defined as "internal"?

Quoted 11 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +11 -0
+
+	plat->bsp_priv = &pdev->dev;
+
+	plat->dma_cfg->pbl = 32;
+	plat->dma_cfg->pblx8 = true;
+
+	plat->clk_ref_rate = 125000000;
+	plat->clk_ptp_rate = 125000000;
+
+	return 0;
+}

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static struct mac_device_info *loongson_setup(void *apriv) · line 385

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +9 -0
+
+static int loongson_gnet_config(struct pci_dev *pdev,
+				struct plat_stmmacenet_data *plat,
+				struct stmmac_resources *res,
+				struct device_node *np)
+{
+	int ret;
+
 
+	ret = loongson_dwmac_config_legacy(pdev, plat, res, np);

Again. This will be moved to the probe() method in one of the next patches leaving loongson_gnet_config() empty. What was the problem with doing that right away with no intermediate change?

Quoted 13 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +9 -0
+
+	return ret;
+}
+
+static struct stmmac_pci_info loongson_gnet_pci_info = {
+	.setup = loongson_gnet_data,
+	.config = loongson_gnet_config,
+};
+
 static int loongson_dwmac_probe(struct pci_dev *pdev,
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +0 -0
 				const struct pci_device_id *id)
 {

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static SIMPLE_DEV_PM_OPS(loongson_dwmac_pm_ops, loongson_dwmac_suspend, · line 566

Quoted 9 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +2 -0
@@ -516,9 +558,11 @@ static SIMPLE_DEV_PM_OPS(loongson_dwmac_pm_ops, loongson_dwmac_suspend,
 			 loongson_dwmac_resume);
 
 #define PCI_DEVICE_ID_LOONGSON_GMAC	0x7a03
 
+#define PCI_DEVICE_ID_LOONGSON_GNET	0x7a13
 
 static const struct pci_device_id loongson_dwmac_id_table[] = {
 	{ PCI_DEVICE_DATA(LOONGSON, GMAC, &loongson_gmac_pci_info) },
+	{ PCI_DEVICE_DATA(LOONGSON, GNET, &loongson_gnet_pci_info) },

After this the driver is supposed to correctly handle the Loongson GNET devices. Based on the patches introduced further it isn't. Please consider re-arranging the changes (see my comments in the further patches).

-Serge(y)

Quoted 6 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +0 -0
 	{}
 };

MODULE_DEVICE_TABLE(pci, loongson_dwmac_id_table);

Signature · 1 line
2.31.4
#50 lore raw

Re: [PATCH net-next v8 07/11] net: stmmac: dwmac-loongson: Add multi-channel supports for loongson

In reply to Yanteng Si
Quoted 2 lines · Yanteng Si

Request allocation for MSI for specific versions.

Please elaborate what is actually done in the patch. What device version it is dedicated for (Loongson GNET?), what IRQs the patch adds, etc.

BTW will GNET device work without this patch? If no you need to either merge it into the patch introducing the GNET-device support or place it before that patch (6/11).

Quoted 3 lines

Some features of Loongson platforms are bound to the GMAC_VERSION register. We have to read its value in order to get the correct channel number.

This message seems misleading. I don't see you doing that in the patch below...

Quoted 13 lines
---
 .../ethernet/stmicro/stmmac/dwmac-loongson.c  | 57 +++++++++++++++----
 1 file changed, 46 insertions(+), 11 deletions(-)
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +0 -0
index 584f7322bd3e..60d0a122d7c9 100644

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static void dwlgmac_dma_init_channel(struct stmmac_priv *priv, · line 105

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +2 -2
@@ -98,10 +98,10 @@ static void dwlgmac_dma_init_channel(struct stmmac_priv *priv,
 	if (dma_cfg->aal)
 		value |= DMA_BUS_MODE_AAL;
 
 
-	writel(value, ioaddr + DMA_BUS_MODE);
+	writel(value, ioaddr + DMA_CHAN_BUS_MODE(chan));
 
 	/* Mask interrupts by writing to CSR7 */
-	writel(DMA_INTR_DEFAULT_MASK_LOONGSON, ioaddr + DMA_INTR_ENA);
+	writel(DMA_INTR_DEFAULT_MASK_LOONGSON, ioaddr + DMA_CHAN_INTR_ENA(chan));

Em, why is this here? There is a patch
[PATCH net-next v8 05/11] net: stmmac: dwmac-loongson: Add Loongson-specific register definitions in this series which was supposed to introduce the fully functional
GNET-specific callbacks. Move this change in there.

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int loongson_dwmac_config_legacy(struct pci_dev *pdev, · line 242

Quoted 9 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +0 -0
 }
 

static int dwlgmac_dma_interrupt(struct stmmac_priv *priv, void __iomem *ioaddr,

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +1 -0
@@ -238,6 +238,45 @@ static int loongson_dwmac_config_legacy(struct pci_dev *pdev,
 	return 0;
 }
 
 
+static int loongson_dwmac_config_multi_msi(struct pci_dev *pdev,

This method seems like the GNET-specific one. What about using the appropriate prefix then?

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int loongson_dwmac_config_legacy(struct pci_dev *pdev, · line 245

Quoted 5 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +4 -0
+					   struct plat_stmmacenet_data *plat,
+					   struct stmmac_resources *res,
+					   struct device_node *np,
 
+					   int channel_num)

Why do you need this parametrization? Since this method is GNET-specific what about defining a macro with the channels amount and using it here?

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int loongson_dwmac_config_legacy(struct pci_dev *pdev, · line 254

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +9 -0
+{
+	int i, ret, vecs;
+
+	vecs = roundup_pow_of_two(channel_num * 2 + 1);
+	ret = pci_alloc_irq_vectors(pdev, vecs, vecs, PCI_IRQ_MSI);
 
+	if (ret < 0) {
+		dev_info(&pdev->dev,
+			 "MSI enable failed, Fallback to legacy interrupt\n");
+		return loongson_dwmac_config_legacy(pdev, plat, res, np);

In what conditions is this possible? Will the loongson_dwmac_config_legacy() method work in that case? Did you test it out?

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int loongson_dwmac_config_legacy(struct pci_dev *pdev, · line 258

Quoted 5 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +4 -0
+	}
+
 
+	plat->rx_queues_to_use = channel_num;
+	plat->tx_queues_to_use = channel_num;

This is supposed to be initialized in the setup() methods. Please move it to the dedicated patch.

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int loongson_dwmac_config_legacy(struct pci_dev *pdev, · line 261

Quoted 4 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +3 -0
+
+	res->irq = pci_irq_vector(pdev, 0);
 
+	res->wol_irq = res->irq;

Once again. wol_irq is optional. If there is no dedicated WoL IRQ leave the field as zero.

Quoted 5 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +5 -0
+
+	/* INT NAME | MAC | CH7 rx | CH7 tx | ... | CH0 rx | CH0 tx |
+	 * --------- ----- -------- --------  ...  -------- --------
+	 * IRQ NUM  |  0  |   1    |   2    | ... |   15   |   16   |
+	 */

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int loongson_dwmac_config_legacy(struct pci_dev *pdev, · line 275

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +9 -0
+	for (i = 0; i < channel_num; i++) {
+		res->rx_irq[channel_num - 1 - i] =
+			pci_irq_vector(pdev, 1 + i * 2);
+		res->tx_irq[channel_num - 1 - i] =
+			pci_irq_vector(pdev, 2 + i * 2);
+	}
+
+	plat->flags |= STMMAC_FLAG_MULTI_MSI_EN;
 
+	dev_info(&pdev->dev, "%s: multi MSI enablement successful\n", __func__);

What's the point in printing this message especially with the __func__ prefix? You'll always be able to figure out the allocated IRQs by means of procfs. I suggest to drop it.

Quoted 22 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +5 -4
+
+	return 0;
+}
+
 
 static void loongson_default_data(struct pci_dev *pdev,
 				  struct plat_stmmacenet_data *plat)
 {
@@ -296,11 +335,8 @@ static int loongson_gmac_config(struct pci_dev *pdev,
 				struct stmmac_resources *res,
 				struct device_node *np)
 {
-	int ret;
-
-	ret = loongson_dwmac_config_legacy(pdev, plat, res, np);
 
-	return ret;
+	return 0;
 }
 
 static struct stmmac_pci_info loongson_gmac_pci_info = {

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int loongson_gnet_config(struct pci_dev *pdev, · line 420

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +1 -5
@@ -380,11 +416,7 @@ static int loongson_gnet_config(struct pci_dev *pdev,
 				struct stmmac_resources *res,
 				struct device_node *np)
 {
-	int ret;
-
-	ret = loongson_dwmac_config_legacy(pdev, plat, res, np);
-
-	return ret;
+	return 0;
 }

Here you are dropping the changes you just introduced leaving the config() methods empty... Why not to place the loongson_dwmac_config_legacy() invocation in the probe() method right at the patches introducing the config() functions and not to add the config() callback in the first place?

-Serge(y)

Quoted 15 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +3 -0
 static struct stmmac_pci_info loongson_gnet_pci_info = {
@@ -483,6 +515,9 @@ static int loongson_dwmac_probe(struct pci_dev *pdev,
 		ld->dwlgmac_dma_ops.dma_interrupt = dwlgmac_dma_interrupt;
 
 		plat->setup = loongson_setup;
+		ret = loongson_dwmac_config_multi_msi(pdev, plat, &res, np, 8);
+	} else {
+		ret = loongson_dwmac_config_legacy(pdev, plat, &res, np);
 	}
 
 	plat->bsp_priv = ld;
Signature · 1 line
2.31.4
#61 lore raw

Re: [PATCH net-next v8 08/11] net: stmmac: dwmac-loongson: Fix MAC speed for GNET

In reply to Yanteng Si
Quoted 2 lines · Yanteng Si

Current GNET on LS7A only supports ANE when speed is set to 1000M.

If so you need to merge it into the patch
[PATCH net-next v8 06/11] net: stmmac: dwmac-loongson: Add GNET support

Quoted 16 lines
---
 .../ethernet/stmicro/stmmac/dwmac-loongson.c  | 19 +++++++++++++++++++
 .../ethernet/stmicro/stmmac/stmmac_ethtool.c  |  6 ++++++
 include/linux/stmmac.h                        |  1 +
 3 files changed, 26 insertions(+)
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +0 -0
index 60d0a122d7c9..264c4c198d5a 100644
@@ -344,6 +344,21 @@ static struct stmmac_pci_info loongson_gmac_pci_info = {
 	.config = loongson_gmac_config,

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static struct stmmac_pci_info loongson_gmac_pci_info = { · line 354

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +7 -0
 };
 
+static void loongson_gnet_fix_speed(void *priv, unsigned int speed, unsigned int mode)
+{
+	struct loongson_data *ld = (struct loongson_data *)priv;
+	struct net_device *ndev = dev_get_drvdata(ld->dev);
+	struct stmmac_priv *ptr = netdev_priv(ndev);
+
 
+	/* The controller and PHY don't work well together.

So there _is_ a PHY. What is the interface between MAC and PHY then?

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static struct stmmac_pci_info loongson_gmac_pci_info = { · line 359

Quoted 7 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +6 -0
+	 * We need to use the PS bit to check if the controller's status
+	 * is correct and reset PHY if necessary.
+	 */
 
+	if (speed == SPEED_1000)
+		if (readl(ptr->ioaddr + MAC_CTRL_REG) & (1 << 15) /* PS */)
+			phy_restart_aneg(ndev->phydev);

1. Please add curly braces for the outer if-statement.
2. MAC_CTRL_REG.15 is defined by the GMAC_CONTROL_PS macro.
3. How is the AN-restart helps? PHY-reset is done in stmmac_init_phy()->phylink_connect_phy()->... a bit earlier than this is called in the framework of the stmmac_mac_link_up() callback. Wouldn't that restart AN too?

Quoted 14 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +2 -0
+}
+
 static struct mac_device_info *loongson_setup(void *apriv)

{

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +1 -0
 	struct stmmac_priv *priv = apriv;
@@ -401,6 +416,7 @@ static int loongson_gnet_data(struct pci_dev *pdev,
 	plat->phy_interface = PHY_INTERFACE_MODE_INTERNAL;
 
 	plat->bsp_priv = &pdev->dev;
+	plat->fix_mac_speed = loongson_gnet_fix_speed;
 
 	plat->dma_cfg->pbl = 32;
 	plat->dma_cfg->pblx8 = true;

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int loongson_gnet_config(struct pci_dev *pdev, · line 438

Quoted 7 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +3 -0
@@ -416,6 +432,9 @@ static int loongson_gnet_config(struct pci_dev *pdev,
 				struct stmmac_resources *res,
 				struct device_node *np)
 {
 
+	if (pdev->revision == 0x00 || pdev->revision == 0x01)
+		plat->flags |= STMMAC_FLAG_DISABLE_FORCE_1000;
+

This should be in the patch
[PATCH net-next v8 06/11] net: stmmac: dwmac-loongson: Add GNET support

drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c stmmac_ethtool_set_link_ksettings(struct net_device *dev, · line 426

Quoted 13 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +0 -0
 	return 0;
 }
drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c +1 -0
index 42d27b97dd1d..31068fbc23c9 100644
@@ -422,6 +422,12 @@ stmmac_ethtool_set_link_ksettings(struct net_device *dev,
 		return 0;
 	}
 
 
+	if (FIELD_GET(STMMAC_FLAG_DISABLE_FORCE_1000, priv->plat->flags)) {

FIELD_GET()?

Quoted 13 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c +5 -0
+		if (cmd->base.speed == SPEED_1000 &&
+		    cmd->base.autoneg != AUTONEG_ENABLE)
+			return -EOPNOTSUPP;
+	}
+
 	return phylink_ethtool_ksettings_set(priv->phylink, cmd);
 }
include/linux/stmmac.h +0 -0
index dee5ad6e48c5..2810361e4048 100644

include/linux/stmmac.h struct dwmac4_addrs { · line 224

Quoted 4 lines
include/linux/stmmac.h +1 -0
@@ -221,6 +221,7 @@ struct dwmac4_addrs {
 #define STMMAC_FLAG_RX_CLK_RUNS_IN_LPI		BIT(10)
 #define STMMAC_FLAG_EN_TX_LPI_CLOCKGATING	BIT(11)
 #define STMMAC_FLAG_HWTSTAMP_CORRECT_LATENCY	BIT(12)
+#define STMMAC_FLAG_DISABLE_FORCE_1000	BIT(13)

Detach the change introducing the STMMAC_FLAG_DISABLE_FORCE_1000 flag into a separate patch a place it before
[PATCH net-next v8 06/11] net: stmmac: dwmac-loongson: Add GNET support as a pre-requisite/preparation patch.
Don't forget a _detailed_ description of why it's necessary, what is wrong with GNET so 1G speed doesn't work without AN.

-Serge(y)

Quoted 6 lines
include/linux/stmmac.h +0 -0
 struct plat_stmmacenet_data {
 	int bus_id;
Signature · 1 line
2.31.4
#77 lore raw

Re: [PATCH net-next v8 09/11] net: stmmac: dwmac-loongson: Fix half duplex

In reply to Yanteng Si
Quoted 22 lines · Yanteng Si

Current GNET does not support half duplex mode.

---
 drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c | 11 ++++++++++-
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c    |  3 ++-
 include/linux/stmmac.h                               |  1 +
 3 files changed, 13 insertions(+), 2 deletions(-)
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +1 -1
index 264c4c198d5a..1753a3c46b77 100644
@@ -432,8 +432,17 @@ static int loongson_gnet_config(struct pci_dev *pdev,
 				struct stmmac_resources *res,
 				struct device_node *np)
 {
 
-	if (pdev->revision == 0x00 || pdev->revision == 0x01)
+	switch (pdev->revision) {

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int loongson_gnet_config(struct pci_dev *pdev, · line 446

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +9 -0
+	case 0x00:
+		plat->flags |= STMMAC_FLAG_DISABLE_FORCE_1000 |
+			       STMMAC_FLAG_DISABLE_HALF_DUPLEX;
+		break;
+	case 0x01:
 		plat->flags |= STMMAC_FLAG_DISABLE_FORCE_1000;
+		break;
+	default:
+		break;
+	}

Move this change into the patch
[PATCH net-next v8 06/11] net: stmmac: dwmac-loongson: Add GNET support

Quoted 23 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +0 -0
 	return 0;
 }
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +2 -1
index 5617b40abbe4..3aa862269eb0 100644
@@ -1201,7 +1201,8 @@ static int stmmac_init_phy(struct net_device *dev)
 static void stmmac_set_half_duplex(struct stmmac_priv *priv)
 {
 
 	/* Half-Duplex can only work with single tx queue */
-	if (priv->plat->tx_queues_to_use > 1)
+	if (priv->plat->tx_queues_to_use > 1 ||
+	    (STMMAC_FLAG_DISABLE_HALF_DUPLEX & priv->plat->flags))
 		priv->phylink_config.mac_capabilities &=
 			~(MAC_10HD | MAC_100HD | MAC_1000HD);
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +0 -0
 	else
include/linux/stmmac.h +0 -0
index 2810361e4048..197f6f914104 100644

include/linux/stmmac.h struct dwmac4_addrs { · line 226

Quoted 5 lines
include/linux/stmmac.h +1 -0
@@ -222,6 +222,7 @@ struct dwmac4_addrs {
 #define STMMAC_FLAG_EN_TX_LPI_CLOCKGATING	BIT(11)
 #define STMMAC_FLAG_HWTSTAMP_CORRECT_LATENCY	BIT(12)
 #define STMMAC_FLAG_DISABLE_FORCE_1000	BIT(13)
+#define STMMAC_FLAG_DISABLE_HALF_DUPLEX	BIT(14)
 

Place the patch with this change before
[PATCH net-next v8 06/11] net: stmmac: dwmac-loongson: Add GNET support as a pre-requisite/preparation patch. Don't forget a thorough description of what is wrong with the GNET Half-Duplex mode.

-Serge(y)

Quoted 5 lines
include/linux/stmmac.h +0 -0
 struct plat_stmmacenet_data {
 	int bus_id;
Signature · 1 line
2.31.4
#78 lore raw

Re: [PATCH net-next v8 09/11] net: stmmac: dwmac-loongson: Fix half duplex

Quoted 63 lines · Serge Semin
Quoted 22 lines · Yanteng Si

Current GNET does not support half duplex mode.

---
 drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c | 11 ++++++++++-
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c    |  3 ++-
 include/linux/stmmac.h                               |  1 +
 3 files changed, 13 insertions(+), 2 deletions(-)
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +1 -1
index 264c4c198d5a..1753a3c46b77 100644
@@ -432,8 +432,17 @@ static int loongson_gnet_config(struct pci_dev *pdev,
 				struct stmmac_resources *res,
 				struct device_node *np)
 {
 
-	if (pdev->revision == 0x00 || pdev->revision == 0x01)
+	switch (pdev->revision) {

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int loongson_gnet_config(struct pci_dev *pdev, · line 446

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +9 -0
+	case 0x00:
+		plat->flags |= STMMAC_FLAG_DISABLE_FORCE_1000 |
+			       STMMAC_FLAG_DISABLE_HALF_DUPLEX;
+		break;
+	case 0x01:
 		plat->flags |= STMMAC_FLAG_DISABLE_FORCE_1000;
+		break;
+	default:
+		break;
+	}

Move this change into the patch
[PATCH net-next v8 06/11] net: stmmac: dwmac-loongson: Add GNET support

Quoted 26 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +0 -0
 	return 0;
 }
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +2 -1
index 5617b40abbe4..3aa862269eb0 100644
@@ -1201,7 +1201,8 @@ static int stmmac_init_phy(struct net_device *dev)
 static void stmmac_set_half_duplex(struct stmmac_priv *priv)
 {
 
 
 	/* Half-Duplex can only work with single tx queue */
-	if (priv->plat->tx_queues_to_use > 1)
+	if (priv->plat->tx_queues_to_use > 1 ||
+	    (STMMAC_FLAG_DISABLE_HALF_DUPLEX & priv->plat->flags))
 		priv->phylink_config.mac_capabilities &=
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +0 -0
 			~(MAC_10HD | MAC_100HD | MAC_1000HD);
 	else
include/linux/stmmac.h +0 -0
index 2810361e4048..197f6f914104 100644
@@ -222,6 +222,7 @@ struct dwmac4_addrs {
 #define STMMAC_FLAG_EN_TX_LPI_CLOCKGATING	BIT(11)
 #define STMMAC_FLAG_HWTSTAMP_CORRECT_LATENCY	BIT(12)
Quoted 8 lines

include/linux/stmmac.h struct dwmac4_addrs { · line 226

Quoted 3 lines
include/linux/stmmac.h +1 -0
 #define STMMAC_FLAG_DISABLE_FORCE_1000	BIT(13)
+#define STMMAC_FLAG_DISABLE_HALF_DUPLEX	BIT(14)
 

Place the patch with this change before
[PATCH net-next v8 06/11] net: stmmac: dwmac-loongson: Add GNET support as a pre-requisite/preparation patch. Don't forget a thorough description of what is wrong with the GNET Half-Duplex mode.

BTW what about re-defining the stmmac_ops.phylink_get_caps() callback instead of adding fixup flags in this patch and in the next one?

-Serge()

Quoted 8 lines

-Serge(y)

Quoted 5 lines
include/linux/stmmac.h +0 -0
 struct plat_stmmacenet_data {
 	int bus_id;
Signature · 1 line
2.31.4
#91 lore raw

Re: [PATCH net-next v8 10/11] net: stmmac: dwmac-loongson: Disable flow control for GMAC

In reply to Yanteng Si
Quoted 46 lines · Yanteng Si

Loongson GMAC does not support Flow Control feature. Set flags to disable it.

---
 drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c | 1 +
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c    | 6 +++---
 include/linux/stmmac.h                               | 1 +
 3 files changed, 5 insertions(+), 3 deletions(-)
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +1 -0
index 1753a3c46b77..b78a73ea748b 100644
@@ -335,6 +335,7 @@ static int loongson_gmac_config(struct pci_dev *pdev,
 				struct stmmac_resources *res,
 				struct device_node *np)
 {
+	plat->flags |= STMMAC_FLAG_DISABLE_FLOW_CONTROL;
 
 	return 0;
 }
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +3 -3
index 3aa862269eb0..8d676cbfba1e 100644
@@ -1237,9 +1237,9 @@ static int stmmac_phy_setup(struct stmmac_priv *priv)
 		xpcs_get_interfaces(priv->hw->xpcs,
 				    priv->phylink_config.supported_interfaces);
 
-	priv->phylink_config.mac_capabilities = MAC_ASYM_PAUSE | MAC_SYM_PAUSE |
-						MAC_10FD | MAC_100FD |
-						MAC_1000FD;
+	priv->phylink_config.mac_capabilities = MAC_10FD | MAC_100FD | MAC_1000FD;
+	if (!(priv->plat->flags & STMMAC_FLAG_DISABLE_FLOW_CONTROL))
+		priv->phylink_config.mac_capabilities |= MAC_ASYM_PAUSE | MAC_SYM_PAUSE;
 
 	stmmac_set_half_duplex(priv);
 
include/linux/stmmac.h +0 -0
index 197f6f914104..832cd8cd688f 100644

include/linux/stmmac.h struct dwmac4_addrs { · line 226

Quoted 4 lines
include/linux/stmmac.h +1 -0
@@ -223,6 +223,7 @@ struct dwmac4_addrs {
 #define STMMAC_FLAG_HWTSTAMP_CORRECT_LATENCY	BIT(12)
 #define STMMAC_FLAG_DISABLE_FORCE_1000	BIT(13)
 #define STMMAC_FLAG_DISABLE_HALF_DUPLEX	BIT(14)
+#define STMMAC_FLAG_DISABLE_FLOW_CONTROL	BIT(15)

See my last comment in patch 9/11. This can be reached by re-defining the stmmac_ops::phylink_get_caps() callback.

-Serge(y)

Quoted 6 lines
include/linux/stmmac.h +0 -0
 struct plat_stmmacenet_data {
 	int bus_id;
Signature · 1 line
2.31.4
#94 lore raw

Re: [PATCH net-next v8 11/11] net: stmmac: dwmac-loongson: Disable coe for some Loongson GNET

In reply to Yanteng Si
Quoted 1 line · Yanteng Si

Some chips of Loongson GNET does not support coe, so disable them.

s/coe/Tx COE

Quoted 15 lines

Set dma_cap->tx_coe to 0 and overwrite get_hw_feature.

---
 .../ethernet/stmicro/stmmac/dwmac-loongson.c  | 46 +++++++++++++++++++
 1 file changed, 46 insertions(+)
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +0 -0
index b78a73ea748b..8018d7d5f31b 100644

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int dwlgmac_dma_interrupt(struct stmmac_priv *priv, void __iomem *ioaddr, · line 200

Quoted 5 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +1 -0
@@ -196,6 +196,51 @@ static int dwlgmac_dma_interrupt(struct stmmac_priv *priv, void __iomem *ioaddr,
 	return ret;
 }
 
 
+static int dwlgmac_get_hw_feature(void __iomem *ioaddr,

Please use GNET-specific prefix.

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int dwlgmac_dma_interrupt(struct stmmac_priv *priv, void __iomem *ioaddr, · line 209

Quoted 11 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +10 -0
+				  struct dma_features *dma_cap)
+{
+	u32 hw_cap = readl(ioaddr + DMA_HW_FEATURE);
+
 
+	if (!hw_cap) {
+		/* 0x00000000 is the value read on old hardware that does not
+		 * implement this register
+		 */
+		return -EOPNOTSUPP;
+	}

This doesn't seems like possible. All your devices have the HW-features register. If so please drop.

Quoted 20 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +20 -0
+
+	dma_cap->mbps_10_100 = (hw_cap & DMA_HW_FEAT_MIISEL);
+	dma_cap->mbps_1000 = (hw_cap & DMA_HW_FEAT_GMIISEL) >> 1;
+	dma_cap->half_duplex = (hw_cap & DMA_HW_FEAT_HDSEL) >> 2;
+	dma_cap->hash_filter = (hw_cap & DMA_HW_FEAT_HASHSEL) >> 4;
+	dma_cap->multi_addr = (hw_cap & DMA_HW_FEAT_ADDMAC) >> 5;
+	dma_cap->pcs = (hw_cap & DMA_HW_FEAT_PCSSEL) >> 6;
+	dma_cap->sma_mdio = (hw_cap & DMA_HW_FEAT_SMASEL) >> 8;
+	dma_cap->pmt_remote_wake_up = (hw_cap & DMA_HW_FEAT_RWKSEL) >> 9;
+	dma_cap->pmt_magic_frame = (hw_cap & DMA_HW_FEAT_MGKSEL) >> 10;
+	/* MMC */
+	dma_cap->rmon = (hw_cap & DMA_HW_FEAT_MMCSEL) >> 11;
+	/* IEEE 1588-2002 */
+	dma_cap->time_stamp =
+	    (hw_cap & DMA_HW_FEAT_TSVER1SEL) >> 12;
+	/* IEEE 1588-2008 */
+	dma_cap->atime_stamp = (hw_cap & DMA_HW_FEAT_TSVER2SEL) >> 13;
+	/* 802.3az - Energy-Efficient Ethernet (EEE) */
+	dma_cap->eee = (hw_cap & DMA_HW_FEAT_EEESEL) >> 14;
+	dma_cap->av = (hw_cap & DMA_HW_FEAT_AVSEL) >> 15;

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int dwlgmac_dma_interrupt(struct stmmac_priv *priv, void __iomem *ioaddr, · line 239

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +10 -0
+	/* TX and RX csum */
+	dma_cap->tx_coe = 0;
+	dma_cap->rx_coe_type1 = (hw_cap & DMA_HW_FEAT_RXTYP1COE) >> 17;
+	dma_cap->rx_coe_type2 = (hw_cap & DMA_HW_FEAT_RXTYP2COE) >> 18;
+	dma_cap->rxfifo_over_2048 = (hw_cap & DMA_HW_FEAT_RXFIFOSIZE) >> 19;
+	/* TX and RX number of channels */
+	dma_cap->number_rx_channel = (hw_cap & DMA_HW_FEAT_RXCHCNT) >> 20;
+	dma_cap->number_tx_channel = (hw_cap & DMA_HW_FEAT_TXCHCNT) >> 22;
+	/* Alternate (enhanced) DESC mode */
+	dma_cap->enh_desc = (hw_cap & DMA_HW_FEAT_ENHDESSEL) >> 24;

I am not sure whether you need to parse the capability register at all seeing this is a GNET-specific method. For that device all the capabilities are already known and can be just initialized in this method.

-Serge(y)

Quoted 18 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +4 -0
+
+	return 0;
+}
+
 struct stmmac_pci_info {
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +1 -0
 	int (*setup)(struct pci_dev *pdev, struct plat_stmmacenet_data *plat);
 	int (*config)(struct pci_dev *pdev, struct plat_stmmacenet_data *plat,
@@ -542,6 +587,7 @@ static int loongson_dwmac_probe(struct pci_dev *pdev,
 		ld->dwlgmac_dma_ops = dwmac1000_dma_ops;
 		ld->dwlgmac_dma_ops.init_chan = dwlgmac_dma_init_channel;
 		ld->dwlgmac_dma_ops.dma_interrupt = dwlgmac_dma_interrupt;
+		ld->dwlgmac_dma_ops.get_hw_feature = dwlgmac_get_hw_feature;
 
 		plat->setup = loongson_setup;
 		ret = loongson_dwmac_config_multi_msi(pdev, plat, &res, np, 8);
Signature · 1 line
2.31.4
author
#5 lore raw

Re: [PATCH net-next v8 01/11] net: stmmac: Add multi-channel support

In reply to Serge Semin
Quoted 39 lines · Serge Semin
Quoted 38 lines · Yanteng Si

DW GMAC v3.x multi-channels feature is implemented as multiple sets of the same CSRs. Here is only preliminary support, it will be useful for the driver further evolution and for the users having multi-channel DWGMAC v3.x devices.

---
  .../net/ethernet/stmicro/stmmac/dwmac-sun8i.c |  2 +-
  .../ethernet/stmicro/stmmac/dwmac1000_dma.c   | 36 ++++++++++---------
  .../net/ethernet/stmicro/stmmac/dwmac_dma.h   | 19 +++++++++-
  .../net/ethernet/stmicro/stmmac/dwmac_lib.c   | 32 ++++++++---------
  drivers/net/ethernet/stmicro/stmmac/hwif.h    |  2 +-
  .../net/ethernet/stmicro/stmmac/stmmac_main.c |  6 ++--
  6 files changed, 58 insertions(+), 39 deletions(-)
drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c +1 -1
index 137741b94122..7cdfa0bdb93a 100644
@@ -395,7 +395,7 @@ static void sun8i_dwmac_dma_start_tx(struct stmmac_priv *priv,
  	writel(v, ioaddr + EMAC_TX_CTL1);
  }
 
-static void sun8i_dwmac_enable_dma_transmission(void __iomem *ioaddr)
+static void sun8i_dwmac_enable_dma_transmission(void __iomem *ioaddr, u32 chan)
  {
  	u32 v;
 
drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c +0 -0
index daf79cdbd3ec..5f7b82ad3ec2 100644
@@ -70,15 +70,18 @@ static void dwmac1000_dma_axi(void __iomem *ioaddr, struct stmmac_axi *axi)
  	writel(value, ioaddr + DMA_AXI_BUS_MODE);
  }
 
Quoted 11 lines

drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c static void dwmac1000_dma_axi(void __iomem *ioaddr, struct stmmac_axi *axi) · line 79

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c +4 -3
-static void dwmac1000_dma_init(void __iomem *ioaddr,
-			       struct stmmac_dma_cfg *dma_cfg, int atds)
+static void dwmac1000_dma_init_channel(struct stmmac_priv *priv,
+				       void __iomem *ioaddr,
+				       struct stmmac_dma_cfg *dma_cfg, u32 chan)
  {
-	u32 value = readl(ioaddr + DMA_BUS_MODE);
+	u32 value;
  	int txpbl = dma_cfg->txpbl ?: dma_cfg->pbl;
  	int rxpbl = dma_cfg->rxpbl ?: dma_cfg->pbl;

Reverse xmas tree please.

OK!

Quoted 6 lines

drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c static void dwmac1000_dma_axi(void __iomem *ioaddr, struct stmmac_axi *axi) · line 81

Quoted 5 lines
drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c +1 -2
-	/*
-	 * Set the DMA PBL (Programmable Burst Length) mode.
+	/* common channel control register config */

Redundant comment. Please drop.

OK!

Quoted 18 lines
Quoted 8 lines
drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c +3 -0
+	value = readl(ioaddr + DMA_CHAN_BUS_MODE(chan));
+
+	/* Set the DMA PBL (Programmable Burst Length) mode.
  	 *
  	 * Note: before stmmac core 3.50 this mode bit was 4xPBL, and
  	 * post 3.5 mode bit acts as 8*PBL.

drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c static void dwmac1000_dma_init(void __iomem *ioaddr, · line 104

Quoted 6 lines
drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c +1 -2
@@ -98,16 +101,15 @@ static void dwmac1000_dma_init(void __iomem *ioaddr,
  	if (dma_cfg->mixed_burst)
  		value |= DMA_BUS_MODE_MB;
 
-	if (atds)
-		value |= DMA_BUS_MODE_ATDS;
+	value |= DMA_BUS_MODE_ATDS;

No, just convert the stmmac_dma_ops.dma_init_channel() to accepting the atds flag as I suggested in v7:
https://lore.kernel.org/netdev/vxcfrxtbfu4pya56m22icnizsyjzqqha5blzb7zpexqcur56uh@uv6vsjf77npa/

Quoted 4 lines

In order to simplify this patch you can provide the stmmac_dma_ops.dma_init_channel() and stmmac_dma_ops.enable_dma_transmission() prototype updates in a pre-requisite/preparation patch.

OK.

Quoted 118 lines
Quoted 87 lines
drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c +10 -10
  	if (dma_cfg->aal)
  		value |= DMA_BUS_MODE_AAL;
 
-	writel(value, ioaddr + DMA_BUS_MODE);
+	writel(value, ioaddr + DMA_CHAN_BUS_MODE(chan));
 
  	/* Mask interrupts by writing to CSR7 */
-	writel(DMA_INTR_DEFAULT_MASK, ioaddr + DMA_INTR_ENA);
+	writel(DMA_INTR_DEFAULT_MASK, ioaddr + DMA_CHAN_INTR_ENA(chan));
  }
 
  static void dwmac1000_dma_init_rx(struct stmmac_priv *priv,
@@ -116,7 +118,7 @@ static void dwmac1000_dma_init_rx(struct stmmac_priv *priv,
  				  dma_addr_t dma_rx_phy, u32 chan)
  {
  	/* RX descriptor base address list must be written into DMA CSR3 */
-	writel(lower_32_bits(dma_rx_phy), ioaddr + DMA_RCV_BASE_ADDR);
+	writel(lower_32_bits(dma_rx_phy), ioaddr + DMA_CHAN_RCV_BASE_ADDR(chan));
  }
 
  static void dwmac1000_dma_init_tx(struct stmmac_priv *priv,
@@ -125,7 +127,7 @@ static void dwmac1000_dma_init_tx(struct stmmac_priv *priv,
  				  dma_addr_t dma_tx_phy, u32 chan)
  {
  	/* TX descriptor base address list must be written into DMA CSR4 */
-	writel(lower_32_bits(dma_tx_phy), ioaddr + DMA_TX_BASE_ADDR);
+	writel(lower_32_bits(dma_tx_phy), ioaddr + DMA_CHAN_TX_BASE_ADDR(chan));
  }
 
  static u32 dwmac1000_configure_fc(u32 csr6, int rxfifosz)
@@ -153,7 +155,7 @@ static void dwmac1000_dma_operation_mode_rx(struct stmmac_priv *priv,
  					    void __iomem *ioaddr, int mode,
  					    u32 channel, int fifosz, u8 qmode)
  {
-	u32 csr6 = readl(ioaddr + DMA_CONTROL);
+	u32 csr6 = readl(ioaddr + DMA_CHAN_CONTROL(channel));
 
  	if (mode == SF_DMA_MODE) {
  		pr_debug("GMAC: enable RX store and forward mode\n");
@@ -175,14 +177,14 @@ static void dwmac1000_dma_operation_mode_rx(struct stmmac_priv *priv,
  	/* Configure flow control based on rx fifo size */
  	csr6 = dwmac1000_configure_fc(csr6, fifosz);
 
-	writel(csr6, ioaddr + DMA_CONTROL);
+	writel(csr6, ioaddr + DMA_CHAN_CONTROL(channel));
  }
 
  static void dwmac1000_dma_operation_mode_tx(struct stmmac_priv *priv,
  					    void __iomem *ioaddr, int mode,
  					    u32 channel, int fifosz, u8 qmode)
  {
-	u32 csr6 = readl(ioaddr + DMA_CONTROL);
+	u32 csr6 = readl(ioaddr + DMA_CHAN_CONTROL(channel));
 
  	if (mode == SF_DMA_MODE) {
  		pr_debug("GMAC: enable TX store and forward mode\n");
@@ -209,7 +211,7 @@ static void dwmac1000_dma_operation_mode_tx(struct stmmac_priv *priv,
  			csr6 |= DMA_CONTROL_TTC_256;
  	}
 
-	writel(csr6, ioaddr + DMA_CONTROL);
+	writel(csr6, ioaddr + DMA_CHAN_CONTROL(channel));
  }
 
  static void dwmac1000_dump_dma_regs(struct stmmac_priv *priv,
@@ -271,12 +273,12 @@ static int dwmac1000_get_hw_feature(void __iomem *ioaddr,
  static void dwmac1000_rx_watchdog(struct stmmac_priv *priv,
  				  void __iomem *ioaddr, u32 riwt, u32 queue)
  {
-	writel(riwt, ioaddr + DMA_RX_WATCHDOG);
+	writel(riwt, ioaddr + DMA_CHAN_RX_WATCHDOG(queue));
  }
 
  const struct stmmac_dma_ops dwmac1000_dma_ops = {
  	.reset = dwmac_dma_reset,
-	.init = dwmac1000_dma_init,
+	.init_chan = dwmac1000_dma_init_channel,
  	.init_rx_chan = dwmac1000_dma_init_rx,
  	.init_tx_chan = dwmac1000_dma_init_tx,
  	.axi = dwmac1000_dma_axi,
drivers/net/ethernet/stmicro/stmmac/dwmac_dma.h +0 -0
index 72672391675f..593be79c46e1 100644

drivers/net/ethernet/stmicro/stmmac/dwmac_dma.h line 153

Quoted 6 lines
drivers/net/ethernet/stmicro/stmmac/dwmac_dma.h +3 -0
@@ -148,11 +148,14 @@
  					 DMA_STATUS_TI | \
  					 DMA_STATUS_MSK_COMMON)
 
+/* Following DMA defines are chanels oriented */    \
+#define DMA_CHAN_OFFSET			0x100   |-------------+
+                                                    /              |
                                                                       |
Please move all of these ---------------------------------------------+-------------------------+
to being defined just below the DMA_MISSED_FRAME_CTR macros definition.                         |
The point is to keep a coherency between dwmac_dma.h and dwmac4_dma.h.                          |
The later header file has first generic DMA-related macros defined                              |
(CSR addresses and flags) and then the channel-specific ones (CSR                               |
addresses and flags). Since in case of the DW GMAC v3.x the                                     |
multi-channels are implemented as a copy of all the DMA CSRs let's                              |
preserve the logic of having all CSR address defined first, then the                            |
CSR flags.                                                                                      |
                                                                                                 |

drivers/net/ethernet/stmicro/stmmac/dwmac_dma.h int dwmac_dma_interrupt(struct stmmac_priv *priv, void __iomem *ioaddr, | · line 174

Quoted 13 lines
drivers/net/ethernet/stmicro/stmmac/dwmac_dma.h +1 -1
  #define NUM_DWMAC100_DMA_REGS	9                                                       |
  #define NUM_DWMAC1000_DMA_REGS	23                                                      |
  #define NUM_DWMAC4_DMA_REGS	27                                                              |
                                                                                               |
-void dwmac_enable_dma_transmission(void __iomem *ioaddr);                                    |
+void dwmac_enable_dma_transmission(void __iomem *ioaddr, u32 chan);                          |
  void dwmac_enable_dma_irq(struct stmmac_priv *priv, void __iomem *ioaddr,                    |
  			  u32 chan, bool rx, bool tx);                                          |
  void dwmac_disable_dma_irq(struct stmmac_priv *priv, void __iomem *ioaddr,                   |
@@ -169,4 +172,18 @@ int dwmac_dma_interrupt(struct stmmac_priv *priv, void __iomem *ioaddr,  |
  			struct stmmac_extra_stats *x, u32 chan, u32 dir);                       |
  int dwmac_dma_reset(void __iomem *ioaddr);                                                   |
                                                                                               |
                                                                                                 |
Quoted 14 lines
Quoted 4 lines
drivers/net/ethernet/stmicro/stmmac/dwmac_dma.h +4 -0
+static inline u32 dma_chan_base_addr(u32 base, u32 chan)                                  \  |
+{                                                                                          | |
+	return base + chan * DMA_CHAN_OFFSET;                                                 | |
+}                                                                                          | |

drivers/net/ethernet/stmicro/stmmac/dwmac_dma.h int dwmac_dma_interrupt(struct stmmac_priv *priv, void __iomem *ioaddr, | · line 188

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac_dma.h +10 -0
+                                                                                           | |
+#define DMA_CHAN_XMT_POLL_DEMAND(chan)	dma_chan_base_addr(DMA_XMT_POLL_DEMAND, chan) | |
+#define DMA_CHAN_INTR_ENA(chan)		dma_chan_base_addr(DMA_INTR_ENA, chan)        | |
+#define DMA_CHAN_CONTROL(chan)		dma_chan_base_addr(DMA_CONTROL, chan)         | |
+#define DMA_CHAN_STATUS(chan)		dma_chan_base_addr(DMA_STATUS, chan)          |-+
+#define DMA_CHAN_BUS_MODE(chan)		dma_chan_base_addr(DMA_BUS_MODE, chan)        |
+#define DMA_CHAN_RCV_BASE_ADDR(chan)	dma_chan_base_addr(DMA_RCV_BASE_ADDR, chan)           |
+#define DMA_CHAN_TX_BASE_ADDR(chan)	dma_chan_base_addr(DMA_TX_BASE_ADDR, chan)            |
+#define DMA_CHAN_RX_WATCHDOG(chan)	dma_chan_base_addr(DMA_RX_WATCHDOG, chan)             |
+                                                                                           /

OK.

Quoted 97 lines
Quoted 97 lines
drivers/net/ethernet/stmicro/stmmac/dwmac_dma.h +0 -0
  #endif /* __DWMAC_DMA_H__ */
drivers/net/ethernet/stmicro/stmmac/dwmac_lib.c +15 -15
index 7907d62d3437..b37368137810 100644
@@ -28,65 +28,65 @@ int dwmac_dma_reset(void __iomem *ioaddr)
  }
 
  /* CSR1 enables the transmit DMA to check for new descriptor */
-void dwmac_enable_dma_transmission(void __iomem *ioaddr)
+void dwmac_enable_dma_transmission(void __iomem *ioaddr, u32 chan)
  {
-	writel(1, ioaddr + DMA_XMT_POLL_DEMAND);
+	writel(1, ioaddr + DMA_CHAN_XMT_POLL_DEMAND(chan));
  }
 
  void dwmac_enable_dma_irq(struct stmmac_priv *priv, void __iomem *ioaddr,
  			  u32 chan, bool rx, bool tx)
  {
-	u32 value = readl(ioaddr + DMA_INTR_ENA);
+	u32 value = readl(ioaddr + DMA_CHAN_INTR_ENA(chan));
 
  	if (rx)
  		value |= DMA_INTR_DEFAULT_RX;
  	if (tx)
  		value |= DMA_INTR_DEFAULT_TX;
 
-	writel(value, ioaddr + DMA_INTR_ENA);
+	writel(value, ioaddr + DMA_CHAN_INTR_ENA(chan));
  }
 
  void dwmac_disable_dma_irq(struct stmmac_priv *priv, void __iomem *ioaddr,
  			   u32 chan, bool rx, bool tx)
  {
-	u32 value = readl(ioaddr + DMA_INTR_ENA);
+	u32 value = readl(ioaddr + DMA_CHAN_INTR_ENA(chan));
 
  	if (rx)
  		value &= ~DMA_INTR_DEFAULT_RX;
  	if (tx)
  		value &= ~DMA_INTR_DEFAULT_TX;
 
-	writel(value, ioaddr + DMA_INTR_ENA);
+	writel(value, ioaddr + DMA_CHAN_INTR_ENA(chan));
  }
 
  void dwmac_dma_start_tx(struct stmmac_priv *priv, void __iomem *ioaddr,
  			u32 chan)
  {
-	u32 value = readl(ioaddr + DMA_CONTROL);
+	u32 value = readl(ioaddr + DMA_CHAN_CONTROL(chan));
  	value |= DMA_CONTROL_ST;
-	writel(value, ioaddr + DMA_CONTROL);
+	writel(value, ioaddr + DMA_CHAN_CONTROL(chan));
  }
 
  void dwmac_dma_stop_tx(struct stmmac_priv *priv, void __iomem *ioaddr, u32 chan)
  {
-	u32 value = readl(ioaddr + DMA_CONTROL);
+	u32 value = readl(ioaddr + DMA_CHAN_CONTROL(chan));
  	value &= ~DMA_CONTROL_ST;
-	writel(value, ioaddr + DMA_CONTROL);
+	writel(value, ioaddr + DMA_CHAN_CONTROL(chan));
  }
 
  void dwmac_dma_start_rx(struct stmmac_priv *priv, void __iomem *ioaddr,
  			u32 chan)
  {
-	u32 value = readl(ioaddr + DMA_CONTROL);
+	u32 value = readl(ioaddr + DMA_CHAN_CONTROL(chan));
  	value |= DMA_CONTROL_SR;
-	writel(value, ioaddr + DMA_CONTROL);
+	writel(value, ioaddr + DMA_CHAN_CONTROL(chan));
  }
 
  void dwmac_dma_stop_rx(struct stmmac_priv *priv, void __iomem *ioaddr, u32 chan)
  {
-	u32 value = readl(ioaddr + DMA_CONTROL);
+	u32 value = readl(ioaddr + DMA_CHAN_CONTROL(chan));
  	value &= ~DMA_CONTROL_SR;
-	writel(value, ioaddr + DMA_CONTROL);
+	writel(value, ioaddr + DMA_CHAN_CONTROL(chan));
  }
 
  #ifdef DWMAC_DMA_DEBUG
@@ -166,7 +166,7 @@ int dwmac_dma_interrupt(struct stmmac_priv *priv, void __iomem *ioaddr,
  	struct stmmac_txq_stats *txq_stats = &priv->xstats.txq_stats[chan];
  	int ret = 0;
  	/* read the status register (CSR5) */
-	u32 intr_status = readl(ioaddr + DMA_STATUS);
+	u32 intr_status = readl(ioaddr + DMA_CHAN_STATUS(chan));
 
  #ifdef DWMAC_DMA_DEBUG
  	/* Enable it to monitor DMA rx/tx status in case of critical problems */
@@ -236,7 +236,7 @@ int dwmac_dma_interrupt(struct stmmac_priv *priv, void __iomem *ioaddr,
  		pr_warn("%s: unexpected status %08x\n", __func__, intr_status);
 
Quoted 5 lines

drivers/net/ethernet/stmicro/stmmac/dwmac_lib.c int dwmac_dma_interrupt(struct stmmac_priv *priv, void __iomem *ioaddr, · line 239

Quoted 3 lines
drivers/net/ethernet/stmicro/stmmac/dwmac_lib.c +1 -1
  	/* Clear the interrupt by writing a logic 1 to the CSR5[15-0] */
-	writel((intr_status & 0x1ffff), ioaddr + DMA_STATUS);
+	writel((intr_status & 0x7ffff), ioaddr + DMA_CHAN_STATUS(chan));

Isn't the mask change going to be implemented in the framework of the Loongson-specific DMA-interrupt handler in some of the further patches?

Yes!

Quoted 2 lines

I'll get back to reviewing the series tomorrow (later today)...

OK, Thanks for your review!  I have read all your comments in others patch.

I will modify the code as soon as possible according to your comments,

but in the next two weeks (Spring Festival), I will not be able to test on all devices.

Thanks,

Yanteng

Quoted 53 lines

-Serge(y)

Quoted 50 lines
drivers/net/ethernet/stmicro/stmmac/dwmac_lib.c +0 -0
  	return ret;
  }
drivers/net/ethernet/stmicro/stmmac/hwif.h +1 -1
index 7be04b54738b..b0db38396171 100644
@@ -198,7 +198,7 @@ struct stmmac_dma_ops {
  	/* To track extra statistic (if supported) */
  	void (*dma_diagnostic_fr)(struct stmmac_extra_stats *x,
  				  void __iomem *ioaddr);
-	void (*enable_dma_transmission) (void __iomem *ioaddr);
+	void (*enable_dma_transmission)(void __iomem *ioaddr, u32 chan);
  	void (*enable_dma_irq)(struct stmmac_priv *priv, void __iomem *ioaddr,
  			       u32 chan, bool rx, bool tx);
  	void (*disable_dma_irq)(struct stmmac_priv *priv, void __iomem *ioaddr,
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +3 -3
index b334eb16da23..5617b40abbe4 100644
@@ -2558,7 +2558,7 @@ static bool stmmac_xdp_xmit_zc(struct stmmac_priv *priv, u32 queue, u32 budget)
  				       true, priv->mode, true, true,
  				       xdp_desc.len);
 
-		stmmac_enable_dma_transmission(priv, priv->ioaddr);
+		stmmac_enable_dma_transmission(priv, priv->ioaddr, queue);
 
  		xsk_tx_metadata_to_compl(meta,
  					 &tx_q->tx_skbuff_dma[entry].xsk_meta);
@@ -4706,7 +4706,7 @@ static netdev_tx_t stmmac_xmit(struct sk_buff *skb, struct net_device *dev)
 
  	netdev_tx_sent_queue(netdev_get_tx_queue(dev, queue), skb->len);
 
-	stmmac_enable_dma_transmission(priv, priv->ioaddr);
+	stmmac_enable_dma_transmission(priv, priv->ioaddr, queue);
 
  	stmmac_flush_tx_descriptors(priv, queue);
  	stmmac_tx_timer_arm(priv, queue);
@@ -4926,7 +4926,7 @@ static int stmmac_xdp_xmit_xdpf(struct stmmac_priv *priv, int queue,
  		u64_stats_update_end_irqrestore(&txq_stats->syncp, flags);
  	}
 
-	stmmac_enable_dma_transmission(priv, priv->ioaddr);
+	stmmac_enable_dma_transmission(priv, priv->ioaddr, queue);
 
  	entry = STMMAC_GET_ENTRY(entry, priv->dma_conf.dma_tx_size);
  	tx_q->cur_tx = entry;
Signature · 1 line
2.31.4
#6 lore raw

Re: [PATCH net-next v8 01/11] net: stmmac: Add multi-channel support

Quoted 289 lines · Yanteng Si
Quoted 39 lines · Serge Semin
Quoted 38 lines · Yanteng Si

DW GMAC v3.x multi-channels feature is implemented as multiple sets of the same CSRs. Here is only preliminary support, it will be useful for the driver further evolution and for the users having multi-channel DWGMAC v3.x devices.

---
  .../net/ethernet/stmicro/stmmac/dwmac-sun8i.c |  2 +-
  .../ethernet/stmicro/stmmac/dwmac1000_dma.c   | 36 ++++++++++---------
  .../net/ethernet/stmicro/stmmac/dwmac_dma.h   | 19 +++++++++-
  .../net/ethernet/stmicro/stmmac/dwmac_lib.c   | 32 ++++++++---------
  drivers/net/ethernet/stmicro/stmmac/hwif.h    |  2 +-
  .../net/ethernet/stmicro/stmmac/stmmac_main.c |  6 ++--
  6 files changed, 58 insertions(+), 39 deletions(-)
drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c +1 -1
index 137741b94122..7cdfa0bdb93a 100644
@@ -395,7 +395,7 @@ static void sun8i_dwmac_dma_start_tx(struct stmmac_priv *priv,
  	writel(v, ioaddr + EMAC_TX_CTL1);
  }
-static void sun8i_dwmac_enable_dma_transmission(void __iomem *ioaddr)
+static void sun8i_dwmac_enable_dma_transmission(void __iomem *ioaddr, u32 chan)
  {
  	u32 v;
drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c +1 -2
index daf79cdbd3ec..5f7b82ad3ec2 100644
@@ -70,15 +70,18 @@ static void dwmac1000_dma_axi(void __iomem *ioaddr, struct stmmac_axi *axi)
  	writel(value, ioaddr + DMA_AXI_BUS_MODE);
  }
-static void dwmac1000_dma_init(void __iomem *ioaddr,
-			       struct stmmac_dma_cfg *dma_cfg, int atds)
+static void dwmac1000_dma_init_channel(struct stmmac_priv *priv,
Quoted 8 lines

drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c static void dwmac1000_dma_axi(void __iomem *ioaddr, struct stmmac_axi *axi) · line 79

Quoted 7 lines
drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c +3 -1
+				       void __iomem *ioaddr,
+				       struct stmmac_dma_cfg *dma_cfg, u32 chan)
  {
-	u32 value = readl(ioaddr + DMA_BUS_MODE);
+	u32 value;
  	int txpbl = dma_cfg->txpbl ?: dma_cfg->pbl;
  	int rxpbl = dma_cfg->rxpbl ?: dma_cfg->pbl;

Reverse xmas tree please.

OK!

Quoted 5 lines

drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c static void dwmac1000_dma_axi(void __iomem *ioaddr, struct stmmac_axi *axi) · line 81

Quoted 4 lines
drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c +1 -2
-	/*
-	 * Set the DMA PBL (Programmable Burst Length) mode.
+	/* common channel control register config */

Redundant comment. Please drop.

OK!

Quoted 17 lines

drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c static void dwmac1000_dma_init(void __iomem *ioaddr, · line 103

Quoted 13 lines
drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c +4 -2
+	value = readl(ioaddr + DMA_CHAN_BUS_MODE(chan));
+
+	/* Set the DMA PBL (Programmable Burst Length) mode.
  	 *
  	 * Note: before stmmac core 3.50 this mode bit was 4xPBL, and
  	 * post 3.5 mode bit acts as 8*PBL.
@@ -98,16 +101,15 @@ static void dwmac1000_dma_init(void __iomem *ioaddr,
  	if (dma_cfg->mixed_burst)
  		value |= DMA_BUS_MODE_MB;
-	if (atds)
-		value |= DMA_BUS_MODE_ATDS;
+	value |= DMA_BUS_MODE_ATDS;

No, just convert the stmmac_dma_ops.dma_init_channel() to accepting the atds flag as I suggested in v7:
https://lore.kernel.org/netdev/vxcfrxtbfu4pya56m22icnizsyjzqqha5blzb7zpexqcur56uh@uv6vsjf77npa/

Quoted 4 lines

In order to simplify this patch you can provide the stmmac_dma_ops.dma_init_channel() and stmmac_dma_ops.enable_dma_transmission() prototype updates in a pre-requisite/preparation patch.

OK.

Quoted 104 lines
Quoted 74 lines
drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c +10 -10
  	if (dma_cfg->aal)
  		value |= DMA_BUS_MODE_AAL;
-	writel(value, ioaddr + DMA_BUS_MODE);
+	writel(value, ioaddr + DMA_CHAN_BUS_MODE(chan));
  	/* Mask interrupts by writing to CSR7 */
-	writel(DMA_INTR_DEFAULT_MASK, ioaddr + DMA_INTR_ENA);
+	writel(DMA_INTR_DEFAULT_MASK, ioaddr + DMA_CHAN_INTR_ENA(chan));
  }
  static void dwmac1000_dma_init_rx(struct stmmac_priv *priv,
@@ -116,7 +118,7 @@ static void dwmac1000_dma_init_rx(struct stmmac_priv *priv,
  				  dma_addr_t dma_rx_phy, u32 chan)
  {
  	/* RX descriptor base address list must be written into DMA CSR3 */
-	writel(lower_32_bits(dma_rx_phy), ioaddr + DMA_RCV_BASE_ADDR);
+	writel(lower_32_bits(dma_rx_phy), ioaddr + DMA_CHAN_RCV_BASE_ADDR(chan));
  }
  static void dwmac1000_dma_init_tx(struct stmmac_priv *priv,
@@ -125,7 +127,7 @@ static void dwmac1000_dma_init_tx(struct stmmac_priv *priv,
  				  dma_addr_t dma_tx_phy, u32 chan)
  {
  	/* TX descriptor base address list must be written into DMA CSR4 */
-	writel(lower_32_bits(dma_tx_phy), ioaddr + DMA_TX_BASE_ADDR);
+	writel(lower_32_bits(dma_tx_phy), ioaddr + DMA_CHAN_TX_BASE_ADDR(chan));
  }
  static u32 dwmac1000_configure_fc(u32 csr6, int rxfifosz)
@@ -153,7 +155,7 @@ static void dwmac1000_dma_operation_mode_rx(struct stmmac_priv *priv,
  					    void __iomem *ioaddr, int mode,
  					    u32 channel, int fifosz, u8 qmode)
  {
-	u32 csr6 = readl(ioaddr + DMA_CONTROL);
+	u32 csr6 = readl(ioaddr + DMA_CHAN_CONTROL(channel));
  	if (mode == SF_DMA_MODE) {
  		pr_debug("GMAC: enable RX store and forward mode\n");
@@ -175,14 +177,14 @@ static void dwmac1000_dma_operation_mode_rx(struct stmmac_priv *priv,
  	/* Configure flow control based on rx fifo size */
  	csr6 = dwmac1000_configure_fc(csr6, fifosz);
-	writel(csr6, ioaddr + DMA_CONTROL);
+	writel(csr6, ioaddr + DMA_CHAN_CONTROL(channel));
  }
  static void dwmac1000_dma_operation_mode_tx(struct stmmac_priv *priv,
  					    void __iomem *ioaddr, int mode,
  					    u32 channel, int fifosz, u8 qmode)
  {
-	u32 csr6 = readl(ioaddr + DMA_CONTROL);
+	u32 csr6 = readl(ioaddr + DMA_CHAN_CONTROL(channel));
  	if (mode == SF_DMA_MODE) {
  		pr_debug("GMAC: enable TX store and forward mode\n");
@@ -209,7 +211,7 @@ static void dwmac1000_dma_operation_mode_tx(struct stmmac_priv *priv,
  			csr6 |= DMA_CONTROL_TTC_256;
  	}
-	writel(csr6, ioaddr + DMA_CONTROL);
+	writel(csr6, ioaddr + DMA_CHAN_CONTROL(channel));
  }
  static void dwmac1000_dump_dma_regs(struct stmmac_priv *priv,
@@ -271,12 +273,12 @@ static int dwmac1000_get_hw_feature(void __iomem *ioaddr,
  static void dwmac1000_rx_watchdog(struct stmmac_priv *priv,
  				  void __iomem *ioaddr, u32 riwt, u32 queue)
  {
-	writel(riwt, ioaddr + DMA_RX_WATCHDOG);
+	writel(riwt, ioaddr + DMA_CHAN_RX_WATCHDOG(queue));
  }
  const struct stmmac_dma_ops dwmac1000_dma_ops = {
  	.reset = dwmac_dma_reset,
-	.init = dwmac1000_dma_init,
+	.init_chan = dwmac1000_dma_init_channel,
  	.init_rx_chan = dwmac1000_dma_init_rx,
  	.init_tx_chan = dwmac1000_dma_init_tx,
  	.axi = dwmac1000_dma_axi,
drivers/net/ethernet/stmicro/stmmac/dwmac_dma.h +0 -0
index 72672391675f..593be79c46e1 100644

drivers/net/ethernet/stmicro/stmmac/dwmac_dma.h line 152

Quoted 5 lines
drivers/net/ethernet/stmicro/stmmac/dwmac_dma.h +3 -0
@@ -148,11 +148,14 @@
  					 DMA_STATUS_TI | \
  					 DMA_STATUS_MSK_COMMON)
+/* Following DMA defines are chanels oriented */    \
+#define DMA_CHAN_OFFSET			0x100   |-------------+
+                                                    /              |
                                                                       |
Please move all of these ---------------------------------------------+-------------------------+
to being defined just below the DMA_MISSED_FRAME_CTR macros definition.                         |
The point is to keep a coherency between dwmac_dma.h and dwmac4_dma.h.                          |
The later header file has first generic DMA-related macros defined                              |
(CSR addresses and flags) and then the channel-specific ones (CSR                               |
addresses and flags). Since in case of the DW GMAC v3.x the                                     |
multi-channels are implemented as a copy of all the DMA CSRs let's                              |
preserve the logic of having all CSR address defined first, then the                            |
CSR flags.                                                                                      |
                                                                                                 |

drivers/net/ethernet/stmicro/stmmac/dwmac_dma.h int dwmac_dma_interrupt(struct stmmac_priv *priv, void __iomem *ioaddr, | · line 174

Quoted 13 lines
drivers/net/ethernet/stmicro/stmmac/dwmac_dma.h +1 -1
  #define NUM_DWMAC100_DMA_REGS	9                                                       |
  #define NUM_DWMAC1000_DMA_REGS	23                                                      |
  #define NUM_DWMAC4_DMA_REGS	27                                                              |
                                                                                               |
-void dwmac_enable_dma_transmission(void __iomem *ioaddr);                                    |
+void dwmac_enable_dma_transmission(void __iomem *ioaddr, u32 chan);                          |
  void dwmac_enable_dma_irq(struct stmmac_priv *priv, void __iomem *ioaddr,                    |
  			  u32 chan, bool rx, bool tx);                                          |
  void dwmac_disable_dma_irq(struct stmmac_priv *priv, void __iomem *ioaddr,                   |
@@ -169,4 +172,18 @@ int dwmac_dma_interrupt(struct stmmac_priv *priv, void __iomem *ioaddr,  |
  			struct stmmac_extra_stats *x, u32 chan, u32 dir);                       |
  int dwmac_dma_reset(void __iomem *ioaddr);                                                   |
                                                                                               |
                                                                                                 |
Quoted 14 lines
Quoted 4 lines
drivers/net/ethernet/stmicro/stmmac/dwmac_dma.h +4 -0
+static inline u32 dma_chan_base_addr(u32 base, u32 chan)                                  \  |
+{                                                                                          | |
+	return base + chan * DMA_CHAN_OFFSET;                                                 | |
+}                                                                                          | |

drivers/net/ethernet/stmicro/stmmac/dwmac_dma.h int dwmac_dma_interrupt(struct stmmac_priv *priv, void __iomem *ioaddr, | · line 188

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac_dma.h +10 -0
+                                                                                           | |
+#define DMA_CHAN_XMT_POLL_DEMAND(chan)	dma_chan_base_addr(DMA_XMT_POLL_DEMAND, chan) | |
+#define DMA_CHAN_INTR_ENA(chan)		dma_chan_base_addr(DMA_INTR_ENA, chan)        | |
+#define DMA_CHAN_CONTROL(chan)		dma_chan_base_addr(DMA_CONTROL, chan)         | |
+#define DMA_CHAN_STATUS(chan)		dma_chan_base_addr(DMA_STATUS, chan)          |-+
+#define DMA_CHAN_BUS_MODE(chan)		dma_chan_base_addr(DMA_BUS_MODE, chan)        |
+#define DMA_CHAN_RCV_BASE_ADDR(chan)	dma_chan_base_addr(DMA_RCV_BASE_ADDR, chan)           |
+#define DMA_CHAN_TX_BASE_ADDR(chan)	dma_chan_base_addr(DMA_TX_BASE_ADDR, chan)            |
+#define DMA_CHAN_RX_WATCHDOG(chan)	dma_chan_base_addr(DMA_RX_WATCHDOG, chan)             |
+                                                                                           /

OK.

Quoted 80 lines
Quoted 80 lines
drivers/net/ethernet/stmicro/stmmac/dwmac_dma.h +0 -0
  #endif /* __DWMAC_DMA_H__ */
drivers/net/ethernet/stmicro/stmmac/dwmac_lib.c +15 -15
index 7907d62d3437..b37368137810 100644
@@ -28,65 +28,65 @@ int dwmac_dma_reset(void __iomem *ioaddr)
  }
  /* CSR1 enables the transmit DMA to check for new descriptor */
-void dwmac_enable_dma_transmission(void __iomem *ioaddr)
+void dwmac_enable_dma_transmission(void __iomem *ioaddr, u32 chan)
  {
-	writel(1, ioaddr + DMA_XMT_POLL_DEMAND);
+	writel(1, ioaddr + DMA_CHAN_XMT_POLL_DEMAND(chan));
  }
  void dwmac_enable_dma_irq(struct stmmac_priv *priv, void __iomem *ioaddr,
  			  u32 chan, bool rx, bool tx)
  {
-	u32 value = readl(ioaddr + DMA_INTR_ENA);
+	u32 value = readl(ioaddr + DMA_CHAN_INTR_ENA(chan));
  	if (rx)
  		value |= DMA_INTR_DEFAULT_RX;
  	if (tx)
  		value |= DMA_INTR_DEFAULT_TX;
-	writel(value, ioaddr + DMA_INTR_ENA);
+	writel(value, ioaddr + DMA_CHAN_INTR_ENA(chan));
  }
  void dwmac_disable_dma_irq(struct stmmac_priv *priv, void __iomem *ioaddr,
  			   u32 chan, bool rx, bool tx)
  {
-	u32 value = readl(ioaddr + DMA_INTR_ENA);
+	u32 value = readl(ioaddr + DMA_CHAN_INTR_ENA(chan));
  	if (rx)
  		value &= ~DMA_INTR_DEFAULT_RX;
  	if (tx)
  		value &= ~DMA_INTR_DEFAULT_TX;
-	writel(value, ioaddr + DMA_INTR_ENA);
+	writel(value, ioaddr + DMA_CHAN_INTR_ENA(chan));
  }
  void dwmac_dma_start_tx(struct stmmac_priv *priv, void __iomem *ioaddr,
  			u32 chan)
  {
-	u32 value = readl(ioaddr + DMA_CONTROL);
+	u32 value = readl(ioaddr + DMA_CHAN_CONTROL(chan));
  	value |= DMA_CONTROL_ST;
-	writel(value, ioaddr + DMA_CONTROL);
+	writel(value, ioaddr + DMA_CHAN_CONTROL(chan));
  }
  void dwmac_dma_stop_tx(struct stmmac_priv *priv, void __iomem *ioaddr, u32 chan)
  {
-	u32 value = readl(ioaddr + DMA_CONTROL);
+	u32 value = readl(ioaddr + DMA_CHAN_CONTROL(chan));
  	value &= ~DMA_CONTROL_ST;
-	writel(value, ioaddr + DMA_CONTROL);
+	writel(value, ioaddr + DMA_CHAN_CONTROL(chan));
  }
  void dwmac_dma_start_rx(struct stmmac_priv *priv, void __iomem *ioaddr,
  			u32 chan)
  {
-	u32 value = readl(ioaddr + DMA_CONTROL);
+	u32 value = readl(ioaddr + DMA_CHAN_CONTROL(chan));
  	value |= DMA_CONTROL_SR;
-	writel(value, ioaddr + DMA_CONTROL);
+	writel(value, ioaddr + DMA_CHAN_CONTROL(chan));
  }
  void dwmac_dma_stop_rx(struct stmmac_priv *priv, void __iomem *ioaddr, u32 chan)
  {
-	u32 value = readl(ioaddr + DMA_CONTROL);
+	u32 value = readl(ioaddr + DMA_CHAN_CONTROL(chan));
  	value &= ~DMA_CONTROL_SR;
-	writel(value, ioaddr + DMA_CONTROL);
+	writel(value, ioaddr + DMA_CHAN_CONTROL(chan));
  }
  #ifdef DWMAC_DMA_DEBUG
@@ -166,7 +166,7 @@ int dwmac_dma_interrupt(struct stmmac_priv *priv, void __iomem *ioaddr,
  	struct stmmac_txq_stats *txq_stats = &priv->xstats.txq_stats[chan];
  	int ret = 0;
  	/* read the status register (CSR5) */
-	u32 intr_status = readl(ioaddr + DMA_STATUS);
+	u32 intr_status = readl(ioaddr + DMA_CHAN_STATUS(chan));
  #ifdef DWMAC_DMA_DEBUG
Quoted 8 lines

drivers/net/ethernet/stmicro/stmmac/dwmac_lib.c int dwmac_dma_interrupt(struct stmmac_priv *priv, void __iomem *ioaddr, · line 238

Quoted 6 lines
drivers/net/ethernet/stmicro/stmmac/dwmac_lib.c +1 -1
  	/* Enable it to monitor DMA rx/tx status in case of critical problems */
@@ -236,7 +236,7 @@ int dwmac_dma_interrupt(struct stmmac_priv *priv, void __iomem *ioaddr,
  		pr_warn("%s: unexpected status %08x\n", __func__, intr_status);
  	/* Clear the interrupt by writing a logic 1 to the CSR5[15-0] */
-	writel((intr_status & 0x1ffff), ioaddr + DMA_STATUS);
+	writel((intr_status & 0x7ffff), ioaddr + DMA_CHAN_STATUS(chan));

Isn't the mask change going to be implemented in the framework of the Loongson-specific DMA-interrupt handler in some of the further patches?

Yes!

Quoted 2 lines

I'll get back to reviewing the series tomorrow (later today)...

Quoted 8 lines

OK, Thanks for your review!  I have read all your comments in others patch.

I will modify the code as soon as possible according to your comments,

but in the next two weeks (Spring Festival), I will not be able to test on all devices.

Ok. Whenever you are ready I'll keep reviewing your series. Even at the current state the patchset looks much much better than it was initially. Some reordering, commit logs elaboration, a few more cycle to polish out some details and I guess it will be ready for merging at least from my point of view.

-Serge(y)

Quoted 52 lines

Thanks,

Yanteng

Quoted 45 lines

-Serge(y)

Quoted 42 lines
drivers/net/ethernet/stmicro/stmmac/dwmac_lib.c +0 -0
  	return ret;
  }
drivers/net/ethernet/stmicro/stmmac/hwif.h +1 -1
index 7be04b54738b..b0db38396171 100644
@@ -198,7 +198,7 @@ struct stmmac_dma_ops {
  	/* To track extra statistic (if supported) */
  	void (*dma_diagnostic_fr)(struct stmmac_extra_stats *x,
  				  void __iomem *ioaddr);
-	void (*enable_dma_transmission) (void __iomem *ioaddr);
+	void (*enable_dma_transmission)(void __iomem *ioaddr, u32 chan);
  	void (*enable_dma_irq)(struct stmmac_priv *priv, void __iomem *ioaddr,
  			       u32 chan, bool rx, bool tx);
  	void (*disable_dma_irq)(struct stmmac_priv *priv, void __iomem *ioaddr,
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +3 -3
index b334eb16da23..5617b40abbe4 100644
@@ -2558,7 +2558,7 @@ static bool stmmac_xdp_xmit_zc(struct stmmac_priv *priv, u32 queue, u32 budget)
  				       true, priv->mode, true, true,
  				       xdp_desc.len);
-		stmmac_enable_dma_transmission(priv, priv->ioaddr);
+		stmmac_enable_dma_transmission(priv, priv->ioaddr, queue);
  		xsk_tx_metadata_to_compl(meta,
  					 &tx_q->tx_skbuff_dma[entry].xsk_meta);
@@ -4706,7 +4706,7 @@ static netdev_tx_t stmmac_xmit(struct sk_buff *skb, struct net_device *dev)
  	netdev_tx_sent_queue(netdev_get_tx_queue(dev, queue), skb->len);
-	stmmac_enable_dma_transmission(priv, priv->ioaddr);
+	stmmac_enable_dma_transmission(priv, priv->ioaddr, queue);
  	stmmac_flush_tx_descriptors(priv, queue);
  	stmmac_tx_timer_arm(priv, queue);
@@ -4926,7 +4926,7 @@ static int stmmac_xdp_xmit_xdpf(struct stmmac_priv *priv, int queue,
  		u64_stats_update_end_irqrestore(&txq_stats->syncp, flags);
  	}
-	stmmac_enable_dma_transmission(priv, priv->ioaddr);
+	stmmac_enable_dma_transmission(priv, priv->ioaddr, queue);
  	entry = STMMAC_GET_ENTRY(entry, priv->dma_conf.dma_tx_size);
  	tx_q->cur_tx = entry;
Signature · 1 line
2.31.4
author
#7 lore raw

Re: [PATCH net-next v8 01/11] net: stmmac: Add multi-channel support

In reply to Serge Semin

Hi Serge

Quoted 74 lines · Serge Semin
Quoted 38 lines · Yanteng Si

DW GMAC v3.x multi-channels feature is implemented as multiple sets of the same CSRs. Here is only preliminary support, it will be useful for the driver further evolution and for the users having multi-channel DWGMAC v3.x devices.

---
  .../net/ethernet/stmicro/stmmac/dwmac-sun8i.c |  2 +-
  .../ethernet/stmicro/stmmac/dwmac1000_dma.c   | 36 ++++++++++---------
  .../net/ethernet/stmicro/stmmac/dwmac_dma.h   | 19 +++++++++-
  .../net/ethernet/stmicro/stmmac/dwmac_lib.c   | 32 ++++++++---------
  drivers/net/ethernet/stmicro/stmmac/hwif.h    |  2 +-
  .../net/ethernet/stmicro/stmmac/stmmac_main.c |  6 ++--
  6 files changed, 58 insertions(+), 39 deletions(-)
drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c +1 -1
index 137741b94122..7cdfa0bdb93a 100644
@@ -395,7 +395,7 @@ static void sun8i_dwmac_dma_start_tx(struct stmmac_priv *priv,
  	writel(v, ioaddr + EMAC_TX_CTL1);
  }
 
-static void sun8i_dwmac_enable_dma_transmission(void __iomem *ioaddr)
+static void sun8i_dwmac_enable_dma_transmission(void __iomem *ioaddr, u32 chan)
  {
  	u32 v;
 
drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c +0 -0
index daf79cdbd3ec..5f7b82ad3ec2 100644
@@ -70,15 +70,18 @@ static void dwmac1000_dma_axi(void __iomem *ioaddr, struct stmmac_axi *axi)
  	writel(value, ioaddr + DMA_AXI_BUS_MODE);
  }
 

drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c static void dwmac1000_dma_axi(void __iomem *ioaddr, struct stmmac_axi *axi) · line 79

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c +4 -3
-static void dwmac1000_dma_init(void __iomem *ioaddr,
-			       struct stmmac_dma_cfg *dma_cfg, int atds)
+static void dwmac1000_dma_init_channel(struct stmmac_priv *priv,
+				       void __iomem *ioaddr,
+				       struct stmmac_dma_cfg *dma_cfg, u32 chan)
  {
-	u32 value = readl(ioaddr + DMA_BUS_MODE);
+	u32 value;
  	int txpbl = dma_cfg->txpbl ?: dma_cfg->pbl;
  	int rxpbl = dma_cfg->rxpbl ?: dma_cfg->pbl;

Reverse xmas tree please.

drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c static void dwmac1000_dma_axi(void __iomem *ioaddr, struct stmmac_axi *axi) · line 80

Quoted 4 lines
drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c +1 -2
-	/*
-	 * Set the DMA PBL (Programmable Burst Length) mode.
+	/* common channel control register config */

Redundant comment. Please drop.

drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c static void dwmac1000_dma_init(void __iomem *ioaddr, · line 104

Quoted 13 lines
drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c +4 -2
+	value = readl(ioaddr + DMA_CHAN_BUS_MODE(chan));
+
+	/* Set the DMA PBL (Programmable Burst Length) mode.
  	 *
  	 * Note: before stmmac core 3.50 this mode bit was 4xPBL, and
  	 * post 3.5 mode bit acts as 8*PBL.
@@ -98,16 +101,15 @@ static void dwmac1000_dma_init(void __iomem *ioaddr,
  	if (dma_cfg->mixed_burst)
  		value |= DMA_BUS_MODE_MB;
 
-	if (atds)
-		value |= DMA_BUS_MODE_ATDS;
+	value |= DMA_BUS_MODE_ATDS;

No, just convert the stmmac_dma_ops.dma_init_channel() to accepting the atds flag as I suggested in v7:
https://lore.kernel.org/netdev/vxcfrxtbfu4pya56m22icnizsyjzqqha5blzb7zpexqcur56uh@uv6vsjf77npa/

Quoted 4 lines

In order to simplify this patch you can provide the stmmac_dma_ops.dma_init_channel() and stmmac_dma_ops.enable_dma_transmission() prototype updates in a pre-requisite/preparation patch.

Sorry to keep you waiting for so long, I finally got the machine again. Regarding atds, is this how it is implemented?

On the basis of applying PATCH v8:

drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c +0 -0
index 0323f0a5049c..ce99f4a1b320 100644
@@ -72,7 +72,8 @@ static void dwmac1000_dma_axi(void __iomem *ioaddr, struct stmmac_axi *axi)
 

 static void dwmac1000_dma_init_channel(struct stmmac_priv *priv,
                        void __iomem *ioaddr,
-                       struct stmmac_dma_cfg *dma_cfg, u32 chan)
+                       struct stmmac_dma_cfg *dma_cfg,
+                       int atds, u32 chan)
 {
     u32 value;
     int txpbl = dma_cfg->txpbl ?: dma_cfg->pbl;
@@ -101,7 +102,8 @@ static void dwmac1000_dma_init_channel(struct stmmac_priv *priv, if (dma_cfg->mixed_burst)
         value |= DMA_BUS_MODE_MB;

-    value |= DMA_BUS_MODE_ATDS;
+    if (atds)
+        value |= DMA_BUS_MODE_ATDS;

     if (dma_cfg->aal)
         value |= DMA_BUS_MODE_AAL;

drivers/net/ethernet/stmicro/stmmac/dwmac4_dma.c +0 -0
index 84d3a8551b03..8a79c154b553 100644
@@ -117,7 +117,8 @@ static void dwmac4_dma_init_tx_chan(struct stmmac_priv *priv,
 

 static void dwmac4_dma_init_channel(struct stmmac_priv *priv,
                     void __iomem *ioaddr,
-                    struct stmmac_dma_cfg *dma_cfg, u32 chan)
+                    struct stmmac_dma_cfg *dma_cfg,
+                                    int atds, u32 chan)
 {
     const struct dwmac4_addrs *dwmac4_addrs = priv->plat->dwmac4_addrs; u32 value;
@@ -135,7 +136,8 @@ static void dwmac4_dma_init_channel(struct stmmac_priv *priv,

 static void dwmac410_dma_init_channel(struct stmmac_priv *priv, void __iomem *ioaddr,
-                      struct stmmac_dma_cfg *dma_cfg, u32 chan) +                      struct stmmac_dma_cfg *dma_cfg,
+                                      int atds, u32 chan)
 {
     const struct dwmac4_addrs *dwmac4_addrs = priv->plat->dwmac4_addrs; u32 value;

drivers/net/ethernet/stmicro/stmmac/dwxgmac2_dma.c +0 -0
index dd2ab6185c40..d1627b2e50c8 100644
@@ -35,7 +35,8 @@ static void dwxgmac2_dma_init(void __iomem *ioaddr,
 

 static void dwxgmac2_dma_init_chan(struct stmmac_priv *priv, void __iomem *ioaddr,
-                   struct stmmac_dma_cfg *dma_cfg, u32 chan) +                   struct stmmac_dma_cfg *dma_cfg, +                                   int atds, u32 chan) {
     u32 value = readl(ioaddr + XGMAC_DMA_CH_CONTROL(chan));

drivers/net/ethernet/stmicro/stmmac/hwif.h +0 -0
index b0db38396171..fb27ad0e97e8 100644
@@ -178,7 +178,7 @@ struct stmmac_dma_ops {

     void (*init)(void __iomem *ioaddr, struct stmmac_dma_cfg *dma_cfg, int atds);
     void (*init_chan)(struct stmmac_priv *priv, void __iomem *ioaddr, -              struct stmmac_dma_cfg *dma_cfg, u32 chan);
+              struct stmmac_dma_cfg *dma_cfg, int atds, u32 chan); void (*init_rx_chan)(struct stmmac_priv *priv, void __iomem *ioaddr, struct stmmac_dma_cfg *dma_cfg,
                  dma_addr_t phy, u32 chan);

drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +0 -0
index 3eed202d1f1c..8705e04913d1 100644
@@ -3039,7 +3039,7 @@ static int stmmac_init_dma_engine(struct stmmac_priv *priv)
 

     /* DMA CSR Channel configuration */
     for (chan = 0; chan < dma_csr_ch; chan++) {
-        stmmac_init_chan(priv, priv->ioaddr, priv->plat->dma_cfg, chan); +        stmmac_init_chan(priv, priv->ioaddr, priv->plat->dma_cfg, atds, chan); stmmac_disable_dma_irq(priv, priv->ioaddr, chan, 1, 1);
     }

@@ -6963,6 +6963,7 @@ int stmmac_xdp_open(struct net_device *dev) u32 buf_size;
     bool sph_en;
     u32 chan;
+     int atds;
     int ret;

     ret = alloc_dma_desc_resources(priv, &priv->dma_conf); @@ -6981,9 +6982,12 @@ int stmmac_xdp_open(struct net_device *dev)

     stmmac_reset_queues_param(priv);

+    if (priv->extend_desc && (priv->mode == STMMAC_RING_MODE))
+        atds = 1;
+
     /* DMA CSR Channel configuration */
     for (chan = 0; chan < dma_csr_ch; chan++) {
-        stmmac_init_chan(priv, priv->ioaddr, priv->plat->dma_cfg, chan); +        stmmac_init_chan(priv, priv->ioaddr, priv->plat->dma_cfg, atds, chan); stmmac_disable_dma_irq(priv, priv->ioaddr, chan, 1, 1);
     }

Thanks,

Yanteng

Quoted 290 lines
Quoted 87 lines
drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c +10 -10
  	if (dma_cfg->aal)
  		value |= DMA_BUS_MODE_AAL;
 
-	writel(value, ioaddr + DMA_BUS_MODE);
+	writel(value, ioaddr + DMA_CHAN_BUS_MODE(chan));
 
  	/* Mask interrupts by writing to CSR7 */
-	writel(DMA_INTR_DEFAULT_MASK, ioaddr + DMA_INTR_ENA);
+	writel(DMA_INTR_DEFAULT_MASK, ioaddr + DMA_CHAN_INTR_ENA(chan));
  }
 
  static void dwmac1000_dma_init_rx(struct stmmac_priv *priv,
@@ -116,7 +118,7 @@ static void dwmac1000_dma_init_rx(struct stmmac_priv *priv,
  				  dma_addr_t dma_rx_phy, u32 chan)
  {
  	/* RX descriptor base address list must be written into DMA CSR3 */
-	writel(lower_32_bits(dma_rx_phy), ioaddr + DMA_RCV_BASE_ADDR);
+	writel(lower_32_bits(dma_rx_phy), ioaddr + DMA_CHAN_RCV_BASE_ADDR(chan));
  }
 
  static void dwmac1000_dma_init_tx(struct stmmac_priv *priv,
@@ -125,7 +127,7 @@ static void dwmac1000_dma_init_tx(struct stmmac_priv *priv,
  				  dma_addr_t dma_tx_phy, u32 chan)
  {
  	/* TX descriptor base address list must be written into DMA CSR4 */
-	writel(lower_32_bits(dma_tx_phy), ioaddr + DMA_TX_BASE_ADDR);
+	writel(lower_32_bits(dma_tx_phy), ioaddr + DMA_CHAN_TX_BASE_ADDR(chan));
  }
 
  static u32 dwmac1000_configure_fc(u32 csr6, int rxfifosz)
@@ -153,7 +155,7 @@ static void dwmac1000_dma_operation_mode_rx(struct stmmac_priv *priv,
  					    void __iomem *ioaddr, int mode,
  					    u32 channel, int fifosz, u8 qmode)
  {
-	u32 csr6 = readl(ioaddr + DMA_CONTROL);
+	u32 csr6 = readl(ioaddr + DMA_CHAN_CONTROL(channel));
 
  	if (mode == SF_DMA_MODE) {
  		pr_debug("GMAC: enable RX store and forward mode\n");
@@ -175,14 +177,14 @@ static void dwmac1000_dma_operation_mode_rx(struct stmmac_priv *priv,
  	/* Configure flow control based on rx fifo size */
  	csr6 = dwmac1000_configure_fc(csr6, fifosz);
 
-	writel(csr6, ioaddr + DMA_CONTROL);
+	writel(csr6, ioaddr + DMA_CHAN_CONTROL(channel));
  }
 
  static void dwmac1000_dma_operation_mode_tx(struct stmmac_priv *priv,
  					    void __iomem *ioaddr, int mode,
  					    u32 channel, int fifosz, u8 qmode)
  {
-	u32 csr6 = readl(ioaddr + DMA_CONTROL);
+	u32 csr6 = readl(ioaddr + DMA_CHAN_CONTROL(channel));
 
  	if (mode == SF_DMA_MODE) {
  		pr_debug("GMAC: enable TX store and forward mode\n");
@@ -209,7 +211,7 @@ static void dwmac1000_dma_operation_mode_tx(struct stmmac_priv *priv,
  			csr6 |= DMA_CONTROL_TTC_256;
  	}
 
-	writel(csr6, ioaddr + DMA_CONTROL);
+	writel(csr6, ioaddr + DMA_CHAN_CONTROL(channel));
  }
 
  static void dwmac1000_dump_dma_regs(struct stmmac_priv *priv,
@@ -271,12 +273,12 @@ static int dwmac1000_get_hw_feature(void __iomem *ioaddr,
  static void dwmac1000_rx_watchdog(struct stmmac_priv *priv,
  				  void __iomem *ioaddr, u32 riwt, u32 queue)
  {
-	writel(riwt, ioaddr + DMA_RX_WATCHDOG);
+	writel(riwt, ioaddr + DMA_CHAN_RX_WATCHDOG(queue));
  }
 
  const struct stmmac_dma_ops dwmac1000_dma_ops = {
  	.reset = dwmac_dma_reset,
-	.init = dwmac1000_dma_init,
+	.init_chan = dwmac1000_dma_init_channel,
  	.init_rx_chan = dwmac1000_dma_init_rx,
  	.init_tx_chan = dwmac1000_dma_init_tx,
  	.axi = dwmac1000_dma_axi,
drivers/net/ethernet/stmicro/stmmac/dwmac_dma.h +0 -0
index 72672391675f..593be79c46e1 100644

drivers/net/ethernet/stmicro/stmmac/dwmac_dma.h line 153

Quoted 6 lines
drivers/net/ethernet/stmicro/stmmac/dwmac_dma.h +3 -0
@@ -148,11 +148,14 @@
  					 DMA_STATUS_TI | \
  					 DMA_STATUS_MSK_COMMON)
 
+/* Following DMA defines are chanels oriented */    \
+#define DMA_CHAN_OFFSET			0x100   |-------------+
+                                                    /              |
                                                                       |
Please move all of these ---------------------------------------------+-------------------------+
to being defined just below the DMA_MISSED_FRAME_CTR macros definition.                         |
The point is to keep a coherency between dwmac_dma.h and dwmac4_dma.h.                          |
The later header file has first generic DMA-related macros defined                              |
(CSR addresses and flags) and then the channel-specific ones (CSR                               |
addresses and flags). Since in case of the DW GMAC v3.x the                                     |
multi-channels are implemented as a copy of all the DMA CSRs let's                              |
preserve the logic of having all CSR address defined first, then the                            |
CSR flags.                                                                                      |
                                                                                                 |

drivers/net/ethernet/stmicro/stmmac/dwmac_dma.h int dwmac_dma_interrupt(struct stmmac_priv *priv, void __iomem *ioaddr, | · line 174

Quoted 13 lines
drivers/net/ethernet/stmicro/stmmac/dwmac_dma.h +1 -1
  #define NUM_DWMAC100_DMA_REGS	9                                                       |
  #define NUM_DWMAC1000_DMA_REGS	23                                                      |
  #define NUM_DWMAC4_DMA_REGS	27                                                              |
                                                                                               |
-void dwmac_enable_dma_transmission(void __iomem *ioaddr);                                    |
+void dwmac_enable_dma_transmission(void __iomem *ioaddr, u32 chan);                          |
  void dwmac_enable_dma_irq(struct stmmac_priv *priv, void __iomem *ioaddr,                    |
  			  u32 chan, bool rx, bool tx);                                          |
  void dwmac_disable_dma_irq(struct stmmac_priv *priv, void __iomem *ioaddr,                   |
@@ -169,4 +172,18 @@ int dwmac_dma_interrupt(struct stmmac_priv *priv, void __iomem *ioaddr,  |
  			struct stmmac_extra_stats *x, u32 chan, u32 dir);                       |
  int dwmac_dma_reset(void __iomem *ioaddr);                                                   |
                                                                                               |
                                                                                                 |
Quoted 109 lines
drivers/net/ethernet/stmicro/stmmac/dwmac_dma.h +14 -0
+static inline u32 dma_chan_base_addr(u32 base, u32 chan)                                  \  |
+{                                                                                          | |
+	return base + chan * DMA_CHAN_OFFSET;                                                 | |
+}                                                                                          | |
+                                                                                           | |
+#define DMA_CHAN_XMT_POLL_DEMAND(chan)	dma_chan_base_addr(DMA_XMT_POLL_DEMAND, chan) | |
+#define DMA_CHAN_INTR_ENA(chan)		dma_chan_base_addr(DMA_INTR_ENA, chan)        | |
+#define DMA_CHAN_CONTROL(chan)		dma_chan_base_addr(DMA_CONTROL, chan)         | |
+#define DMA_CHAN_STATUS(chan)		dma_chan_base_addr(DMA_STATUS, chan)          |-+
+#define DMA_CHAN_BUS_MODE(chan)		dma_chan_base_addr(DMA_BUS_MODE, chan)        |
+#define DMA_CHAN_RCV_BASE_ADDR(chan)	dma_chan_base_addr(DMA_RCV_BASE_ADDR, chan)           |
+#define DMA_CHAN_TX_BASE_ADDR(chan)	dma_chan_base_addr(DMA_TX_BASE_ADDR, chan)            |
+#define DMA_CHAN_RX_WATCHDOG(chan)	dma_chan_base_addr(DMA_RX_WATCHDOG, chan)             |
+                                                                                           /
  #endif /* __DWMAC_DMA_H__ */
drivers/net/ethernet/stmicro/stmmac/dwmac_lib.c +15 -15
index 7907d62d3437..b37368137810 100644
@@ -28,65 +28,65 @@ int dwmac_dma_reset(void __iomem *ioaddr)
  }
 
  /* CSR1 enables the transmit DMA to check for new descriptor */
-void dwmac_enable_dma_transmission(void __iomem *ioaddr)
+void dwmac_enable_dma_transmission(void __iomem *ioaddr, u32 chan)
  {
-	writel(1, ioaddr + DMA_XMT_POLL_DEMAND);
+	writel(1, ioaddr + DMA_CHAN_XMT_POLL_DEMAND(chan));
  }
 
  void dwmac_enable_dma_irq(struct stmmac_priv *priv, void __iomem *ioaddr,
  			  u32 chan, bool rx, bool tx)
  {
-	u32 value = readl(ioaddr + DMA_INTR_ENA);
+	u32 value = readl(ioaddr + DMA_CHAN_INTR_ENA(chan));
 
  	if (rx)
  		value |= DMA_INTR_DEFAULT_RX;
  	if (tx)
  		value |= DMA_INTR_DEFAULT_TX;
 
-	writel(value, ioaddr + DMA_INTR_ENA);
+	writel(value, ioaddr + DMA_CHAN_INTR_ENA(chan));
  }
 
  void dwmac_disable_dma_irq(struct stmmac_priv *priv, void __iomem *ioaddr,
  			   u32 chan, bool rx, bool tx)
  {
-	u32 value = readl(ioaddr + DMA_INTR_ENA);
+	u32 value = readl(ioaddr + DMA_CHAN_INTR_ENA(chan));
 
  	if (rx)
  		value &= ~DMA_INTR_DEFAULT_RX;
  	if (tx)
  		value &= ~DMA_INTR_DEFAULT_TX;
 
-	writel(value, ioaddr + DMA_INTR_ENA);
+	writel(value, ioaddr + DMA_CHAN_INTR_ENA(chan));
  }
 
  void dwmac_dma_start_tx(struct stmmac_priv *priv, void __iomem *ioaddr,
  			u32 chan)
  {
-	u32 value = readl(ioaddr + DMA_CONTROL);
+	u32 value = readl(ioaddr + DMA_CHAN_CONTROL(chan));
  	value |= DMA_CONTROL_ST;
-	writel(value, ioaddr + DMA_CONTROL);
+	writel(value, ioaddr + DMA_CHAN_CONTROL(chan));
  }
 
  void dwmac_dma_stop_tx(struct stmmac_priv *priv, void __iomem *ioaddr, u32 chan)
  {
-	u32 value = readl(ioaddr + DMA_CONTROL);
+	u32 value = readl(ioaddr + DMA_CHAN_CONTROL(chan));
  	value &= ~DMA_CONTROL_ST;
-	writel(value, ioaddr + DMA_CONTROL);
+	writel(value, ioaddr + DMA_CHAN_CONTROL(chan));
  }
 
  void dwmac_dma_start_rx(struct stmmac_priv *priv, void __iomem *ioaddr,
  			u32 chan)
  {
-	u32 value = readl(ioaddr + DMA_CONTROL);
+	u32 value = readl(ioaddr + DMA_CHAN_CONTROL(chan));
  	value |= DMA_CONTROL_SR;
-	writel(value, ioaddr + DMA_CONTROL);
+	writel(value, ioaddr + DMA_CHAN_CONTROL(chan));
  }
 
  void dwmac_dma_stop_rx(struct stmmac_priv *priv, void __iomem *ioaddr, u32 chan)
  {
-	u32 value = readl(ioaddr + DMA_CONTROL);
+	u32 value = readl(ioaddr + DMA_CHAN_CONTROL(chan));
  	value &= ~DMA_CONTROL_SR;
-	writel(value, ioaddr + DMA_CONTROL);
+	writel(value, ioaddr + DMA_CHAN_CONTROL(chan));
  }
 
  #ifdef DWMAC_DMA_DEBUG
@@ -166,7 +166,7 @@ int dwmac_dma_interrupt(struct stmmac_priv *priv, void __iomem *ioaddr,
  	struct stmmac_txq_stats *txq_stats = &priv->xstats.txq_stats[chan];
  	int ret = 0;
  	/* read the status register (CSR5) */
-	u32 intr_status = readl(ioaddr + DMA_STATUS);
+	u32 intr_status = readl(ioaddr + DMA_CHAN_STATUS(chan));
 
  #ifdef DWMAC_DMA_DEBUG
  	/* Enable it to monitor DMA rx/tx status in case of critical problems */

drivers/net/ethernet/stmicro/stmmac/dwmac_lib.c int dwmac_dma_interrupt(struct stmmac_priv *priv, void __iomem *ioaddr, · line 239

Quoted 5 lines
drivers/net/ethernet/stmicro/stmmac/dwmac_lib.c +1 -1
@@ -236,7 +236,7 @@ int dwmac_dma_interrupt(struct stmmac_priv *priv, void __iomem *ioaddr,
  		pr_warn("%s: unexpected status %08x\n", __func__, intr_status);
 
  	/* Clear the interrupt by writing a logic 1 to the CSR5[15-0] */
-	writel((intr_status & 0x1ffff), ioaddr + DMA_STATUS);
+	writel((intr_status & 0x7ffff), ioaddr + DMA_CHAN_STATUS(chan));

Isn't the mask change going to be implemented in the framework of the Loongson-specific DMA-interrupt handler in some of the further patches?

I'll get back to reviewing the series tomorrow (later today)...

-Serge(y)

Quoted 50 lines
drivers/net/ethernet/stmicro/stmmac/dwmac_lib.c +0 -0
  	return ret;
  }
drivers/net/ethernet/stmicro/stmmac/hwif.h +1 -1
index 7be04b54738b..b0db38396171 100644
@@ -198,7 +198,7 @@ struct stmmac_dma_ops {
  	/* To track extra statistic (if supported) */
  	void (*dma_diagnostic_fr)(struct stmmac_extra_stats *x,
  				  void __iomem *ioaddr);
-	void (*enable_dma_transmission) (void __iomem *ioaddr);
+	void (*enable_dma_transmission)(void __iomem *ioaddr, u32 chan);
  	void (*enable_dma_irq)(struct stmmac_priv *priv, void __iomem *ioaddr,
  			       u32 chan, bool rx, bool tx);
  	void (*disable_dma_irq)(struct stmmac_priv *priv, void __iomem *ioaddr,
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +3 -3
index b334eb16da23..5617b40abbe4 100644
@@ -2558,7 +2558,7 @@ static bool stmmac_xdp_xmit_zc(struct stmmac_priv *priv, u32 queue, u32 budget)
  				       true, priv->mode, true, true,
  				       xdp_desc.len);
 
-		stmmac_enable_dma_transmission(priv, priv->ioaddr);
+		stmmac_enable_dma_transmission(priv, priv->ioaddr, queue);
 
  		xsk_tx_metadata_to_compl(meta,
  					 &tx_q->tx_skbuff_dma[entry].xsk_meta);
@@ -4706,7 +4706,7 @@ static netdev_tx_t stmmac_xmit(struct sk_buff *skb, struct net_device *dev)
 
  	netdev_tx_sent_queue(netdev_get_tx_queue(dev, queue), skb->len);
 
-	stmmac_enable_dma_transmission(priv, priv->ioaddr);
+	stmmac_enable_dma_transmission(priv, priv->ioaddr, queue);
 
  	stmmac_flush_tx_descriptors(priv, queue);
  	stmmac_tx_timer_arm(priv, queue);
@@ -4926,7 +4926,7 @@ static int stmmac_xdp_xmit_xdpf(struct stmmac_priv *priv, int queue,
  		u64_stats_update_end_irqrestore(&txq_stats->syncp, flags);
  	}
 
-	stmmac_enable_dma_transmission(priv, priv->ioaddr);
+	stmmac_enable_dma_transmission(priv, priv->ioaddr, queue);
 
  	entry = STMMAC_GET_ENTRY(entry, priv->dma_conf.dma_tx_size);
  	tx_q->cur_tx = entry;
Signature · 1 line
2.31.4
author
#23 lore raw

Re: [PATCH net-next v8 03/11] net: stmmac: dwmac-loongson: Add full PCI support

In reply to Serge Semin
Quoted 8 lines · Serge Semin
Quoted 3 lines · Yanteng Si

Current dwmac-loongson only support LS2K in the "probed with PCI and configured with DT" manner. Add LS7A support on which the devices are fully PCI (non-DT).

Please add to the commit log more details of what LS7A is like and bind that description to the changes below like the interface settings, ref and PTP clock settings, etc. What is the difference between LS2K and LS7A?

OK,

Quoted 29 lines
Quoted 29 lines
---
  .../ethernet/stmicro/stmmac/dwmac-loongson.c  | 79 +++++++++++--------
  1 file changed, 44 insertions(+), 35 deletions(-)
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +5 -0
index e2dcb339b8b0..979c9b6dab3f 100644
@@ -16,6 +16,10 @@ struct stmmac_pci_info {
  static void loongson_default_data(struct pci_dev *pdev,
  				  struct plat_stmmacenet_data *plat)
  {
+	/* Get bus_id, this can be overloaded later */
+	plat->bus_id = (pci_domain_nr(pdev->bus) << 16) |
+		       PCI_DEVID(pdev->bus->number, pdev->devfn);
+
  	plat->clk_csr = 2;	/* clk_csr_i = 20-35MHz & MDC = clk_csr_i/16 */
  	plat->has_gmac = 1;
  	plat->force_sf_dma_mode = 1;
@@ -51,10 +55,14 @@ static int loongson_gmac_data(struct pci_dev *pdev,
  	plat->mdio_bus_data->phy_mask = 0;
 
  	plat->phy_addr = -1;
+	plat->phy_interface = PHY_INTERFACE_MODE_RGMII_ID;
 
Quoted 7 lines

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int loongson_gmac_data(struct pci_dev *pdev, · line 65

Quoted 6 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +3 -0
  	plat->dma_cfg->pbl = 32;
  	plat->dma_cfg->pblx8 = true;
 
+	plat->clk_ref_rate = 125000000;
+	plat->clk_ptp_rate = 125000000;
+

Is this compatible with the LS2K GMAC?

Of course!

Quoted 22 lines
Quoted 22 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +0 -7
  	return 0;
  }
 
@@ -71,13 +79,6 @@ static int loongson_dwmac_probe(struct pci_dev *pdev,
  	struct stmmac_resources res;
  	struct device_node *np;
 
-	np = dev_of_node(&pdev->dev);
-
-	if (!np) {
-		pr_info("dwmac_loongson_pci: No OF node\n");
-		return -ENODEV;
-	}
-
  	plat = devm_kzalloc(&pdev->dev, sizeof(*plat), GFP_KERNEL);
  	if (!plat)
  		return -ENOMEM;
@@ -93,6 +94,7 @@ static int loongson_dwmac_probe(struct pci_dev *pdev,
  	if (!plat->dma_cfg)
  		return -ENOMEM;
 
Quoted 5 lines

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int loongson_dwmac_probe(struct pci_dev *pdev, · line 100

Quoted 4 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +1 -0
+	np = dev_of_node(&pdev->dev);
  	plat->mdio_node = of_get_child_by_name(np, "mdio");
  	if (plat->mdio_node) {
  		dev_info(&pdev->dev, "Found MDIO subnode\n");

Shouldn't mdio_node setup being done under the "if (np)" clause?

Yes, they will be moved there.

Quoted 13 lines
Quoted 13 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +4 -3
@@ -123,41 +125,48 @@ static int loongson_dwmac_probe(struct pci_dev *pdev,
  	if (ret)
  		goto err_disable_device;
 
-	bus_id = of_alias_get_id(np, "ethernet");
-	if (bus_id >= 0)
-		plat->bus_id = bus_id;
+	if (np) {
+		bus_id = of_alias_get_id(np, "ethernet");
+		if (bus_id >= 0)
+			plat->bus_id = bus_id;
 
Quoted 15 lines

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int loongson_dwmac_probe(struct pci_dev *pdev, · line 140

Quoted 13 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +7 -5
-	phy_mode = device_get_phy_mode(&pdev->dev);
-	if (phy_mode < 0) {
-		dev_err(&pdev->dev, "phy_mode not found\n");
-		ret = phy_mode;
-		goto err_disable_device;
+		phy_mode = device_get_phy_mode(&pdev->dev);
+		if (phy_mode < 0) {
+			dev_err(&pdev->dev, "phy_mode not found\n");
+			ret = phy_mode;
+			goto err_disable_device;
+		}
+		plat->phy_interface = phy_mode;
  	}

Please collect all OF-specific code in the same "if (np)" clause if possible.

OK,

Quoted 45 lines
Quoted 45 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +19 -20
-	plat->phy_interface = phy_mode;	np = dev_of_node(&pdev->dev);
-
  	pci_enable_msi(pdev);
  	memset(&res, 0, sizeof(res));
  	res.addr = pcim_iomap_table(pdev)[0];
 
-	res.irq = of_irq_get_byname(np, "macirq");
-	if (res.irq < 0) {
-		dev_err(&pdev->dev, "IRQ macirq not found\n");
-		ret = -ENODEV;
-		goto err_disable_msi;
-	}
-
-	res.wol_irq = of_irq_get_byname(np, "eth_wake_irq");
-	if (res.wol_irq < 0) {
-		dev_info(&pdev->dev, "IRQ eth_wake_irq not found, using macirq\n");
-		res.wol_irq = res.irq;
-	}
-
-	res.lpi_irq = of_irq_get_byname(np, "eth_lpi");
-	if (res.lpi_irq < 0) {
-		dev_err(&pdev->dev, "IRQ eth_lpi not found\n");
-		ret = -ENODEV;
-		goto err_disable_msi;
+	if (np) {
+		res.irq = of_irq_get_byname(np, "macirq");
+		if (res.irq < 0) {
+			dev_err(&pdev->dev, "IRQ macirq not found\n");
+			ret = -ENODEV;
+			goto err_disable_msi;
+		}
+
+		res.wol_irq = of_irq_get_byname(np, "eth_wake_irq");
+		if (res.wol_irq < 0) {
+			dev_info(&pdev->dev,
+				 "IRQ eth_wake_irq not found, using macirq\n");
+			res.wol_irq = res.irq;
+		}
+
+		res.lpi_irq = of_irq_get_byname(np, "eth_lpi");
+		if (res.lpi_irq < 0) {
+			dev_err(&pdev->dev, "IRQ eth_lpi not found\n");
+			ret = -ENODEV;
Quoted 8 lines

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int loongson_dwmac_probe(struct pci_dev *pdev, · line 169

Quoted 5 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +5 -0
+			goto err_disable_msi;
+		}
+	} else {
+		res.irq = pdev->irq;
+		res.wol_irq = pdev->irq;

This seems redundant. If res.wol_irq matches res_irq it won't be used (see stmmac_request_irq_multi_msi() and stmmac_request_irq_single()). What about dropping it?

Okay, actually, it was removed by subsequent patches.

Thanks,

Yanteng

Quoted 9 lines

-Serge(y)

Quoted 6 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +0 -0
  	}
 
  	ret = stmmac_dvr_probe(&pdev->dev, plat, &res);
Signature · 1 line
2.31.4
#8 lore raw

Re: [PATCH net-next v8 01/11] net: stmmac: Add multi-channel support

In reply to Yanteng Si

Hi Yanteng

Quoted 193 lines · Yanteng Si

Hi Serge

Quoted 69 lines · Serge Semin
Quoted 35 lines · Yanteng Si

DW GMAC v3.x multi-channels feature is implemented as multiple sets of the same CSRs. Here is only preliminary support, it will be useful for the driver further evolution and for the users having multi-channel DWGMAC v3.x devices.

---
  .../net/ethernet/stmicro/stmmac/dwmac-sun8i.c |  2 +-
  .../ethernet/stmicro/stmmac/dwmac1000_dma.c   | 36 ++++++++++---------
  .../net/ethernet/stmicro/stmmac/dwmac_dma.h   | 19 +++++++++-
  .../net/ethernet/stmicro/stmmac/dwmac_lib.c   | 32 ++++++++---------
  drivers/net/ethernet/stmicro/stmmac/hwif.h    |  2 +-
  .../net/ethernet/stmicro/stmmac/stmmac_main.c |  6 ++--
  6 files changed, 58 insertions(+), 39 deletions(-)
drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c +1 -1
index 137741b94122..7cdfa0bdb93a 100644
@@ -395,7 +395,7 @@ static void sun8i_dwmac_dma_start_tx(struct stmmac_priv *priv,
  	writel(v, ioaddr + EMAC_TX_CTL1);
  }
-static void sun8i_dwmac_enable_dma_transmission(void __iomem *ioaddr)
+static void sun8i_dwmac_enable_dma_transmission(void __iomem *ioaddr, u32 chan)
  {
  	u32 v;
drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c +0 -0
index daf79cdbd3ec..5f7b82ad3ec2 100644
@@ -70,15 +70,18 @@ static void dwmac1000_dma_axi(void __iomem *ioaddr, struct stmmac_axi *axi)
  	writel(value, ioaddr + DMA_AXI_BUS_MODE);
  }

drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c static void dwmac1000_dma_axi(void __iomem *ioaddr, struct stmmac_axi *axi) · line 78

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c +4 -3
-static void dwmac1000_dma_init(void __iomem *ioaddr,
-			       struct stmmac_dma_cfg *dma_cfg, int atds)
+static void dwmac1000_dma_init_channel(struct stmmac_priv *priv,
+				       void __iomem *ioaddr,
+				       struct stmmac_dma_cfg *dma_cfg, u32 chan)
  {
-	u32 value = readl(ioaddr + DMA_BUS_MODE);
+	u32 value;
  	int txpbl = dma_cfg->txpbl ?: dma_cfg->pbl;
  	int rxpbl = dma_cfg->rxpbl ?: dma_cfg->pbl;

Reverse xmas tree please.

drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c static void dwmac1000_dma_axi(void __iomem *ioaddr, struct stmmac_axi *axi) · line 79

Quoted 3 lines
drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c +1 -2
-	/*
-	 * Set the DMA PBL (Programmable Burst Length) mode.
+	/* common channel control register config */

Redundant comment. Please drop.

drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c static void dwmac1000_dma_init(void __iomem *ioaddr, · line 103

Quoted 12 lines
drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c +4 -2
+	value = readl(ioaddr + DMA_CHAN_BUS_MODE(chan));
+
+	/* Set the DMA PBL (Programmable Burst Length) mode.
  	 *
  	 * Note: before stmmac core 3.50 this mode bit was 4xPBL, and
  	 * post 3.5 mode bit acts as 8*PBL.
@@ -98,16 +101,15 @@ static void dwmac1000_dma_init(void __iomem *ioaddr,
  	if (dma_cfg->mixed_burst)
  		value |= DMA_BUS_MODE_MB;
-	if (atds)
-		value |= DMA_BUS_MODE_ATDS;
+	value |= DMA_BUS_MODE_ATDS;

No, just convert the stmmac_dma_ops.dma_init_channel() to accepting the atds flag as I suggested in v7:
https://lore.kernel.org/netdev/vxcfrxtbfu4pya56m22icnizsyjzqqha5blzb7zpexqcur56uh@uv6vsjf77npa/

Quoted 4 lines

In order to simplify this patch you can provide the stmmac_dma_ops.dma_init_channel() and stmmac_dma_ops.enable_dma_transmission() prototype updates in a pre-requisite/preparation patch.

Sorry to keep you waiting for so long, I finally got the machine again. Regarding atds, is this how it is implemented?

On the basis of applying PATCH v8:

drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c +2 -1
index 0323f0a5049c..ce99f4a1b320 100644
@@ -72,7 +72,8 @@ static void dwmac1000_dma_axi(void __iomem *ioaddr, struct
 stmmac_axi *axi)
 
  static void dwmac1000_dma_init_channel(struct stmmac_priv *priv,
                         void __iomem *ioaddr,
-                       struct stmmac_dma_cfg *dma_cfg, u32 chan)
+                       struct stmmac_dma_cfg *dma_cfg,
+                       int atds, u32 chan)
  {
      u32 value;

     int txpbl = dma_cfg->txpbl ?: dma_cfg->pbl;

drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c +2 -1
@@ -101,7 +102,8 @@ static void dwmac1000_dma_init_channel(struct
 stmmac_priv *priv,
      if (dma_cfg->mixed_burst)
          value |= DMA_BUS_MODE_MB;
 
-    value |= DMA_BUS_MODE_ATDS;
+    if (atds)
+        value |= DMA_BUS_MODE_ATDS;
 
      if (dma_cfg->aal)

         value |= DMA_BUS_MODE_AAL;

drivers/net/ethernet/stmicro/stmmac/dwmac4_dma.c +2 -1
index 84d3a8551b03..8a79c154b553 100644
@@ -117,7 +117,8 @@ static void dwmac4_dma_init_tx_chan(struct stmmac_priv
 *priv,
 
  static void dwmac4_dma_init_channel(struct stmmac_priv *priv,
                      void __iomem *ioaddr,
-                    struct stmmac_dma_cfg *dma_cfg, u32 chan)
+                    struct stmmac_dma_cfg *dma_cfg,
+                                    int atds, u32 chan)
  {
      const struct dwmac4_addrs *dwmac4_addrs = priv->plat->dwmac4_addrs;

     u32 value;

drivers/net/ethernet/stmicro/stmmac/dwmac4_dma.c +2 -1
@@ -135,7 +136,8 @@ static void dwmac4_dma_init_channel(struct stmmac_priv
 *priv,
 
  static void dwmac410_dma_init_channel(struct stmmac_priv *priv,
                        void __iomem *ioaddr,
-                      struct stmmac_dma_cfg *dma_cfg, u32 chan)
+                      struct stmmac_dma_cfg *dma_cfg,
+                                      int atds, u32 chan)
  {
      const struct dwmac4_addrs *dwmac4_addrs = priv->plat->dwmac4_addrs;

     u32 value;

drivers/net/ethernet/stmicro/stmmac/dwxgmac2_dma.c +2 -1
index dd2ab6185c40..d1627b2e50c8 100644
@@ -35,7 +35,8 @@ static void dwxgmac2_dma_init(void __iomem *ioaddr,
 
  static void dwxgmac2_dma_init_chan(struct stmmac_priv *priv,
                     void __iomem *ioaddr,
-                   struct stmmac_dma_cfg *dma_cfg, u32 chan)
+                   struct stmmac_dma_cfg *dma_cfg,
+                                   int atds, u32 chan)
  {
      u32 value = readl(ioaddr + XGMAC_DMA_CH_CONTROL(chan));
 
drivers/net/ethernet/stmicro/stmmac/hwif.h +1 -1
index b0db38396171..fb27ad0e97e8 100644
@@ -178,7 +178,7 @@ struct stmmac_dma_ops {
      void (*init)(void __iomem *ioaddr, struct stmmac_dma_cfg *dma_cfg,
               int atds);
      void (*init_chan)(struct stmmac_priv *priv, void __iomem *ioaddr,
-              struct stmmac_dma_cfg *dma_cfg, u32 chan);
+              struct stmmac_dma_cfg *dma_cfg, int atds, u32 chan);
      void (*init_rx_chan)(struct stmmac_priv *priv, void __iomem *ioaddr,
                   struct stmmac_dma_cfg *dma_cfg,
                   dma_addr_t phy, u32 chan);
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +1 -1
index 3eed202d1f1c..8705e04913d1 100644
@@ -3039,7 +3039,7 @@ static int stmmac_init_dma_engine(struct stmmac_priv
 *priv)
 
      /* DMA CSR Channel configuration */
      for (chan = 0; chan < dma_csr_ch; chan++) {
-        stmmac_init_chan(priv, priv->ioaddr, priv->plat->dma_cfg, chan);
+        stmmac_init_chan(priv, priv->ioaddr, priv->plat->dma_cfg, atds,
 chan);
          stmmac_disable_dma_irq(priv, priv->ioaddr, chan, 1, 1);

     }

drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +1 -0
@@ -6963,6 +6963,7 @@ int stmmac_xdp_open(struct net_device *dev)
      u32 buf_size;
      bool sph_en;
      u32 chan;
+     int atds;
      int ret;
 
      ret = alloc_dma_desc_resources(priv, &priv->dma_conf);
@@ -6981,9 +6982,12 @@ int stmmac_xdp_open(struct net_device *dev)
 
      stmmac_reset_queues_param(priv);
 

drivers/net/ethernet/stmicro/stmmac/stmmac_main.c int stmmac_xdp_open(struct net_device *dev) · line 6993

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +4 -1
+    if (priv->extend_desc && (priv->mode == STMMAC_RING_MODE))
+        atds = 1;
+
      /* DMA CSR Channel configuration */
      for (chan = 0; chan < dma_csr_ch; chan++) {
-        stmmac_init_chan(priv, priv->ioaddr, priv->plat->dma_cfg, chan);
+        stmmac_init_chan(priv, priv->ioaddr, priv->plat->dma_cfg, atds,
 chan);
          stmmac_disable_dma_irq(priv, priv->ioaddr, chan, 1, 1);
      }

Looking more thoroughly at this part I suggest to act a bit differently. Let's move the atds flag to the stmmac_dma_cfg structure. Alternate Descriptor Size (ATDS) is a part of the DMA-configs together with the PBL, ALL, AEME, etc so the structure is the most suitable place for it. Here is what should be done for that:
1. Add stmmac_dma_cfg::atds boolean field.
2. Drop atds argument from the stmmac_dma_ops::init() callback and use the stmmac_dma_cfg::atds field in the callback implementations.
3. Alter stmmac_init_dma_engine() to updating the dma_cfg->atds field instead of the local variable.

Please implement that update in a pre-requisite/preparation patch.

After that you can freely use the stmmac_dma_cfg::atds field in the stmmac_init_chan() method too.

-Serge(y)

Quoted 261 lines

Thanks,

Yanteng

Quoted 254 lines
Quoted 74 lines
drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c +10 -10
  	if (dma_cfg->aal)
  		value |= DMA_BUS_MODE_AAL;
-	writel(value, ioaddr + DMA_BUS_MODE);
+	writel(value, ioaddr + DMA_CHAN_BUS_MODE(chan));
  	/* Mask interrupts by writing to CSR7 */
-	writel(DMA_INTR_DEFAULT_MASK, ioaddr + DMA_INTR_ENA);
+	writel(DMA_INTR_DEFAULT_MASK, ioaddr + DMA_CHAN_INTR_ENA(chan));
  }
  static void dwmac1000_dma_init_rx(struct stmmac_priv *priv,
@@ -116,7 +118,7 @@ static void dwmac1000_dma_init_rx(struct stmmac_priv *priv,
  				  dma_addr_t dma_rx_phy, u32 chan)
  {
  	/* RX descriptor base address list must be written into DMA CSR3 */
-	writel(lower_32_bits(dma_rx_phy), ioaddr + DMA_RCV_BASE_ADDR);
+	writel(lower_32_bits(dma_rx_phy), ioaddr + DMA_CHAN_RCV_BASE_ADDR(chan));
  }
  static void dwmac1000_dma_init_tx(struct stmmac_priv *priv,
@@ -125,7 +127,7 @@ static void dwmac1000_dma_init_tx(struct stmmac_priv *priv,
  				  dma_addr_t dma_tx_phy, u32 chan)
  {
  	/* TX descriptor base address list must be written into DMA CSR4 */
-	writel(lower_32_bits(dma_tx_phy), ioaddr + DMA_TX_BASE_ADDR);
+	writel(lower_32_bits(dma_tx_phy), ioaddr + DMA_CHAN_TX_BASE_ADDR(chan));
  }
  static u32 dwmac1000_configure_fc(u32 csr6, int rxfifosz)
@@ -153,7 +155,7 @@ static void dwmac1000_dma_operation_mode_rx(struct stmmac_priv *priv,
  					    void __iomem *ioaddr, int mode,
  					    u32 channel, int fifosz, u8 qmode)
  {
-	u32 csr6 = readl(ioaddr + DMA_CONTROL);
+	u32 csr6 = readl(ioaddr + DMA_CHAN_CONTROL(channel));
  	if (mode == SF_DMA_MODE) {
  		pr_debug("GMAC: enable RX store and forward mode\n");
@@ -175,14 +177,14 @@ static void dwmac1000_dma_operation_mode_rx(struct stmmac_priv *priv,
  	/* Configure flow control based on rx fifo size */
  	csr6 = dwmac1000_configure_fc(csr6, fifosz);
-	writel(csr6, ioaddr + DMA_CONTROL);
+	writel(csr6, ioaddr + DMA_CHAN_CONTROL(channel));
  }
  static void dwmac1000_dma_operation_mode_tx(struct stmmac_priv *priv,
  					    void __iomem *ioaddr, int mode,
  					    u32 channel, int fifosz, u8 qmode)
  {
-	u32 csr6 = readl(ioaddr + DMA_CONTROL);
+	u32 csr6 = readl(ioaddr + DMA_CHAN_CONTROL(channel));
  	if (mode == SF_DMA_MODE) {
  		pr_debug("GMAC: enable TX store and forward mode\n");
@@ -209,7 +211,7 @@ static void dwmac1000_dma_operation_mode_tx(struct stmmac_priv *priv,
  			csr6 |= DMA_CONTROL_TTC_256;
  	}
-	writel(csr6, ioaddr + DMA_CONTROL);
+	writel(csr6, ioaddr + DMA_CHAN_CONTROL(channel));
  }
  static void dwmac1000_dump_dma_regs(struct stmmac_priv *priv,
@@ -271,12 +273,12 @@ static int dwmac1000_get_hw_feature(void __iomem *ioaddr,
  static void dwmac1000_rx_watchdog(struct stmmac_priv *priv,
  				  void __iomem *ioaddr, u32 riwt, u32 queue)
  {
-	writel(riwt, ioaddr + DMA_RX_WATCHDOG);
+	writel(riwt, ioaddr + DMA_CHAN_RX_WATCHDOG(queue));
  }
  const struct stmmac_dma_ops dwmac1000_dma_ops = {
  	.reset = dwmac_dma_reset,
-	.init = dwmac1000_dma_init,
+	.init_chan = dwmac1000_dma_init_channel,
  	.init_rx_chan = dwmac1000_dma_init_rx,
  	.init_tx_chan = dwmac1000_dma_init_tx,
  	.axi = dwmac1000_dma_axi,
drivers/net/ethernet/stmicro/stmmac/dwmac_dma.h +0 -0
index 72672391675f..593be79c46e1 100644

drivers/net/ethernet/stmicro/stmmac/dwmac_dma.h line 152

Quoted 5 lines
drivers/net/ethernet/stmicro/stmmac/dwmac_dma.h +3 -0
@@ -148,11 +148,14 @@
  					 DMA_STATUS_TI | \
  					 DMA_STATUS_MSK_COMMON)
+/* Following DMA defines are chanels oriented */    \
+#define DMA_CHAN_OFFSET			0x100   |-------------+
+                                                    /              |
                                                                       |
Please move all of these ---------------------------------------------+-------------------------+
to being defined just below the DMA_MISSED_FRAME_CTR macros definition.                         |
The point is to keep a coherency between dwmac_dma.h and dwmac4_dma.h.                          |
The later header file has first generic DMA-related macros defined                              |
(CSR addresses and flags) and then the channel-specific ones (CSR                               |
addresses and flags). Since in case of the DW GMAC v3.x the                                     |
multi-channels are implemented as a copy of all the DMA CSRs let's                              |
preserve the logic of having all CSR address defined first, then the                            |
CSR flags.                                                                                      |
                                                                                                 |

drivers/net/ethernet/stmicro/stmmac/dwmac_dma.h int dwmac_dma_interrupt(struct stmmac_priv *priv, void __iomem *ioaddr, | · line 174

Quoted 13 lines
drivers/net/ethernet/stmicro/stmmac/dwmac_dma.h +1 -1
  #define NUM_DWMAC100_DMA_REGS	9                                                       |
  #define NUM_DWMAC1000_DMA_REGS	23                                                      |
  #define NUM_DWMAC4_DMA_REGS	27                                                              |
                                                                                               |
-void dwmac_enable_dma_transmission(void __iomem *ioaddr);                                    |
+void dwmac_enable_dma_transmission(void __iomem *ioaddr, u32 chan);                          |
  void dwmac_enable_dma_irq(struct stmmac_priv *priv, void __iomem *ioaddr,                    |
  			  u32 chan, bool rx, bool tx);                                          |
  void dwmac_disable_dma_irq(struct stmmac_priv *priv, void __iomem *ioaddr,                   |
@@ -169,4 +172,18 @@ int dwmac_dma_interrupt(struct stmmac_priv *priv, void __iomem *ioaddr,  |
  			struct stmmac_extra_stats *x, u32 chan, u32 dir);                       |
  int dwmac_dma_reset(void __iomem *ioaddr);                                                   |
                                                                                               |
                                                                                                 |
Quoted 96 lines
drivers/net/ethernet/stmicro/stmmac/dwmac_dma.h +14 -0
+static inline u32 dma_chan_base_addr(u32 base, u32 chan)                                  \  |
+{                                                                                          | |
+	return base + chan * DMA_CHAN_OFFSET;                                                 | |
+}                                                                                          | |
+                                                                                           | |
+#define DMA_CHAN_XMT_POLL_DEMAND(chan)	dma_chan_base_addr(DMA_XMT_POLL_DEMAND, chan) | |
+#define DMA_CHAN_INTR_ENA(chan)		dma_chan_base_addr(DMA_INTR_ENA, chan)        | |
+#define DMA_CHAN_CONTROL(chan)		dma_chan_base_addr(DMA_CONTROL, chan)         | |
+#define DMA_CHAN_STATUS(chan)		dma_chan_base_addr(DMA_STATUS, chan)          |-+
+#define DMA_CHAN_BUS_MODE(chan)		dma_chan_base_addr(DMA_BUS_MODE, chan)        |
+#define DMA_CHAN_RCV_BASE_ADDR(chan)	dma_chan_base_addr(DMA_RCV_BASE_ADDR, chan)           |
+#define DMA_CHAN_TX_BASE_ADDR(chan)	dma_chan_base_addr(DMA_TX_BASE_ADDR, chan)            |
+#define DMA_CHAN_RX_WATCHDOG(chan)	dma_chan_base_addr(DMA_RX_WATCHDOG, chan)             |
+                                                                                           /
  #endif /* __DWMAC_DMA_H__ */
drivers/net/ethernet/stmicro/stmmac/dwmac_lib.c +15 -15
index 7907d62d3437..b37368137810 100644
@@ -28,65 +28,65 @@ int dwmac_dma_reset(void __iomem *ioaddr)
  }
  /* CSR1 enables the transmit DMA to check for new descriptor */
-void dwmac_enable_dma_transmission(void __iomem *ioaddr)
+void dwmac_enable_dma_transmission(void __iomem *ioaddr, u32 chan)
  {
-	writel(1, ioaddr + DMA_XMT_POLL_DEMAND);
+	writel(1, ioaddr + DMA_CHAN_XMT_POLL_DEMAND(chan));
  }
  void dwmac_enable_dma_irq(struct stmmac_priv *priv, void __iomem *ioaddr,
  			  u32 chan, bool rx, bool tx)
  {
-	u32 value = readl(ioaddr + DMA_INTR_ENA);
+	u32 value = readl(ioaddr + DMA_CHAN_INTR_ENA(chan));
  	if (rx)
  		value |= DMA_INTR_DEFAULT_RX;
  	if (tx)
  		value |= DMA_INTR_DEFAULT_TX;
-	writel(value, ioaddr + DMA_INTR_ENA);
+	writel(value, ioaddr + DMA_CHAN_INTR_ENA(chan));
  }
  void dwmac_disable_dma_irq(struct stmmac_priv *priv, void __iomem *ioaddr,
  			   u32 chan, bool rx, bool tx)
  {
-	u32 value = readl(ioaddr + DMA_INTR_ENA);
+	u32 value = readl(ioaddr + DMA_CHAN_INTR_ENA(chan));
  	if (rx)
  		value &= ~DMA_INTR_DEFAULT_RX;
  	if (tx)
  		value &= ~DMA_INTR_DEFAULT_TX;
-	writel(value, ioaddr + DMA_INTR_ENA);
+	writel(value, ioaddr + DMA_CHAN_INTR_ENA(chan));
  }
  void dwmac_dma_start_tx(struct stmmac_priv *priv, void __iomem *ioaddr,
  			u32 chan)
  {
-	u32 value = readl(ioaddr + DMA_CONTROL);
+	u32 value = readl(ioaddr + DMA_CHAN_CONTROL(chan));
  	value |= DMA_CONTROL_ST;
-	writel(value, ioaddr + DMA_CONTROL);
+	writel(value, ioaddr + DMA_CHAN_CONTROL(chan));
  }
  void dwmac_dma_stop_tx(struct stmmac_priv *priv, void __iomem *ioaddr, u32 chan)
  {
-	u32 value = readl(ioaddr + DMA_CONTROL);
+	u32 value = readl(ioaddr + DMA_CHAN_CONTROL(chan));
  	value &= ~DMA_CONTROL_ST;
-	writel(value, ioaddr + DMA_CONTROL);
+	writel(value, ioaddr + DMA_CHAN_CONTROL(chan));
  }
  void dwmac_dma_start_rx(struct stmmac_priv *priv, void __iomem *ioaddr,
  			u32 chan)
  {
-	u32 value = readl(ioaddr + DMA_CONTROL);
+	u32 value = readl(ioaddr + DMA_CHAN_CONTROL(chan));
  	value |= DMA_CONTROL_SR;
-	writel(value, ioaddr + DMA_CONTROL);
+	writel(value, ioaddr + DMA_CHAN_CONTROL(chan));
  }
  void dwmac_dma_stop_rx(struct stmmac_priv *priv, void __iomem *ioaddr, u32 chan)
  {
-	u32 value = readl(ioaddr + DMA_CONTROL);
+	u32 value = readl(ioaddr + DMA_CHAN_CONTROL(chan));
  	value &= ~DMA_CONTROL_SR;
-	writel(value, ioaddr + DMA_CONTROL);
+	writel(value, ioaddr + DMA_CHAN_CONTROL(chan));
  }
  #ifdef DWMAC_DMA_DEBUG
@@ -166,7 +166,7 @@ int dwmac_dma_interrupt(struct stmmac_priv *priv, void __iomem *ioaddr,
  	struct stmmac_txq_stats *txq_stats = &priv->xstats.txq_stats[chan];
  	int ret = 0;
  	/* read the status register (CSR5) */
-	u32 intr_status = readl(ioaddr + DMA_STATUS);
+	u32 intr_status = readl(ioaddr + DMA_CHAN_STATUS(chan));
  #ifdef DWMAC_DMA_DEBUG
  	/* Enable it to monitor DMA rx/tx status in case of critical problems */

drivers/net/ethernet/stmicro/stmmac/dwmac_lib.c int dwmac_dma_interrupt(struct stmmac_priv *priv, void __iomem *ioaddr, · line 238

Quoted 4 lines
drivers/net/ethernet/stmicro/stmmac/dwmac_lib.c +1 -1
@@ -236,7 +236,7 @@ int dwmac_dma_interrupt(struct stmmac_priv *priv, void __iomem *ioaddr,
  		pr_warn("%s: unexpected status %08x\n", __func__, intr_status);
  	/* Clear the interrupt by writing a logic 1 to the CSR5[15-0] */
-	writel((intr_status & 0x1ffff), ioaddr + DMA_STATUS);
+	writel((intr_status & 0x7ffff), ioaddr + DMA_CHAN_STATUS(chan));

Isn't the mask change going to be implemented in the framework of the Loongson-specific DMA-interrupt handler in some of the further patches?

I'll get back to reviewing the series tomorrow (later today)...

-Serge(y)

Quoted 42 lines
drivers/net/ethernet/stmicro/stmmac/dwmac_lib.c +0 -0
  	return ret;
  }
drivers/net/ethernet/stmicro/stmmac/hwif.h +1 -1
index 7be04b54738b..b0db38396171 100644
@@ -198,7 +198,7 @@ struct stmmac_dma_ops {
  	/* To track extra statistic (if supported) */
  	void (*dma_diagnostic_fr)(struct stmmac_extra_stats *x,
  				  void __iomem *ioaddr);
-	void (*enable_dma_transmission) (void __iomem *ioaddr);
+	void (*enable_dma_transmission)(void __iomem *ioaddr, u32 chan);
  	void (*enable_dma_irq)(struct stmmac_priv *priv, void __iomem *ioaddr,
  			       u32 chan, bool rx, bool tx);
  	void (*disable_dma_irq)(struct stmmac_priv *priv, void __iomem *ioaddr,
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +3 -3
index b334eb16da23..5617b40abbe4 100644
@@ -2558,7 +2558,7 @@ static bool stmmac_xdp_xmit_zc(struct stmmac_priv *priv, u32 queue, u32 budget)
  				       true, priv->mode, true, true,
  				       xdp_desc.len);
-		stmmac_enable_dma_transmission(priv, priv->ioaddr);
+		stmmac_enable_dma_transmission(priv, priv->ioaddr, queue);
  		xsk_tx_metadata_to_compl(meta,
  					 &tx_q->tx_skbuff_dma[entry].xsk_meta);
@@ -4706,7 +4706,7 @@ static netdev_tx_t stmmac_xmit(struct sk_buff *skb, struct net_device *dev)
  	netdev_tx_sent_queue(netdev_get_tx_queue(dev, queue), skb->len);
-	stmmac_enable_dma_transmission(priv, priv->ioaddr);
+	stmmac_enable_dma_transmission(priv, priv->ioaddr, queue);
  	stmmac_flush_tx_descriptors(priv, queue);
  	stmmac_tx_timer_arm(priv, queue);
@@ -4926,7 +4926,7 @@ static int stmmac_xdp_xmit_xdpf(struct stmmac_priv *priv, int queue,
  		u64_stats_update_end_irqrestore(&txq_stats->syncp, flags);
  	}
-	stmmac_enable_dma_transmission(priv, priv->ioaddr);
+	stmmac_enable_dma_transmission(priv, priv->ioaddr, queue);
  	entry = STMMAC_GET_ENTRY(entry, priv->dma_conf.dma_tx_size);
  	tx_q->cur_tx = entry;
Signature · 1 line
2.31.4
author
#31 lore raw

Re: [PATCH net-next v8 05/11] net: stmmac: dwmac-loongson: Add Loongson-specific register definitions

In reply to Serge Semin
Quoted 79 lines · Serge Semin
Quoted 78 lines · Yanteng Si

There are two types of Loongson DWGMAC. The first type shares the same register definitions and has similar logic as dwmac1000. The second type uses several different register definitions, we think it is necessary to distinguish rx and tx, so we split these bits into two.

Simply put, we split some single bit fields into double bits fileds:

Name Tx Rx

DMA_INTR_ENA_NIE = 0x00040000 | 0x00020000;
DMA_INTR_ENA_AIE = 0x00010000 | 0x00008000;
DMA_STATUS_NIS   = 0x00040000 | 0x00020000;
DMA_STATUS_AIS   = 0x00010000 | 0x00008000;
DMA_STATUS_FBI   = 0x00002000 | 0x00001000;

Therefore, when using, TX and RX must be set at the same time.

How to use them:
1. Create the Loongson GNET-specific stmmac_dma_ops.dma_interrupt() stmmac_dma_ops.init_chan()
methods in the dwmac-loongson.c driver. Adding all the Loongson-specific macros

2. Create a Loongson GNET-specific platform setup method with the next semantics:
+ allocate stmmac_dma_ops instance and initialize it with dwmac1000_dma_ops.
+ override the stmmac_dma_ops.{dma_interrupt, init_chan} with the pointers to the methods defined in 2.
+ allocate mac_device_info instance and initialize the mac_device_info.dma field with a pointer to the new stmmac_dma_ops instance.
+ initialize mac_device_info in a way it's done in dwmac1000_setup().

3. Initialize plat_stmmacenet_data.setup() with the pointer to the method created in 2.

---
  .../ethernet/stmicro/stmmac/dwmac-loongson.c  | 248 ++++++++++++++++++
  1 file changed, 248 insertions(+)
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +24 -0
index e7ce027cc14e..3b3578318cc1 100644
@@ -8,6 +8,193 @@
  #include <linux/device.h>
  #include <linux/of_irq.h>
  #include "stmmac.h"
+#include "dwmac_dma.h"
+#include "dwmac1000.h"
+
+#define DMA_INTR_ENA_NIE_TX_LOONGSON 0x00040000	/* Normal Loongson Tx Summary */
+#define DMA_INTR_ENA_NIE_RX_LOONGSON 0x00020000	/* Normal Loongson Rx Summary */
+#define DMA_INTR_NORMAL_LOONGSON	(DMA_INTR_ENA_NIE_TX_LOONGSON | \
+			 DMA_INTR_ENA_NIE_RX_LOONGSON | DMA_INTR_ENA_RIE | \
+			 DMA_INTR_ENA_TIE)
+
+#define DMA_INTR_ENA_AIE_TX_LOONGSON 0x00010000	/* Abnormal Loongson Tx Summary */
+#define DMA_INTR_ENA_AIE_RX_LOONGSON 0x00008000	/* Abnormal Loongson Rx Summary */
+
+#define DMA_INTR_ABNORMAL_LOONGSON	(DMA_INTR_ENA_AIE_TX_LOONGSON | \
+				DMA_INTR_ENA_AIE_RX_LOONGSON | DMA_INTR_ENA_FBE | \
+				DMA_INTR_ENA_UNE)
+
+#define DMA_INTR_DEFAULT_MASK_LOONGSON	(DMA_INTR_NORMAL_LOONGSON | DMA_INTR_ABNORMAL_LOONGSON)
+
+#define DMA_STATUS_NIS_TX_LOONGSON	0x00040000	/* Normal Loongson Tx Interrupt Summary */
+#define DMA_STATUS_NIS_RX_LOONGSON	0x00020000	/* Normal Loongson Rx Interrupt Summary */
+
+#define DMA_STATUS_AIS_TX_LOONGSON	0x00010000	/* Abnormal Loongson Tx Interrupt Summary */
+#define DMA_STATUS_AIS_RX_LOONGSON	0x00008000	/* Abnormal Loongson Rx Interrupt Summary */
+
Quoted 8 lines

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c line 41

Quoted 7 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +7 -0
+#define DMA_STATUS_FBI_TX_LOONGSON	0x00002000	/* Fatal Loongson Tx Bus Error Interrupt */
+#define DMA_STATUS_FBI_RX_LOONGSON	0x00001000	/* Fatal Loongson Rx Bus Error Interrupt */
+
+#define DMA_STATUS_MSK_COMMON_LOONGSON		(DMA_STATUS_NIS_TX_LOONGSON | \
+					 DMA_STATUS_NIS_RX_LOONGSON | DMA_STATUS_AIS_TX_LOONGSON | \
+					 DMA_STATUS_AIS_RX_LOONGSON | DMA_STATUS_FBI_TX_LOONGSON | \
+					 DMA_STATUS_FBI_RX_LOONGSON)

Max 80 chars per line please.

OK,

Quoted 25 lines
Quoted 12 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +11 -0
+
+#define DMA_STATUS_MSK_RX_LOONGSON		(DMA_STATUS_ERI | \
+					 DMA_STATUS_RWT | \
+					 DMA_STATUS_RPS | \
+					 DMA_STATUS_RU | \
+					 DMA_STATUS_RI | \
+					 DMA_STATUS_OVF | \
+					 DMA_STATUS_MSK_COMMON_LOONGSON)
+
+#define DMA_STATUS_MSK_TX_LOONGSON		(DMA_STATUS_ETI | \
+					 DMA_STATUS_UNF | \

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c line 62

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +10 -0
+					 DMA_STATUS_TJT | \
+					 DMA_STATUS_TU | \
+					 DMA_STATUS_TPS | \
+					 DMA_STATUS_TI | \
+					 DMA_STATUS_MSK_COMMON_LOONGSON)
+
+struct loongson_data {
+	struct device *dev;
+	u32 lgmac_version;
+	struct stmmac_dma_ops dwlgmac_dma_ops;

Just figured out we can do without this field being added to the private data. See my note in the loongson_setup() method.

Quoted 7 lines

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c line 65

Quoted 3 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +3 -0
+};
+
+static void dwlgmac_dma_init_channel(struct stmmac_priv *priv,

The "dwlgmac_" prefix is confusing. There is the DW XLGMAC IP-core for which the "dwxlgmac_" is more appropriate and "x" is easy to miss should your version of the prefix is met. Consider changing it to something like "loongson_gnet_".

OK,

Quoted 56 lines
Quoted 33 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +32 -0
+				     void __iomem *ioaddr,
+				     struct stmmac_dma_cfg *dma_cfg, u32 chan)
+{
+	u32 value;
+	int txpbl = dma_cfg->txpbl ?: dma_cfg->pbl;
+	int rxpbl = dma_cfg->rxpbl ?: dma_cfg->pbl;
+
+	/* common channel control register config */
+	value = readl(ioaddr + DMA_CHAN_BUS_MODE(chan));
+
+	/* Set the DMA PBL (Programmable Burst Length) mode.
+	 *
+	 * Note: before stmmac core 3.50 this mode bit was 4xPBL, and
+	 * post 3.5 mode bit acts as 8*PBL.
+	 */
+	if (dma_cfg->pblx8)
+		value |= DMA_BUS_MODE_MAXPBL;
+	value |= DMA_BUS_MODE_USP;
+	value &= ~(DMA_BUS_MODE_PBL_MASK | DMA_BUS_MODE_RPBL_MASK);
+	value |= (txpbl << DMA_BUS_MODE_PBL_SHIFT);
+	value |= (rxpbl << DMA_BUS_MODE_RPBL_SHIFT);
+
+	/* Set the Fixed burst mode */
+	if (dma_cfg->fixed_burst)
+		value |= DMA_BUS_MODE_FB;
+
+	/* Mixed Burst has no effect when fb is set */
+	if (dma_cfg->mixed_burst)
+		value |= DMA_BUS_MODE_MB;
+
+	value |= DMA_BUS_MODE_ATDS;
+

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c line 107

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +10 -0
+	if (dma_cfg->aal)
+		value |= DMA_BUS_MODE_AAL;
+
+	writel(value, ioaddr + DMA_BUS_MODE);
+
+	/* Mask interrupts by writing to CSR7 */
+	writel(DMA_INTR_DEFAULT_MASK_LOONGSON, ioaddr + DMA_INTR_ENA);
+}
+
+static int dwlgmac_dma_interrupt(struct stmmac_priv *priv, void __iomem *ioaddr,

The same note as above.

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c line 116

Quoted 9 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +9 -0
+				 struct stmmac_extra_stats *x, u32 chan, u32 dir)
+{
+	struct stmmac_rxq_stats *rxq_stats = &priv->xstats.rxq_stats[chan];
+	struct stmmac_txq_stats *txq_stats = &priv->xstats.txq_stats[chan];
+	int ret = 0;
+	/* read the status register (CSR5) */
+	u32 nor_intr_status;
+	u32 abnor_intr_status;
+	u32 fb_intr_status;

Reverse xmas tree please.

Quoted 2 lines

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c line 117

Quoted 1 line
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +1 -0
+	u32 intr_status = readl(ioaddr + DMA_CHAN_STATUS(chan));

Please move the initialization into a separate statement.

OK,

Quoted 105 lines

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c line 124

Quoted 8 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +7 -0
+
+#ifdef DWMAC_DMA_DEBUG
+	/* Enable it to monitor DMA rx/tx status in case of critical problems */
+	pr_debug("%s: [CSR5: 0x%08x]\n", __func__, intr_status);
+	show_tx_process_state(intr_status);
+	show_rx_process_state(intr_status);
+#endif

This will cause a build-error if DWMAC_DMA_DEBUG is defined. Just drop it.
OK,

Quoted 77 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +73 -0
+
+	if (dir == DMA_DIR_RX)
+		intr_status &= DMA_STATUS_MSK_RX_LOONGSON;
+	else if (dir == DMA_DIR_TX)
+		intr_status &= DMA_STATUS_MSK_TX_LOONGSON;
+
+	nor_intr_status = intr_status & (DMA_STATUS_NIS_TX_LOONGSON |
+		DMA_STATUS_NIS_RX_LOONGSON);
+	abnor_intr_status = intr_status & (DMA_STATUS_AIS_TX_LOONGSON |
+		DMA_STATUS_AIS_RX_LOONGSON);
+	fb_intr_status = intr_status & (DMA_STATUS_FBI_TX_LOONGSON |
+		DMA_STATUS_FBI_RX_LOONGSON);
+
+	/* ABNORMAL interrupts */
+	if (unlikely(abnor_intr_status)) {
+		if (unlikely(intr_status & DMA_STATUS_UNF)) {
+			ret = tx_hard_error_bump_tc;
+			x->tx_undeflow_irq++;
+		}
+		if (unlikely(intr_status & DMA_STATUS_TJT))
+			x->tx_jabber_irq++;
+
+		if (unlikely(intr_status & DMA_STATUS_OVF))
+			x->rx_overflow_irq++;
+
+		if (unlikely(intr_status & DMA_STATUS_RU))
+			x->rx_buf_unav_irq++;
+		if (unlikely(intr_status & DMA_STATUS_RPS))
+			x->rx_process_stopped_irq++;
+		if (unlikely(intr_status & DMA_STATUS_RWT))
+			x->rx_watchdog_irq++;
+		if (unlikely(intr_status & DMA_STATUS_ETI))
+			x->tx_early_irq++;
+		if (unlikely(intr_status & DMA_STATUS_TPS)) {
+			x->tx_process_stopped_irq++;
+			ret = tx_hard_error;
+		}
+		if (unlikely(intr_status & fb_intr_status)) {
+			x->fatal_bus_error_irq++;
+			ret = tx_hard_error;
+		}
+	}
+	/* TX/RX NORMAL interrupts */
+	if (likely(nor_intr_status)) {
+		if (likely(intr_status & DMA_STATUS_RI)) {
+			u32 value = readl(ioaddr + DMA_INTR_ENA);
+			/* to schedule NAPI on real RIE event. */
+			if (likely(value & DMA_INTR_ENA_RIE)) {
+				u64_stats_update_begin(&rxq_stats->syncp);
+				rxq_stats->rx_normal_irq_n++;
+				u64_stats_update_end(&rxq_stats->syncp);
+				ret |= handle_rx;
+			}
+		}
+		if (likely(intr_status & DMA_STATUS_TI)) {
+			u64_stats_update_begin(&txq_stats->syncp);
+			txq_stats->tx_normal_irq_n++;
+			u64_stats_update_end(&txq_stats->syncp);
+			ret |= handle_tx;
+		}
+		if (unlikely(intr_status & DMA_STATUS_ERI))
+			x->rx_early_irq++;
+	}
+	/* Optional hardware blocks, interrupts should be disabled */
+	if (unlikely(intr_status &
+		     (DMA_STATUS_GPI | DMA_STATUS_GMI | DMA_STATUS_GLI)))
+		pr_warn("%s: unexpected status %08x\n", __func__, intr_status);
+
+	/* Clear the interrupt by writing a logic 1 to the CSR5[15-0] */
+	writel((intr_status & 0x7ffff), ioaddr + DMA_CHAN_STATUS(chan));
+
+	return ret;
+}
 
  struct stmmac_pci_info {
  	int (*setup)(struct pci_dev *pdev, struct plat_stmmacenet_data *plat);

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static struct stmmac_pci_info loongson_gmac_pci_info = { · line 311

Quoted 4 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +1 -0
@@ -121,6 +308,48 @@ static struct stmmac_pci_info loongson_gmac_pci_info = {
  	.config = loongson_gmac_config,
  };
 
+static struct mac_device_info *loongson_setup(void *apriv)

Consider using the GNET-specific prefix, like "loongson_gnet_".

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static struct stmmac_pci_info loongson_gmac_pci_info = { · line 319

Quoted 8 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +8 -0
+{
+	struct stmmac_priv *priv = apriv;
+	struct mac_device_info *mac;
+	struct loongson_data *ld;
+
+	mac = devm_kzalloc(priv->device, sizeof(*mac), GFP_KERNEL);
+	if (!mac)
+		return NULL;

What about devm_kzalloc()-ing the stmmac_dma_ops instance here and initializing it as it's done in the probe method? Thus ...

Quoted 8 lines

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static struct stmmac_pci_info loongson_gmac_pci_info = { · line 322

Quoted 3 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +3 -0
+
+	ld = priv->plat->bsp_priv;
+	mac->dma = &ld->dwlgmac_dma_ops;

... this can be replaced with:

	mac->dma = devm_kzalloc(priv->device, sizeof(*mac->dma), GFP_KERNEL);
	if (!mac->dma)
		return -ENOMEM;

Great, but It seems that we cannot return an int value here.

Quoted 63 lines
	*mac->dma = dwmac1000_dma_ops;
	mac->dma->init_chan = loongson_gnet_dma_init_channel;
	mac->dma->dma_interrupt = loongson_gnet_dma_interrupt;
Quoted 34 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +30 -0
+
+	/* Pre-initialize the respective "mac" fields as it's done in
+	 * dwmac1000_setup()
+	 */
+	priv->dev->priv_flags |= IFF_UNICAST_FLT;
+	mac->pcsr = priv->ioaddr;
+	mac->multicast_filter_bins = priv->plat->multicast_filter_bins;
+	mac->unicast_filter_entries = priv->plat->unicast_filter_entries;
+	mac->mcast_bits_log2 = 0;
+
+	if (mac->multicast_filter_bins)
+		mac->mcast_bits_log2 = ilog2(mac->multicast_filter_bins);
+
+	mac->link.duplex = GMAC_CONTROL_DM;
+	mac->link.speed10 = GMAC_CONTROL_PS;
+	mac->link.speed100 = GMAC_CONTROL_PS | GMAC_CONTROL_FES;
+	mac->link.speed1000 = 0;
+	mac->link.speed_mask = GMAC_CONTROL_PS | GMAC_CONTROL_FES;
+	mac->mii.addr = GMAC_MII_ADDR;
+	mac->mii.data = GMAC_MII_DATA;
+	mac->mii.addr_shift = 11;
+	mac->mii.addr_mask = 0x0000F800;
+	mac->mii.reg_shift = 6;
+	mac->mii.reg_mask = 0x000007C0;
+	mac->mii.clk_csr_shift = 2;
+	mac->mii.clk_csr_mask = GENMASK(5, 2);
+
+	return mac;
+}
+
  static int loongson_dwmac_probe(struct pci_dev *pdev,
  				const struct pci_device_id *id)
  {

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int loongson_dwmac_probe(struct pci_dev *pdev, · line 361

Quoted 4 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +1 -0
@@ -129,6 +358,7 @@ static int loongson_dwmac_probe(struct pci_dev *pdev,
  	struct stmmac_pci_info *info;
  	struct stmmac_resources res;
  	struct device_node *np;
+	struct loongson_data *ld;

reverse xmas tree order please.

Quoted 18 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +4 -0
  	plat = devm_kzalloc(&pdev->dev, sizeof(*plat), GFP_KERNEL);
  	if (!plat)
@@ -145,6 +375,10 @@ static int loongson_dwmac_probe(struct pci_dev *pdev,
  	if (!plat->dma_cfg)
  		return -ENOMEM;
 
+	ld = devm_kzalloc(&pdev->dev, sizeof(*ld), GFP_KERNEL);
+	if (!ld)
+		return -ENOMEM;
+
  	np = dev_of_node(&pdev->dev);
  	plat->mdio_node = of_get_child_by_name(np, "mdio");
  	if (plat->mdio_node) {
@@ -197,6 +431,20 @@ static int loongson_dwmac_probe(struct pci_dev *pdev,
  	if (ret)
  		goto err_disable_device;
 
Quoted 4 lines

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int loongson_dwmac_probe(struct pci_dev *pdev, · line 435

Quoted 2 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +2 -0
+	ld->dev = &pdev->dev;
+	ld->lgmac_version = readl(res.addr + GMAC_VERSION) & 0xff;

AFAICS the lgmac_version is unused in out of the probe() method context. What about locally defining it?

OK,

Quoted 5 lines

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int loongson_dwmac_probe(struct pci_dev *pdev, · line 438

Quoted 4 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +3 -0
+
+	/* Activate loongson custom ip */
+	if (ld->lgmac_version < DWMAC_CORE_3_50) {

Please define a new macro for the GNET MAC.

OK.

Quoted 5 lines

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int loongson_dwmac_probe(struct pci_dev *pdev, · line 441

Quoted 4 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +3 -0
+		ld->dwlgmac_dma_ops = dwmac1000_dma_ops;
+		ld->dwlgmac_dma_ops.init_chan = dwlgmac_dma_init_channel;
+		ld->dwlgmac_dma_ops.dma_interrupt = dwlgmac_dma_interrupt;

See my comment in the loongson_setup() method.

This will introduce a compilation warning:

warning: returning 'int' from a function with return type 'struct mac_device_info *' makes pointer from integer without a cast [-Wint-conversion] 418 |                 return -ENOMEM;

Thanks,

Yanteng

Quoted 15 lines

-Serge(y)

Quoted 12 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +6 -0
+
+		plat->setup = loongson_setup;
+	}
+
+	plat->bsp_priv = ld;
+
  	ret = stmmac_dvr_probe(&pdev->dev, plat, &res);
  	if (ret)
  		goto err_disable_device;
Signature · 1 line
2.31.4
#32 lore raw

Re: [PATCH net-next v8 05/11] net: stmmac: dwmac-loongson: Add Loongson-specific register definitions

Quoted 290 lines · Yanteng Si
Quoted 79 lines · Serge Semin
Quoted 78 lines · Yanteng Si

There are two types of Loongson DWGMAC. The first type shares the same register definitions and has similar logic as dwmac1000. The second type uses several different register definitions, we think it is necessary to distinguish rx and tx, so we split these bits into two.

Simply put, we split some single bit fields into double bits fileds:

Name Tx Rx

DMA_INTR_ENA_NIE = 0x00040000 | 0x00020000;
DMA_INTR_ENA_AIE = 0x00010000 | 0x00008000;
DMA_STATUS_NIS   = 0x00040000 | 0x00020000;
DMA_STATUS_AIS   = 0x00010000 | 0x00008000;
DMA_STATUS_FBI   = 0x00002000 | 0x00001000;

Therefore, when using, TX and RX must be set at the same time.

How to use them:
1. Create the Loongson GNET-specific stmmac_dma_ops.dma_interrupt() stmmac_dma_ops.init_chan()
methods in the dwmac-loongson.c driver. Adding all the Loongson-specific macros

2. Create a Loongson GNET-specific platform setup method with the next semantics:
+ allocate stmmac_dma_ops instance and initialize it with dwmac1000_dma_ops.
+ override the stmmac_dma_ops.{dma_interrupt, init_chan} with the pointers to the methods defined in 2.
+ allocate mac_device_info instance and initialize the mac_device_info.dma field with a pointer to the new stmmac_dma_ops instance.
+ initialize mac_device_info in a way it's done in dwmac1000_setup().

3. Initialize plat_stmmacenet_data.setup() with the pointer to the method created in 2.

---
  .../ethernet/stmicro/stmmac/dwmac-loongson.c  | 248 ++++++++++++++++++
  1 file changed, 248 insertions(+)
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +24 -0
index e7ce027cc14e..3b3578318cc1 100644
@@ -8,6 +8,193 @@
  #include <linux/device.h>
  #include <linux/of_irq.h>
  #include "stmmac.h"
+#include "dwmac_dma.h"
+#include "dwmac1000.h"
+
+#define DMA_INTR_ENA_NIE_TX_LOONGSON 0x00040000	/* Normal Loongson Tx Summary */
+#define DMA_INTR_ENA_NIE_RX_LOONGSON 0x00020000	/* Normal Loongson Rx Summary */
+#define DMA_INTR_NORMAL_LOONGSON	(DMA_INTR_ENA_NIE_TX_LOONGSON | \
+			 DMA_INTR_ENA_NIE_RX_LOONGSON | DMA_INTR_ENA_RIE | \
+			 DMA_INTR_ENA_TIE)
+
+#define DMA_INTR_ENA_AIE_TX_LOONGSON 0x00010000	/* Abnormal Loongson Tx Summary */
+#define DMA_INTR_ENA_AIE_RX_LOONGSON 0x00008000	/* Abnormal Loongson Rx Summary */
+
+#define DMA_INTR_ABNORMAL_LOONGSON	(DMA_INTR_ENA_AIE_TX_LOONGSON | \
+				DMA_INTR_ENA_AIE_RX_LOONGSON | DMA_INTR_ENA_FBE | \
+				DMA_INTR_ENA_UNE)
+
+#define DMA_INTR_DEFAULT_MASK_LOONGSON	(DMA_INTR_NORMAL_LOONGSON | DMA_INTR_ABNORMAL_LOONGSON)
+
+#define DMA_STATUS_NIS_TX_LOONGSON	0x00040000	/* Normal Loongson Tx Interrupt Summary */
+#define DMA_STATUS_NIS_RX_LOONGSON	0x00020000	/* Normal Loongson Rx Interrupt Summary */
+
+#define DMA_STATUS_AIS_TX_LOONGSON	0x00010000	/* Abnormal Loongson Tx Interrupt Summary */
+#define DMA_STATUS_AIS_RX_LOONGSON	0x00008000	/* Abnormal Loongson Rx Interrupt Summary */
+
Quoted 8 lines

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c line 41

Quoted 7 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +7 -0
+#define DMA_STATUS_FBI_TX_LOONGSON	0x00002000	/* Fatal Loongson Tx Bus Error Interrupt */
+#define DMA_STATUS_FBI_RX_LOONGSON	0x00001000	/* Fatal Loongson Rx Bus Error Interrupt */
+
+#define DMA_STATUS_MSK_COMMON_LOONGSON		(DMA_STATUS_NIS_TX_LOONGSON | \
+					 DMA_STATUS_NIS_RX_LOONGSON | DMA_STATUS_AIS_TX_LOONGSON | \
+					 DMA_STATUS_AIS_RX_LOONGSON | DMA_STATUS_FBI_TX_LOONGSON | \
+					 DMA_STATUS_FBI_RX_LOONGSON)

Max 80 chars per line please.

OK,

Quoted 25 lines
Quoted 12 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +11 -0
+
+#define DMA_STATUS_MSK_RX_LOONGSON		(DMA_STATUS_ERI | \
+					 DMA_STATUS_RWT | \
+					 DMA_STATUS_RPS | \
+					 DMA_STATUS_RU | \
+					 DMA_STATUS_RI | \
+					 DMA_STATUS_OVF | \
+					 DMA_STATUS_MSK_COMMON_LOONGSON)
+
+#define DMA_STATUS_MSK_TX_LOONGSON		(DMA_STATUS_ETI | \
+					 DMA_STATUS_UNF | \

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c line 62

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +10 -0
+					 DMA_STATUS_TJT | \
+					 DMA_STATUS_TU | \
+					 DMA_STATUS_TPS | \
+					 DMA_STATUS_TI | \
+					 DMA_STATUS_MSK_COMMON_LOONGSON)
+
+struct loongson_data {
+	struct device *dev;
+	u32 lgmac_version;
+	struct stmmac_dma_ops dwlgmac_dma_ops;

Just figured out we can do without this field being added to the private data. See my note in the loongson_setup() method.

Quoted 7 lines

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c line 65

Quoted 3 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +3 -0
+};
+
+static void dwlgmac_dma_init_channel(struct stmmac_priv *priv,

The "dwlgmac_" prefix is confusing. There is the DW XLGMAC IP-core for which the "dwxlgmac_" is more appropriate and "x" is easy to miss should your version of the prefix is met. Consider changing it to something like "loongson_gnet_".

OK,

Quoted 56 lines
Quoted 33 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +32 -0
+				     void __iomem *ioaddr,
+				     struct stmmac_dma_cfg *dma_cfg, u32 chan)
+{
+	u32 value;
+	int txpbl = dma_cfg->txpbl ?: dma_cfg->pbl;
+	int rxpbl = dma_cfg->rxpbl ?: dma_cfg->pbl;
+
+	/* common channel control register config */
+	value = readl(ioaddr + DMA_CHAN_BUS_MODE(chan));
+
+	/* Set the DMA PBL (Programmable Burst Length) mode.
+	 *
+	 * Note: before stmmac core 3.50 this mode bit was 4xPBL, and
+	 * post 3.5 mode bit acts as 8*PBL.
+	 */
+	if (dma_cfg->pblx8)
+		value |= DMA_BUS_MODE_MAXPBL;
+	value |= DMA_BUS_MODE_USP;
+	value &= ~(DMA_BUS_MODE_PBL_MASK | DMA_BUS_MODE_RPBL_MASK);
+	value |= (txpbl << DMA_BUS_MODE_PBL_SHIFT);
+	value |= (rxpbl << DMA_BUS_MODE_RPBL_SHIFT);
+
+	/* Set the Fixed burst mode */
+	if (dma_cfg->fixed_burst)
+		value |= DMA_BUS_MODE_FB;
+
+	/* Mixed Burst has no effect when fb is set */
+	if (dma_cfg->mixed_burst)
+		value |= DMA_BUS_MODE_MB;
+
+	value |= DMA_BUS_MODE_ATDS;
+

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c line 107

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +10 -0
+	if (dma_cfg->aal)
+		value |= DMA_BUS_MODE_AAL;
+
+	writel(value, ioaddr + DMA_BUS_MODE);
+
+	/* Mask interrupts by writing to CSR7 */
+	writel(DMA_INTR_DEFAULT_MASK_LOONGSON, ioaddr + DMA_INTR_ENA);
+}
+
+static int dwlgmac_dma_interrupt(struct stmmac_priv *priv, void __iomem *ioaddr,

The same note as above.

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c line 116

Quoted 9 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +9 -0
+				 struct stmmac_extra_stats *x, u32 chan, u32 dir)
+{
+	struct stmmac_rxq_stats *rxq_stats = &priv->xstats.rxq_stats[chan];
+	struct stmmac_txq_stats *txq_stats = &priv->xstats.txq_stats[chan];
+	int ret = 0;
+	/* read the status register (CSR5) */
+	u32 nor_intr_status;
+	u32 abnor_intr_status;
+	u32 fb_intr_status;

Reverse xmas tree please.

Quoted 2 lines

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c line 117

Quoted 1 line
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +1 -0
+	u32 intr_status = readl(ioaddr + DMA_CHAN_STATUS(chan));

Please move the initialization into a separate statement.

OK,

Quoted 108 lines

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c line 124

Quoted 8 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +7 -0
+
+#ifdef DWMAC_DMA_DEBUG
+	/* Enable it to monitor DMA rx/tx status in case of critical problems */
+	pr_debug("%s: [CSR5: 0x%08x]\n", __func__, intr_status);
+	show_tx_process_state(intr_status);
+	show_rx_process_state(intr_status);
+#endif

This will cause a build-error if DWMAC_DMA_DEBUG is defined. Just drop it.
OK,

Quoted 76 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +73 -0
+
+	if (dir == DMA_DIR_RX)
+		intr_status &= DMA_STATUS_MSK_RX_LOONGSON;
+	else if (dir == DMA_DIR_TX)
+		intr_status &= DMA_STATUS_MSK_TX_LOONGSON;
+
+	nor_intr_status = intr_status & (DMA_STATUS_NIS_TX_LOONGSON |
+		DMA_STATUS_NIS_RX_LOONGSON);
+	abnor_intr_status = intr_status & (DMA_STATUS_AIS_TX_LOONGSON |
+		DMA_STATUS_AIS_RX_LOONGSON);
+	fb_intr_status = intr_status & (DMA_STATUS_FBI_TX_LOONGSON |
+		DMA_STATUS_FBI_RX_LOONGSON);
+
+	/* ABNORMAL interrupts */
+	if (unlikely(abnor_intr_status)) {
+		if (unlikely(intr_status & DMA_STATUS_UNF)) {
+			ret = tx_hard_error_bump_tc;
+			x->tx_undeflow_irq++;
+		}
+		if (unlikely(intr_status & DMA_STATUS_TJT))
+			x->tx_jabber_irq++;
+
+		if (unlikely(intr_status & DMA_STATUS_OVF))
+			x->rx_overflow_irq++;
+
+		if (unlikely(intr_status & DMA_STATUS_RU))
+			x->rx_buf_unav_irq++;
+		if (unlikely(intr_status & DMA_STATUS_RPS))
+			x->rx_process_stopped_irq++;
+		if (unlikely(intr_status & DMA_STATUS_RWT))
+			x->rx_watchdog_irq++;
+		if (unlikely(intr_status & DMA_STATUS_ETI))
+			x->tx_early_irq++;
+		if (unlikely(intr_status & DMA_STATUS_TPS)) {
+			x->tx_process_stopped_irq++;
+			ret = tx_hard_error;
+		}
+		if (unlikely(intr_status & fb_intr_status)) {
+			x->fatal_bus_error_irq++;
+			ret = tx_hard_error;
+		}
+	}
+	/* TX/RX NORMAL interrupts */
+	if (likely(nor_intr_status)) {
+		if (likely(intr_status & DMA_STATUS_RI)) {
+			u32 value = readl(ioaddr + DMA_INTR_ENA);
+			/* to schedule NAPI on real RIE event. */
+			if (likely(value & DMA_INTR_ENA_RIE)) {
+				u64_stats_update_begin(&rxq_stats->syncp);
+				rxq_stats->rx_normal_irq_n++;
+				u64_stats_update_end(&rxq_stats->syncp);
+				ret |= handle_rx;
+			}
+		}
+		if (likely(intr_status & DMA_STATUS_TI)) {
+			u64_stats_update_begin(&txq_stats->syncp);
+			txq_stats->tx_normal_irq_n++;
+			u64_stats_update_end(&txq_stats->syncp);
+			ret |= handle_tx;
+		}
+		if (unlikely(intr_status & DMA_STATUS_ERI))
+			x->rx_early_irq++;
+	}
+	/* Optional hardware blocks, interrupts should be disabled */
+	if (unlikely(intr_status &
+		     (DMA_STATUS_GPI | DMA_STATUS_GMI | DMA_STATUS_GLI)))
+		pr_warn("%s: unexpected status %08x\n", __func__, intr_status);
+
+	/* Clear the interrupt by writing a logic 1 to the CSR5[15-0] */
+	writel((intr_status & 0x7ffff), ioaddr + DMA_CHAN_STATUS(chan));
+
+	return ret;
+}
  struct stmmac_pci_info {
  	int (*setup)(struct pci_dev *pdev, struct plat_stmmacenet_data *plat);

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static struct stmmac_pci_info loongson_gmac_pci_info = { · line 310

Quoted 3 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +1 -0
@@ -121,6 +308,48 @@ static struct stmmac_pci_info loongson_gmac_pci_info = {
  	.config = loongson_gmac_config,
  };
+static struct mac_device_info *loongson_setup(void *apriv)

Consider using the GNET-specific prefix, like "loongson_gnet_".

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static struct stmmac_pci_info loongson_gmac_pci_info = { · line 319

Quoted 8 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +8 -0
+{
+	struct stmmac_priv *priv = apriv;
+	struct mac_device_info *mac;
+	struct loongson_data *ld;
+
+	mac = devm_kzalloc(priv->device, sizeof(*mac), GFP_KERNEL);
+	if (!mac)
+		return NULL;

What about devm_kzalloc()-ing the stmmac_dma_ops instance here and initializing it as it's done in the probe method? Thus ...

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static struct stmmac_pci_info loongson_gmac_pci_info = { · line 322

Quoted 3 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +3 -0
+
+	ld = priv->plat->bsp_priv;
+	mac->dma = &ld->dwlgmac_dma_ops;

... this can be replaced with:

Quoted 5 lines
Quoted 3 lines
	mac->dma = devm_kzalloc(priv->device, sizeof(*mac->dma), GFP_KERNEL);
	if (!mac->dma)
		return -ENOMEM;

Great, but It seems that we cannot return an int value here.

Just

		return NULL;

then.

Quoted 77 lines
Quoted 56 lines
	*mac->dma = dwmac1000_dma_ops;
	mac->dma->init_chan = loongson_gnet_dma_init_channel;
	mac->dma->dma_interrupt = loongson_gnet_dma_interrupt;
Quoted 34 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +30 -0
+
+	/* Pre-initialize the respective "mac" fields as it's done in
+	 * dwmac1000_setup()
+	 */
+	priv->dev->priv_flags |= IFF_UNICAST_FLT;
+	mac->pcsr = priv->ioaddr;
+	mac->multicast_filter_bins = priv->plat->multicast_filter_bins;
+	mac->unicast_filter_entries = priv->plat->unicast_filter_entries;
+	mac->mcast_bits_log2 = 0;
+
+	if (mac->multicast_filter_bins)
+		mac->mcast_bits_log2 = ilog2(mac->multicast_filter_bins);
+
+	mac->link.duplex = GMAC_CONTROL_DM;
+	mac->link.speed10 = GMAC_CONTROL_PS;
+	mac->link.speed100 = GMAC_CONTROL_PS | GMAC_CONTROL_FES;
+	mac->link.speed1000 = 0;
+	mac->link.speed_mask = GMAC_CONTROL_PS | GMAC_CONTROL_FES;
+	mac->mii.addr = GMAC_MII_ADDR;
+	mac->mii.data = GMAC_MII_DATA;
+	mac->mii.addr_shift = 11;
+	mac->mii.addr_mask = 0x0000F800;
+	mac->mii.reg_shift = 6;
+	mac->mii.reg_mask = 0x000007C0;
+	mac->mii.clk_csr_shift = 2;
+	mac->mii.clk_csr_mask = GENMASK(5, 2);
+
+	return mac;
+}
+
  static int loongson_dwmac_probe(struct pci_dev *pdev,
  				const struct pci_device_id *id)
  {

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int loongson_dwmac_probe(struct pci_dev *pdev, · line 361

Quoted 4 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +1 -0
@@ -129,6 +358,7 @@ static int loongson_dwmac_probe(struct pci_dev *pdev,
  	struct stmmac_pci_info *info;
  	struct stmmac_resources res;
  	struct device_node *np;
+	struct loongson_data *ld;

reverse xmas tree order please.

Quoted 11 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +4 -0
  	plat = devm_kzalloc(&pdev->dev, sizeof(*plat), GFP_KERNEL);
  	if (!plat)
@@ -145,6 +375,10 @@ static int loongson_dwmac_probe(struct pci_dev *pdev,
  	if (!plat->dma_cfg)
  		return -ENOMEM;
+	ld = devm_kzalloc(&pdev->dev, sizeof(*ld), GFP_KERNEL);
+	if (!ld)
+		return -ENOMEM;
+
  	np = dev_of_node(&pdev->dev);
  	plat->mdio_node = of_get_child_by_name(np, "mdio");
Quoted 8 lines

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int loongson_dwmac_probe(struct pci_dev *pdev, · line 434

Quoted 6 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +2 -0
  	if (plat->mdio_node) {
@@ -197,6 +431,20 @@ static int loongson_dwmac_probe(struct pci_dev *pdev,
  	if (ret)
  		goto err_disable_device;
+	ld->dev = &pdev->dev;
+	ld->lgmac_version = readl(res.addr + GMAC_VERSION) & 0xff;

AFAICS the lgmac_version is unused in out of the probe() method context. What about locally defining it?

OK,

Quoted 5 lines

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int loongson_dwmac_probe(struct pci_dev *pdev, · line 438

Quoted 4 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +3 -0
+
+	/* Activate loongson custom ip */
+	if (ld->lgmac_version < DWMAC_CORE_3_50) {

Please define a new macro for the GNET MAC.

OK.

Quoted 5 lines

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int loongson_dwmac_probe(struct pci_dev *pdev, · line 441

Quoted 4 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +3 -0
+		ld->dwlgmac_dma_ops = dwmac1000_dma_ops;
+		ld->dwlgmac_dma_ops.init_chan = dwlgmac_dma_init_channel;
+		ld->dwlgmac_dma_ops.dma_interrupt = dwlgmac_dma_interrupt;

See my comment in the loongson_setup() method.

Quoted 6 lines

This will introduce a compilation warning:

warning: returning 'int' from a function with return type 'struct mac_device_info *' makes pointer from integer without a cast [-Wint-conversion]
  418 |                 return -ENOMEM;

stmmac_hwif_init() expects priv->plat->setup(priv) returning NULL if something wrong. As I suggested above just return NULL then if mac_device_info couldn't be allocated.

-Serge(y)

Quoted 22 lines

Thanks,

Yanteng

Quoted 15 lines

-Serge(y)

Quoted 12 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +6 -0
+
+		plat->setup = loongson_setup;
+	}
+
+	plat->bsp_priv = ld;
+
  	ret = stmmac_dvr_probe(&pdev->dev, plat, &res);
  	if (ret)
  		goto err_disable_device;
Signature · 1 line
2.31.4
author
#33 lore raw

Re: [PATCH net-next v8 05/11] net: stmmac: dwmac-loongson: Add Loongson-specific register definitions

Hi Serge,

Quoted 287 lines · Serge Semin
Quoted 286 lines · Yanteng Si
Quoted 79 lines · Serge Semin
Quoted 78 lines · Yanteng Si

There are two types of Loongson DWGMAC. The first type shares the same register definitions and has similar logic as dwmac1000. The second type uses several different register definitions, we think it is necessary to distinguish rx and tx, so we split these bits into two.

Simply put, we split some single bit fields into double bits fileds:

Name Tx Rx

DMA_INTR_ENA_NIE = 0x00040000 | 0x00020000;
DMA_INTR_ENA_AIE = 0x00010000 | 0x00008000;
DMA_STATUS_NIS   = 0x00040000 | 0x00020000;
DMA_STATUS_AIS   = 0x00010000 | 0x00008000;
DMA_STATUS_FBI   = 0x00002000 | 0x00001000;

Therefore, when using, TX and RX must be set at the same time.

How to use them:
1. Create the Loongson GNET-specific stmmac_dma_ops.dma_interrupt() stmmac_dma_ops.init_chan()
methods in the dwmac-loongson.c driver. Adding all the Loongson-specific macros

2. Create a Loongson GNET-specific platform setup method with the next semantics:
+ allocate stmmac_dma_ops instance and initialize it with dwmac1000_dma_ops.
+ override the stmmac_dma_ops.{dma_interrupt, init_chan} with the pointers to the methods defined in 2.
+ allocate mac_device_info instance and initialize the mac_device_info.dma field with a pointer to the new stmmac_dma_ops instance.
+ initialize mac_device_info in a way it's done in dwmac1000_setup().

3. Initialize plat_stmmacenet_data.setup() with the pointer to the method created in 2.

---
   .../ethernet/stmicro/stmmac/dwmac-loongson.c  | 248 ++++++++++++++++++
   1 file changed, 248 insertions(+)
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +24 -0
index e7ce027cc14e..3b3578318cc1 100644
@@ -8,6 +8,193 @@
   #include <linux/device.h>
   #include <linux/of_irq.h>
   #include "stmmac.h"
+#include "dwmac_dma.h"
+#include "dwmac1000.h"
+
+#define DMA_INTR_ENA_NIE_TX_LOONGSON 0x00040000	/* Normal Loongson Tx Summary */
+#define DMA_INTR_ENA_NIE_RX_LOONGSON 0x00020000	/* Normal Loongson Rx Summary */
+#define DMA_INTR_NORMAL_LOONGSON	(DMA_INTR_ENA_NIE_TX_LOONGSON | \
+			 DMA_INTR_ENA_NIE_RX_LOONGSON | DMA_INTR_ENA_RIE | \
+			 DMA_INTR_ENA_TIE)
+
+#define DMA_INTR_ENA_AIE_TX_LOONGSON 0x00010000	/* Abnormal Loongson Tx Summary */
+#define DMA_INTR_ENA_AIE_RX_LOONGSON 0x00008000	/* Abnormal Loongson Rx Summary */
+
+#define DMA_INTR_ABNORMAL_LOONGSON	(DMA_INTR_ENA_AIE_TX_LOONGSON | \
+				DMA_INTR_ENA_AIE_RX_LOONGSON | DMA_INTR_ENA_FBE | \
+				DMA_INTR_ENA_UNE)
+
+#define DMA_INTR_DEFAULT_MASK_LOONGSON	(DMA_INTR_NORMAL_LOONGSON | DMA_INTR_ABNORMAL_LOONGSON)
+
+#define DMA_STATUS_NIS_TX_LOONGSON	0x00040000	/* Normal Loongson Tx Interrupt Summary */
+#define DMA_STATUS_NIS_RX_LOONGSON	0x00020000	/* Normal Loongson Rx Interrupt Summary */
+
+#define DMA_STATUS_AIS_TX_LOONGSON	0x00010000	/* Abnormal Loongson Tx Interrupt Summary */
+#define DMA_STATUS_AIS_RX_LOONGSON	0x00008000	/* Abnormal Loongson Rx Interrupt Summary */
+
Quoted 8 lines

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c line 41

Quoted 7 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +7 -0
+#define DMA_STATUS_FBI_TX_LOONGSON	0x00002000	/* Fatal Loongson Tx Bus Error Interrupt */
+#define DMA_STATUS_FBI_RX_LOONGSON	0x00001000	/* Fatal Loongson Rx Bus Error Interrupt */
+
+#define DMA_STATUS_MSK_COMMON_LOONGSON		(DMA_STATUS_NIS_TX_LOONGSON | \
+					 DMA_STATUS_NIS_RX_LOONGSON | DMA_STATUS_AIS_TX_LOONGSON | \
+					 DMA_STATUS_AIS_RX_LOONGSON | DMA_STATUS_FBI_TX_LOONGSON | \
+					 DMA_STATUS_FBI_RX_LOONGSON)

Max 80 chars per line please.

OK,

Quoted 24 lines
Quoted 11 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +11 -0
+
+#define DMA_STATUS_MSK_RX_LOONGSON		(DMA_STATUS_ERI | \
+					 DMA_STATUS_RWT | \
+					 DMA_STATUS_RPS | \
+					 DMA_STATUS_RU | \
+					 DMA_STATUS_RI | \
+					 DMA_STATUS_OVF | \
+					 DMA_STATUS_MSK_COMMON_LOONGSON)
+
+#define DMA_STATUS_MSK_TX_LOONGSON		(DMA_STATUS_ETI | \
+					 DMA_STATUS_UNF | \

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c line 62

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +10 -0
+					 DMA_STATUS_TJT | \
+					 DMA_STATUS_TU | \
+					 DMA_STATUS_TPS | \
+					 DMA_STATUS_TI | \
+					 DMA_STATUS_MSK_COMMON_LOONGSON)
+
+struct loongson_data {
+	struct device *dev;
+	u32 lgmac_version;
+	struct stmmac_dma_ops dwlgmac_dma_ops;

Just figured out we can do without this field being added to the private data. See my note in the loongson_setup() method.

Quoted 7 lines

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c line 65

Quoted 3 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +3 -0
+};
+
+static void dwlgmac_dma_init_channel(struct stmmac_priv *priv,

The "dwlgmac_" prefix is confusing. There is the DW XLGMAC IP-core for which the "dwxlgmac_" is more appropriate and "x" is easy to miss should your version of the prefix is met. Consider changing it to something like "loongson_gnet_".

OK,

Quoted 55 lines
Quoted 32 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +32 -0
+				     void __iomem *ioaddr,
+				     struct stmmac_dma_cfg *dma_cfg, u32 chan)
+{
+	u32 value;
+	int txpbl = dma_cfg->txpbl ?: dma_cfg->pbl;
+	int rxpbl = dma_cfg->rxpbl ?: dma_cfg->pbl;
+
+	/* common channel control register config */
+	value = readl(ioaddr + DMA_CHAN_BUS_MODE(chan));
+
+	/* Set the DMA PBL (Programmable Burst Length) mode.
+	 *
+	 * Note: before stmmac core 3.50 this mode bit was 4xPBL, and
+	 * post 3.5 mode bit acts as 8*PBL.
+	 */
+	if (dma_cfg->pblx8)
+		value |= DMA_BUS_MODE_MAXPBL;
+	value |= DMA_BUS_MODE_USP;
+	value &= ~(DMA_BUS_MODE_PBL_MASK | DMA_BUS_MODE_RPBL_MASK);
+	value |= (txpbl << DMA_BUS_MODE_PBL_SHIFT);
+	value |= (rxpbl << DMA_BUS_MODE_RPBL_SHIFT);
+
+	/* Set the Fixed burst mode */
+	if (dma_cfg->fixed_burst)
+		value |= DMA_BUS_MODE_FB;
+
+	/* Mixed Burst has no effect when fb is set */
+	if (dma_cfg->mixed_burst)
+		value |= DMA_BUS_MODE_MB;
+
+	value |= DMA_BUS_MODE_ATDS;
+

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c line 107

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +10 -0
+	if (dma_cfg->aal)
+		value |= DMA_BUS_MODE_AAL;
+
+	writel(value, ioaddr + DMA_BUS_MODE);
+
+	/* Mask interrupts by writing to CSR7 */
+	writel(DMA_INTR_DEFAULT_MASK_LOONGSON, ioaddr + DMA_INTR_ENA);
+}
+
+static int dwlgmac_dma_interrupt(struct stmmac_priv *priv, void __iomem *ioaddr,

The same note as above.

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c line 116

Quoted 9 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +9 -0
+				 struct stmmac_extra_stats *x, u32 chan, u32 dir)
+{
+	struct stmmac_rxq_stats *rxq_stats = &priv->xstats.rxq_stats[chan];
+	struct stmmac_txq_stats *txq_stats = &priv->xstats.txq_stats[chan];
+	int ret = 0;
+	/* read the status register (CSR5) */
+	u32 nor_intr_status;
+	u32 abnor_intr_status;
+	u32 fb_intr_status;

Reverse xmas tree please.

Quoted 2 lines

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c line 117

Quoted 1 line
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +1 -0
+	u32 intr_status = readl(ioaddr + DMA_CHAN_STATUS(chan));

Please move the initialization into a separate statement.

OK,

Quoted 107 lines

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c line 124

Quoted 7 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +7 -0
+
+#ifdef DWMAC_DMA_DEBUG
+	/* Enable it to monitor DMA rx/tx status in case of critical problems */
+	pr_debug("%s: [CSR5: 0x%08x]\n", __func__, intr_status);
+	show_tx_process_state(intr_status);
+	show_rx_process_state(intr_status);
+#endif

This will cause a build-error if DWMAC_DMA_DEBUG is defined. Just drop it.
OK,

Quoted 76 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +73 -0
+
+	if (dir == DMA_DIR_RX)
+		intr_status &= DMA_STATUS_MSK_RX_LOONGSON;
+	else if (dir == DMA_DIR_TX)
+		intr_status &= DMA_STATUS_MSK_TX_LOONGSON;
+
+	nor_intr_status = intr_status & (DMA_STATUS_NIS_TX_LOONGSON |
+		DMA_STATUS_NIS_RX_LOONGSON);
+	abnor_intr_status = intr_status & (DMA_STATUS_AIS_TX_LOONGSON |
+		DMA_STATUS_AIS_RX_LOONGSON);
+	fb_intr_status = intr_status & (DMA_STATUS_FBI_TX_LOONGSON |
+		DMA_STATUS_FBI_RX_LOONGSON);
+
+	/* ABNORMAL interrupts */
+	if (unlikely(abnor_intr_status)) {
+		if (unlikely(intr_status & DMA_STATUS_UNF)) {
+			ret = tx_hard_error_bump_tc;
+			x->tx_undeflow_irq++;
+		}
+		if (unlikely(intr_status & DMA_STATUS_TJT))
+			x->tx_jabber_irq++;
+
+		if (unlikely(intr_status & DMA_STATUS_OVF))
+			x->rx_overflow_irq++;
+
+		if (unlikely(intr_status & DMA_STATUS_RU))
+			x->rx_buf_unav_irq++;
+		if (unlikely(intr_status & DMA_STATUS_RPS))
+			x->rx_process_stopped_irq++;
+		if (unlikely(intr_status & DMA_STATUS_RWT))
+			x->rx_watchdog_irq++;
+		if (unlikely(intr_status & DMA_STATUS_ETI))
+			x->tx_early_irq++;
+		if (unlikely(intr_status & DMA_STATUS_TPS)) {
+			x->tx_process_stopped_irq++;
+			ret = tx_hard_error;
+		}
+		if (unlikely(intr_status & fb_intr_status)) {
+			x->fatal_bus_error_irq++;
+			ret = tx_hard_error;
+		}
+	}
+	/* TX/RX NORMAL interrupts */
+	if (likely(nor_intr_status)) {
+		if (likely(intr_status & DMA_STATUS_RI)) {
+			u32 value = readl(ioaddr + DMA_INTR_ENA);
+			/* to schedule NAPI on real RIE event. */
+			if (likely(value & DMA_INTR_ENA_RIE)) {
+				u64_stats_update_begin(&rxq_stats->syncp);
+				rxq_stats->rx_normal_irq_n++;
+				u64_stats_update_end(&rxq_stats->syncp);
+				ret |= handle_rx;
+			}
+		}
+		if (likely(intr_status & DMA_STATUS_TI)) {
+			u64_stats_update_begin(&txq_stats->syncp);
+			txq_stats->tx_normal_irq_n++;
+			u64_stats_update_end(&txq_stats->syncp);
+			ret |= handle_tx;
+		}
+		if (unlikely(intr_status & DMA_STATUS_ERI))
+			x->rx_early_irq++;
+	}
+	/* Optional hardware blocks, interrupts should be disabled */
+	if (unlikely(intr_status &
+		     (DMA_STATUS_GPI | DMA_STATUS_GMI | DMA_STATUS_GLI)))
+		pr_warn("%s: unexpected status %08x\n", __func__, intr_status);
+
+	/* Clear the interrupt by writing a logic 1 to the CSR5[15-0] */
+	writel((intr_status & 0x7ffff), ioaddr + DMA_CHAN_STATUS(chan));
+
+	return ret;
+}
   struct stmmac_pci_info {
   	int (*setup)(struct pci_dev *pdev, struct plat_stmmacenet_data *plat);

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static struct stmmac_pci_info loongson_gmac_pci_info = { · line 310

Quoted 3 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +1 -0
@@ -121,6 +308,48 @@ static struct stmmac_pci_info loongson_gmac_pci_info = {
   	.config = loongson_gmac_config,
   };
+static struct mac_device_info *loongson_setup(void *apriv)

Consider using the GNET-specific prefix, like "loongson_gnet_".

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static struct stmmac_pci_info loongson_gmac_pci_info = { · line 319

Quoted 8 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +8 -0
+{
+	struct stmmac_priv *priv = apriv;
+	struct mac_device_info *mac;
+	struct loongson_data *ld;
+
+	mac = devm_kzalloc(priv->device, sizeof(*mac), GFP_KERNEL);
+	if (!mac)
+		return NULL;

What about devm_kzalloc()-ing the stmmac_dma_ops instance here and initializing it as it's done in the probe method? Thus ...

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static struct stmmac_pci_info loongson_gmac_pci_info = { · line 322

Quoted 3 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +3 -0
+
+	ld = priv->plat->bsp_priv;
+	mac->dma = &ld->dwlgmac_dma_ops;

... this can be replaced with:

Quoted 6 lines
Quoted 4 lines
Quoted 3 lines
	mac->dma = devm_kzalloc(priv->device, sizeof(*mac->dma), GFP_KERNEL);
	if (!mac->dma)
		return -ENOMEM;

Great, but It seems that we cannot return an int value here.

Just

		return NULL;

OK,

Quoted 5 lines

then.

Quoted 3 lines
Quoted 3 lines
	*mac->dma = dwmac1000_dma_ops;
	mac->dma->init_chan = loongson_gnet_dma_init_channel;
	mac->dma->dma_interrupt = loongson_gnet_dma_interrupt;

It seems that we still cannot do this because: structmac_device_info{
...
conststructstmmac_mmc_ops*mmc;
...
}
some errors output:
error: assignment of read-only location '*mac->dma'
error: assignment of member 'init_chan' in read-only object
...
Thanks,
Yanteng

Quoted 101 lines
Quoted 70 lines
Quoted 52 lines
Quoted 35 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +30 -0
+
+	/* Pre-initialize the respective "mac" fields as it's done in
+	 * dwmac1000_setup()
+	 */
+	priv->dev->priv_flags |= IFF_UNICAST_FLT;
+	mac->pcsr = priv->ioaddr;
+	mac->multicast_filter_bins = priv->plat->multicast_filter_bins;
+	mac->unicast_filter_entries = priv->plat->unicast_filter_entries;
+	mac->mcast_bits_log2 = 0;
+
+	if (mac->multicast_filter_bins)
+		mac->mcast_bits_log2 = ilog2(mac->multicast_filter_bins);
+
+	mac->link.duplex = GMAC_CONTROL_DM;
+	mac->link.speed10 = GMAC_CONTROL_PS;
+	mac->link.speed100 = GMAC_CONTROL_PS | GMAC_CONTROL_FES;
+	mac->link.speed1000 = 0;
+	mac->link.speed_mask = GMAC_CONTROL_PS | GMAC_CONTROL_FES;
+	mac->mii.addr = GMAC_MII_ADDR;
+	mac->mii.data = GMAC_MII_DATA;
+	mac->mii.addr_shift = 11;
+	mac->mii.addr_mask = 0x0000F800;
+	mac->mii.reg_shift = 6;
+	mac->mii.reg_mask = 0x000007C0;
+	mac->mii.clk_csr_shift = 2;
+	mac->mii.clk_csr_mask = GENMASK(5, 2);
+
+	return mac;
+}
+
   static int loongson_dwmac_probe(struct pci_dev *pdev,
   				const struct pci_device_id *id)
   {

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int loongson_dwmac_probe(struct pci_dev *pdev, · line 361

Quoted 4 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +1 -0
@@ -129,6 +358,7 @@ static int loongson_dwmac_probe(struct pci_dev *pdev,
   	struct stmmac_pci_info *info;
   	struct stmmac_resources res;
   	struct device_node *np;
+	struct loongson_data *ld;

reverse xmas tree order please.

Quoted 11 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +4 -0
   	plat = devm_kzalloc(&pdev->dev, sizeof(*plat), GFP_KERNEL);
   	if (!plat)
@@ -145,6 +375,10 @@ static int loongson_dwmac_probe(struct pci_dev *pdev,
   	if (!plat->dma_cfg)
   		return -ENOMEM;
+	ld = devm_kzalloc(&pdev->dev, sizeof(*ld), GFP_KERNEL);
+	if (!ld)
+		return -ENOMEM;
+
   	np = dev_of_node(&pdev->dev);
   	plat->mdio_node = of_get_child_by_name(np, "mdio");
Quoted 8 lines

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int loongson_dwmac_probe(struct pci_dev *pdev, · line 434

Quoted 6 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +2 -0
   	if (plat->mdio_node) {
@@ -197,6 +431,20 @@ static int loongson_dwmac_probe(struct pci_dev *pdev,
   	if (ret)
   		goto err_disable_device;
+	ld->dev = &pdev->dev;
+	ld->lgmac_version = readl(res.addr + GMAC_VERSION) & 0xff;

AFAICS the lgmac_version is unused in out of the probe() method context. What about locally defining it?

OK,

Quoted 4 lines

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int loongson_dwmac_probe(struct pci_dev *pdev, · line 438

Quoted 3 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +3 -0
+
+	/* Activate loongson custom ip */
+	if (ld->lgmac_version < DWMAC_CORE_3_50) {

Please define a new macro for the GNET MAC.

OK.

Quoted 4 lines

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int loongson_dwmac_probe(struct pci_dev *pdev, · line 441

Quoted 3 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +3 -0
+		ld->dwlgmac_dma_ops = dwmac1000_dma_ops;
+		ld->dwlgmac_dma_ops.init_chan = dwlgmac_dma_init_channel;
+		ld->dwlgmac_dma_ops.dma_interrupt = dwlgmac_dma_interrupt;

See my comment in the loongson_setup() method.

Quoted 6 lines

This will introduce a compilation warning:

warning: returning 'int' from a function with return type 'struct mac_device_info *' makes pointer from integer without a cast [-Wint-conversion]
  418 |                 return -ENOMEM;

stmmac_hwif_init() expects priv->plat->setup(priv) returning NULL if something wrong. As I suggested above just return NULL then if mac_device_info couldn't be allocated.

-Serge(y)

Quoted 19 lines

Thanks,

Yanteng

Quoted 14 lines

-Serge(y)

Quoted 12 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +6 -0
+
+		plat->setup = loongson_setup;
+	}
+
+	plat->bsp_priv = ld;
+
   	ret = stmmac_dvr_probe(&pdev->dev, plat, &res);
   	if (ret)
   		goto err_disable_device;
Signature · 1 line
2.31.4
#34 lore raw

Re: [PATCH net-next v8 05/11] net: stmmac: dwmac-loongson: Add Loongson-specific register definitions

Quoted 302 lines · Yanteng Si

Hi Serge,

Quoted 287 lines · Serge Semin
Quoted 286 lines · Yanteng Si
Quoted 79 lines · Serge Semin
Quoted 78 lines · Yanteng Si

There are two types of Loongson DWGMAC. The first type shares the same register definitions and has similar logic as dwmac1000. The second type uses several different register definitions, we think it is necessary to distinguish rx and tx, so we split these bits into two.

Simply put, we split some single bit fields into double bits fileds:

Name Tx Rx

DMA_INTR_ENA_NIE = 0x00040000 | 0x00020000;
DMA_INTR_ENA_AIE = 0x00010000 | 0x00008000;
DMA_STATUS_NIS   = 0x00040000 | 0x00020000;
DMA_STATUS_AIS   = 0x00010000 | 0x00008000;
DMA_STATUS_FBI   = 0x00002000 | 0x00001000;

Therefore, when using, TX and RX must be set at the same time.

How to use them:
1. Create the Loongson GNET-specific stmmac_dma_ops.dma_interrupt() stmmac_dma_ops.init_chan()
methods in the dwmac-loongson.c driver. Adding all the Loongson-specific macros

2. Create a Loongson GNET-specific platform setup method with the next semantics:
+ allocate stmmac_dma_ops instance and initialize it with dwmac1000_dma_ops.
+ override the stmmac_dma_ops.{dma_interrupt, init_chan} with the pointers to the methods defined in 2.
+ allocate mac_device_info instance and initialize the mac_device_info.dma field with a pointer to the new stmmac_dma_ops instance.
+ initialize mac_device_info in a way it's done in dwmac1000_setup().

3. Initialize plat_stmmacenet_data.setup() with the pointer to the method created in 2.

---
   .../ethernet/stmicro/stmmac/dwmac-loongson.c  | 248 ++++++++++++++++++
   1 file changed, 248 insertions(+)
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +24 -0
index e7ce027cc14e..3b3578318cc1 100644
@@ -8,6 +8,193 @@
   #include <linux/device.h>
   #include <linux/of_irq.h>
   #include "stmmac.h"
+#include "dwmac_dma.h"
+#include "dwmac1000.h"
+
+#define DMA_INTR_ENA_NIE_TX_LOONGSON 0x00040000	/* Normal Loongson Tx Summary */
+#define DMA_INTR_ENA_NIE_RX_LOONGSON 0x00020000	/* Normal Loongson Rx Summary */
+#define DMA_INTR_NORMAL_LOONGSON	(DMA_INTR_ENA_NIE_TX_LOONGSON | \
+			 DMA_INTR_ENA_NIE_RX_LOONGSON | DMA_INTR_ENA_RIE | \
+			 DMA_INTR_ENA_TIE)
+
+#define DMA_INTR_ENA_AIE_TX_LOONGSON 0x00010000	/* Abnormal Loongson Tx Summary */
+#define DMA_INTR_ENA_AIE_RX_LOONGSON 0x00008000	/* Abnormal Loongson Rx Summary */
+
+#define DMA_INTR_ABNORMAL_LOONGSON	(DMA_INTR_ENA_AIE_TX_LOONGSON | \
+				DMA_INTR_ENA_AIE_RX_LOONGSON | DMA_INTR_ENA_FBE | \
+				DMA_INTR_ENA_UNE)
+
+#define DMA_INTR_DEFAULT_MASK_LOONGSON	(DMA_INTR_NORMAL_LOONGSON | DMA_INTR_ABNORMAL_LOONGSON)
+
+#define DMA_STATUS_NIS_TX_LOONGSON	0x00040000	/* Normal Loongson Tx Interrupt Summary */
+#define DMA_STATUS_NIS_RX_LOONGSON	0x00020000	/* Normal Loongson Rx Interrupt Summary */
+
+#define DMA_STATUS_AIS_TX_LOONGSON	0x00010000	/* Abnormal Loongson Tx Interrupt Summary */
+#define DMA_STATUS_AIS_RX_LOONGSON	0x00008000	/* Abnormal Loongson Rx Interrupt Summary */
+
Quoted 8 lines

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c line 41

Quoted 7 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +7 -0
+#define DMA_STATUS_FBI_TX_LOONGSON	0x00002000	/* Fatal Loongson Tx Bus Error Interrupt */
+#define DMA_STATUS_FBI_RX_LOONGSON	0x00001000	/* Fatal Loongson Rx Bus Error Interrupt */
+
+#define DMA_STATUS_MSK_COMMON_LOONGSON		(DMA_STATUS_NIS_TX_LOONGSON | \
+					 DMA_STATUS_NIS_RX_LOONGSON | DMA_STATUS_AIS_TX_LOONGSON | \
+					 DMA_STATUS_AIS_RX_LOONGSON | DMA_STATUS_FBI_TX_LOONGSON | \
+					 DMA_STATUS_FBI_RX_LOONGSON)

Max 80 chars per line please.

OK,

Quoted 24 lines
Quoted 11 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +11 -0
+
+#define DMA_STATUS_MSK_RX_LOONGSON		(DMA_STATUS_ERI | \
+					 DMA_STATUS_RWT | \
+					 DMA_STATUS_RPS | \
+					 DMA_STATUS_RU | \
+					 DMA_STATUS_RI | \
+					 DMA_STATUS_OVF | \
+					 DMA_STATUS_MSK_COMMON_LOONGSON)
+
+#define DMA_STATUS_MSK_TX_LOONGSON		(DMA_STATUS_ETI | \
+					 DMA_STATUS_UNF | \

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c line 62

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +10 -0
+					 DMA_STATUS_TJT | \
+					 DMA_STATUS_TU | \
+					 DMA_STATUS_TPS | \
+					 DMA_STATUS_TI | \
+					 DMA_STATUS_MSK_COMMON_LOONGSON)
+
+struct loongson_data {
+	struct device *dev;
+	u32 lgmac_version;
+	struct stmmac_dma_ops dwlgmac_dma_ops;

Just figured out we can do without this field being added to the private data. See my note in the loongson_setup() method.

Quoted 7 lines

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c line 65

Quoted 3 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +3 -0
+};
+
+static void dwlgmac_dma_init_channel(struct stmmac_priv *priv,

The "dwlgmac_" prefix is confusing. There is the DW XLGMAC IP-core for which the "dwxlgmac_" is more appropriate and "x" is easy to miss should your version of the prefix is met. Consider changing it to something like "loongson_gnet_".

OK,

Quoted 55 lines
Quoted 32 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +32 -0
+				     void __iomem *ioaddr,
+				     struct stmmac_dma_cfg *dma_cfg, u32 chan)
+{
+	u32 value;
+	int txpbl = dma_cfg->txpbl ?: dma_cfg->pbl;
+	int rxpbl = dma_cfg->rxpbl ?: dma_cfg->pbl;
+
+	/* common channel control register config */
+	value = readl(ioaddr + DMA_CHAN_BUS_MODE(chan));
+
+	/* Set the DMA PBL (Programmable Burst Length) mode.
+	 *
+	 * Note: before stmmac core 3.50 this mode bit was 4xPBL, and
+	 * post 3.5 mode bit acts as 8*PBL.
+	 */
+	if (dma_cfg->pblx8)
+		value |= DMA_BUS_MODE_MAXPBL;
+	value |= DMA_BUS_MODE_USP;
+	value &= ~(DMA_BUS_MODE_PBL_MASK | DMA_BUS_MODE_RPBL_MASK);
+	value |= (txpbl << DMA_BUS_MODE_PBL_SHIFT);
+	value |= (rxpbl << DMA_BUS_MODE_RPBL_SHIFT);
+
+	/* Set the Fixed burst mode */
+	if (dma_cfg->fixed_burst)
+		value |= DMA_BUS_MODE_FB;
+
+	/* Mixed Burst has no effect when fb is set */
+	if (dma_cfg->mixed_burst)
+		value |= DMA_BUS_MODE_MB;
+
+	value |= DMA_BUS_MODE_ATDS;
+

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c line 107

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +10 -0
+	if (dma_cfg->aal)
+		value |= DMA_BUS_MODE_AAL;
+
+	writel(value, ioaddr + DMA_BUS_MODE);
+
+	/* Mask interrupts by writing to CSR7 */
+	writel(DMA_INTR_DEFAULT_MASK_LOONGSON, ioaddr + DMA_INTR_ENA);
+}
+
+static int dwlgmac_dma_interrupt(struct stmmac_priv *priv, void __iomem *ioaddr,

The same note as above.

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c line 116

Quoted 9 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +9 -0
+				 struct stmmac_extra_stats *x, u32 chan, u32 dir)
+{
+	struct stmmac_rxq_stats *rxq_stats = &priv->xstats.rxq_stats[chan];
+	struct stmmac_txq_stats *txq_stats = &priv->xstats.txq_stats[chan];
+	int ret = 0;
+	/* read the status register (CSR5) */
+	u32 nor_intr_status;
+	u32 abnor_intr_status;
+	u32 fb_intr_status;

Reverse xmas tree please.

Quoted 2 lines

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c line 117

Quoted 1 line
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +1 -0
+	u32 intr_status = readl(ioaddr + DMA_CHAN_STATUS(chan));

Please move the initialization into a separate statement.

OK,

Quoted 107 lines

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c line 124

Quoted 7 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +7 -0
+
+#ifdef DWMAC_DMA_DEBUG
+	/* Enable it to monitor DMA rx/tx status in case of critical problems */
+	pr_debug("%s: [CSR5: 0x%08x]\n", __func__, intr_status);
+	show_tx_process_state(intr_status);
+	show_rx_process_state(intr_status);
+#endif

This will cause a build-error if DWMAC_DMA_DEBUG is defined. Just drop it.
OK,

Quoted 76 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +73 -0
+
+	if (dir == DMA_DIR_RX)
+		intr_status &= DMA_STATUS_MSK_RX_LOONGSON;
+	else if (dir == DMA_DIR_TX)
+		intr_status &= DMA_STATUS_MSK_TX_LOONGSON;
+
+	nor_intr_status = intr_status & (DMA_STATUS_NIS_TX_LOONGSON |
+		DMA_STATUS_NIS_RX_LOONGSON);
+	abnor_intr_status = intr_status & (DMA_STATUS_AIS_TX_LOONGSON |
+		DMA_STATUS_AIS_RX_LOONGSON);
+	fb_intr_status = intr_status & (DMA_STATUS_FBI_TX_LOONGSON |
+		DMA_STATUS_FBI_RX_LOONGSON);
+
+	/* ABNORMAL interrupts */
+	if (unlikely(abnor_intr_status)) {
+		if (unlikely(intr_status & DMA_STATUS_UNF)) {
+			ret = tx_hard_error_bump_tc;
+			x->tx_undeflow_irq++;
+		}
+		if (unlikely(intr_status & DMA_STATUS_TJT))
+			x->tx_jabber_irq++;
+
+		if (unlikely(intr_status & DMA_STATUS_OVF))
+			x->rx_overflow_irq++;
+
+		if (unlikely(intr_status & DMA_STATUS_RU))
+			x->rx_buf_unav_irq++;
+		if (unlikely(intr_status & DMA_STATUS_RPS))
+			x->rx_process_stopped_irq++;
+		if (unlikely(intr_status & DMA_STATUS_RWT))
+			x->rx_watchdog_irq++;
+		if (unlikely(intr_status & DMA_STATUS_ETI))
+			x->tx_early_irq++;
+		if (unlikely(intr_status & DMA_STATUS_TPS)) {
+			x->tx_process_stopped_irq++;
+			ret = tx_hard_error;
+		}
+		if (unlikely(intr_status & fb_intr_status)) {
+			x->fatal_bus_error_irq++;
+			ret = tx_hard_error;
+		}
+	}
+	/* TX/RX NORMAL interrupts */
+	if (likely(nor_intr_status)) {
+		if (likely(intr_status & DMA_STATUS_RI)) {
+			u32 value = readl(ioaddr + DMA_INTR_ENA);
+			/* to schedule NAPI on real RIE event. */
+			if (likely(value & DMA_INTR_ENA_RIE)) {
+				u64_stats_update_begin(&rxq_stats->syncp);
+				rxq_stats->rx_normal_irq_n++;
+				u64_stats_update_end(&rxq_stats->syncp);
+				ret |= handle_rx;
+			}
+		}
+		if (likely(intr_status & DMA_STATUS_TI)) {
+			u64_stats_update_begin(&txq_stats->syncp);
+			txq_stats->tx_normal_irq_n++;
+			u64_stats_update_end(&txq_stats->syncp);
+			ret |= handle_tx;
+		}
+		if (unlikely(intr_status & DMA_STATUS_ERI))
+			x->rx_early_irq++;
+	}
+	/* Optional hardware blocks, interrupts should be disabled */
+	if (unlikely(intr_status &
+		     (DMA_STATUS_GPI | DMA_STATUS_GMI | DMA_STATUS_GLI)))
+		pr_warn("%s: unexpected status %08x\n", __func__, intr_status);
+
+	/* Clear the interrupt by writing a logic 1 to the CSR5[15-0] */
+	writel((intr_status & 0x7ffff), ioaddr + DMA_CHAN_STATUS(chan));
+
+	return ret;
+}
   struct stmmac_pci_info {
   	int (*setup)(struct pci_dev *pdev, struct plat_stmmacenet_data *plat);

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static struct stmmac_pci_info loongson_gmac_pci_info = { · line 310

Quoted 3 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +1 -0
@@ -121,6 +308,48 @@ static struct stmmac_pci_info loongson_gmac_pci_info = {
   	.config = loongson_gmac_config,
   };
+static struct mac_device_info *loongson_setup(void *apriv)

Consider using the GNET-specific prefix, like "loongson_gnet_".

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static struct stmmac_pci_info loongson_gmac_pci_info = { · line 319

Quoted 8 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +8 -0
+{
+	struct stmmac_priv *priv = apriv;
+	struct mac_device_info *mac;
+	struct loongson_data *ld;
+
+	mac = devm_kzalloc(priv->device, sizeof(*mac), GFP_KERNEL);
+	if (!mac)
+		return NULL;

What about devm_kzalloc()-ing the stmmac_dma_ops instance here and initializing it as it's done in the probe method? Thus ...

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static struct stmmac_pci_info loongson_gmac_pci_info = { · line 322

Quoted 3 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +3 -0
+
+	ld = priv->plat->bsp_priv;
+	mac->dma = &ld->dwlgmac_dma_ops;

... this can be replaced with:

Quoted 6 lines
Quoted 4 lines
Quoted 3 lines
	mac->dma = devm_kzalloc(priv->device, sizeof(*mac->dma), GFP_KERNEL);
	if (!mac->dma)
		return -ENOMEM;

Great, but It seems that we cannot return an int value here.

Just

		return NULL;

OK,

Quoted 5 lines

then.

Quoted 3 lines
Quoted 3 lines
	*mac->dma = dwmac1000_dma_ops;
	mac->dma->init_chan = loongson_gnet_dma_init_channel;
	mac->dma->dma_interrupt = loongson_gnet_dma_interrupt;
Quoted 10 lines

It seems that we still cannot do this because: structmac_device_info{
...
conststructstmmac_mmc_ops*mmc;
...
}
some errors output:
error: assignment of read-only location '*mac->dma'
error: assignment of member 'init_chan' in read-only object
...

No, we can. Just use a temporary non-const pointer to stmmac_dma_ops:

+static struct mac_device_info *loongson_gnet_setup(void *apriv) +{
+ struct stmmac_priv *priv = apriv;
+ struct mac_device_info *mac;
+ struct stmmac_dma_ops *dma;
+ struct loongson_data *ld;
+
+ mac = devm_kzalloc(priv->device, sizeof(*mac), GFP_KERNEL);
+ if (!mac)
+ return NULL;
+
+ dma = devm_kzalloc(priv->device, sizeof(*dma), GFP_KERNEL);
+ if (!mac->dma)
+ return NULL;
+
+ *dma = dwmac1000_dma_ops;
+ dma->init_chan = loongson_gnet_dma_init_channel;
+ dma->dma_interrupt = loongson_gnet_dma_interrupt;
+ mac->dma = dma;
+
+ ...

-Serge(y)

Quoted 104 lines

Thanks,
Yanteng

Quoted 101 lines
Quoted 70 lines
Quoted 52 lines
Quoted 35 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +30 -0
+
+	/* Pre-initialize the respective "mac" fields as it's done in
+	 * dwmac1000_setup()
+	 */
+	priv->dev->priv_flags |= IFF_UNICAST_FLT;
+	mac->pcsr = priv->ioaddr;
+	mac->multicast_filter_bins = priv->plat->multicast_filter_bins;
+	mac->unicast_filter_entries = priv->plat->unicast_filter_entries;
+	mac->mcast_bits_log2 = 0;
+
+	if (mac->multicast_filter_bins)
+		mac->mcast_bits_log2 = ilog2(mac->multicast_filter_bins);
+
+	mac->link.duplex = GMAC_CONTROL_DM;
+	mac->link.speed10 = GMAC_CONTROL_PS;
+	mac->link.speed100 = GMAC_CONTROL_PS | GMAC_CONTROL_FES;
+	mac->link.speed1000 = 0;
+	mac->link.speed_mask = GMAC_CONTROL_PS | GMAC_CONTROL_FES;
+	mac->mii.addr = GMAC_MII_ADDR;
+	mac->mii.data = GMAC_MII_DATA;
+	mac->mii.addr_shift = 11;
+	mac->mii.addr_mask = 0x0000F800;
+	mac->mii.reg_shift = 6;
+	mac->mii.reg_mask = 0x000007C0;
+	mac->mii.clk_csr_shift = 2;
+	mac->mii.clk_csr_mask = GENMASK(5, 2);
+
+	return mac;
+}
+
   static int loongson_dwmac_probe(struct pci_dev *pdev,
   				const struct pci_device_id *id)
   {

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int loongson_dwmac_probe(struct pci_dev *pdev, · line 361

Quoted 4 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +1 -0
@@ -129,6 +358,7 @@ static int loongson_dwmac_probe(struct pci_dev *pdev,
   	struct stmmac_pci_info *info;
   	struct stmmac_resources res;
   	struct device_node *np;
+	struct loongson_data *ld;

reverse xmas tree order please.

Quoted 11 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +4 -0
   	plat = devm_kzalloc(&pdev->dev, sizeof(*plat), GFP_KERNEL);
   	if (!plat)
@@ -145,6 +375,10 @@ static int loongson_dwmac_probe(struct pci_dev *pdev,
   	if (!plat->dma_cfg)
   		return -ENOMEM;
+	ld = devm_kzalloc(&pdev->dev, sizeof(*ld), GFP_KERNEL);
+	if (!ld)
+		return -ENOMEM;
+
   	np = dev_of_node(&pdev->dev);
   	plat->mdio_node = of_get_child_by_name(np, "mdio");
Quoted 8 lines

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int loongson_dwmac_probe(struct pci_dev *pdev, · line 434

Quoted 6 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +2 -0
   	if (plat->mdio_node) {
@@ -197,6 +431,20 @@ static int loongson_dwmac_probe(struct pci_dev *pdev,
   	if (ret)
   		goto err_disable_device;
+	ld->dev = &pdev->dev;
+	ld->lgmac_version = readl(res.addr + GMAC_VERSION) & 0xff;

AFAICS the lgmac_version is unused in out of the probe() method context. What about locally defining it?

OK,

Quoted 4 lines

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int loongson_dwmac_probe(struct pci_dev *pdev, · line 438

Quoted 3 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +3 -0
+
+	/* Activate loongson custom ip */
+	if (ld->lgmac_version < DWMAC_CORE_3_50) {

Please define a new macro for the GNET MAC.

OK.

Quoted 4 lines

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int loongson_dwmac_probe(struct pci_dev *pdev, · line 441

Quoted 3 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +3 -0
+		ld->dwlgmac_dma_ops = dwmac1000_dma_ops;
+		ld->dwlgmac_dma_ops.init_chan = dwlgmac_dma_init_channel;
+		ld->dwlgmac_dma_ops.dma_interrupt = dwlgmac_dma_interrupt;

See my comment in the loongson_setup() method.

Quoted 6 lines

This will introduce a compilation warning:

warning: returning 'int' from a function with return type 'struct mac_device_info *' makes pointer from integer without a cast [-Wint-conversion]
  418 |                 return -ENOMEM;

stmmac_hwif_init() expects priv->plat->setup(priv) returning NULL if something wrong. As I suggested above just return NULL then if mac_device_info couldn't be allocated.

-Serge(y)

Quoted 19 lines

Thanks,

Yanteng

Quoted 14 lines

-Serge(y)

Quoted 12 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +6 -0
+
+		plat->setup = loongson_setup;
+	}
+
+	plat->bsp_priv = ld;
+
   	ret = stmmac_dvr_probe(&pdev->dev, plat, &res);
   	if (ret)
   		goto err_disable_device;
Signature · 1 line
2.31.4
author
#35 lore raw

Re: [PATCH net-next v8 05/11] net: stmmac: dwmac-loongson: Add Loongson-specific register definitions

Hi Serge,

Sorry for keeping you waiting for so long.

Quoted 318 lines · Serge Semin
Quoted 302 lines · Yanteng Si

Hi Serge,

Quoted 287 lines · Serge Semin
Quoted 286 lines · Yanteng Si
Quoted 79 lines · Serge Semin
Quoted 78 lines · Yanteng Si

There are two types of Loongson DWGMAC. The first type shares the same register definitions and has similar logic as dwmac1000. The second type uses several different register definitions, we think it is necessary to distinguish rx and tx, so we split these bits into two.

Simply put, we split some single bit fields into double bits fileds:

Name Tx Rx

DMA_INTR_ENA_NIE = 0x00040000 | 0x00020000;
DMA_INTR_ENA_AIE = 0x00010000 | 0x00008000;
DMA_STATUS_NIS   = 0x00040000 | 0x00020000;
DMA_STATUS_AIS   = 0x00010000 | 0x00008000;
DMA_STATUS_FBI   = 0x00002000 | 0x00001000;

Therefore, when using, TX and RX must be set at the same time.

How to use them:
1. Create the Loongson GNET-specific stmmac_dma_ops.dma_interrupt() stmmac_dma_ops.init_chan()
methods in the dwmac-loongson.c driver. Adding all the Loongson-specific macros

2. Create a Loongson GNET-specific platform setup method with the next semantics:
+ allocate stmmac_dma_ops instance and initialize it with dwmac1000_dma_ops.
+ override the stmmac_dma_ops.{dma_interrupt, init_chan} with the pointers to the methods defined in 2.
+ allocate mac_device_info instance and initialize the mac_device_info.dma field with a pointer to the new stmmac_dma_ops instance.
+ initialize mac_device_info in a way it's done in dwmac1000_setup().

3. Initialize plat_stmmacenet_data.setup() with the pointer to the method created in 2.

---
    .../ethernet/stmicro/stmmac/dwmac-loongson.c  | 248 ++++++++++++++++++
    1 file changed, 248 insertions(+)
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +24 -0
index e7ce027cc14e..3b3578318cc1 100644
@@ -8,6 +8,193 @@
    #include <linux/device.h>
    #include <linux/of_irq.h>
    #include "stmmac.h"
+#include "dwmac_dma.h"
+#include "dwmac1000.h"
+
+#define DMA_INTR_ENA_NIE_TX_LOONGSON 0x00040000	/* Normal Loongson Tx Summary */
+#define DMA_INTR_ENA_NIE_RX_LOONGSON 0x00020000	/* Normal Loongson Rx Summary */
+#define DMA_INTR_NORMAL_LOONGSON	(DMA_INTR_ENA_NIE_TX_LOONGSON | \
+			 DMA_INTR_ENA_NIE_RX_LOONGSON | DMA_INTR_ENA_RIE | \
+			 DMA_INTR_ENA_TIE)
+
+#define DMA_INTR_ENA_AIE_TX_LOONGSON 0x00010000	/* Abnormal Loongson Tx Summary */
+#define DMA_INTR_ENA_AIE_RX_LOONGSON 0x00008000	/* Abnormal Loongson Rx Summary */
+
+#define DMA_INTR_ABNORMAL_LOONGSON	(DMA_INTR_ENA_AIE_TX_LOONGSON | \
+				DMA_INTR_ENA_AIE_RX_LOONGSON | DMA_INTR_ENA_FBE | \
+				DMA_INTR_ENA_UNE)
+
+#define DMA_INTR_DEFAULT_MASK_LOONGSON	(DMA_INTR_NORMAL_LOONGSON | DMA_INTR_ABNORMAL_LOONGSON)
+
+#define DMA_STATUS_NIS_TX_LOONGSON	0x00040000	/* Normal Loongson Tx Interrupt Summary */
+#define DMA_STATUS_NIS_RX_LOONGSON	0x00020000	/* Normal Loongson Rx Interrupt Summary */
+
+#define DMA_STATUS_AIS_TX_LOONGSON	0x00010000	/* Abnormal Loongson Tx Interrupt Summary */
+#define DMA_STATUS_AIS_RX_LOONGSON	0x00008000	/* Abnormal Loongson Rx Interrupt Summary */
+
Quoted 8 lines

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c line 41

Quoted 7 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +7 -0
+#define DMA_STATUS_FBI_TX_LOONGSON	0x00002000	/* Fatal Loongson Tx Bus Error Interrupt */
+#define DMA_STATUS_FBI_RX_LOONGSON	0x00001000	/* Fatal Loongson Rx Bus Error Interrupt */
+
+#define DMA_STATUS_MSK_COMMON_LOONGSON		(DMA_STATUS_NIS_TX_LOONGSON | \
+					 DMA_STATUS_NIS_RX_LOONGSON | DMA_STATUS_AIS_TX_LOONGSON | \
+					 DMA_STATUS_AIS_RX_LOONGSON | DMA_STATUS_FBI_TX_LOONGSON | \
+					 DMA_STATUS_FBI_RX_LOONGSON)

Max 80 chars per line please.

OK,

Quoted 24 lines
Quoted 11 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +11 -0
+
+#define DMA_STATUS_MSK_RX_LOONGSON		(DMA_STATUS_ERI | \
+					 DMA_STATUS_RWT | \
+					 DMA_STATUS_RPS | \
+					 DMA_STATUS_RU | \
+					 DMA_STATUS_RI | \
+					 DMA_STATUS_OVF | \
+					 DMA_STATUS_MSK_COMMON_LOONGSON)
+
+#define DMA_STATUS_MSK_TX_LOONGSON		(DMA_STATUS_ETI | \
+					 DMA_STATUS_UNF | \

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c line 62

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +10 -0
+					 DMA_STATUS_TJT | \
+					 DMA_STATUS_TU | \
+					 DMA_STATUS_TPS | \
+					 DMA_STATUS_TI | \
+					 DMA_STATUS_MSK_COMMON_LOONGSON)
+
+struct loongson_data {
+	struct device *dev;
+	u32 lgmac_version;
+	struct stmmac_dma_ops dwlgmac_dma_ops;

Just figured out we can do without this field being added to the private data. See my note in the loongson_setup() method.

Quoted 7 lines

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c line 65

Quoted 3 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +3 -0
+};
+
+static void dwlgmac_dma_init_channel(struct stmmac_priv *priv,

The "dwlgmac_" prefix is confusing. There is the DW XLGMAC IP-core for which the "dwxlgmac_" is more appropriate and "x" is easy to miss should your version of the prefix is met. Consider changing it to something like "loongson_gnet_".

OK,

Quoted 55 lines
Quoted 32 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +32 -0
+				     void __iomem *ioaddr,
+				     struct stmmac_dma_cfg *dma_cfg, u32 chan)
+{
+	u32 value;
+	int txpbl = dma_cfg->txpbl ?: dma_cfg->pbl;
+	int rxpbl = dma_cfg->rxpbl ?: dma_cfg->pbl;
+
+	/* common channel control register config */
+	value = readl(ioaddr + DMA_CHAN_BUS_MODE(chan));
+
+	/* Set the DMA PBL (Programmable Burst Length) mode.
+	 *
+	 * Note: before stmmac core 3.50 this mode bit was 4xPBL, and
+	 * post 3.5 mode bit acts as 8*PBL.
+	 */
+	if (dma_cfg->pblx8)
+		value |= DMA_BUS_MODE_MAXPBL;
+	value |= DMA_BUS_MODE_USP;
+	value &= ~(DMA_BUS_MODE_PBL_MASK | DMA_BUS_MODE_RPBL_MASK);
+	value |= (txpbl << DMA_BUS_MODE_PBL_SHIFT);
+	value |= (rxpbl << DMA_BUS_MODE_RPBL_SHIFT);
+
+	/* Set the Fixed burst mode */
+	if (dma_cfg->fixed_burst)
+		value |= DMA_BUS_MODE_FB;
+
+	/* Mixed Burst has no effect when fb is set */
+	if (dma_cfg->mixed_burst)
+		value |= DMA_BUS_MODE_MB;
+
+	value |= DMA_BUS_MODE_ATDS;
+

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c line 107

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +10 -0
+	if (dma_cfg->aal)
+		value |= DMA_BUS_MODE_AAL;
+
+	writel(value, ioaddr + DMA_BUS_MODE);
+
+	/* Mask interrupts by writing to CSR7 */
+	writel(DMA_INTR_DEFAULT_MASK_LOONGSON, ioaddr + DMA_INTR_ENA);
+}
+
+static int dwlgmac_dma_interrupt(struct stmmac_priv *priv, void __iomem *ioaddr,

The same note as above.

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c line 116

Quoted 9 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +9 -0
+				 struct stmmac_extra_stats *x, u32 chan, u32 dir)
+{
+	struct stmmac_rxq_stats *rxq_stats = &priv->xstats.rxq_stats[chan];
+	struct stmmac_txq_stats *txq_stats = &priv->xstats.txq_stats[chan];
+	int ret = 0;
+	/* read the status register (CSR5) */
+	u32 nor_intr_status;
+	u32 abnor_intr_status;
+	u32 fb_intr_status;

Reverse xmas tree please.

Quoted 2 lines

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c line 117

Quoted 1 line
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +1 -0
+	u32 intr_status = readl(ioaddr + DMA_CHAN_STATUS(chan));

Please move the initialization into a separate statement.

OK,

Quoted 107 lines

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c line 124

Quoted 7 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +7 -0
+
+#ifdef DWMAC_DMA_DEBUG
+	/* Enable it to monitor DMA rx/tx status in case of critical problems */
+	pr_debug("%s: [CSR5: 0x%08x]\n", __func__, intr_status);
+	show_tx_process_state(intr_status);
+	show_rx_process_state(intr_status);
+#endif

This will cause a build-error if DWMAC_DMA_DEBUG is defined. Just drop it.
OK,

Quoted 76 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +73 -0
+
+	if (dir == DMA_DIR_RX)
+		intr_status &= DMA_STATUS_MSK_RX_LOONGSON;
+	else if (dir == DMA_DIR_TX)
+		intr_status &= DMA_STATUS_MSK_TX_LOONGSON;
+
+	nor_intr_status = intr_status & (DMA_STATUS_NIS_TX_LOONGSON |
+		DMA_STATUS_NIS_RX_LOONGSON);
+	abnor_intr_status = intr_status & (DMA_STATUS_AIS_TX_LOONGSON |
+		DMA_STATUS_AIS_RX_LOONGSON);
+	fb_intr_status = intr_status & (DMA_STATUS_FBI_TX_LOONGSON |
+		DMA_STATUS_FBI_RX_LOONGSON);
+
+	/* ABNORMAL interrupts */
+	if (unlikely(abnor_intr_status)) {
+		if (unlikely(intr_status & DMA_STATUS_UNF)) {
+			ret = tx_hard_error_bump_tc;
+			x->tx_undeflow_irq++;
+		}
+		if (unlikely(intr_status & DMA_STATUS_TJT))
+			x->tx_jabber_irq++;
+
+		if (unlikely(intr_status & DMA_STATUS_OVF))
+			x->rx_overflow_irq++;
+
+		if (unlikely(intr_status & DMA_STATUS_RU))
+			x->rx_buf_unav_irq++;
+		if (unlikely(intr_status & DMA_STATUS_RPS))
+			x->rx_process_stopped_irq++;
+		if (unlikely(intr_status & DMA_STATUS_RWT))
+			x->rx_watchdog_irq++;
+		if (unlikely(intr_status & DMA_STATUS_ETI))
+			x->tx_early_irq++;
+		if (unlikely(intr_status & DMA_STATUS_TPS)) {
+			x->tx_process_stopped_irq++;
+			ret = tx_hard_error;
+		}
+		if (unlikely(intr_status & fb_intr_status)) {
+			x->fatal_bus_error_irq++;
+			ret = tx_hard_error;
+		}
+	}
+	/* TX/RX NORMAL interrupts */
+	if (likely(nor_intr_status)) {
+		if (likely(intr_status & DMA_STATUS_RI)) {
+			u32 value = readl(ioaddr + DMA_INTR_ENA);
+			/* to schedule NAPI on real RIE event. */
+			if (likely(value & DMA_INTR_ENA_RIE)) {
+				u64_stats_update_begin(&rxq_stats->syncp);
+				rxq_stats->rx_normal_irq_n++;
+				u64_stats_update_end(&rxq_stats->syncp);
+				ret |= handle_rx;
+			}
+		}
+		if (likely(intr_status & DMA_STATUS_TI)) {
+			u64_stats_update_begin(&txq_stats->syncp);
+			txq_stats->tx_normal_irq_n++;
+			u64_stats_update_end(&txq_stats->syncp);
+			ret |= handle_tx;
+		}
+		if (unlikely(intr_status & DMA_STATUS_ERI))
+			x->rx_early_irq++;
+	}
+	/* Optional hardware blocks, interrupts should be disabled */
+	if (unlikely(intr_status &
+		     (DMA_STATUS_GPI | DMA_STATUS_GMI | DMA_STATUS_GLI)))
+		pr_warn("%s: unexpected status %08x\n", __func__, intr_status);
+
+	/* Clear the interrupt by writing a logic 1 to the CSR5[15-0] */
+	writel((intr_status & 0x7ffff), ioaddr + DMA_CHAN_STATUS(chan));
+
+	return ret;
+}
    struct stmmac_pci_info {
    	int (*setup)(struct pci_dev *pdev, struct plat_stmmacenet_data *plat);

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static struct stmmac_pci_info loongson_gmac_pci_info = { · line 310

Quoted 3 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +1 -0
@@ -121,6 +308,48 @@ static struct stmmac_pci_info loongson_gmac_pci_info = {
    	.config = loongson_gmac_config,
    };
+static struct mac_device_info *loongson_setup(void *apriv)

Consider using the GNET-specific prefix, like "loongson_gnet_".

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static struct stmmac_pci_info loongson_gmac_pci_info = { · line 319

Quoted 8 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +8 -0
+{
+	struct stmmac_priv *priv = apriv;
+	struct mac_device_info *mac;
+	struct loongson_data *ld;
+
+	mac = devm_kzalloc(priv->device, sizeof(*mac), GFP_KERNEL);
+	if (!mac)
+		return NULL;

What about devm_kzalloc()-ing the stmmac_dma_ops instance here and initializing it as it's done in the probe method? Thus ...

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static struct stmmac_pci_info loongson_gmac_pci_info = { · line 322

Quoted 3 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +3 -0
+
+	ld = priv->plat->bsp_priv;
+	mac->dma = &ld->dwlgmac_dma_ops;

... this can be replaced with:

Quoted 6 lines
Quoted 4 lines
Quoted 3 lines
	mac->dma = devm_kzalloc(priv->device, sizeof(*mac->dma), GFP_KERNEL);
	if (!mac->dma)
		return -ENOMEM;

Great, but It seems that we cannot return an int value here.

Just

		return NULL;

OK,

Quoted 5 lines

then.

Quoted 3 lines
Quoted 3 lines
	*mac->dma = dwmac1000_dma_ops;
	mac->dma->init_chan = loongson_gnet_dma_init_channel;
	mac->dma->dma_interrupt = loongson_gnet_dma_interrupt;
Quoted 10 lines

It seems that we still cannot do this because: structmac_device_info{
...
conststructstmmac_mmc_ops*mmc;
...
}
some errors output:
error: assignment of read-only location '*mac->dma'
error: assignment of member 'init_chan' in read-only object
...

No, we can. Just use a temporary non-const pointer to stmmac_dma_ops:

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +3 -0
+static struct mac_device_info *loongson_gnet_setup(void *apriv)
+{
+	struct stmmac_priv *priv = apriv;

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static struct stmmac_pci_info loongson_gmac_pci_info = {

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +10 -0
+	struct mac_device_info *mac;
+	struct stmmac_dma_ops *dma;
+	struct loongson_data *ld;
+
+	mac = devm_kzalloc(priv->device, sizeof(*mac), GFP_KERNEL);
+	if (!mac)
+		return NULL;
+
+	dma = devm_kzalloc(priv->device, sizeof(*dma), GFP_KERNEL);
+	if (!mac->dma)

We have already modified it according to this comment. By the way, this should be "if (!mac)",

otherwise the following part of the code will not work:

Review

Quoted 8 lines
(quoted diff) +8 -0
+		return NULL;
+
+	*dma = dwmac1000_dma_ops;
+	dma->init_chan = loongson_gnet_dma_init_channel;
+	dma->dma_interrupt = loongson_gnet_dma_interrupt;
+	mac->dma = dma;
+
+	...

Tomorrow I will continue to modify other patches based on your comment.

Thanks,

Yanteng

Quoted 104 lines

-Serge(y)

Quoted 101 lines

Thanks,
Yanteng

Quoted 99 lines
Quoted 69 lines
Quoted 51 lines
Quoted 34 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +30 -0
+
+	/* Pre-initialize the respective "mac" fields as it's done in
+	 * dwmac1000_setup()
+	 */
+	priv->dev->priv_flags |= IFF_UNICAST_FLT;
+	mac->pcsr = priv->ioaddr;
+	mac->multicast_filter_bins = priv->plat->multicast_filter_bins;
+	mac->unicast_filter_entries = priv->plat->unicast_filter_entries;
+	mac->mcast_bits_log2 = 0;
+
+	if (mac->multicast_filter_bins)
+		mac->mcast_bits_log2 = ilog2(mac->multicast_filter_bins);
+
+	mac->link.duplex = GMAC_CONTROL_DM;
+	mac->link.speed10 = GMAC_CONTROL_PS;
+	mac->link.speed100 = GMAC_CONTROL_PS | GMAC_CONTROL_FES;
+	mac->link.speed1000 = 0;
+	mac->link.speed_mask = GMAC_CONTROL_PS | GMAC_CONTROL_FES;
+	mac->mii.addr = GMAC_MII_ADDR;
+	mac->mii.data = GMAC_MII_DATA;
+	mac->mii.addr_shift = 11;
+	mac->mii.addr_mask = 0x0000F800;
+	mac->mii.reg_shift = 6;
+	mac->mii.reg_mask = 0x000007C0;
+	mac->mii.clk_csr_shift = 2;
+	mac->mii.clk_csr_mask = GENMASK(5, 2);
+
+	return mac;
+}
+
    static int loongson_dwmac_probe(struct pci_dev *pdev,
    				const struct pci_device_id *id)
    {

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int loongson_dwmac_probe(struct pci_dev *pdev, · line 361

Quoted 4 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +1 -0
@@ -129,6 +358,7 @@ static int loongson_dwmac_probe(struct pci_dev *pdev,
    	struct stmmac_pci_info *info;
    	struct stmmac_resources res;
    	struct device_node *np;
+	struct loongson_data *ld;

reverse xmas tree order please.

Quoted 11 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +4 -0
    	plat = devm_kzalloc(&pdev->dev, sizeof(*plat), GFP_KERNEL);
    	if (!plat)
@@ -145,6 +375,10 @@ static int loongson_dwmac_probe(struct pci_dev *pdev,
    	if (!plat->dma_cfg)
    		return -ENOMEM;
+	ld = devm_kzalloc(&pdev->dev, sizeof(*ld), GFP_KERNEL);
+	if (!ld)
+		return -ENOMEM;
+
    	np = dev_of_node(&pdev->dev);
    	plat->mdio_node = of_get_child_by_name(np, "mdio");
Quoted 8 lines

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int loongson_dwmac_probe(struct pci_dev *pdev, · line 434

Quoted 6 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +2 -0
    	if (plat->mdio_node) {
@@ -197,6 +431,20 @@ static int loongson_dwmac_probe(struct pci_dev *pdev,
    	if (ret)
    		goto err_disable_device;
+	ld->dev = &pdev->dev;
+	ld->lgmac_version = readl(res.addr + GMAC_VERSION) & 0xff;

AFAICS the lgmac_version is unused in out of the probe() method context. What about locally defining it?

OK,

Quoted 4 lines

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int loongson_dwmac_probe(struct pci_dev *pdev, · line 438

Quoted 3 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +3 -0
+
+	/* Activate loongson custom ip */
+	if (ld->lgmac_version < DWMAC_CORE_3_50) {

Please define a new macro for the GNET MAC.

OK.

Quoted 4 lines

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int loongson_dwmac_probe(struct pci_dev *pdev, · line 441

Quoted 3 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +3 -0
+		ld->dwlgmac_dma_ops = dwmac1000_dma_ops;
+		ld->dwlgmac_dma_ops.init_chan = dwlgmac_dma_init_channel;
+		ld->dwlgmac_dma_ops.dma_interrupt = dwlgmac_dma_interrupt;

See my comment in the loongson_setup() method.

Quoted 6 lines

This will introduce a compilation warning:

warning: returning 'int' from a function with return type 'struct mac_device_info *' makes pointer from integer without a cast [-Wint-conversion]
  418 |                 return -ENOMEM;

stmmac_hwif_init() expects priv->plat->setup(priv) returning NULL if something wrong. As I suggested above just return NULL then if mac_device_info couldn't be allocated.

-Serge(y)

Quoted 18 lines

Thanks,

Yanteng

Quoted 14 lines

-Serge(y)

Quoted 12 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +6 -0
+
+		plat->setup = loongson_setup;
+	}
+
+	plat->bsp_priv = ld;
+
    	ret = stmmac_dvr_probe(&pdev->dev, plat, &res);
    	if (ret)
    		goto err_disable_device;
Signature · 1 line
2.31.4
#36 lore raw

Re: [PATCH net-next v8 05/11] net: stmmac: dwmac-loongson: Add Loongson-specific register definitions

Quoted 330 lines · Yanteng Si

Hi Serge,

Sorry for keeping you waiting for so long.

Quoted 324 lines · Serge Semin
Quoted 302 lines · Yanteng Si

Hi Serge,

Quoted 287 lines · Serge Semin
Quoted 286 lines · Yanteng Si
Quoted 79 lines · Serge Semin
Quoted 78 lines · Yanteng Si

There are two types of Loongson DWGMAC. The first type shares the same register definitions and has similar logic as dwmac1000. The second type uses several different register definitions, we think it is necessary to distinguish rx and tx, so we split these bits into two.

Simply put, we split some single bit fields into double bits fileds:

Name Tx Rx

DMA_INTR_ENA_NIE = 0x00040000 | 0x00020000;
DMA_INTR_ENA_AIE = 0x00010000 | 0x00008000;
DMA_STATUS_NIS   = 0x00040000 | 0x00020000;
DMA_STATUS_AIS   = 0x00010000 | 0x00008000;
DMA_STATUS_FBI   = 0x00002000 | 0x00001000;

Therefore, when using, TX and RX must be set at the same time.

How to use them:
1. Create the Loongson GNET-specific stmmac_dma_ops.dma_interrupt() stmmac_dma_ops.init_chan()
methods in the dwmac-loongson.c driver. Adding all the Loongson-specific macros

2. Create a Loongson GNET-specific platform setup method with the next semantics:
+ allocate stmmac_dma_ops instance and initialize it with dwmac1000_dma_ops.
+ override the stmmac_dma_ops.{dma_interrupt, init_chan} with the pointers to the methods defined in 2.
+ allocate mac_device_info instance and initialize the mac_device_info.dma field with a pointer to the new stmmac_dma_ops instance.
+ initialize mac_device_info in a way it's done in dwmac1000_setup().

3. Initialize plat_stmmacenet_data.setup() with the pointer to the method created in 2.

---
    .../ethernet/stmicro/stmmac/dwmac-loongson.c  | 248 ++++++++++++++++++
    1 file changed, 248 insertions(+)
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +24 -0
index e7ce027cc14e..3b3578318cc1 100644
@@ -8,6 +8,193 @@
    #include <linux/device.h>
    #include <linux/of_irq.h>
    #include "stmmac.h"
+#include "dwmac_dma.h"
+#include "dwmac1000.h"
+
+#define DMA_INTR_ENA_NIE_TX_LOONGSON 0x00040000	/* Normal Loongson Tx Summary */
+#define DMA_INTR_ENA_NIE_RX_LOONGSON 0x00020000	/* Normal Loongson Rx Summary */
+#define DMA_INTR_NORMAL_LOONGSON	(DMA_INTR_ENA_NIE_TX_LOONGSON | \
+			 DMA_INTR_ENA_NIE_RX_LOONGSON | DMA_INTR_ENA_RIE | \
+			 DMA_INTR_ENA_TIE)
+
+#define DMA_INTR_ENA_AIE_TX_LOONGSON 0x00010000	/* Abnormal Loongson Tx Summary */
+#define DMA_INTR_ENA_AIE_RX_LOONGSON 0x00008000	/* Abnormal Loongson Rx Summary */
+
+#define DMA_INTR_ABNORMAL_LOONGSON	(DMA_INTR_ENA_AIE_TX_LOONGSON | \
+				DMA_INTR_ENA_AIE_RX_LOONGSON | DMA_INTR_ENA_FBE | \
+				DMA_INTR_ENA_UNE)
+
+#define DMA_INTR_DEFAULT_MASK_LOONGSON	(DMA_INTR_NORMAL_LOONGSON | DMA_INTR_ABNORMAL_LOONGSON)
+
+#define DMA_STATUS_NIS_TX_LOONGSON	0x00040000	/* Normal Loongson Tx Interrupt Summary */
+#define DMA_STATUS_NIS_RX_LOONGSON	0x00020000	/* Normal Loongson Rx Interrupt Summary */
+
+#define DMA_STATUS_AIS_TX_LOONGSON	0x00010000	/* Abnormal Loongson Tx Interrupt Summary */
+#define DMA_STATUS_AIS_RX_LOONGSON	0x00008000	/* Abnormal Loongson Rx Interrupt Summary */
+
Quoted 8 lines

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c line 41

Quoted 7 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +7 -0
+#define DMA_STATUS_FBI_TX_LOONGSON	0x00002000	/* Fatal Loongson Tx Bus Error Interrupt */
+#define DMA_STATUS_FBI_RX_LOONGSON	0x00001000	/* Fatal Loongson Rx Bus Error Interrupt */
+
+#define DMA_STATUS_MSK_COMMON_LOONGSON		(DMA_STATUS_NIS_TX_LOONGSON | \
+					 DMA_STATUS_NIS_RX_LOONGSON | DMA_STATUS_AIS_TX_LOONGSON | \
+					 DMA_STATUS_AIS_RX_LOONGSON | DMA_STATUS_FBI_TX_LOONGSON | \
+					 DMA_STATUS_FBI_RX_LOONGSON)

Max 80 chars per line please.

OK,

Quoted 24 lines
Quoted 11 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +11 -0
+
+#define DMA_STATUS_MSK_RX_LOONGSON		(DMA_STATUS_ERI | \
+					 DMA_STATUS_RWT | \
+					 DMA_STATUS_RPS | \
+					 DMA_STATUS_RU | \
+					 DMA_STATUS_RI | \
+					 DMA_STATUS_OVF | \
+					 DMA_STATUS_MSK_COMMON_LOONGSON)
+
+#define DMA_STATUS_MSK_TX_LOONGSON		(DMA_STATUS_ETI | \
+					 DMA_STATUS_UNF | \

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c line 62

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +10 -0
+					 DMA_STATUS_TJT | \
+					 DMA_STATUS_TU | \
+					 DMA_STATUS_TPS | \
+					 DMA_STATUS_TI | \
+					 DMA_STATUS_MSK_COMMON_LOONGSON)
+
+struct loongson_data {
+	struct device *dev;
+	u32 lgmac_version;
+	struct stmmac_dma_ops dwlgmac_dma_ops;

Just figured out we can do without this field being added to the private data. See my note in the loongson_setup() method.

Quoted 7 lines

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c line 65

Quoted 3 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +3 -0
+};
+
+static void dwlgmac_dma_init_channel(struct stmmac_priv *priv,

The "dwlgmac_" prefix is confusing. There is the DW XLGMAC IP-core for which the "dwxlgmac_" is more appropriate and "x" is easy to miss should your version of the prefix is met. Consider changing it to something like "loongson_gnet_".

OK,

Quoted 55 lines
Quoted 32 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +32 -0
+				     void __iomem *ioaddr,
+				     struct stmmac_dma_cfg *dma_cfg, u32 chan)
+{
+	u32 value;
+	int txpbl = dma_cfg->txpbl ?: dma_cfg->pbl;
+	int rxpbl = dma_cfg->rxpbl ?: dma_cfg->pbl;
+
+	/* common channel control register config */
+	value = readl(ioaddr + DMA_CHAN_BUS_MODE(chan));
+
+	/* Set the DMA PBL (Programmable Burst Length) mode.
+	 *
+	 * Note: before stmmac core 3.50 this mode bit was 4xPBL, and
+	 * post 3.5 mode bit acts as 8*PBL.
+	 */
+	if (dma_cfg->pblx8)
+		value |= DMA_BUS_MODE_MAXPBL;
+	value |= DMA_BUS_MODE_USP;
+	value &= ~(DMA_BUS_MODE_PBL_MASK | DMA_BUS_MODE_RPBL_MASK);
+	value |= (txpbl << DMA_BUS_MODE_PBL_SHIFT);
+	value |= (rxpbl << DMA_BUS_MODE_RPBL_SHIFT);
+
+	/* Set the Fixed burst mode */
+	if (dma_cfg->fixed_burst)
+		value |= DMA_BUS_MODE_FB;
+
+	/* Mixed Burst has no effect when fb is set */
+	if (dma_cfg->mixed_burst)
+		value |= DMA_BUS_MODE_MB;
+
+	value |= DMA_BUS_MODE_ATDS;
+

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c line 107

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +10 -0
+	if (dma_cfg->aal)
+		value |= DMA_BUS_MODE_AAL;
+
+	writel(value, ioaddr + DMA_BUS_MODE);
+
+	/* Mask interrupts by writing to CSR7 */
+	writel(DMA_INTR_DEFAULT_MASK_LOONGSON, ioaddr + DMA_INTR_ENA);
+}
+
+static int dwlgmac_dma_interrupt(struct stmmac_priv *priv, void __iomem *ioaddr,

The same note as above.

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c line 116

Quoted 9 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +9 -0
+				 struct stmmac_extra_stats *x, u32 chan, u32 dir)
+{
+	struct stmmac_rxq_stats *rxq_stats = &priv->xstats.rxq_stats[chan];
+	struct stmmac_txq_stats *txq_stats = &priv->xstats.txq_stats[chan];
+	int ret = 0;
+	/* read the status register (CSR5) */
+	u32 nor_intr_status;
+	u32 abnor_intr_status;
+	u32 fb_intr_status;

Reverse xmas tree please.

Quoted 2 lines

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c line 117

Quoted 1 line
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +1 -0
+	u32 intr_status = readl(ioaddr + DMA_CHAN_STATUS(chan));

Please move the initialization into a separate statement.

OK,

Quoted 107 lines

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c line 124

Quoted 7 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +7 -0
+
+#ifdef DWMAC_DMA_DEBUG
+	/* Enable it to monitor DMA rx/tx status in case of critical problems */
+	pr_debug("%s: [CSR5: 0x%08x]\n", __func__, intr_status);
+	show_tx_process_state(intr_status);
+	show_rx_process_state(intr_status);
+#endif

This will cause a build-error if DWMAC_DMA_DEBUG is defined. Just drop it.
OK,

Quoted 76 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +73 -0
+
+	if (dir == DMA_DIR_RX)
+		intr_status &= DMA_STATUS_MSK_RX_LOONGSON;
+	else if (dir == DMA_DIR_TX)
+		intr_status &= DMA_STATUS_MSK_TX_LOONGSON;
+
+	nor_intr_status = intr_status & (DMA_STATUS_NIS_TX_LOONGSON |
+		DMA_STATUS_NIS_RX_LOONGSON);
+	abnor_intr_status = intr_status & (DMA_STATUS_AIS_TX_LOONGSON |
+		DMA_STATUS_AIS_RX_LOONGSON);
+	fb_intr_status = intr_status & (DMA_STATUS_FBI_TX_LOONGSON |
+		DMA_STATUS_FBI_RX_LOONGSON);
+
+	/* ABNORMAL interrupts */
+	if (unlikely(abnor_intr_status)) {
+		if (unlikely(intr_status & DMA_STATUS_UNF)) {
+			ret = tx_hard_error_bump_tc;
+			x->tx_undeflow_irq++;
+		}
+		if (unlikely(intr_status & DMA_STATUS_TJT))
+			x->tx_jabber_irq++;
+
+		if (unlikely(intr_status & DMA_STATUS_OVF))
+			x->rx_overflow_irq++;
+
+		if (unlikely(intr_status & DMA_STATUS_RU))
+			x->rx_buf_unav_irq++;
+		if (unlikely(intr_status & DMA_STATUS_RPS))
+			x->rx_process_stopped_irq++;
+		if (unlikely(intr_status & DMA_STATUS_RWT))
+			x->rx_watchdog_irq++;
+		if (unlikely(intr_status & DMA_STATUS_ETI))
+			x->tx_early_irq++;
+		if (unlikely(intr_status & DMA_STATUS_TPS)) {
+			x->tx_process_stopped_irq++;
+			ret = tx_hard_error;
+		}
+		if (unlikely(intr_status & fb_intr_status)) {
+			x->fatal_bus_error_irq++;
+			ret = tx_hard_error;
+		}
+	}
+	/* TX/RX NORMAL interrupts */
+	if (likely(nor_intr_status)) {
+		if (likely(intr_status & DMA_STATUS_RI)) {
+			u32 value = readl(ioaddr + DMA_INTR_ENA);
+			/* to schedule NAPI on real RIE event. */
+			if (likely(value & DMA_INTR_ENA_RIE)) {
+				u64_stats_update_begin(&rxq_stats->syncp);
+				rxq_stats->rx_normal_irq_n++;
+				u64_stats_update_end(&rxq_stats->syncp);
+				ret |= handle_rx;
+			}
+		}
+		if (likely(intr_status & DMA_STATUS_TI)) {
+			u64_stats_update_begin(&txq_stats->syncp);
+			txq_stats->tx_normal_irq_n++;
+			u64_stats_update_end(&txq_stats->syncp);
+			ret |= handle_tx;
+		}
+		if (unlikely(intr_status & DMA_STATUS_ERI))
+			x->rx_early_irq++;
+	}
+	/* Optional hardware blocks, interrupts should be disabled */
+	if (unlikely(intr_status &
+		     (DMA_STATUS_GPI | DMA_STATUS_GMI | DMA_STATUS_GLI)))
+		pr_warn("%s: unexpected status %08x\n", __func__, intr_status);
+
+	/* Clear the interrupt by writing a logic 1 to the CSR5[15-0] */
+	writel((intr_status & 0x7ffff), ioaddr + DMA_CHAN_STATUS(chan));
+
+	return ret;
+}
    struct stmmac_pci_info {
    	int (*setup)(struct pci_dev *pdev, struct plat_stmmacenet_data *plat);

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static struct stmmac_pci_info loongson_gmac_pci_info = { · line 310

Quoted 3 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +1 -0
@@ -121,6 +308,48 @@ static struct stmmac_pci_info loongson_gmac_pci_info = {
    	.config = loongson_gmac_config,
    };
+static struct mac_device_info *loongson_setup(void *apriv)

Consider using the GNET-specific prefix, like "loongson_gnet_".

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static struct stmmac_pci_info loongson_gmac_pci_info = { · line 318

Quoted 8 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +8 -0
+{
+	struct stmmac_priv *priv = apriv;
+	struct mac_device_info *mac;
+	struct loongson_data *ld;
+
+	mac = devm_kzalloc(priv->device, sizeof(*mac), GFP_KERNEL);
+	if (!mac)
+		return NULL;

What about devm_kzalloc()-ing the stmmac_dma_ops instance here and initializing it as it's done in the probe method? Thus ...

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static struct stmmac_pci_info loongson_gmac_pci_info = { · line 321

Quoted 3 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +3 -0
+
+	ld = priv->plat->bsp_priv;
+	mac->dma = &ld->dwlgmac_dma_ops;

... this can be replaced with:

Quoted 6 lines
Quoted 4 lines
Quoted 3 lines
	mac->dma = devm_kzalloc(priv->device, sizeof(*mac->dma), GFP_KERNEL);
	if (!mac->dma)
		return -ENOMEM;

Great, but It seems that we cannot return an int value here.

Just

		return NULL;

OK,

Quoted 5 lines

then.

Quoted 3 lines
Quoted 3 lines
	*mac->dma = dwmac1000_dma_ops;
	mac->dma->init_chan = loongson_gnet_dma_init_channel;
	mac->dma->dma_interrupt = loongson_gnet_dma_interrupt;
Quoted 10 lines

It seems that we still cannot do this because: structmac_device_info{
...
conststructstmmac_mmc_ops*mmc;
...
}
some errors output:
error: assignment of read-only location '*mac->dma'
error: assignment of member 'init_chan' in read-only object
...

No, we can. Just use a temporary non-const pointer to stmmac_dma_ops:

(quoted diff) +9 -0
+static struct mac_device_info *loongson_gnet_setup(void *apriv)
+{
+	struct stmmac_priv *priv = apriv;
+	struct mac_device_info *mac;
+	struct stmmac_dma_ops *dma;
+	struct loongson_data *ld;
+
+	mac = devm_kzalloc(priv->device, sizeof(*mac), GFP_KERNEL);
+	if (!mac)
Quoted 8 lines

Review

Quoted 4 lines
(quoted diff) +4 -0
+		return NULL;
+
+	dma = devm_kzalloc(priv->device, sizeof(*dma), GFP_KERNEL);
+	if (!mac->dma)

We have already modified it according to this comment. By the way, this should be "if (!mac)",

if (!dma)

but you were right. My hand-written code was incorrect in that part.

-Serge(y)

Quoted 123 lines

otherwise the following part of the code will not work:

Review

Quoted 8 lines
(quoted diff) +8 -0
+		return NULL;
+
+	*dma = dwmac1000_dma_ops;
+	dma->init_chan = loongson_gnet_dma_init_channel;
+	dma->dma_interrupt = loongson_gnet_dma_interrupt;
+	mac->dma = dma;
+
+	...

Tomorrow I will continue to modify other patches based on your comment.

Thanks,

Yanteng

Quoted 104 lines

-Serge(y)

Quoted 101 lines

Thanks,
Yanteng

Quoted 99 lines
Quoted 69 lines
Quoted 51 lines
Quoted 34 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +30 -0
+
+	/* Pre-initialize the respective "mac" fields as it's done in
+	 * dwmac1000_setup()
+	 */
+	priv->dev->priv_flags |= IFF_UNICAST_FLT;
+	mac->pcsr = priv->ioaddr;
+	mac->multicast_filter_bins = priv->plat->multicast_filter_bins;
+	mac->unicast_filter_entries = priv->plat->unicast_filter_entries;
+	mac->mcast_bits_log2 = 0;
+
+	if (mac->multicast_filter_bins)
+		mac->mcast_bits_log2 = ilog2(mac->multicast_filter_bins);
+
+	mac->link.duplex = GMAC_CONTROL_DM;
+	mac->link.speed10 = GMAC_CONTROL_PS;
+	mac->link.speed100 = GMAC_CONTROL_PS | GMAC_CONTROL_FES;
+	mac->link.speed1000 = 0;
+	mac->link.speed_mask = GMAC_CONTROL_PS | GMAC_CONTROL_FES;
+	mac->mii.addr = GMAC_MII_ADDR;
+	mac->mii.data = GMAC_MII_DATA;
+	mac->mii.addr_shift = 11;
+	mac->mii.addr_mask = 0x0000F800;
+	mac->mii.reg_shift = 6;
+	mac->mii.reg_mask = 0x000007C0;
+	mac->mii.clk_csr_shift = 2;
+	mac->mii.clk_csr_mask = GENMASK(5, 2);
+
+	return mac;
+}
+
    static int loongson_dwmac_probe(struct pci_dev *pdev,
    				const struct pci_device_id *id)
    {

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int loongson_dwmac_probe(struct pci_dev *pdev, · line 361

Quoted 4 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +1 -0
@@ -129,6 +358,7 @@ static int loongson_dwmac_probe(struct pci_dev *pdev,
    	struct stmmac_pci_info *info;
    	struct stmmac_resources res;
    	struct device_node *np;
+	struct loongson_data *ld;

reverse xmas tree order please.

Quoted 11 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +4 -0
    	plat = devm_kzalloc(&pdev->dev, sizeof(*plat), GFP_KERNEL);
    	if (!plat)
@@ -145,6 +375,10 @@ static int loongson_dwmac_probe(struct pci_dev *pdev,
    	if (!plat->dma_cfg)
    		return -ENOMEM;
+	ld = devm_kzalloc(&pdev->dev, sizeof(*ld), GFP_KERNEL);
+	if (!ld)
+		return -ENOMEM;
+
    	np = dev_of_node(&pdev->dev);
    	plat->mdio_node = of_get_child_by_name(np, "mdio");
Quoted 8 lines

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int loongson_dwmac_probe(struct pci_dev *pdev, · line 434

Quoted 6 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +2 -0
    	if (plat->mdio_node) {
@@ -197,6 +431,20 @@ static int loongson_dwmac_probe(struct pci_dev *pdev,
    	if (ret)
    		goto err_disable_device;
+	ld->dev = &pdev->dev;
+	ld->lgmac_version = readl(res.addr + GMAC_VERSION) & 0xff;

AFAICS the lgmac_version is unused in out of the probe() method context. What about locally defining it?

OK,

Quoted 4 lines

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int loongson_dwmac_probe(struct pci_dev *pdev, · line 437

Quoted 3 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +3 -0
+
+	/* Activate loongson custom ip */
+	if (ld->lgmac_version < DWMAC_CORE_3_50) {

Please define a new macro for the GNET MAC.

OK.

Quoted 4 lines

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int loongson_dwmac_probe(struct pci_dev *pdev, · line 440

Quoted 3 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +3 -0
+		ld->dwlgmac_dma_ops = dwmac1000_dma_ops;
+		ld->dwlgmac_dma_ops.init_chan = dwlgmac_dma_init_channel;
+		ld->dwlgmac_dma_ops.dma_interrupt = dwlgmac_dma_interrupt;

See my comment in the loongson_setup() method.

Quoted 6 lines

This will introduce a compilation warning:

warning: returning 'int' from a function with return type 'struct mac_device_info *' makes pointer from integer without a cast [-Wint-conversion]
  418 |                 return -ENOMEM;

stmmac_hwif_init() expects priv->plat->setup(priv) returning NULL if something wrong. As I suggested above just return NULL then if mac_device_info couldn't be allocated.

-Serge(y)

Quoted 18 lines

Thanks,

Yanteng

Quoted 14 lines

-Serge(y)

Quoted 12 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +6 -0
+
+		plat->setup = loongson_setup;
+	}
+
+	plat->bsp_priv = ld;
+
    	ret = stmmac_dvr_probe(&pdev->dev, plat, &res);
    	if (ret)
    		goto err_disable_device;
Signature · 1 line
2.31.4
author
#37 lore raw

Re: [PATCH net-next v8 05/11] net: stmmac: dwmac-loongson: Add Loongson-specific register definitions

Quoted 337 lines · Serge Semin
Quoted 321 lines · Yanteng Si

Hi Serge,

Sorry for keeping you waiting for so long.

Quoted 315 lines · Serge Semin
Quoted 302 lines · Yanteng Si

Hi Serge,

Quoted 287 lines · Serge Semin
Quoted 286 lines · Yanteng Si
Quoted 79 lines · Serge Semin
Quoted 78 lines · Yanteng Si

There are two types of Loongson DWGMAC. The first type shares the same register definitions and has similar logic as dwmac1000. The second type uses several different register definitions, we think it is necessary to distinguish rx and tx, so we split these bits into two.

Simply put, we split some single bit fields into double bits fileds:

Name Tx Rx

DMA_INTR_ENA_NIE = 0x00040000 | 0x00020000;
DMA_INTR_ENA_AIE = 0x00010000 | 0x00008000;
DMA_STATUS_NIS   = 0x00040000 | 0x00020000;
DMA_STATUS_AIS   = 0x00010000 | 0x00008000;
DMA_STATUS_FBI   = 0x00002000 | 0x00001000;

Therefore, when using, TX and RX must be set at the same time.

How to use them:
1. Create the Loongson GNET-specific stmmac_dma_ops.dma_interrupt() stmmac_dma_ops.init_chan()
methods in the dwmac-loongson.c driver. Adding all the Loongson-specific macros

2. Create a Loongson GNET-specific platform setup method with the next semantics:
+ allocate stmmac_dma_ops instance and initialize it with dwmac1000_dma_ops.
+ override the stmmac_dma_ops.{dma_interrupt, init_chan} with the pointers to the methods defined in 2.
+ allocate mac_device_info instance and initialize the mac_device_info.dma field with a pointer to the new stmmac_dma_ops instance.
+ initialize mac_device_info in a way it's done in dwmac1000_setup().

3. Initialize plat_stmmacenet_data.setup() with the pointer to the method created in 2.

---
     .../ethernet/stmicro/stmmac/dwmac-loongson.c  | 248 ++++++++++++++++++
     1 file changed, 248 insertions(+)
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +24 -0
index e7ce027cc14e..3b3578318cc1 100644
@@ -8,6 +8,193 @@
     #include <linux/device.h>
     #include <linux/of_irq.h>
     #include "stmmac.h"
+#include "dwmac_dma.h"
+#include "dwmac1000.h"
+
+#define DMA_INTR_ENA_NIE_TX_LOONGSON 0x00040000	/* Normal Loongson Tx Summary */
+#define DMA_INTR_ENA_NIE_RX_LOONGSON 0x00020000	/* Normal Loongson Rx Summary */
+#define DMA_INTR_NORMAL_LOONGSON	(DMA_INTR_ENA_NIE_TX_LOONGSON | \
+			 DMA_INTR_ENA_NIE_RX_LOONGSON | DMA_INTR_ENA_RIE | \
+			 DMA_INTR_ENA_TIE)
+
+#define DMA_INTR_ENA_AIE_TX_LOONGSON 0x00010000	/* Abnormal Loongson Tx Summary */
+#define DMA_INTR_ENA_AIE_RX_LOONGSON 0x00008000	/* Abnormal Loongson Rx Summary */
+
+#define DMA_INTR_ABNORMAL_LOONGSON	(DMA_INTR_ENA_AIE_TX_LOONGSON | \
+				DMA_INTR_ENA_AIE_RX_LOONGSON | DMA_INTR_ENA_FBE | \
+				DMA_INTR_ENA_UNE)
+
+#define DMA_INTR_DEFAULT_MASK_LOONGSON	(DMA_INTR_NORMAL_LOONGSON | DMA_INTR_ABNORMAL_LOONGSON)
+
+#define DMA_STATUS_NIS_TX_LOONGSON	0x00040000	/* Normal Loongson Tx Interrupt Summary */
+#define DMA_STATUS_NIS_RX_LOONGSON	0x00020000	/* Normal Loongson Rx Interrupt Summary */
+
+#define DMA_STATUS_AIS_TX_LOONGSON	0x00010000	/* Abnormal Loongson Tx Interrupt Summary */
+#define DMA_STATUS_AIS_RX_LOONGSON	0x00008000	/* Abnormal Loongson Rx Interrupt Summary */
+
Quoted 8 lines

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c line 41

Quoted 7 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +7 -0
+#define DMA_STATUS_FBI_TX_LOONGSON	0x00002000	/* Fatal Loongson Tx Bus Error Interrupt */
+#define DMA_STATUS_FBI_RX_LOONGSON	0x00001000	/* Fatal Loongson Rx Bus Error Interrupt */
+
+#define DMA_STATUS_MSK_COMMON_LOONGSON		(DMA_STATUS_NIS_TX_LOONGSON | \
+					 DMA_STATUS_NIS_RX_LOONGSON | DMA_STATUS_AIS_TX_LOONGSON | \
+					 DMA_STATUS_AIS_RX_LOONGSON | DMA_STATUS_FBI_TX_LOONGSON | \
+					 DMA_STATUS_FBI_RX_LOONGSON)

Max 80 chars per line please.

OK,

Quoted 24 lines
Quoted 11 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +11 -0
+
+#define DMA_STATUS_MSK_RX_LOONGSON		(DMA_STATUS_ERI | \
+					 DMA_STATUS_RWT | \
+					 DMA_STATUS_RPS | \
+					 DMA_STATUS_RU | \
+					 DMA_STATUS_RI | \
+					 DMA_STATUS_OVF | \
+					 DMA_STATUS_MSK_COMMON_LOONGSON)
+
+#define DMA_STATUS_MSK_TX_LOONGSON		(DMA_STATUS_ETI | \
+					 DMA_STATUS_UNF | \

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c line 62

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +10 -0
+					 DMA_STATUS_TJT | \
+					 DMA_STATUS_TU | \
+					 DMA_STATUS_TPS | \
+					 DMA_STATUS_TI | \
+					 DMA_STATUS_MSK_COMMON_LOONGSON)
+
+struct loongson_data {
+	struct device *dev;
+	u32 lgmac_version;
+	struct stmmac_dma_ops dwlgmac_dma_ops;

Just figured out we can do without this field being added to the private data. See my note in the loongson_setup() method.

Quoted 7 lines

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c line 65

Quoted 3 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +3 -0
+};
+
+static void dwlgmac_dma_init_channel(struct stmmac_priv *priv,

The "dwlgmac_" prefix is confusing. There is the DW XLGMAC IP-core for which the "dwxlgmac_" is more appropriate and "x" is easy to miss should your version of the prefix is met. Consider changing it to something like "loongson_gnet_".

OK,

Quoted 55 lines
Quoted 32 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +32 -0
+				     void __iomem *ioaddr,
+				     struct stmmac_dma_cfg *dma_cfg, u32 chan)
+{
+	u32 value;
+	int txpbl = dma_cfg->txpbl ?: dma_cfg->pbl;
+	int rxpbl = dma_cfg->rxpbl ?: dma_cfg->pbl;
+
+	/* common channel control register config */
+	value = readl(ioaddr + DMA_CHAN_BUS_MODE(chan));
+
+	/* Set the DMA PBL (Programmable Burst Length) mode.
+	 *
+	 * Note: before stmmac core 3.50 this mode bit was 4xPBL, and
+	 * post 3.5 mode bit acts as 8*PBL.
+	 */
+	if (dma_cfg->pblx8)
+		value |= DMA_BUS_MODE_MAXPBL;
+	value |= DMA_BUS_MODE_USP;
+	value &= ~(DMA_BUS_MODE_PBL_MASK | DMA_BUS_MODE_RPBL_MASK);
+	value |= (txpbl << DMA_BUS_MODE_PBL_SHIFT);
+	value |= (rxpbl << DMA_BUS_MODE_RPBL_SHIFT);
+
+	/* Set the Fixed burst mode */
+	if (dma_cfg->fixed_burst)
+		value |= DMA_BUS_MODE_FB;
+
+	/* Mixed Burst has no effect when fb is set */
+	if (dma_cfg->mixed_burst)
+		value |= DMA_BUS_MODE_MB;
+
+	value |= DMA_BUS_MODE_ATDS;
+

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c line 107

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +10 -0
+	if (dma_cfg->aal)
+		value |= DMA_BUS_MODE_AAL;
+
+	writel(value, ioaddr + DMA_BUS_MODE);
+
+	/* Mask interrupts by writing to CSR7 */
+	writel(DMA_INTR_DEFAULT_MASK_LOONGSON, ioaddr + DMA_INTR_ENA);
+}
+
+static int dwlgmac_dma_interrupt(struct stmmac_priv *priv, void __iomem *ioaddr,

The same note as above.

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c line 116

Quoted 9 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +9 -0
+				 struct stmmac_extra_stats *x, u32 chan, u32 dir)
+{
+	struct stmmac_rxq_stats *rxq_stats = &priv->xstats.rxq_stats[chan];
+	struct stmmac_txq_stats *txq_stats = &priv->xstats.txq_stats[chan];
+	int ret = 0;
+	/* read the status register (CSR5) */
+	u32 nor_intr_status;
+	u32 abnor_intr_status;
+	u32 fb_intr_status;

Reverse xmas tree please.

Quoted 2 lines

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c line 117

Quoted 1 line
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +1 -0
+	u32 intr_status = readl(ioaddr + DMA_CHAN_STATUS(chan));

Please move the initialization into a separate statement.

OK,

Quoted 107 lines

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c line 124

Quoted 7 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +7 -0
+
+#ifdef DWMAC_DMA_DEBUG
+	/* Enable it to monitor DMA rx/tx status in case of critical problems */
+	pr_debug("%s: [CSR5: 0x%08x]\n", __func__, intr_status);
+	show_tx_process_state(intr_status);
+	show_rx_process_state(intr_status);
+#endif

This will cause a build-error if DWMAC_DMA_DEBUG is defined. Just drop it.
OK,

Quoted 76 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +73 -0
+
+	if (dir == DMA_DIR_RX)
+		intr_status &= DMA_STATUS_MSK_RX_LOONGSON;
+	else if (dir == DMA_DIR_TX)
+		intr_status &= DMA_STATUS_MSK_TX_LOONGSON;
+
+	nor_intr_status = intr_status & (DMA_STATUS_NIS_TX_LOONGSON |
+		DMA_STATUS_NIS_RX_LOONGSON);
+	abnor_intr_status = intr_status & (DMA_STATUS_AIS_TX_LOONGSON |
+		DMA_STATUS_AIS_RX_LOONGSON);
+	fb_intr_status = intr_status & (DMA_STATUS_FBI_TX_LOONGSON |
+		DMA_STATUS_FBI_RX_LOONGSON);
+
+	/* ABNORMAL interrupts */
+	if (unlikely(abnor_intr_status)) {
+		if (unlikely(intr_status & DMA_STATUS_UNF)) {
+			ret = tx_hard_error_bump_tc;
+			x->tx_undeflow_irq++;
+		}
+		if (unlikely(intr_status & DMA_STATUS_TJT))
+			x->tx_jabber_irq++;
+
+		if (unlikely(intr_status & DMA_STATUS_OVF))
+			x->rx_overflow_irq++;
+
+		if (unlikely(intr_status & DMA_STATUS_RU))
+			x->rx_buf_unav_irq++;
+		if (unlikely(intr_status & DMA_STATUS_RPS))
+			x->rx_process_stopped_irq++;
+		if (unlikely(intr_status & DMA_STATUS_RWT))
+			x->rx_watchdog_irq++;
+		if (unlikely(intr_status & DMA_STATUS_ETI))
+			x->tx_early_irq++;
+		if (unlikely(intr_status & DMA_STATUS_TPS)) {
+			x->tx_process_stopped_irq++;
+			ret = tx_hard_error;
+		}
+		if (unlikely(intr_status & fb_intr_status)) {
+			x->fatal_bus_error_irq++;
+			ret = tx_hard_error;
+		}
+	}
+	/* TX/RX NORMAL interrupts */
+	if (likely(nor_intr_status)) {
+		if (likely(intr_status & DMA_STATUS_RI)) {
+			u32 value = readl(ioaddr + DMA_INTR_ENA);
+			/* to schedule NAPI on real RIE event. */
+			if (likely(value & DMA_INTR_ENA_RIE)) {
+				u64_stats_update_begin(&rxq_stats->syncp);
+				rxq_stats->rx_normal_irq_n++;
+				u64_stats_update_end(&rxq_stats->syncp);
+				ret |= handle_rx;
+			}
+		}
+		if (likely(intr_status & DMA_STATUS_TI)) {
+			u64_stats_update_begin(&txq_stats->syncp);
+			txq_stats->tx_normal_irq_n++;
+			u64_stats_update_end(&txq_stats->syncp);
+			ret |= handle_tx;
+		}
+		if (unlikely(intr_status & DMA_STATUS_ERI))
+			x->rx_early_irq++;
+	}
+	/* Optional hardware blocks, interrupts should be disabled */
+	if (unlikely(intr_status &
+		     (DMA_STATUS_GPI | DMA_STATUS_GMI | DMA_STATUS_GLI)))
+		pr_warn("%s: unexpected status %08x\n", __func__, intr_status);
+
+	/* Clear the interrupt by writing a logic 1 to the CSR5[15-0] */
+	writel((intr_status & 0x7ffff), ioaddr + DMA_CHAN_STATUS(chan));
+
+	return ret;
+}
     struct stmmac_pci_info {
     	int (*setup)(struct pci_dev *pdev, struct plat_stmmacenet_data *plat);

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static struct stmmac_pci_info loongson_gmac_pci_info = { · line 310

Quoted 3 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +1 -0
@@ -121,6 +308,48 @@ static struct stmmac_pci_info loongson_gmac_pci_info = {
     	.config = loongson_gmac_config,
     };
+static struct mac_device_info *loongson_setup(void *apriv)

Consider using the GNET-specific prefix, like "loongson_gnet_".

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static struct stmmac_pci_info loongson_gmac_pci_info = { · line 318

Quoted 8 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +8 -0
+{
+	struct stmmac_priv *priv = apriv;
+	struct mac_device_info *mac;
+	struct loongson_data *ld;
+
+	mac = devm_kzalloc(priv->device, sizeof(*mac), GFP_KERNEL);
+	if (!mac)
+		return NULL;

What about devm_kzalloc()-ing the stmmac_dma_ops instance here and initializing it as it's done in the probe method? Thus ...

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static struct stmmac_pci_info loongson_gmac_pci_info = { · line 321

Quoted 3 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +3 -0
+
+	ld = priv->plat->bsp_priv;
+	mac->dma = &ld->dwlgmac_dma_ops;

... this can be replaced with:

Quoted 6 lines
Quoted 4 lines
Quoted 3 lines
	mac->dma = devm_kzalloc(priv->device, sizeof(*mac->dma), GFP_KERNEL);
	if (!mac->dma)
		return -ENOMEM;

Great, but It seems that we cannot return an int value here.

Just

		return NULL;

OK,

Quoted 5 lines

then.

Quoted 3 lines
Quoted 3 lines
	*mac->dma = dwmac1000_dma_ops;
	mac->dma->init_chan = loongson_gnet_dma_init_channel;
	mac->dma->dma_interrupt = loongson_gnet_dma_interrupt;
Quoted 10 lines

It seems that we still cannot do this because: structmac_device_info{
...
conststructstmmac_mmc_ops*mmc;
...
}
some errors output:
error: assignment of read-only location '*mac->dma'
error: assignment of member 'init_chan' in read-only object
...

No, we can. Just use a temporary non-const pointer to stmmac_dma_ops:

Quoted 15 lines

Review

Quoted 13 lines
(quoted diff) +13 -0
+static struct mac_device_info *loongson_gnet_setup(void *apriv)
+{
+	struct stmmac_priv *priv = apriv;
+	struct mac_device_info *mac;
+	struct stmmac_dma_ops *dma;
+	struct loongson_data *ld;
+
+	mac = devm_kzalloc(priv->device, sizeof(*mac), GFP_KERNEL);
+	if (!mac)
+		return NULL;
+
+	dma = devm_kzalloc(priv->device, sizeof(*dma), GFP_KERNEL);
+	if (!mac->dma)

We have already modified it according to this comment. By the way, this should be "if (!mac)",

Quoted 1 line

if (!dma)

Yes, you are right!

Thanks,

Yanteng

Quoted 122 lines

-Serge(y)

Quoted 119 lines

otherwise the following part of the code will not work:

Review

Quoted 8 lines
(quoted diff) +8 -0
+		return NULL;
+
+	*dma = dwmac1000_dma_ops;
+	dma->init_chan = loongson_gnet_dma_init_channel;
+	dma->dma_interrupt = loongson_gnet_dma_interrupt;
+	mac->dma = dma;
+
+	...

Tomorrow I will continue to modify other patches based on your comment.

Thanks,

Yanteng

Quoted 103 lines

-Serge(y)

Quoted 101 lines

Thanks,
Yanteng

Quoted 99 lines
Quoted 69 lines
Quoted 51 lines
Quoted 34 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +30 -0
+
+	/* Pre-initialize the respective "mac" fields as it's done in
+	 * dwmac1000_setup()
+	 */
+	priv->dev->priv_flags |= IFF_UNICAST_FLT;
+	mac->pcsr = priv->ioaddr;
+	mac->multicast_filter_bins = priv->plat->multicast_filter_bins;
+	mac->unicast_filter_entries = priv->plat->unicast_filter_entries;
+	mac->mcast_bits_log2 = 0;
+
+	if (mac->multicast_filter_bins)
+		mac->mcast_bits_log2 = ilog2(mac->multicast_filter_bins);
+
+	mac->link.duplex = GMAC_CONTROL_DM;
+	mac->link.speed10 = GMAC_CONTROL_PS;
+	mac->link.speed100 = GMAC_CONTROL_PS | GMAC_CONTROL_FES;
+	mac->link.speed1000 = 0;
+	mac->link.speed_mask = GMAC_CONTROL_PS | GMAC_CONTROL_FES;
+	mac->mii.addr = GMAC_MII_ADDR;
+	mac->mii.data = GMAC_MII_DATA;
+	mac->mii.addr_shift = 11;
+	mac->mii.addr_mask = 0x0000F800;
+	mac->mii.reg_shift = 6;
+	mac->mii.reg_mask = 0x000007C0;
+	mac->mii.clk_csr_shift = 2;
+	mac->mii.clk_csr_mask = GENMASK(5, 2);
+
+	return mac;
+}
+
     static int loongson_dwmac_probe(struct pci_dev *pdev,
     				const struct pci_device_id *id)
     {

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int loongson_dwmac_probe(struct pci_dev *pdev, · line 361

Quoted 4 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +1 -0
@@ -129,6 +358,7 @@ static int loongson_dwmac_probe(struct pci_dev *pdev,
     	struct stmmac_pci_info *info;
     	struct stmmac_resources res;
     	struct device_node *np;
+	struct loongson_data *ld;

reverse xmas tree order please.

Quoted 11 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +4 -0
     	plat = devm_kzalloc(&pdev->dev, sizeof(*plat), GFP_KERNEL);
     	if (!plat)
@@ -145,6 +375,10 @@ static int loongson_dwmac_probe(struct pci_dev *pdev,
     	if (!plat->dma_cfg)
     		return -ENOMEM;
+	ld = devm_kzalloc(&pdev->dev, sizeof(*ld), GFP_KERNEL);
+	if (!ld)
+		return -ENOMEM;
+
     	np = dev_of_node(&pdev->dev);
     	plat->mdio_node = of_get_child_by_name(np, "mdio");
Quoted 8 lines

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int loongson_dwmac_probe(struct pci_dev *pdev, · line 434

Quoted 6 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +2 -0
     	if (plat->mdio_node) {
@@ -197,6 +431,20 @@ static int loongson_dwmac_probe(struct pci_dev *pdev,
     	if (ret)
     		goto err_disable_device;
+	ld->dev = &pdev->dev;
+	ld->lgmac_version = readl(res.addr + GMAC_VERSION) & 0xff;

AFAICS the lgmac_version is unused in out of the probe() method context. What about locally defining it?

OK,

Quoted 4 lines

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int loongson_dwmac_probe(struct pci_dev *pdev, · line 437

Quoted 3 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +3 -0
+
+	/* Activate loongson custom ip */
+	if (ld->lgmac_version < DWMAC_CORE_3_50) {

Please define a new macro for the GNET MAC.

OK.

Quoted 4 lines

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int loongson_dwmac_probe(struct pci_dev *pdev, · line 440

Quoted 3 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +3 -0
+		ld->dwlgmac_dma_ops = dwmac1000_dma_ops;
+		ld->dwlgmac_dma_ops.init_chan = dwlgmac_dma_init_channel;
+		ld->dwlgmac_dma_ops.dma_interrupt = dwlgmac_dma_interrupt;

See my comment in the loongson_setup() method.

Quoted 6 lines

This will introduce a compilation warning:

warning: returning 'int' from a function with return type 'struct mac_device_info *' makes pointer from integer without a cast [-Wint-conversion]
  418 |                 return -ENOMEM;

stmmac_hwif_init() expects priv->plat->setup(priv) returning NULL if something wrong. As I suggested above just return NULL then if mac_device_info couldn't be allocated.

-Serge(y)

Quoted 18 lines

Thanks,

Yanteng

Quoted 14 lines

-Serge(y)

Quoted 12 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +6 -0
+
+		plat->setup = loongson_setup;
+	}
+
+	plat->bsp_priv = ld;
+
     	ret = stmmac_dvr_probe(&pdev->dev, plat, &res);
     	if (ret)
     		goto err_disable_device;
Signature · 1 line
2.31.4
author
#26 lore raw

Re: [PATCH net-next v8 04/11] net: stmmac: dwmac-loongson: Move irq config to loongson_gmac_config

In reply to Serge Semin
Quoted 8 lines · Serge Semin
Quoted 5 lines · Yanteng Si

Add loongson_dwmac_config and moving irq config related code to loongson_dwmac_config.

Removing MSI to prepare for adding loongson multi-channel support later.

Please detach this change into a separate patch and thoroughly explain why it was necessary.

OK.

Quoted 47 lines
Quoted 47 lines
---
  .../ethernet/stmicro/stmmac/dwmac-loongson.c  | 85 ++++++++++++-------
  1 file changed, 55 insertions(+), 30 deletions(-)
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +29 -0
index 979c9b6dab3f..e7ce027cc14e 100644
@@ -11,8 +11,46 @@
 
  struct stmmac_pci_info {
  	int (*setup)(struct pci_dev *pdev, struct plat_stmmacenet_data *plat);
+	int (*config)(struct pci_dev *pdev, struct plat_stmmacenet_data *plat,
+		      struct stmmac_resources *res, struct device_node *np);
  };
 
+static int loongson_dwmac_config_legacy(struct pci_dev *pdev,
+					struct plat_stmmacenet_data *plat,
+					struct stmmac_resources *res,
+					struct device_node *np)
+{
+	if (np) {
+		res->irq = of_irq_get_byname(np, "macirq");
+		if (res->irq < 0) {
+			dev_err(&pdev->dev, "IRQ macirq not found\n");
+			return -ENODEV;
+		}
+
+		res->wol_irq = of_irq_get_byname(np, "eth_wake_irq");
+		if (res->wol_irq < 0) {
+			dev_info(&pdev->dev,
+				 "IRQ eth_wake_irq not found, using macirq\n");
+			res->wol_irq = res->irq;
+		}
+
+		res->lpi_irq = of_irq_get_byname(np, "eth_lpi");
+		if (res->lpi_irq < 0) {
+			dev_err(&pdev->dev, "IRQ eth_lpi not found\n");
+			return -ENODEV;
+		}
+	} else {
+		res->irq = pdev->irq;
+		res->wol_irq = res->irq;
Quoted 8 lines

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c line 49

Quoted 5 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +5 -0
+	}
+
+	plat->flags &= ~STMMAC_FLAG_MULTI_MSI_EN;
+	dev_info(&pdev->dev, "%s: Single IRQ enablement successful\n",
+		 __func__);

Why is this here all of the sudden? I don't see this in the original code. Please move it to the patch which requires the flag setup/cleanup or drop if it isn't necessary.

+ plat->flags &= ~STMMAC_FLAG_MULTI_MSI_EN;
This cannot be removed because it appeared in a rebase(v4 -> v5). See <https://lore.kernel.org/all/[email protected]/> + dev_info(&pdev->dev, "%s: Single IRQ enablement successful\n",
+ __func__);

OK, drop it.

Quoted 21 lines
Quoted 21 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +13 -0
+
+	return 0;
+}
+
  static void loongson_default_data(struct pci_dev *pdev,
  				  struct plat_stmmacenet_data *plat)
  {
@@ -66,8 +104,21 @@ static int loongson_gmac_data(struct pci_dev *pdev,
  	return 0;
  }
 
+static int loongson_gmac_config(struct pci_dev *pdev,
+				struct plat_stmmacenet_data *plat,
+				struct stmmac_resources *res,
+				struct device_node *np)
+{
+	int ret;
+
+	ret = loongson_dwmac_config_legacy(pdev, plat, res, np);
+
Quoted 8 lines

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int loongson_gmac_data(struct pci_dev *pdev, · line 118

Quoted 3 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +3 -0
+	return ret;
+}
+

You introduce the config callback here and convert to a dummy method in
[PATCH 07/11] net: stmmac: dwmac-loongson: Add multi-channel supports for loongson It's just pointless. What about introducing the loongson_dwmac_config_legacy() method and call it directly?

OK, I will try.

Quoted 6 lines
Quoted 6 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +1 -0
  static struct stmmac_pci_info loongson_gmac_pci_info = {
  	.setup = loongson_gmac_data,
+	.config = loongson_gmac_config,
  };
 
Quoted 7 lines

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int loongson_dwmac_probe(struct pci_dev *pdev, · line 142

Quoted 6 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +0 -1
  static int loongson_dwmac_probe(struct pci_dev *pdev,
@@ -139,44 +190,19 @@ static int loongson_dwmac_probe(struct pci_dev *pdev,
  		plat->phy_interface = phy_mode;
  	}
 
-	pci_enable_msi(pdev);

See my first note in this message.

OK.

Thanks,

Yanteng

Quoted 58 lines

-Serge(y)

Quoted 55 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +4 -29
  	memset(&res, 0, sizeof(res));
  	res.addr = pcim_iomap_table(pdev)[0];
 
-	if (np) {
-		res.irq = of_irq_get_byname(np, "macirq");
-		if (res.irq < 0) {
-			dev_err(&pdev->dev, "IRQ macirq not found\n");
-			ret = -ENODEV;
-			goto err_disable_msi;
-		}
-
-		res.wol_irq = of_irq_get_byname(np, "eth_wake_irq");
-		if (res.wol_irq < 0) {
-			dev_info(&pdev->dev,
-				 "IRQ eth_wake_irq not found, using macirq\n");
-			res.wol_irq = res.irq;
-		}
-
-		res.lpi_irq = of_irq_get_byname(np, "eth_lpi");
-		if (res.lpi_irq < 0) {
-			dev_err(&pdev->dev, "IRQ eth_lpi not found\n");
-			ret = -ENODEV;
-			goto err_disable_msi;
-		}
-	} else {
-		res.irq = pdev->irq;
-		res.wol_irq = pdev->irq;
-	}
+	ret = info->config(pdev, plat, &res, np);
+	if (ret)
+		goto err_disable_device;
 
  	ret = stmmac_dvr_probe(&pdev->dev, plat, &res);
  	if (ret)
-		goto err_disable_msi;
+		goto err_disable_device;
 
  	return ret;
 
-err_disable_msi:
-	pci_disable_msi(pdev);
  err_disable_device:
  	pci_disable_device(pdev);
  err_put_node:
@@ -200,7 +226,6 @@ static void loongson_dwmac_remove(struct pci_dev *pdev)
  		break;
  	}
 
-	pci_disable_msi(pdev);
  	pci_disable_device(pdev);
  }
 
Signature · 1 line
2.31.4
author
#10 lore raw

Re: [PATCH net-next v8 01/11] net: stmmac: Add multi-channel support

In reply to a message not in the archive

Hi Serge

Quoted 719 lines · Yanteng Si
Quoted 216 lines · Serge Semin

Hi Yanteng

Quoted 192 lines · Yanteng Si

Hi Serge

Quoted 69 lines · Serge Semin
Quoted 35 lines · Yanteng Si

DW GMAC v3.x multi-channels feature is implemented as multiple sets of the same CSRs. Here is only preliminary support, it will be useful for the driver further evolution and for the users having multi-channel DWGMAC v3.x devices.

---
   .../net/ethernet/stmicro/stmmac/dwmac-sun8i.c |  2 +-
   .../ethernet/stmicro/stmmac/dwmac1000_dma.c   | 36 ++++++++++---------
   .../net/ethernet/stmicro/stmmac/dwmac_dma.h   | 19 +++++++++-
   .../net/ethernet/stmicro/stmmac/dwmac_lib.c   | 32 ++++++++---------
   drivers/net/ethernet/stmicro/stmmac/hwif.h    |  2 +-
   .../net/ethernet/stmicro/stmmac/stmmac_main.c |  6 ++--
   6 files changed, 58 insertions(+), 39 deletions(-)
drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c +1 -1
index 137741b94122..7cdfa0bdb93a 100644
@@ -395,7 +395,7 @@ static void sun8i_dwmac_dma_start_tx(struct stmmac_priv *priv,
   	writel(v, ioaddr + EMAC_TX_CTL1);
   }
-static void sun8i_dwmac_enable_dma_transmission(void __iomem *ioaddr)
+static void sun8i_dwmac_enable_dma_transmission(void __iomem *ioaddr, u32 chan)
   {
   	u32 v;
drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c +0 -0
index daf79cdbd3ec..5f7b82ad3ec2 100644
@@ -70,15 +70,18 @@ static void dwmac1000_dma_axi(void __iomem *ioaddr, struct stmmac_axi *axi)
   	writel(value, ioaddr + DMA_AXI_BUS_MODE);
   }

drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c static void dwmac1000_dma_axi(void __iomem *ioaddr, struct stmmac_axi *axi) · line 78

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c +4 -3
-static void dwmac1000_dma_init(void __iomem *ioaddr,
-			       struct stmmac_dma_cfg *dma_cfg, int atds)
+static void dwmac1000_dma_init_channel(struct stmmac_priv *priv,
+				       void __iomem *ioaddr,
+				       struct stmmac_dma_cfg *dma_cfg, u32 chan)
   {
-	u32 value = readl(ioaddr + DMA_BUS_MODE);
+	u32 value;
   	int txpbl = dma_cfg->txpbl ?: dma_cfg->pbl;
   	int rxpbl = dma_cfg->rxpbl ?: dma_cfg->pbl;

Reverse xmas tree please.

drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c static void dwmac1000_dma_axi(void __iomem *ioaddr, struct stmmac_axi *axi) · line 79

Quoted 3 lines
drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c +1 -2
-	/*
-	 * Set the DMA PBL (Programmable Burst Length) mode.
+	/* common channel control register config */

Redundant comment. Please drop.

drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c static void dwmac1000_dma_init(void __iomem *ioaddr, · line 103

Quoted 12 lines
drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c +4 -2
+	value = readl(ioaddr + DMA_CHAN_BUS_MODE(chan));
+
+	/* Set the DMA PBL (Programmable Burst Length) mode.
   	 *
   	 * Note: before stmmac core 3.50 this mode bit was 4xPBL, and
   	 * post 3.5 mode bit acts as 8*PBL.
@@ -98,16 +101,15 @@ static void dwmac1000_dma_init(void __iomem *ioaddr,
   	if (dma_cfg->mixed_burst)
   		value |= DMA_BUS_MODE_MB;
-	if (atds)
-		value |= DMA_BUS_MODE_ATDS;
+	value |= DMA_BUS_MODE_ATDS;

No, just convert the stmmac_dma_ops.dma_init_channel() to accepting the atds flag as I suggested in v7:
https://lore.kernel.org/netdev/vxcfrxtbfu4pya56m22icnizsyjzqqha5blzb7zpexqcur56uh@uv6vsjf77npa/

Quoted 4 lines

In order to simplify this patch you can provide the stmmac_dma_ops.dma_init_channel() and stmmac_dma_ops.enable_dma_transmission() prototype updates in a pre-requisite/preparation patch.

Sorry to keep you waiting for so long, I finally got the machine again. Regarding atds, is this how it is implemented?

On the basis of applying PATCH v8:

drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c +2 -1
index 0323f0a5049c..ce99f4a1b320 100644
@@ -72,7 +72,8 @@ static void dwmac1000_dma_axi(void __iomem *ioaddr, struct
 stmmac_axi *axi)
 
  static void dwmac1000_dma_init_channel(struct stmmac_priv *priv,
                         void __iomem *ioaddr,
-                       struct stmmac_dma_cfg *dma_cfg, u32 chan)
+                       struct stmmac_dma_cfg *dma_cfg,
+                       int atds, u32 chan)
  {
      u32 value;
      int txpbl = dma_cfg->txpbl ?: dma_cfg->pbl;
drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c +2 -1
@@ -101,7 +102,8 @@ static void dwmac1000_dma_init_channel(struct
 stmmac_priv *priv,
      if (dma_cfg->mixed_burst)
          value |= DMA_BUS_MODE_MB;
 
-    value |= DMA_BUS_MODE_ATDS;
+    if (atds)
+        value |= DMA_BUS_MODE_ATDS;
 
      if (dma_cfg->aal)
          value |= DMA_BUS_MODE_AAL;
drivers/net/ethernet/stmicro/stmmac/dwmac4_dma.c +2 -1
index 84d3a8551b03..8a79c154b553 100644
@@ -117,7 +117,8 @@ static void dwmac4_dma_init_tx_chan(struct stmmac_priv
 *priv,
 
  static void dwmac4_dma_init_channel(struct stmmac_priv *priv,
                      void __iomem *ioaddr,
-                    struct stmmac_dma_cfg *dma_cfg, u32 chan)
+                    struct stmmac_dma_cfg *dma_cfg,
+                                    int atds, u32 chan)
  {
      const struct dwmac4_addrs *dwmac4_addrs = priv->plat->dwmac4_addrs;
      u32 value;
drivers/net/ethernet/stmicro/stmmac/dwmac4_dma.c +2 -1
@@ -135,7 +136,8 @@ static void dwmac4_dma_init_channel(struct stmmac_priv
 *priv,
 
  static void dwmac410_dma_init_channel(struct stmmac_priv *priv,
                        void __iomem *ioaddr,
-                      struct stmmac_dma_cfg *dma_cfg, u32 chan)
+                      struct stmmac_dma_cfg *dma_cfg,
+                                      int atds, u32 chan)
  {
      const struct dwmac4_addrs *dwmac4_addrs = priv->plat->dwmac4_addrs;
      u32 value;
drivers/net/ethernet/stmicro/stmmac/dwxgmac2_dma.c +2 -1
index dd2ab6185c40..d1627b2e50c8 100644
@@ -35,7 +35,8 @@ static void dwxgmac2_dma_init(void __iomem *ioaddr,
 
  static void dwxgmac2_dma_init_chan(struct stmmac_priv *priv,
                     void __iomem *ioaddr,
-                   struct stmmac_dma_cfg *dma_cfg, u32 chan)
+                   struct stmmac_dma_cfg *dma_cfg,
+                                   int atds, u32 chan)
  {
      u32 value = readl(ioaddr + XGMAC_DMA_CH_CONTROL(chan));
 
drivers/net/ethernet/stmicro/stmmac/hwif.h +1 -1
index b0db38396171..fb27ad0e97e8 100644
@@ -178,7 +178,7 @@ struct stmmac_dma_ops {
      void (*init)(void __iomem *ioaddr, struct stmmac_dma_cfg *dma_cfg,
               int atds);
      void (*init_chan)(struct stmmac_priv *priv, void __iomem *ioaddr,
-              struct stmmac_dma_cfg *dma_cfg, u32 chan);
+              struct stmmac_dma_cfg *dma_cfg, int atds, u32 chan);
      void (*init_rx_chan)(struct stmmac_priv *priv, void __iomem *ioaddr,
                   struct stmmac_dma_cfg *dma_cfg,
                   dma_addr_t phy, u32 chan);
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +1 -1
index 3eed202d1f1c..8705e04913d1 100644
@@ -3039,7 +3039,7 @@ static int stmmac_init_dma_engine(struct stmmac_priv
 *priv)
 
      /* DMA CSR Channel configuration */
      for (chan = 0; chan < dma_csr_ch; chan++) {
-        stmmac_init_chan(priv, priv->ioaddr, priv->plat->dma_cfg, chan);
+        stmmac_init_chan(priv, priv->ioaddr, priv->plat->dma_cfg, atds,
 chan);
          stmmac_disable_dma_irq(priv, priv->ioaddr, chan, 1, 1);
      }
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +1 -0
@@ -6963,6 +6963,7 @@ int stmmac_xdp_open(struct net_device *dev)
      u32 buf_size;
      bool sph_en;
      u32 chan;
+     int atds;
      int ret;
 
      ret = alloc_dma_desc_resources(priv, &priv->dma_conf);
@@ -6981,9 +6982,12 @@ int stmmac_xdp_open(struct net_device *dev)
 
      stmmac_reset_queues_param(priv);
 

drivers/net/ethernet/stmicro/stmmac/stmmac_main.c int stmmac_xdp_open(struct net_device *dev) · line 6993

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +4 -1
+    if (priv->extend_desc && (priv->mode == STMMAC_RING_MODE))
+        atds = 1;
+
      /* DMA CSR Channel configuration */
      for (chan = 0; chan < dma_csr_ch; chan++) {
-        stmmac_init_chan(priv, priv->ioaddr, priv->plat->dma_cfg, chan);
+        stmmac_init_chan(priv, priv->ioaddr, priv->plat->dma_cfg, atds,
 chan);
          stmmac_disable_dma_irq(priv, priv->ioaddr, chan, 1, 1);
      }

Looking more thoroughly at this part I suggest to act a bit differently. Let's move the atds flag to the stmmac_dma_cfg structure. Alternate Descriptor Size (ATDS) is a part of the DMA-configs together with the PBL, ALL, AEME, etc so the structure is the most suitable place for it. Here is what should be done for that:
1. Add stmmac_dma_cfg::atds boolean field.
2. Drop atds argument from the stmmac_dma_ops::init() callback and use the stmmac_dma_cfg::atds field in the callback implementations.
3. Alter stmmac_init_dma_engine() to updating the dma_cfg->atds field instead of the local variable.

Quoted 4 lines

Please implement that update in a pre-requisite/preparation patch.

After that you can freely use the stmmac_dma_cfg::atds field in the stmmac_init_chan() method too.

OK.

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +2 -3
index b57e1325ce62..dabd6a3772f2 100644
@@ -66,8 +66,7 @@ struct loongson_data {
 
   static void loongson_gnet_dma_init_channel(struct stmmac_priv *priv,
                        void __iomem *ioaddr,
-                     struct stmmac_dma_cfg *dma_cfg,
-                                     int atds, u32 chan)
+                     struct stmmac_dma_cfg *dma_cfg, u32 chan)
   {
       int txpbl = dma_cfg->txpbl ?: dma_cfg->pbl;
       int rxpbl = dma_cfg->rxpbl ?: dma_cfg->pbl;
@@ -96,7 +95,7 @@ static void loongson_gnet_dma_init_channel(struct stmmac_priv
 *priv,
       if (dma_cfg->mixed_burst)
           value |= DMA_BUS_MODE_MB;
 
-    if (atds)
+    if (dma_cfg->atds)
           value |= DMA_BUS_MODE_ATDS;
 
       if (dma_cfg->aal)
drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c +1 -1
index 7001a86425ea..ae9240736e64 100644
@@ -299,7 +299,7 @@ static int sun8i_dwmac_dma_reset(void __iomem *ioaddr)
    * Called from stmmac via stmmac_dma_ops->init
    */
   static void sun8i_dwmac_dma_init(void __iomem *ioaddr,
-                 struct stmmac_dma_cfg *dma_cfg, int atds)
+                 struct stmmac_dma_cfg *dma_cfg)
   {
       writel(EMAC_RX_INT | EMAC_TX_INT, ioaddr + EMAC_INT_EN);
       writel(0x1FFFFFF, ioaddr + EMAC_INT_STA);
drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c +1 -2
index fd5ecc043251..66c0c22908b1 100644
@@ -72,8 +72,7 @@ static void dwmac1000_dma_axi(void __iomem *ioaddr, struct
 stmmac_axi *axi)
 
   static void dwmac1000_dma_init_channel(struct stmmac_priv *priv,
                          void __iomem *ioaddr,
-                       struct stmmac_dma_cfg *dma_cfg,
-                       int atds, u32 chan)
+                       struct stmmac_dma_cfg *dma_cfg, u32 chan)
   {
       int txpbl = dma_cfg->txpbl ?: dma_cfg->pbl;
       int rxpbl = dma_cfg->rxpbl ?: dma_cfg->pbl;
drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c +1 -1
@@ -101,7 +100,7 @@ static void dwmac1000_dma_init_channel(struct stmmac_priv *priv,
       if (dma_cfg->mixed_burst)
           value |= DMA_BUS_MODE_MB;
 
-    if (atds)
+    if (dma_cfg->atds)
           value |= DMA_BUS_MODE_ATDS;
 
       if (dma_cfg->aal)
drivers/net/ethernet/stmicro/stmmac/dwmac100_dma.c +1 -1
index dea270f60cc3..f861babc06f9 100644
@@ -19,7 +19,7 @@
   #include "dwmac_dma.h"
 
   static void dwmac100_dma_init(void __iomem *ioaddr,
-                  struct stmmac_dma_cfg *dma_cfg, int atds)
+                  struct stmmac_dma_cfg *dma_cfg)
   {
       /* Enable Application Access by writing to DMA CSR0 */
       writel(DMA_BUS_MODE_DEFAULT | (dma_cfg->pbl << DMA_BUS_MODE_PBL_SHIFT),
drivers/net/ethernet/stmicro/stmmac/dwmac4_dma.c +3 -5
index 8a79c154b553..e0165358c4ac 100644
@@ -117,8 +117,7 @@ static void dwmac4_dma_init_tx_chan(struct stmmac_priv *priv,
 
   static void dwmac4_dma_init_channel(struct stmmac_priv *priv,
                       void __iomem *ioaddr,
-                    struct stmmac_dma_cfg *dma_cfg,
-                                    int atds, u32 chan)
+                    struct stmmac_dma_cfg *dma_cfg, u32 chan)
   {
       const struct dwmac4_addrs *dwmac4_addrs = priv->plat->dwmac4_addrs;
       u32 value;
@@ -136,8 +135,7 @@ static void dwmac4_dma_init_channel(struct stmmac_priv *priv,
 
   static void dwmac410_dma_init_channel(struct stmmac_priv *priv,
                         void __iomem *ioaddr,
-                      struct stmmac_dma_cfg *dma_cfg,
-                                      int atds, u32 chan)
+                      struct stmmac_dma_cfg *dma_cfg, u32 chan)
   {
       const struct dwmac4_addrs *dwmac4_addrs = priv->plat->dwmac4_addrs;
       u32 value;
@@ -155,7 +153,7 @@ static void dwmac410_dma_init_channel(struct stmmac_priv *priv,
   }
 
   static void dwmac4_dma_init(void __iomem *ioaddr,
-                struct stmmac_dma_cfg *dma_cfg, int atds)
+                struct stmmac_dma_cfg *dma_cfg)
   {
       u32 value = readl(ioaddr + DMA_SYS_BUS_MODE);
 
drivers/net/ethernet/stmicro/stmmac/dwxgmac2_dma.c +2 -3
index d1627b2e50c8..7840bc403788 100644
@@ -20,7 +20,7 @@ static int dwxgmac2_dma_reset(void __iomem *ioaddr)
   }
 
   static void dwxgmac2_dma_init(void __iomem *ioaddr,
-                  struct stmmac_dma_cfg *dma_cfg, int atds)
+                  struct stmmac_dma_cfg *dma_cfg)
   {
       u32 value = readl(ioaddr + XGMAC_DMA_SYSBUS_MODE);
 
@@ -35,8 +35,7 @@ static void dwxgmac2_dma_init(void __iomem *ioaddr,
 
   static void dwxgmac2_dma_init_chan(struct stmmac_priv *priv,
                      void __iomem *ioaddr,
-                   struct stmmac_dma_cfg *dma_cfg,
-                                   int atds, u32 chan)
+                   struct stmmac_dma_cfg *dma_cfg, u32 chan)
   {
       u32 value = readl(ioaddr + XGMAC_DMA_CH_CONTROL(chan));
 
drivers/net/ethernet/stmicro/stmmac/hwif.h +2 -3
index fb27ad0e97e8..3b20fb7f3a61 100644
@@ -175,10 +175,9 @@ struct dma_features;
   struct stmmac_dma_ops {
       /* DMA core initialization */
       int (*reset)(void __iomem *ioaddr);
-    void (*init)(void __iomem *ioaddr, struct stmmac_dma_cfg *dma_cfg,
-             int atds);
+    void (*init)(void __iomem *ioaddr, struct stmmac_dma_cfg *dma_cfg);
       void (*init_chan)(struct stmmac_priv *priv, void __iomem *ioaddr,
-              struct stmmac_dma_cfg *dma_cfg, int atds, u32 chan);
+              struct stmmac_dma_cfg *dma_cfg, u32 chan);
       void (*init_rx_chan)(struct stmmac_priv *priv, void __iomem *ioaddr,
                    struct stmmac_dma_cfg *dma_cfg,
                    dma_addr_t phy, u32 chan);
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +4 -9
index 7c656f970575..957dfabc663d 100644
@@ -3013,7 +3013,6 @@ static int stmmac_init_dma_engine(struct stmmac_priv *priv)
       struct stmmac_rx_queue *rx_q;
       struct stmmac_tx_queue *tx_q;
       u32 chan = 0;
-    int atds = 0;
       int ret = 0;
 
       if (!priv->plat->dma_cfg || !priv->plat->dma_cfg->pbl) {
@@ -3022,7 +3021,7 @@ static int stmmac_init_dma_engine(struct stmmac_priv *priv)
       }
 
       if (priv->extend_desc && (priv->mode == STMMAC_RING_MODE))
-        atds = 1;
+        priv->plat->dma_cfg->atds = 1;
 
       ret = stmmac_reset(priv, priv->ioaddr);
       if (ret) {
@@ -3031,14 +3030,14 @@ static int stmmac_init_dma_engine(struct stmmac_priv *priv)
       }
 
       /* DMA Configuration */
-    stmmac_dma_init(priv, priv->ioaddr, priv->plat->dma_cfg, atds);
+    stmmac_dma_init(priv, priv->ioaddr, priv->plat->dma_cfg);
 
       if (priv->plat->axi)
           stmmac_axi(priv, priv->ioaddr, priv->plat->axi);
 
       /* DMA CSR Channel configuration */
       for (chan = 0; chan < dma_csr_ch; chan++) {
-        stmmac_init_chan(priv, priv->ioaddr, priv->plat->dma_cfg, atds, chan);
+        stmmac_init_chan(priv, priv->ioaddr, priv->plat->dma_cfg, chan);
           stmmac_disable_dma_irq(priv, priv->ioaddr, chan, 1, 1);
       }
 
@@ -6962,7 +6961,6 @@ int stmmac_xdp_open(struct net_device *dev)
       u32 buf_size;
       bool sph_en;
       u32 chan;
-        int atds;
       int ret;
 
       ret = alloc_dma_desc_resources(priv, &priv->dma_conf);
@@ -6981,12 +6979,9 @@ int stmmac_xdp_open(struct net_device *dev)
 
       stmmac_reset_queues_param(priv);
 
-    if (priv->extend_desc && (priv->mode == STMMAC_RING_MODE))
-        atds = 1;
-
       /* DMA CSR Channel configuration */
       for (chan = 0; chan < dma_csr_ch; chan++) {
-        stmmac_init_chan(priv, priv->ioaddr, priv->plat->dma_cfg, atds, chan);
+        stmmac_init_chan(priv, priv->ioaddr, priv->plat->dma_cfg, chan);
           stmmac_disable_dma_irq(priv, priv->ioaddr, chan, 1, 1);
       }
 
include/linux/stmmac.h +1 -0
index 23bfe3c1465f..c827dc1213b9 100644
@@ -100,6 +100,7 @@ struct stmmac_dma_cfg {
       bool eame;
       bool multi_msi_en;
       bool dche;
+    bool atds;
   };
 
   #define AXI_BLEN    7

Thanks,

Yanteng

Quoted 261 lines

-Serge(y)

Quoted 258 lines

Thanks,

Yanteng

Quoted 253 lines
Quoted 73 lines
drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c +10 -10
   	if (dma_cfg->aal)
   		value |= DMA_BUS_MODE_AAL;
-	writel(value, ioaddr + DMA_BUS_MODE);
+	writel(value, ioaddr + DMA_CHAN_BUS_MODE(chan));
   	/* Mask interrupts by writing to CSR7 */
-	writel(DMA_INTR_DEFAULT_MASK, ioaddr + DMA_INTR_ENA);
+	writel(DMA_INTR_DEFAULT_MASK, ioaddr + DMA_CHAN_INTR_ENA(chan));
   }
   static void dwmac1000_dma_init_rx(struct stmmac_priv *priv,
@@ -116,7 +118,7 @@ static void dwmac1000_dma_init_rx(struct stmmac_priv *priv,
   				  dma_addr_t dma_rx_phy, u32 chan)
   {
   	/* RX descriptor base address list must be written into DMA CSR3 */
-	writel(lower_32_bits(dma_rx_phy), ioaddr + DMA_RCV_BASE_ADDR);
+	writel(lower_32_bits(dma_rx_phy), ioaddr + DMA_CHAN_RCV_BASE_ADDR(chan));
   }
   static void dwmac1000_dma_init_tx(struct stmmac_priv *priv,
@@ -125,7 +127,7 @@ static void dwmac1000_dma_init_tx(struct stmmac_priv *priv,
   				  dma_addr_t dma_tx_phy, u32 chan)
   {
   	/* TX descriptor base address list must be written into DMA CSR4 */
-	writel(lower_32_bits(dma_tx_phy), ioaddr + DMA_TX_BASE_ADDR);
+	writel(lower_32_bits(dma_tx_phy), ioaddr + DMA_CHAN_TX_BASE_ADDR(chan));
   }
   static u32 dwmac1000_configure_fc(u32 csr6, int rxfifosz)
@@ -153,7 +155,7 @@ static void dwmac1000_dma_operation_mode_rx(struct stmmac_priv *priv,
   					    void __iomem *ioaddr, int mode,
   					    u32 channel, int fifosz, u8 qmode)
   {
-	u32 csr6 = readl(ioaddr + DMA_CONTROL);
+	u32 csr6 = readl(ioaddr + DMA_CHAN_CONTROL(channel));
   	if (mode == SF_DMA_MODE) {
   		pr_debug("GMAC: enable RX store and forward mode\n");
@@ -175,14 +177,14 @@ static void dwmac1000_dma_operation_mode_rx(struct stmmac_priv *priv,
   	/* Configure flow control based on rx fifo size */
   	csr6 = dwmac1000_configure_fc(csr6, fifosz);
-	writel(csr6, ioaddr + DMA_CONTROL);
+	writel(csr6, ioaddr + DMA_CHAN_CONTROL(channel));
   }
   static void dwmac1000_dma_operation_mode_tx(struct stmmac_priv *priv,
   					    void __iomem *ioaddr, int mode,
   					    u32 channel, int fifosz, u8 qmode)
   {
-	u32 csr6 = readl(ioaddr + DMA_CONTROL);
+	u32 csr6 = readl(ioaddr + DMA_CHAN_CONTROL(channel));
   	if (mode == SF_DMA_MODE) {
   		pr_debug("GMAC: enable TX store and forward mode\n");
@@ -209,7 +211,7 @@ static void dwmac1000_dma_operation_mode_tx(struct stmmac_priv *priv,
   			csr6 |= DMA_CONTROL_TTC_256;
   	}
-	writel(csr6, ioaddr + DMA_CONTROL);
+	writel(csr6, ioaddr + DMA_CHAN_CONTROL(channel));
   }
   static void dwmac1000_dump_dma_regs(struct stmmac_priv *priv,
@@ -271,12 +273,12 @@ static int dwmac1000_get_hw_feature(void __iomem *ioaddr,
   static void dwmac1000_rx_watchdog(struct stmmac_priv *priv,
   				  void __iomem *ioaddr, u32 riwt, u32 queue)
   {
-	writel(riwt, ioaddr + DMA_RX_WATCHDOG);
+	writel(riwt, ioaddr + DMA_CHAN_RX_WATCHDOG(queue));
   }
   const struct stmmac_dma_ops dwmac1000_dma_ops = {
   	.reset = dwmac_dma_reset,
-	.init = dwmac1000_dma_init,
+	.init_chan = dwmac1000_dma_init_channel,
   	.init_rx_chan = dwmac1000_dma_init_rx,
   	.init_tx_chan = dwmac1000_dma_init_tx,
   	.axi = dwmac1000_dma_axi,
drivers/net/ethernet/stmicro/stmmac/dwmac_dma.h +0 -0
index 72672391675f..593be79c46e1 100644

drivers/net/ethernet/stmicro/stmmac/dwmac_dma.h line 152

Quoted 5 lines
drivers/net/ethernet/stmicro/stmmac/dwmac_dma.h +3 -0
@@ -148,11 +148,14 @@
   					 DMA_STATUS_TI | \
   					 DMA_STATUS_MSK_COMMON)
+/* Following DMA defines are chanels oriented */    \
+#define DMA_CHAN_OFFSET			0x100   |-------------+
+                                                    /              |
                                                                        |
Please move all of these ---------------------------------------------+-------------------------+
to being defined just below the DMA_MISSED_FRAME_CTR macros definition.                         |
The point is to keep a coherency between dwmac_dma.h and dwmac4_dma.h.                          |
The later header file has first generic DMA-related macros defined                              |
(CSR addresses and flags) and then the channel-specific ones (CSR                               |
addresses and flags). Since in case of the DW GMAC v3.x the                                     |
multi-channels are implemented as a copy of all the DMA CSRs let's                              |
preserve the logic of having all CSR address defined first, then the                            |
CSR flags.                                                                                      |
                                                                                                  |

drivers/net/ethernet/stmicro/stmmac/dwmac_dma.h int dwmac_dma_interrupt(struct stmmac_priv *priv, void __iomem *ioaddr, | · line 174

Quoted 13 lines
drivers/net/ethernet/stmicro/stmmac/dwmac_dma.h +1 -1
   #define NUM_DWMAC100_DMA_REGS	9                                                       |
   #define NUM_DWMAC1000_DMA_REGS	23                                                      |
   #define NUM_DWMAC4_DMA_REGS	27                                                              |
                                                                                                |
-void dwmac_enable_dma_transmission(void __iomem *ioaddr);                                    |
+void dwmac_enable_dma_transmission(void __iomem *ioaddr, u32 chan);                          |
   void dwmac_enable_dma_irq(struct stmmac_priv *priv, void __iomem *ioaddr,                    |
   			  u32 chan, bool rx, bool tx);                                          |
   void dwmac_disable_dma_irq(struct stmmac_priv *priv, void __iomem *ioaddr,                   |
@@ -169,4 +172,18 @@ int dwmac_dma_interrupt(struct stmmac_priv *priv, void __iomem *ioaddr,  |
   			struct stmmac_extra_stats *x, u32 chan, u32 dir);                       |
   int dwmac_dma_reset(void __iomem *ioaddr);                                                   |
                                                                                                |
                                                                                                  |
Quoted 96 lines
drivers/net/ethernet/stmicro/stmmac/dwmac_dma.h +14 -0
+static inline u32 dma_chan_base_addr(u32 base, u32 chan)                                  \  |
+{                                                                                          | |
+	return base + chan * DMA_CHAN_OFFSET;                                                 | |
+}                                                                                          | |
+                                                                                           | |
+#define DMA_CHAN_XMT_POLL_DEMAND(chan)	dma_chan_base_addr(DMA_XMT_POLL_DEMAND, chan) | |
+#define DMA_CHAN_INTR_ENA(chan)		dma_chan_base_addr(DMA_INTR_ENA, chan)        | |
+#define DMA_CHAN_CONTROL(chan)		dma_chan_base_addr(DMA_CONTROL, chan)         | |
+#define DMA_CHAN_STATUS(chan)		dma_chan_base_addr(DMA_STATUS, chan)          |-+
+#define DMA_CHAN_BUS_MODE(chan)		dma_chan_base_addr(DMA_BUS_MODE, chan)        |
+#define DMA_CHAN_RCV_BASE_ADDR(chan)	dma_chan_base_addr(DMA_RCV_BASE_ADDR, chan)           |
+#define DMA_CHAN_TX_BASE_ADDR(chan)	dma_chan_base_addr(DMA_TX_BASE_ADDR, chan)            |
+#define DMA_CHAN_RX_WATCHDOG(chan)	dma_chan_base_addr(DMA_RX_WATCHDOG, chan)             |
+                                                                                           /
   #endif /* __DWMAC_DMA_H__ */
drivers/net/ethernet/stmicro/stmmac/dwmac_lib.c +15 -15
index 7907d62d3437..b37368137810 100644
@@ -28,65 +28,65 @@ int dwmac_dma_reset(void __iomem *ioaddr)
   }
   /* CSR1 enables the transmit DMA to check for new descriptor */
-void dwmac_enable_dma_transmission(void __iomem *ioaddr)
+void dwmac_enable_dma_transmission(void __iomem *ioaddr, u32 chan)
   {
-	writel(1, ioaddr + DMA_XMT_POLL_DEMAND);
+	writel(1, ioaddr + DMA_CHAN_XMT_POLL_DEMAND(chan));
   }
   void dwmac_enable_dma_irq(struct stmmac_priv *priv, void __iomem *ioaddr,
   			  u32 chan, bool rx, bool tx)
   {
-	u32 value = readl(ioaddr + DMA_INTR_ENA);
+	u32 value = readl(ioaddr + DMA_CHAN_INTR_ENA(chan));
   	if (rx)
   		value |= DMA_INTR_DEFAULT_RX;
   	if (tx)
   		value |= DMA_INTR_DEFAULT_TX;
-	writel(value, ioaddr + DMA_INTR_ENA);
+	writel(value, ioaddr + DMA_CHAN_INTR_ENA(chan));
   }
   void dwmac_disable_dma_irq(struct stmmac_priv *priv, void __iomem *ioaddr,
   			   u32 chan, bool rx, bool tx)
   {
-	u32 value = readl(ioaddr + DMA_INTR_ENA);
+	u32 value = readl(ioaddr + DMA_CHAN_INTR_ENA(chan));
   	if (rx)
   		value &= ~DMA_INTR_DEFAULT_RX;
   	if (tx)
   		value &= ~DMA_INTR_DEFAULT_TX;
-	writel(value, ioaddr + DMA_INTR_ENA);
+	writel(value, ioaddr + DMA_CHAN_INTR_ENA(chan));
   }
   void dwmac_dma_start_tx(struct stmmac_priv *priv, void __iomem *ioaddr,
   			u32 chan)
   {
-	u32 value = readl(ioaddr + DMA_CONTROL);
+	u32 value = readl(ioaddr + DMA_CHAN_CONTROL(chan));
   	value |= DMA_CONTROL_ST;
-	writel(value, ioaddr + DMA_CONTROL);
+	writel(value, ioaddr + DMA_CHAN_CONTROL(chan));
   }
   void dwmac_dma_stop_tx(struct stmmac_priv *priv, void __iomem *ioaddr, u32 chan)
   {
-	u32 value = readl(ioaddr + DMA_CONTROL);
+	u32 value = readl(ioaddr + DMA_CHAN_CONTROL(chan));
   	value &= ~DMA_CONTROL_ST;
-	writel(value, ioaddr + DMA_CONTROL);
+	writel(value, ioaddr + DMA_CHAN_CONTROL(chan));
   }
   void dwmac_dma_start_rx(struct stmmac_priv *priv, void __iomem *ioaddr,
   			u32 chan)
   {
-	u32 value = readl(ioaddr + DMA_CONTROL);
+	u32 value = readl(ioaddr + DMA_CHAN_CONTROL(chan));
   	value |= DMA_CONTROL_SR;
-	writel(value, ioaddr + DMA_CONTROL);
+	writel(value, ioaddr + DMA_CHAN_CONTROL(chan));
   }
   void dwmac_dma_stop_rx(struct stmmac_priv *priv, void __iomem *ioaddr, u32 chan)
   {
-	u32 value = readl(ioaddr + DMA_CONTROL);
+	u32 value = readl(ioaddr + DMA_CHAN_CONTROL(chan));
   	value &= ~DMA_CONTROL_SR;
-	writel(value, ioaddr + DMA_CONTROL);
+	writel(value, ioaddr + DMA_CHAN_CONTROL(chan));
   }
   #ifdef DWMAC_DMA_DEBUG
@@ -166,7 +166,7 @@ int dwmac_dma_interrupt(struct stmmac_priv *priv, void __iomem *ioaddr,
   	struct stmmac_txq_stats *txq_stats = &priv->xstats.txq_stats[chan];
   	int ret = 0;
   	/* read the status register (CSR5) */
-	u32 intr_status = readl(ioaddr + DMA_STATUS);
+	u32 intr_status = readl(ioaddr + DMA_CHAN_STATUS(chan));
   #ifdef DWMAC_DMA_DEBUG
   	/* Enable it to monitor DMA rx/tx status in case of critical problems */

drivers/net/ethernet/stmicro/stmmac/dwmac_lib.c int dwmac_dma_interrupt(struct stmmac_priv *priv, void __iomem *ioaddr, · line 238

Quoted 4 lines
drivers/net/ethernet/stmicro/stmmac/dwmac_lib.c +1 -1
@@ -236,7 +236,7 @@ int dwmac_dma_interrupt(struct stmmac_priv *priv, void __iomem *ioaddr,
   		pr_warn("%s: unexpected status %08x\n", __func__, intr_status);
   	/* Clear the interrupt by writing a logic 1 to the CSR5[15-0] */
-	writel((intr_status & 0x1ffff), ioaddr + DMA_STATUS);
+	writel((intr_status & 0x7ffff), ioaddr + DMA_CHAN_STATUS(chan));

Isn't the mask change going to be implemented in the framework of the Loongson-specific DMA-interrupt handler in some of the further patches?

I'll get back to reviewing the series tomorrow (later today)...

-Serge(y)

Quoted 42 lines
drivers/net/ethernet/stmicro/stmmac/dwmac_lib.c +0 -0
   	return ret;
   }
drivers/net/ethernet/stmicro/stmmac/hwif.h +1 -1
index 7be04b54738b..b0db38396171 100644
@@ -198,7 +198,7 @@ struct stmmac_dma_ops {
   	/* To track extra statistic (if supported) */
   	void (*dma_diagnostic_fr)(struct stmmac_extra_stats *x,
   				  void __iomem *ioaddr);
-	void (*enable_dma_transmission) (void __iomem *ioaddr);
+	void (*enable_dma_transmission)(void __iomem *ioaddr, u32 chan);
   	void (*enable_dma_irq)(struct stmmac_priv *priv, void __iomem *ioaddr,
   			       u32 chan, bool rx, bool tx);
   	void (*disable_dma_irq)(struct stmmac_priv *priv, void __iomem *ioaddr,
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +3 -3
index b334eb16da23..5617b40abbe4 100644
@@ -2558,7 +2558,7 @@ static bool stmmac_xdp_xmit_zc(struct stmmac_priv *priv, u32 queue, u32 budget)
   				       true, priv->mode, true, true,
   				       xdp_desc.len);
-		stmmac_enable_dma_transmission(priv, priv->ioaddr);
+		stmmac_enable_dma_transmission(priv, priv->ioaddr, queue);
   		xsk_tx_metadata_to_compl(meta,
   					 &tx_q->tx_skbuff_dma[entry].xsk_meta);
@@ -4706,7 +4706,7 @@ static netdev_tx_t stmmac_xmit(struct sk_buff *skb, struct net_device *dev)
   	netdev_tx_sent_queue(netdev_get_tx_queue(dev, queue), skb->len);
-	stmmac_enable_dma_transmission(priv, priv->ioaddr);
+	stmmac_enable_dma_transmission(priv, priv->ioaddr, queue);
   	stmmac_flush_tx_descriptors(priv, queue);
   	stmmac_tx_timer_arm(priv, queue);
@@ -4926,7 +4926,7 @@ static int stmmac_xdp_xmit_xdpf(struct stmmac_priv *priv, int queue,
   		u64_stats_update_end_irqrestore(&txq_stats->syncp, flags);
   	}
-	stmmac_enable_dma_transmission(priv, priv->ioaddr);
+	stmmac_enable_dma_transmission(priv, priv->ioaddr, queue);
   	entry = STMMAC_GET_ENTRY(entry, priv->dma_conf.dma_tx_size);
   	tx_q->cur_tx = entry;
Signature · 1 line
2.31.4
author
#79 lore raw

Re: [PATCH net-next v8 09/11] net: stmmac: dwmac-loongson: Fix half duplex

In reply to Serge Semin
Quoted 67 lines · Serge Semin
Quoted 58 lines · Serge Semin
Quoted 21 lines · Yanteng Si

Current GNET does not support half duplex mode.

---
  drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c | 11 ++++++++++-
  drivers/net/ethernet/stmicro/stmmac/stmmac_main.c    |  3 ++-
  include/linux/stmmac.h                               |  1 +
  3 files changed, 13 insertions(+), 2 deletions(-)
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +1 -1
index 264c4c198d5a..1753a3c46b77 100644
@@ -432,8 +432,17 @@ static int loongson_gnet_config(struct pci_dev *pdev,
  				struct stmmac_resources *res,
  				struct device_node *np)
  {
-	if (pdev->revision == 0x00 || pdev->revision == 0x01)
+	switch (pdev->revision) {

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int loongson_gnet_config(struct pci_dev *pdev, · line 445

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +9 -0
+	case 0x00:
+		plat->flags |= STMMAC_FLAG_DISABLE_FORCE_1000 |
+			       STMMAC_FLAG_DISABLE_HALF_DUPLEX;
+		break;
+	case 0x01:
  		plat->flags |= STMMAC_FLAG_DISABLE_FORCE_1000;
+		break;
+	default:
+		break;
+	}

Move this change into the patch
[PATCH net-next v8 06/11] net: stmmac: dwmac-loongson: Add GNET support

Quoted 23 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +0 -0
  	return 0;
  }
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +2 -1
index 5617b40abbe4..3aa862269eb0 100644
@@ -1201,7 +1201,8 @@ static int stmmac_init_phy(struct net_device *dev)
  static void stmmac_set_half_duplex(struct stmmac_priv *priv)
  {
  	/* Half-Duplex can only work with single tx queue */
-	if (priv->plat->tx_queues_to_use > 1)
+	if (priv->plat->tx_queues_to_use > 1 ||
+	    (STMMAC_FLAG_DISABLE_HALF_DUPLEX & priv->plat->flags))
  		priv->phylink_config.mac_capabilities &=
  			~(MAC_10HD | MAC_100HD | MAC_1000HD);
  	else
include/linux/stmmac.h +0 -0
index 2810361e4048..197f6f914104 100644
@@ -222,6 +222,7 @@ struct dwmac4_addrs {
  #define STMMAC_FLAG_EN_TX_LPI_CLOCKGATING	BIT(11)
Quoted 8 lines

include/linux/stmmac.h struct dwmac4_addrs { · line 226

Quoted 4 lines
include/linux/stmmac.h +1 -0
  #define STMMAC_FLAG_HWTSTAMP_CORRECT_LATENCY	BIT(12)
  #define STMMAC_FLAG_DISABLE_FORCE_1000	BIT(13)
+#define STMMAC_FLAG_DISABLE_HALF_DUPLEX	BIT(14)
 

Place the patch with this change before
[PATCH net-next v8 06/11] net: stmmac: dwmac-loongson: Add GNET support as a pre-requisite/preparation patch. Don't forget a thorough description of what is wrong with the GNET Half-Duplex mode.

Quoted 2 lines

BTW what about re-defining the stmmac_ops.phylink_get_caps() callback instead of adding fixup flags in this patch and in the next one?

ok.

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +0 -0
index ac1b48ff7199..b57e1325ce62 100644
@@ -238,6 +234,13 @@ static int loongson_gnet_get_hw_feature(void __iomem *ioaddr,

     return 0;
 }

+static void loongson_phylink_get_caps(struct stmmac_priv *priv)
+{
+    priv->phylink_config.mac_capabilities = (MAC_10FD |
+        MAC_100FD | MAC_1000FD) & ~(MAC_10HD | MAC_100HD | MAC_1000HD);
+
+}
+
 struct stmmac_pci_info {
     int (*setup)(struct pci_dev *pdev, struct plat_stmmacenet_data *plat);
     int (*config)(struct pci_dev *pdev, struct plat_stmmacenet_data *plat,
@@ -403,10 +405,15 @@ static void loongson_gnet_fix_speed(void *priv, unsigned int speed, unsigned int

 static struct mac_device_info *loongson_setup(void *apriv) {
+    struct stmmac_ops *loongson_dwmac_ops;
     struct stmmac_priv *priv = apriv;
     struct mac_device_info *mac;
     struct stmmac_dma_ops *dma;

+    loongson_dwmac_ops = devm_kzalloc(priv->device, sizeof(*loongson_dwmac_ops), GFP_KERNEL); +    if (!loongson_dwmac_ops)
+        return NULL;
+
     mac = devm_kzalloc(priv->device, sizeof(*mac), GFP_KERNEL);
     if (!mac)
         return NULL;
@@ -417,6 +424,10 @@ static struct mac_device_info *loongson_setup(void *apriv)

     priv->synopsys_id = 0x37;    /*Overwrite custom IP*/

+    *loongson_dwmac_ops = dwmac1000_ops;
+    loongson_dwmac_ops->phylink_get_caps = loongson_phylink_get_caps; +    mac->mac = loongson_dwmac_ops;
+
     *dma = dwmac1000_dma_ops;
     dma->init_chan = loongson_gnet_dma_init_channel; dma->dma_interrupt = loongson_gnet_dma_interrupt;
@@ -375,8 +375,6 @@ static int loongson_gmac_config(struct pci_dev *pdev, struct stmmac_resources *res, struct device_node *np)
 {
-       plat->flags |= STMMAC_FLAG_DISABLE_FLOW_CONTROL;
-
        return 0;
 }

@@ -489,17 +487,7 @@ static int loongson_gnet_config(struct pci_dev *pdev, struct stmmac_resources *res, struct device_node *np)
 {
-       switch (pdev->revision) {
-       case 0x00:
-               plat->flags |= STMMAC_FLAG_DISABLE_FORCE_1000 | -                              STMMAC_FLAG_DISABLE_HALF_DUPLEX; -               break;
-       case 0x01:
-               plat->flags |= STMMAC_FLAG_DISABLE_FORCE_1000; -               break;
-       default:
-               break;
-       }
+       plat->flags |= STMMAC_FLAG_DISABLE_FORCE_1000;

        return 0;
 }

drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +0 -0
index 8705e04913d1..7c656f970575 100644
@@ -1201,8 +1201,7 @@ static int stmmac_init_phy(struct net_device *dev)

 static void stmmac_set_half_duplex(struct stmmac_priv *priv)
 {
     /* Half-Duplex can only work with single tx queue */
-    if (priv->plat->tx_queues_to_use > 1 ||
-        (STMMAC_FLAG_DISABLE_HALF_DUPLEX & priv->plat->flags)) +    if (priv->plat->tx_queues_to_use > 1) priv->phylink_config.mac_capabilities &=
             ~(MAC_10HD | MAC_100HD | MAC_1000HD);
     else
@@ -1237,9 +1236,9 @@ static int stmmac_phy_setup(struct stmmac_priv *priv) xpcs_get_interfaces(priv->hw->xpcs, priv->phylink_config.supported_interfaces);

-    priv->phylink_config.mac_capabilities = MAC_10FD | MAC_100FD | MAC_1000FD; -    if (!(priv->plat->flags & STMMAC_FLAG_DISABLE_FLOW_CONTROL))
-        priv->phylink_config.mac_capabilities |= MAC_ASYM_PAUSE | MAC_SYM_PAUSE; +    priv->phylink_config.mac_capabilities = MAC_ASYM_PAUSE | MAC_SYM_PAUSE | +                        MAC_10FD | MAC_100FD |
+                        MAC_1000FD;

     stmmac_set_half_duplex(priv);
 -----

loongson_gmac/gnet_config()

I will try to remove these two functions according to your comment in another patch。

Thanks,

Yanteng

Quoted 10 lines

-Serge()

Quoted 7 lines

-Serge(y)

Quoted 5 lines
include/linux/stmmac.h +0 -0
  struct plat_stmmacenet_data {
  	int bus_id;
Signature · 1 line
2.31.4
author
#92 lore raw

Re: [PATCH net-next v8 10/11] net: stmmac: dwmac-loongson: Disable flow control for GMAC

In reply to Serge Semin
Quoted 42 lines · Serge Semin
Quoted 41 lines · Yanteng Si

Loongson GMAC does not support Flow Control feature. Set flags to disable it.

---
  drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c | 1 +
  drivers/net/ethernet/stmicro/stmmac/stmmac_main.c    | 6 +++---
  include/linux/stmmac.h                               | 1 +
  3 files changed, 5 insertions(+), 3 deletions(-)
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +1 -0
index 1753a3c46b77..b78a73ea748b 100644
@@ -335,6 +335,7 @@ static int loongson_gmac_config(struct pci_dev *pdev,
  				struct stmmac_resources *res,
  				struct device_node *np)
  {
+	plat->flags |= STMMAC_FLAG_DISABLE_FLOW_CONTROL;
 
  	return 0;
  }
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +3 -3
index 3aa862269eb0..8d676cbfba1e 100644
@@ -1237,9 +1237,9 @@ static int stmmac_phy_setup(struct stmmac_priv *priv)
  		xpcs_get_interfaces(priv->hw->xpcs,
  				    priv->phylink_config.supported_interfaces);
 
-	priv->phylink_config.mac_capabilities = MAC_ASYM_PAUSE | MAC_SYM_PAUSE |
-						MAC_10FD | MAC_100FD |
-						MAC_1000FD;
+	priv->phylink_config.mac_capabilities = MAC_10FD | MAC_100FD | MAC_1000FD;
+	if (!(priv->plat->flags & STMMAC_FLAG_DISABLE_FLOW_CONTROL))
+		priv->phylink_config.mac_capabilities |= MAC_ASYM_PAUSE | MAC_SYM_PAUSE;
 
  	stmmac_set_half_duplex(priv);
 
Quoted 11 lines

include/linux/stmmac.h struct dwmac4_addrs { · line 226

Quoted 9 lines
include/linux/stmmac.h +1 -0
index 197f6f914104..832cd8cd688f 100644
@@ -223,6 +223,7 @@ struct dwmac4_addrs {
  #define STMMAC_FLAG_HWTSTAMP_CORRECT_LATENCY	BIT(12)
  #define STMMAC_FLAG_DISABLE_FORCE_1000	BIT(13)
  #define STMMAC_FLAG_DISABLE_HALF_DUPLEX	BIT(14)
+#define STMMAC_FLAG_DISABLE_FLOW_CONTROL	BIT(15)

See my last comment in patch 9/11. This can be reached by re-defining the stmmac_ops::phylink_get_caps() callback.

OK.

Thanks,

Yanteng

Quoted 9 lines

-Serge(y)

Quoted 6 lines
include/linux/stmmac.h +0 -0
  struct plat_stmmacenet_data {
  	int bus_id;
Signature · 1 line
2.31.4
author
#95 lore raw

Re: [PATCH net-next v8 11/11] net: stmmac: dwmac-loongson: Disable coe for some Loongson GNET

In reply to Serge Semin
Quoted 3 lines · Serge Semin
Quoted 1 line · Yanteng Si

Some chips of Loongson GNET does not support coe, so disable them.

s/coe/Tx COE

OK.

Quoted 18 lines
Quoted 18 lines

Set dma_cap->tx_coe to 0 and overwrite get_hw_feature.

---
  .../ethernet/stmicro/stmmac/dwmac-loongson.c  | 46 +++++++++++++++++++
  1 file changed, 46 insertions(+)
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +0 -0
index b78a73ea748b..8018d7d5f31b 100644
@@ -196,6 +196,51 @@ static int dwlgmac_dma_interrupt(struct stmmac_priv *priv, void __iomem *ioaddr,
  	return ret;
  }
 
Quoted 2 lines

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int dwlgmac_dma_interrupt(struct stmmac_priv *priv, void __iomem *ioaddr, · line 199

Quoted 1 line
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +1 -0
+static int dwlgmac_get_hw_feature(void __iomem *ioaddr,

Please use GNET-specific prefix.

OK. loongson_gnet_get_hw_feature()

Quoted 13 lines

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int dwlgmac_dma_interrupt(struct stmmac_priv *priv, void __iomem *ioaddr, · line 209

Quoted 11 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +10 -0
+				  struct dma_features *dma_cap)
+{
+	u32 hw_cap = readl(ioaddr + DMA_HW_FEATURE);
+
+	if (!hw_cap) {
+		/* 0x00000000 is the value read on old hardware that does not
+		 * implement this register
+		 */
+		return -EOPNOTSUPP;
+	}

This doesn't seems like possible. All your devices have the HW-features register. If so please drop.

OK, drop it.

Quoted 27 lines
Quoted 27 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +26 -0
+
+	dma_cap->mbps_10_100 = (hw_cap & DMA_HW_FEAT_MIISEL);
+	dma_cap->mbps_1000 = (hw_cap & DMA_HW_FEAT_GMIISEL) >> 1;
+	dma_cap->half_duplex = (hw_cap & DMA_HW_FEAT_HDSEL) >> 2;
+	dma_cap->hash_filter = (hw_cap & DMA_HW_FEAT_HASHSEL) >> 4;
+	dma_cap->multi_addr = (hw_cap & DMA_HW_FEAT_ADDMAC) >> 5;
+	dma_cap->pcs = (hw_cap & DMA_HW_FEAT_PCSSEL) >> 6;
+	dma_cap->sma_mdio = (hw_cap & DMA_HW_FEAT_SMASEL) >> 8;
+	dma_cap->pmt_remote_wake_up = (hw_cap & DMA_HW_FEAT_RWKSEL) >> 9;
+	dma_cap->pmt_magic_frame = (hw_cap & DMA_HW_FEAT_MGKSEL) >> 10;
+	/* MMC */
+	dma_cap->rmon = (hw_cap & DMA_HW_FEAT_MMCSEL) >> 11;
+	/* IEEE 1588-2002 */
+	dma_cap->time_stamp =
+	    (hw_cap & DMA_HW_FEAT_TSVER1SEL) >> 12;
+	/* IEEE 1588-2008 */
+	dma_cap->atime_stamp = (hw_cap & DMA_HW_FEAT_TSVER2SEL) >> 13;
+	/* 802.3az - Energy-Efficient Ethernet (EEE) */
+	dma_cap->eee = (hw_cap & DMA_HW_FEAT_EEESEL) >> 14;
+	dma_cap->av = (hw_cap & DMA_HW_FEAT_AVSEL) >> 15;
+	/* TX and RX csum */
+	dma_cap->tx_coe = 0;
+	dma_cap->rx_coe_type1 = (hw_cap & DMA_HW_FEAT_RXTYP1COE) >> 17;
+	dma_cap->rx_coe_type2 = (hw_cap & DMA_HW_FEAT_RXTYP2COE) >> 18;
+	dma_cap->rxfifo_over_2048 = (hw_cap & DMA_HW_FEAT_RXFIFOSIZE) >> 19;
+	/* TX and RX number of channels */
Quoted 8 lines

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int dwlgmac_dma_interrupt(struct stmmac_priv *priv, void __iomem *ioaddr, · line 239

Quoted 4 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +4 -0
+	dma_cap->number_rx_channel = (hw_cap & DMA_HW_FEAT_RXCHCNT) >> 20;
+	dma_cap->number_tx_channel = (hw_cap & DMA_HW_FEAT_TXCHCNT) >> 22;
+	/* Alternate (enhanced) DESC mode */
+	dma_cap->enh_desc = (hw_cap & DMA_HW_FEAT_ENHDESSEL) >> 24;

I am not sure whether you need to parse the capability register at all seeing this is a GNET-specific method. For that device all the capabilities are already known and can be just initialized in this method.

-dma_cap->tx_coe = (hw_cap & DMA_HW_FEAT_TXCOESEL) >> 16;

+dma_cap->tx_coe = 0;

I'm a little confused. Actually, I only modified this line, which is used to fix the checksum.

2k2000 of Loongson GNET does not support coe.

Thanks,
Yanteng

Quoted 21 lines

-Serge(y)

Quoted 18 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +5 -0
+
+	return 0;
+}
+
  struct stmmac_pci_info {
  	int (*setup)(struct pci_dev *pdev, struct plat_stmmacenet_data *plat);
  	int (*config)(struct pci_dev *pdev, struct plat_stmmacenet_data *plat,
@@ -542,6 +587,7 @@ static int loongson_dwmac_probe(struct pci_dev *pdev,
  		ld->dwlgmac_dma_ops = dwmac1000_dma_ops;
  		ld->dwlgmac_dma_ops.init_chan = dwlgmac_dma_init_channel;
  		ld->dwlgmac_dma_ops.dma_interrupt = dwlgmac_dma_interrupt;
+		ld->dwlgmac_dma_ops.get_hw_feature = dwlgmac_get_hw_feature;
 
  		plat->setup = loongson_setup;
  		ret = loongson_dwmac_config_multi_msi(pdev, plat, &res, np, 8);
Signature · 1 line
2.31.4
author
#96 lore raw

Re: [PATCH net-next v8 11/11] net: stmmac: dwmac-loongson: Disable coe for some Loongson GNET

Quoted 82 lines · Yanteng Si
Quoted 3 lines · Serge Semin
Quoted 1 line · Yanteng Si

Some chips of Loongson GNET does not support coe, so disable them.

s/coe/Tx COE

OK.

Quoted 11 lines
Quoted 11 lines

Set dma_cap->tx_coe to 0 and overwrite get_hw_feature.

---
  .../ethernet/stmicro/stmmac/dwmac-loongson.c  | 46
+++++++++++++++++++

  1 file changed, 46 insertions(+)
Quoted 10 lines

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int dwlgmac_dma_interrupt(struct · line 199

Quoted 9 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +0 -0
index b78a73ea748b..8018d7d5f31b 100644
@@ -196,6 +196,51 @@ static int dwlgmac_dma_interrupt(struct 
 stmmac_priv *priv, void __iomem *ioaddr,
       return ret;
   }
   +static int dwlgmac_get_hw_feature(void __iomem *ioaddr,

Please use GNET-specific prefix.

OK. loongson_gnet_get_hw_feature()

Quoted 13 lines

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int dwlgmac_dma_interrupt(struct stmmac_priv *priv, void __iomem *ioaddr, · line 209

Quoted 11 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +10 -0
+                  struct dma_features *dma_cap)
+{
+    u32 hw_cap = readl(ioaddr + DMA_HW_FEATURE);
+
+    if (!hw_cap) {
+        /* 0x00000000 is the value read on old hardware that does not
+         * implement this register
+         */
+        return -EOPNOTSUPP;
+    }

This doesn't seems like possible. All your devices have the HW-features register. If so please drop.

OK, drop it.

Quoted 36 lines
Quoted 22 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +21 -0
+
+    dma_cap->mbps_10_100 = (hw_cap & DMA_HW_FEAT_MIISEL);
+    dma_cap->mbps_1000 = (hw_cap & DMA_HW_FEAT_GMIISEL) >> 1;
+    dma_cap->half_duplex = (hw_cap & DMA_HW_FEAT_HDSEL) >> 2;
+    dma_cap->hash_filter = (hw_cap & DMA_HW_FEAT_HASHSEL) >> 4;
+    dma_cap->multi_addr = (hw_cap & DMA_HW_FEAT_ADDMAC) >> 5;
+    dma_cap->pcs = (hw_cap & DMA_HW_FEAT_PCSSEL) >> 6;
+    dma_cap->sma_mdio = (hw_cap & DMA_HW_FEAT_SMASEL) >> 8;
+    dma_cap->pmt_remote_wake_up = (hw_cap & DMA_HW_FEAT_RWKSEL) >> 9;
+    dma_cap->pmt_magic_frame = (hw_cap & DMA_HW_FEAT_MGKSEL) >> 10;
+    /* MMC */
+    dma_cap->rmon = (hw_cap & DMA_HW_FEAT_MMCSEL) >> 11;
+    /* IEEE 1588-2002 */
+    dma_cap->time_stamp =
+        (hw_cap & DMA_HW_FEAT_TSVER1SEL) >> 12;
+    /* IEEE 1588-2008 */
+    dma_cap->atime_stamp = (hw_cap & DMA_HW_FEAT_TSVER2SEL) >> 13;
+    /* 802.3az - Energy-Efficient Ethernet (EEE) */
+    dma_cap->eee = (hw_cap & DMA_HW_FEAT_EEESEL) >> 14;
+    dma_cap->av = (hw_cap & DMA_HW_FEAT_AVSEL) >> 15;
+    /* TX and RX csum */

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int dwlgmac_dma_interrupt(struct stmmac_priv *priv, void __iomem *ioaddr, · line 239

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +9 -0
+    dma_cap->tx_coe = 0;
+    dma_cap->rx_coe_type1 = (hw_cap & DMA_HW_FEAT_RXTYP1COE) >> 17;
+    dma_cap->rx_coe_type2 = (hw_cap & DMA_HW_FEAT_RXTYP2COE) >> 18;
+    dma_cap->rxfifo_over_2048 = (hw_cap & DMA_HW_FEAT_RXFIFOSIZE) 
 >> 19;
+    /* TX and RX number of channels */
+    dma_cap->number_rx_channel = (hw_cap & DMA_HW_FEAT_RXCHCNT) >> 20;
+    dma_cap->number_tx_channel = (hw_cap & DMA_HW_FEAT_TXCHCNT) >> 22;
+    /* Alternate (enhanced) DESC mode */
+    dma_cap->enh_desc = (hw_cap & DMA_HW_FEAT_ENHDESSEL) >> 24;

I am not sure whether you need to parse the capability register at all seeing this is a GNET-specific method. For that device all the capabilities are already known and can be just initialized in this method.

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +1 -1
-dma_cap->tx_coe = (hw_cap & DMA_HW_FEAT_TXCOESEL) >> 16;
 
+dma_cap->tx_coe = 0;
Quoted 3 lines

I'm a little confused. Actually, I only modified this line, which is used to fix the checksum.

2k2000  of Loongson GNET does not support coe.

Specifically, it is to ensure the normal operation of multiple channels, as other channels except for channel 0 cannot perform checksum.

Thanks,

Yanteng

Quoted 26 lines

Thanks,
Yanteng

Quoted 21 lines

-Serge(y)

Quoted 18 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +4 -0
+
+    return 0;
+}
+
   struct stmmac_pci_info {

      int (*setup)(struct pci_dev *pdev, struct plat_stmmacenet_data *plat); int (*config)(struct pci_dev *pdev, struct plat_stmmacenet_data *plat,

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +1 -0
@@ -542,6 +587,7 @@ static int loongson_dwmac_probe(struct pci_dev 
 *pdev,
           ld->dwlgmac_dma_ops = dwmac1000_dma_ops;
           ld->dwlgmac_dma_ops.init_chan = dwlgmac_dma_init_channel;
           ld->dwlgmac_dma_ops.dma_interrupt = dwlgmac_dma_interrupt;
+        ld->dwlgmac_dma_ops.get_hw_feature = dwlgmac_get_hw_feature;
             plat->setup = loongson_setup;
           ret = loongson_dwmac_config_multi_msi(pdev, plat, &res, np, 8);
Signature · 1 line
2.31.4
#80 lore raw

Re: [PATCH net-next v8 09/11] net: stmmac: dwmac-loongson: Fix half duplex

In reply to Yanteng Si
Quoted 77 lines · Yanteng Si
Quoted 65 lines · Serge Semin
Quoted 56 lines · Serge Semin
Quoted 21 lines · Yanteng Si

Current GNET does not support half duplex mode.

---
  drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c | 11 ++++++++++-
  drivers/net/ethernet/stmicro/stmmac/stmmac_main.c    |  3 ++-
  include/linux/stmmac.h                               |  1 +
  3 files changed, 13 insertions(+), 2 deletions(-)
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +1 -1
index 264c4c198d5a..1753a3c46b77 100644
@@ -432,8 +432,17 @@ static int loongson_gnet_config(struct pci_dev *pdev,
  				struct stmmac_resources *res,
  				struct device_node *np)
  {
-	if (pdev->revision == 0x00 || pdev->revision == 0x01)
+	switch (pdev->revision) {

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int loongson_gnet_config(struct pci_dev *pdev, · line 445

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +9 -0
+	case 0x00:
+		plat->flags |= STMMAC_FLAG_DISABLE_FORCE_1000 |
+			       STMMAC_FLAG_DISABLE_HALF_DUPLEX;
+		break;
+	case 0x01:
  		plat->flags |= STMMAC_FLAG_DISABLE_FORCE_1000;
+		break;
+	default:
+		break;
+	}

Move this change into the patch
[PATCH net-next v8 06/11] net: stmmac: dwmac-loongson: Add GNET support

Quoted 21 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +0 -0
  	return 0;
  }
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +2 -1
index 5617b40abbe4..3aa862269eb0 100644
@@ -1201,7 +1201,8 @@ static int stmmac_init_phy(struct net_device *dev)
  static void stmmac_set_half_duplex(struct stmmac_priv *priv)
  {
  	/* Half-Duplex can only work with single tx queue */
-	if (priv->plat->tx_queues_to_use > 1)
+	if (priv->plat->tx_queues_to_use > 1 ||
+	    (STMMAC_FLAG_DISABLE_HALF_DUPLEX & priv->plat->flags))
  		priv->phylink_config.mac_capabilities &=
  			~(MAC_10HD | MAC_100HD | MAC_1000HD);
  	else
include/linux/stmmac.h +0 -0
index 2810361e4048..197f6f914104 100644
@@ -222,6 +222,7 @@ struct dwmac4_addrs {
Quoted 8 lines

include/linux/stmmac.h struct dwmac4_addrs { · line 225

Quoted 4 lines
include/linux/stmmac.h +1 -0
  #define STMMAC_FLAG_EN_TX_LPI_CLOCKGATING	BIT(11)
  #define STMMAC_FLAG_HWTSTAMP_CORRECT_LATENCY	BIT(12)
  #define STMMAC_FLAG_DISABLE_FORCE_1000	BIT(13)
+#define STMMAC_FLAG_DISABLE_HALF_DUPLEX	BIT(14)

Place the patch with this change before
[PATCH net-next v8 06/11] net: stmmac: dwmac-loongson: Add GNET support as a pre-requisite/preparation patch. Don't forget a thorough description of what is wrong with the GNET Half-Duplex mode.

Quoted 2 lines

BTW what about re-defining the stmmac_ops.phylink_get_caps() callback instead of adding fixup flags in this patch and in the next one?

ok.

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +0 -0
index ac1b48ff7199..b57e1325ce62 100644

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int loongson_gnet_get_hw_feature(void __iomem · line 241

Quoted 8 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +4 -0
@@ -238,6 +234,13 @@ static int loongson_gnet_get_hw_feature(void __iomem
 *ioaddr,
      return 0;
  }
 
+static void loongson_phylink_get_caps(struct stmmac_priv *priv)
+{
+    priv->phylink_config.mac_capabilities = (MAC_10FD |
+        MAC_100FD | MAC_1000FD) & ~(MAC_10HD | MAC_100HD | MAC_1000HD);

Why is this so complicated? It would be silly if the _full duplex_ definitions also defined the _half duplex_ bits. This should be just:

	priv->phylink_config.mac_capabilities = MAC_10FD | MAC_100FD |
						MAC_1000FD;

if that is all you support. Do you not support any pause modes (they would need to be included as well here.)

As to this approach, I don't think it's a good model to override the stmmac MAC operations. Instead, I would suggest that a better approach would be for the platform to provide its capabilities to the stmmac core code (maybe a new member in stmmac_priv) which, when set, is used to reduce the capabilities provided to phylink via priv->phylink_config.mac_capabilities.

Why? The driver has several components that are involved in the overall capabilities, and the capabilities of the system is the logical subset of all these capabilities. One component should not be setting capabilities that a different component doesn't support.

Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
author
#81 lore raw

Re: [PATCH net-next v8 09/11] net: stmmac: dwmac-loongson: Fix half duplex

Quoted 71 lines · Russell King (Oracle)
Quoted 70 lines · Yanteng Si
Quoted 65 lines · Serge Semin
Quoted 56 lines · Serge Semin
Quoted 21 lines · Yanteng Si

Current GNET does not support half duplex mode.

---
   drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c | 11 ++++++++++-
   drivers/net/ethernet/stmicro/stmmac/stmmac_main.c    |  3 ++-
   include/linux/stmmac.h                               |  1 +
   3 files changed, 13 insertions(+), 2 deletions(-)
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +1 -1
index 264c4c198d5a..1753a3c46b77 100644
@@ -432,8 +432,17 @@ static int loongson_gnet_config(struct pci_dev *pdev,
   				struct stmmac_resources *res,
   				struct device_node *np)
   {
-	if (pdev->revision == 0x00 || pdev->revision == 0x01)
+	switch (pdev->revision) {

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int loongson_gnet_config(struct pci_dev *pdev, · line 445

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +9 -0
+	case 0x00:
+		plat->flags |= STMMAC_FLAG_DISABLE_FORCE_1000 |
+			       STMMAC_FLAG_DISABLE_HALF_DUPLEX;
+		break;
+	case 0x01:
   		plat->flags |= STMMAC_FLAG_DISABLE_FORCE_1000;
+		break;
+	default:
+		break;
+	}

Move this change into the patch
[PATCH net-next v8 06/11] net: stmmac: dwmac-loongson: Add GNET support

Quoted 21 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +0 -0
   	return 0;
   }
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +2 -1
index 5617b40abbe4..3aa862269eb0 100644
@@ -1201,7 +1201,8 @@ static int stmmac_init_phy(struct net_device *dev)
   static void stmmac_set_half_duplex(struct stmmac_priv *priv)
   {
   	/* Half-Duplex can only work with single tx queue */
-	if (priv->plat->tx_queues_to_use > 1)
+	if (priv->plat->tx_queues_to_use > 1 ||
+	    (STMMAC_FLAG_DISABLE_HALF_DUPLEX & priv->plat->flags))
   		priv->phylink_config.mac_capabilities &=
   			~(MAC_10HD | MAC_100HD | MAC_1000HD);
   	else
include/linux/stmmac.h +0 -0
index 2810361e4048..197f6f914104 100644
@@ -222,6 +222,7 @@ struct dwmac4_addrs {
Quoted 8 lines

include/linux/stmmac.h struct dwmac4_addrs { · line 225

Quoted 4 lines
include/linux/stmmac.h +1 -0
   #define STMMAC_FLAG_EN_TX_LPI_CLOCKGATING	BIT(11)
   #define STMMAC_FLAG_HWTSTAMP_CORRECT_LATENCY	BIT(12)
   #define STMMAC_FLAG_DISABLE_FORCE_1000	BIT(13)
+#define STMMAC_FLAG_DISABLE_HALF_DUPLEX	BIT(14)

Place the patch with this change before
[PATCH net-next v8 06/11] net: stmmac: dwmac-loongson: Add GNET support as a pre-requisite/preparation patch. Don't forget a thorough description of what is wrong with the GNET Half-Duplex mode.

Quoted 2 lines

BTW what about re-defining the stmmac_ops.phylink_get_caps() callback instead of adding fixup flags in this patch and in the next one?

ok.

Quoted 9 lines

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int loongson_gnet_get_hw_feature(void __iomem · line 236

Quoted 9 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +0 -0
index ac1b48ff7199..b57e1325ce62 100644
@@ -238,6 +234,13 @@ static int loongson_gnet_get_hw_feature(void __iomem
 *ioaddr,
      return 0;
  }

Hi Russell,

Quoted 9 lines

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int loongson_gnet_get_hw_feature(void __iomem · line 240

Quoted 4 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +4 -0
+static void loongson_phylink_get_caps(struct stmmac_priv *priv)
+{
+    priv->phylink_config.mac_capabilities = (MAC_10FD |
+        MAC_100FD | MAC_1000FD) & ~(MAC_10HD | MAC_100HD | MAC_1000HD);

Why is this so complicated? It would be silly if the _full duplex_ definitions also defined the _half duplex_ bits. This should be just:

	priv->phylink_config.mac_capabilities = MAC_10FD | MAC_100FD |
						MAC_1000FD;

Yes, you are right. Our gnet device (7a2000) does not support half-duplex, while the gnet device (2k2000) does.

I plan to use PCI IDand IP CORE as the condition to separate full-duplex and half-duplex.

Quoted 3 lines

if that is all you support. Do you not support any pause modes (they would need to be included as well here.)

I have tested it and our gnet device supports MAC_ASYM_PAUSE and MAC_SYM_PAUSE, but gmac does not. I will fix this in the patch v9.

This is also easy to do because all GMAC devices have the same PCI ID.

Quoted 8 lines

As to this approach, I don't think it's a good model to override the stmmac MAC operations. Instead, I would suggest that a better approach would be for the platform to provide its capabilities to the stmmac core code (maybe a new member in stmmac_priv) which, when set, is used to reduce the capabilities provided to phylink via priv->phylink_config.mac_capabilities.

Quoted 4 lines

Why? The driver has several components that are involved in the overall capabilities, and the capabilities of the system is the logical subset of all these capabilities. One component should not be setting capabilities that a different component doesn't support.

Hi Serge,

It seems to be going back again, what do you think?

Thanks,

Yanteng

Quoted 1 line
author
#41 lore raw

Re: [PATCH net-next v8 06/11] net: stmmac: dwmac-loongson: Add GNET support

In reply to a message not in the archive
Quoted 149 lines · Yanteng Si
Quoted 11 lines · Serge Semin
Quoted 2 lines · Yanteng Si

Add Loongson GNET (GMAC with PHY) support, override stmmac_priv.synopsys_id with 0x37.

Please add more details of all the device capabilities: supported speeds, duplexness, IP-core version, DMA-descriptors type (normal/enhanced), MTL Tx/Rx FIFO size, Perfect and Hash-based MAC Filter tables size, L3/L4 filters availability, VLAN hash table filter, PHY-interface (GMII, RGMII, etc), EEE support, AV-feature/Multi-channels support, IEEE 1588 Timestamp support, Magic Frame support, Remote Wake-up support, IP Checksum, Tx/Rx TCP/IP Checksum, Mac Management Counters (MMC), SMA/MDIO interface,

The gnet (2k2000) of 0x10 supports full-duplex and half-duplex at 1000/100/10M. The gnet of 0x37 (i.e. the gnet of 7a2000) supports 1000/100/10M full duplex.

The gnet with 0x10 has 8 DMA channels, except for channel 0, which does not support sending hardware checksums.

Supported AV features are Qav, Qat, and Qas, and other features should be consistent with the 3.73 IP.

Quoted 16 lines
Quoted 16 lines
---
  .../ethernet/stmicro/stmmac/dwmac-loongson.c  | 44 +++++++++++++++++++
  1 file changed, 44 insertions(+)
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +0 -0
index 3b3578318cc1..584f7322bd3e 100644
@@ -318,6 +318,8 @@ static struct mac_device_info *loongson_setup(void *apriv)
  	if (!mac)
  		return NULL;
 
Quoted 6 lines

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static struct mac_device_info *loongson_setup(void *apriv) · line 322

Quoted 2 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +2 -0
+	priv->synopsys_id = 0x37;	/*Overwrite custom IP*/
+

Please add a more descriptive comment _above_ the subjected line. In particular note why the override is needed, what is the real DW GMAC IP-core version and what is the original value the statement above overrides.

The IP-core version of the gnet device on the loongson 2k2000 is 0x10, which is a custom IP.

Compared to 0x37, we have split some of the dma registers into two (tx and rx). After overwriting stmmac_dma_ops.dma_interrupt() and stmmac_dma_ops.init_chan(), the logic is consistent with 0x37,

so we overwrite synopsys_id to 0x37.

Quoted 7 lines
Quoted 7 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +0 -0
  	ld = priv->plat->bsp_priv;
  	mac->dma = &ld->dwlgmac_dma_ops;
 
@@ -350,6 +352,46 @@ static struct mac_device_info *loongson_setup(void *apriv)
  	return mac;
  }
 
Quoted 12 lines

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static struct mac_device_info *loongson_setup(void *apriv) · line 365

Quoted 11 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +11 -0
+static int loongson_gnet_data(struct pci_dev *pdev,
+			      struct plat_stmmacenet_data *plat)
+{
+	loongson_default_data(pdev, plat);
+
+	plat->multicast_filter_bins = 256;
+
+	plat->mdio_bus_data->phy_mask =  ~(u32)BIT(2);
+
+	plat->phy_addr = 2;
+	plat->phy_interface = PHY_INTERFACE_MODE_INTERNAL;

Are you sure PHY-interface is supposed to be defined as "internal"?

Yes, because the gnet hardware has a integrated PHY, so we set it to internal,

Correspondingly, our gmac hardware PHY is external.

Quoted 15 lines
Quoted 15 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +15 -0
+
+	plat->bsp_priv = &pdev->dev;
+
+	plat->dma_cfg->pbl = 32;
+	plat->dma_cfg->pblx8 = true;
+
+	plat->clk_ref_rate = 125000000;
+	plat->clk_ptp_rate = 125000000;
+
+	return 0;
+}
+
+static int loongson_gnet_config(struct pci_dev *pdev,
+				struct plat_stmmacenet_data *plat,
+				struct stmmac_resources *res,
Quoted 8 lines

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static struct mac_device_info *loongson_setup(void *apriv) · line 385

Quoted 5 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +5 -0
+				struct device_node *np)
+{
+	int ret;
+
+	ret = loongson_dwmac_config_legacy(pdev, plat, res, np);

Again. This will be moved to the probe() method in one of the next patches leaving loongson_gnet_config() empty. What was the problem with doing that right away with no intermediate change?

No problem. My original intention is to break the patches down into smaller pieces.

In the next version, I will try to re-break them based on your comments.

Quoted 19 lines
Quoted 19 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +10 -0
+
+	return ret;
+}
+
+static struct stmmac_pci_info loongson_gnet_pci_info = {
+	.setup = loongson_gnet_data,
+	.config = loongson_gnet_config,
+};
+
  static int loongson_dwmac_probe(struct pci_dev *pdev,
  				const struct pci_device_id *id)
  {
@@ -516,9 +558,11 @@ static SIMPLE_DEV_PM_OPS(loongson_dwmac_pm_ops, loongson_dwmac_suspend,
  			 loongson_dwmac_resume);
 
  #define PCI_DEVICE_ID_LOONGSON_GMAC	0x7a03
+#define PCI_DEVICE_ID_LOONGSON_GNET	0x7a13
 
Quoted 7 lines

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static SIMPLE_DEV_PM_OPS(loongson_dwmac_pm_ops, loongson_dwmac_suspend, · line 565

Quoted 3 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +1 -0
  static const struct pci_device_id loongson_dwmac_id_table[] = {
  	{ PCI_DEVICE_DATA(LOONGSON, GMAC, &loongson_gmac_pci_info) },
+	{ PCI_DEVICE_DATA(LOONGSON, GNET, &loongson_gnet_pci_info) },

After this the driver is supposed to correctly handle the Loongson GNET devices. Based on the patches introduced further it isn't. Please consider re-arranging the changes (see my comments in the further patches).

OK.

Thanks,

Yanteng

Quoted 9 lines

-Serge(y)

Quoted 6 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +0 -0
  	{}
  };
  MODULE_DEVICE_TABLE(pci, loongson_dwmac_id_table);
Signature · 1 line
2.31.4
author
#52 lore raw

Re: [PATCH net-next v8 07/11] net: stmmac: dwmac-loongson: Add multi-channel supports for loongson

In reply to a message not in the archive
Quoted 190 lines · Yanteng Si
Quoted 6 lines · Serge Semin
Quoted 2 lines · Yanteng Si

Request allocation for MSI for specific versions.

Please elaborate what is actually done in the patch. What device version it is dedicated for (Loongson GNET?), what IRQs the patch adds, etc.

gnet_device   core IP    IRQ
7a2000        0x37    legacy
2k2000        0x10    multi_msi
Quoted 4 lines

BTW will GNET device work without this patch? If no you need to either merge it into the patch introducing the GNET-device support or place it before that patch (6/11).

OK, GNET device work need this patch.

Quoted 5 lines
Quoted 4 lines

Some features of Loongson platforms are bound to the GMAC_VERSION register. We have to read its value in order to get the correct channel number.

This message seems misleading. I don't see you doing that in the patch below...

Because part of our gnet hardware (7a2000) core IP is 0x37

Quoted 20 lines
Quoted 20 lines
---
  .../ethernet/stmicro/stmmac/dwmac-loongson.c  | 57 +++++++++++++++----
  1 file changed, 46 insertions(+), 11 deletions(-)
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +1 -1
index 584f7322bd3e..60d0a122d7c9 100644
@@ -98,10 +98,10 @@ static void dwlgmac_dma_init_channel(struct stmmac_priv *priv,
  	if (dma_cfg->aal)
  		value |= DMA_BUS_MODE_AAL;
 
 
-	writel(value, ioaddr + DMA_BUS_MODE);
+	writel(value, ioaddr + DMA_CHAN_BUS_MODE(chan));
 
Quoted 7 lines

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static void dwlgmac_dma_init_channel(struct stmmac_priv *priv, · line 104

Quoted 3 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +1 -1
  	/* Mask interrupts by writing to CSR7 */
-	writel(DMA_INTR_DEFAULT_MASK_LOONGSON, ioaddr + DMA_INTR_ENA);
+	writel(DMA_INTR_DEFAULT_MASK_LOONGSON, ioaddr + DMA_CHAN_INTR_ENA(chan));

Em, why is this here? There is a patch
[PATCH net-next v8 05/11] net: stmmac: dwmac-loongson: Add Loongson-specific register definitions in this series which was supposed to introduce the fully functional
GNET-specific callbacks. Move this change in there.

OK.

Quoted 11 lines

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int loongson_dwmac_config_legacy(struct pci_dev *pdev, · line 241

Quoted 9 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +0 -0
  }
 

static int dwlgmac_dma_interrupt(struct stmmac_priv *priv, void __iomem *ioaddr,

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +1 -0
@@ -238,6 +238,45 @@ static int loongson_dwmac_config_legacy(struct pci_dev *pdev,
  	return 0;
  }
 
+static int loongson_dwmac_config_multi_msi(struct pci_dev *pdev,

This method seems like the GNET-specific one. What about using the appropriate prefix then?

OK. loongson_gnet_config_multi_msi()

Quoted 8 lines

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int loongson_dwmac_config_legacy(struct pci_dev *pdev, · line 245

Quoted 5 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +4 -0
+					   struct plat_stmmacenet_data *plat,
+					   struct stmmac_resources *res,
+					   struct device_node *np,
+					   int channel_num)

Why do you need this parametrization? Since this method is GNET-specific what about defining a macro with the channels amount and using it here?

OK.

#define CHANNEL_NUM 8

Quoted 13 lines

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int loongson_dwmac_config_legacy(struct pci_dev *pdev, · line 254

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +9 -0
+{
+	int i, ret, vecs;
+
+	vecs = roundup_pow_of_two(channel_num * 2 + 1);
+	ret = pci_alloc_irq_vectors(pdev, vecs, vecs, PCI_IRQ_MSI);
+	if (ret < 0) {
+		dev_info(&pdev->dev,
+			 "MSI enable failed, Fallback to legacy interrupt\n");
+		return loongson_dwmac_config_legacy(pdev, plat, res, np);

In what conditions is this possible? Will the loongson_dwmac_config_legacy() method work in that case? Did you test it out?

Failed to apply for msi interrupt when the interrupt number is not enough,For example, there are a large number of devices。

Quoted 6 lines

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int loongson_dwmac_config_legacy(struct pci_dev *pdev, · line 258

Quoted 4 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +4 -0
+	}
+
+	plat->rx_queues_to_use = channel_num;
+	plat->tx_queues_to_use = channel_num;

This is supposed to be initialized in the setup() methods. Please move it to the dedicated patch.

No, referring to my previous reply, only the 0x10 gnet device has 8 channels, and the 0x37 device has a single channel.

Quoted 6 lines

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int loongson_dwmac_config_legacy(struct pci_dev *pdev, · line 261

Quoted 4 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +3 -0
+
+	res->irq = pci_irq_vector(pdev, 0);
+	res->wol_irq = res->irq;

Once again. wol_irq is optional. If there is no dedicated WoL IRQ leave the field as zero.

OK.

res->wol_irq = 0;

Quoted 10 lines
Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +9 -0
+
+	/* INT NAME | MAC | CH7 rx | CH7 tx | ... | CH0 rx | CH0 tx |
+	 * --------- ----- -------- --------  ...  -------- --------
+	 * IRQ NUM  |  0  |   1    |   2    | ... |   15   |   16   |
+	 */
+	for (i = 0; i < channel_num; i++) {
+		res->rx_irq[channel_num - 1 - i] =
+			pci_irq_vector(pdev, 1 + i * 2);
+		res->tx_irq[channel_num - 1 - i] =
Quoted 8 lines

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int loongson_dwmac_config_legacy(struct pci_dev *pdev, · line 275

Quoted 5 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +5 -0
+			pci_irq_vector(pdev, 2 + i * 2);
+	}
+
+	plat->flags |= STMMAC_FLAG_MULTI_MSI_EN;
+	dev_info(&pdev->dev, "%s: multi MSI enablement successful\n", __func__);

What's the point in printing this message especially with the __func__ prefix? You'll always be able to figure out the allocated IRQs by means of procfs. I suggest to drop it.

OK.

Quoted 29 lines
Quoted 29 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +5 -8
+
+	return 0;
+}
+
  static void loongson_default_data(struct pci_dev *pdev,
  				  struct plat_stmmacenet_data *plat)
  {
@@ -296,11 +335,8 @@ static int loongson_gmac_config(struct pci_dev *pdev,
  				struct stmmac_resources *res,
  				struct device_node *np)
  {
-	int ret;
-
-	ret = loongson_dwmac_config_legacy(pdev, plat, res, np);
 
-	return ret;
+	return 0;
  }
 
  static struct stmmac_pci_info loongson_gmac_pci_info = {
@@ -380,11 +416,7 @@ static int loongson_gnet_config(struct pci_dev *pdev,
  				struct stmmac_resources *res,
  				struct device_node *np)
  {
-	int ret;
-
-	ret = loongson_dwmac_config_legacy(pdev, plat, res, np);
-
Quoted 8 lines

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int loongson_gmac_config(struct pci_dev *pdev, · line 340

Quoted 3 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +1 -1
-	return ret;
+	return 0;
  }

Here you are dropping the changes you just introduced leaving the config() methods empty... Why not to place the loongson_dwmac_config_legacy() invocation in the probe() method right at the patches introducing the config() functions and not to add the config() callback in the first place?

OK, I will try.

Thanks,

Yanteng

Quoted 18 lines

-Serge(y)

Quoted 15 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +3 -0
  static struct stmmac_pci_info loongson_gnet_pci_info = {
@@ -483,6 +515,9 @@ static int loongson_dwmac_probe(struct pci_dev *pdev,
  		ld->dwlgmac_dma_ops.dma_interrupt = dwlgmac_dma_interrupt;
 
  		plat->setup = loongson_setup;
+		ret = loongson_dwmac_config_multi_msi(pdev, plat, &res, np, 8);
+	} else {
+		ret = loongson_dwmac_config_legacy(pdev, plat, &res, np);
  	}
 
  	plat->bsp_priv = ld;
Signature · 1 line
2.31.4
author
#63 lore raw

Re: [PATCH net-next v8 08/11] net: stmmac: dwmac-loongson: Fix MAC speed for GNET

In reply to a message not in the archive
Quoted 4 lines · Yanteng Si
Quoted 3 lines · Serge Semin
Quoted 2 lines · Yanteng Si

Current GNET on LS7A only supports ANE when speed is set to 1000M.

Quoted 8 lines
Quoted 5 lines

If so you need to merge it into the patch
[PATCH net-next v8 06/11] net: stmmac: dwmac-loongson: Add GNET support

Current GNET on LS7A only supports ANE when speed is set to 1000M.

If so you need to merge it into the patch
[PATCH net-next v8 06/11] net: stmmac: dwmac-loongson: Add GNET support

OK.

Quoted 138 lines
Quoted 27 lines
Quoted 15 lines
---
  .../ethernet/stmicro/stmmac/dwmac-loongson.c  | 19 +++++++++++++++++++
  .../ethernet/stmicro/stmmac/stmmac_ethtool.c  |  6 ++++++
  include/linux/stmmac.h                        |  1 +
  3 files changed, 26 insertions(+)
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +0 -0
index 60d0a122d7c9..264c4c198d5a 100644

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static struct stmmac_pci_info loongson_gmac_pci_info = { · line 353

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +7 -0
@@ -344,6 +344,21 @@ static struct stmmac_pci_info loongson_gmac_pci_info = {
  	.config = loongson_gmac_config,
  };
 
+static void loongson_gnet_fix_speed(void *priv, unsigned int speed, unsigned int mode)
+{
+	struct loongson_data *ld = (struct loongson_data *)priv;
+	struct net_device *ndev = dev_get_drvdata(ld->dev);
+	struct stmmac_priv *ptr = netdev_priv(ndev);
+
+	/* The controller and PHY don't work well together.

So there _is_ a PHY. What is the interface between MAC and PHY then?

Quoted 8 lines

GMAC only has a MAC chip inside the chip and needs an external PHY chip; GNET has the PHY chip inside the chip.

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static struct stmmac_pci_info loongson_gmac_pci_info = { · line 359

Quoted 6 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +6 -0
+	 * We need to use the PS bit to check if the controller's status
+	 * is correct and reset PHY if necessary.
+	 */
+	if (speed == SPEED_1000)
+		if (readl(ptr->ioaddr + MAC_CTRL_REG) & (1 << 15) /* PS */)
+			phy_restart_aneg(ndev->phydev);

1. Please add curly braces for the outer if-statement.

OK,

Quoted 1 line

2. MAC_CTRL_REG.15 is defined by the GMAC_CONTROL_PS macro.

OK.

if(speed==SPEED_1000){
/*MAC_CTRL_REG.15 is defined by the GMAC_CONTROL_PS macro.*/ if(readl(ptr->ioaddr+MAC_CTRL_REG) &(1<<15)) phy_restart_aneg(ndev->phydev);
}

Quoted 4 lines

3. How is the AN-restart helps? PHY-reset is done in stmmac_init_phy()->phylink_connect_phy()->... a bit earlier than this is called in the framework of the stmmac_mac_link_up() callback. Wouldn't that restart AN too?

Due to a bug in the chip's internal PHY, the network is still not working after the first self-negotiation, and it needs to be self-negotiated again.

Quoted 12 lines
Quoted 12 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +3 -0
+}
+
  static struct mac_device_info *loongson_setup(void *apriv)
  {
  	struct stmmac_priv *priv = apriv;
@@ -401,6 +416,7 @@ static int loongson_gnet_data(struct pci_dev *pdev,
  	plat->phy_interface = PHY_INTERFACE_MODE_INTERNAL;
 
  	plat->bsp_priv = &pdev->dev;
+	plat->fix_mac_speed = loongson_gnet_fix_speed;
 
Quoted 11 lines

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int loongson_gnet_config(struct pci_dev *pdev, · line 437

Quoted 9 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +3 -0
  	plat->dma_cfg->pbl = 32;
  	plat->dma_cfg->pblx8 = true;
@@ -416,6 +432,9 @@ static int loongson_gnet_config(struct pci_dev *pdev,
  				struct stmmac_resources *res,
  				struct device_node *np)
  {
+	if (pdev->revision == 0x00 || pdev->revision == 0x01)
+		plat->flags |= STMMAC_FLAG_DISABLE_FORCE_1000;
+

This should be in the patch
[PATCH net-next v8 06/11] net: stmmac: dwmac-loongson: Add GNET support

OK.

Quoted 12 lines
Quoted 12 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +0 -0
  	return 0;
  }
 
drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c +0 -0
index 42d27b97dd1d..31068fbc23c9 100644
@@ -422,6 +422,12 @@ stmmac_ethtool_set_link_ksettings(struct net_device *dev,
  		return 0;
  	}
 
Quoted 2 lines

drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c stmmac_ethtool_set_link_ksettings(struct net_device *dev, · line 425

Quoted 1 line
drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c +1 -0
+	if (FIELD_GET(STMMAC_FLAG_DISABLE_FORCE_1000, priv->plat->flags)) {

FIELD_GET()?

OK,

if (STMMAC_FLAG_DISABLE_FORCE_1000 & priv->plat->flags) {

Quoted 9 lines
Quoted 9 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c +5 -0
+		if (cmd->base.speed == SPEED_1000 &&
+		    cmd->base.autoneg != AUTONEG_ENABLE)
+			return -EOPNOTSUPP;
+	}
+
  	return phylink_ethtool_ksettings_set(priv->phylink, cmd);
  }
 
Quoted 15 lines

include/linux/stmmac.h struct dwmac4_addrs { · line 224

Quoted 9 lines
include/linux/stmmac.h +1 -0
index dee5ad6e48c5..2810361e4048 100644
@@ -221,6 +221,7 @@ struct dwmac4_addrs {
  #define STMMAC_FLAG_RX_CLK_RUNS_IN_LPI		BIT(10)
  #define STMMAC_FLAG_EN_TX_LPI_CLOCKGATING	BIT(11)
  #define STMMAC_FLAG_HWTSTAMP_CORRECT_LATENCY	BIT(12)
+#define STMMAC_FLAG_DISABLE_FORCE_1000	BIT(13)

Detach the change introducing the STMMAC_FLAG_DISABLE_FORCE_1000 flag into a separate patch a place it before
[PATCH net-next v8 06/11] net: stmmac: dwmac-loongson: Add GNET support as a pre-requisite/preparation patch.
Don't forget a _detailed_ description of why it's necessary, what is wrong with GNET so 1G speed doesn't work without AN.

OK.

Thanks,

Yanteng

Quoted 9 lines

-Serge(y)

Quoted 6 lines
include/linux/stmmac.h +0 -0
  struct plat_stmmacenet_data {
  	int bus_id;
Signature · 1 line
2.31.4
#27 lore raw

Re: [PATCH net-next v8 04/11] net: stmmac: dwmac-loongson: Move irq config to loongson_gmac_config

In reply to Yanteng Si
Quoted 67 lines · Yanteng Si
Quoted 8 lines · Serge Semin
Quoted 5 lines · Yanteng Si

Add loongson_dwmac_config and moving irq config related code to loongson_dwmac_config.

Removing MSI to prepare for adding loongson multi-channel support later.

Please detach this change into a separate patch and thoroughly explain why it was necessary.

OK.

Quoted 53 lines
Quoted 40 lines
---
  .../ethernet/stmicro/stmmac/dwmac-loongson.c  | 85 ++++++++++++-------
  1 file changed, 55 insertions(+), 30 deletions(-)
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +24 -0
index 979c9b6dab3f..e7ce027cc14e 100644
@@ -11,8 +11,46 @@
  struct stmmac_pci_info {
  	int (*setup)(struct pci_dev *pdev, struct plat_stmmacenet_data *plat);
+	int (*config)(struct pci_dev *pdev, struct plat_stmmacenet_data *plat,
+		      struct stmmac_resources *res, struct device_node *np);
  };
+static int loongson_dwmac_config_legacy(struct pci_dev *pdev,
+					struct plat_stmmacenet_data *plat,
+					struct stmmac_resources *res,
+					struct device_node *np)
+{
+	if (np) {
+		res->irq = of_irq_get_byname(np, "macirq");
+		if (res->irq < 0) {
+			dev_err(&pdev->dev, "IRQ macirq not found\n");
+			return -ENODEV;
+		}
+
+		res->wol_irq = of_irq_get_byname(np, "eth_wake_irq");
+		if (res->wol_irq < 0) {
+			dev_info(&pdev->dev,
+				 "IRQ eth_wake_irq not found, using macirq\n");
+			res->wol_irq = res->irq;
+		}
+
+		res->lpi_irq = of_irq_get_byname(np, "eth_lpi");
+		if (res->lpi_irq < 0) {
+			dev_err(&pdev->dev, "IRQ eth_lpi not found\n");

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c line 47

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +10 -0
+			return -ENODEV;
+		}
+	} else {
+		res->irq = pdev->irq;
+		res->wol_irq = res->irq;
+	}
+
+	plat->flags &= ~STMMAC_FLAG_MULTI_MSI_EN;
+	dev_info(&pdev->dev, "%s: Single IRQ enablement successful\n",
+		 __func__);

Why is this here all of the sudden? I don't see this in the original code. Please move it to the patch which requires the flag setup/cleanup or drop if it isn't necessary.

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +1 -0
+	plat->flags &= ~STMMAC_FLAG_MULTI_MSI_EN;
Quoted 2 lines

This cannot be removed because it appeared in a rebase(v4 -> v5). See
<https://lore.kernel.org/all/[email protected]/>

AFAICS it _can_ be removed. The patch you referred to is a formal conversion of
- plat->multi_msi_en = 0;
to
+ plat->flags &= ~STMMAC_FLAG_MULTI_MSI_EN;
First of all the "multi_msi_en" field clearance had been redundant there since the code setting the flag was executed after the code which may cause the field clearance performed. Second AFAICS the "multi_msi_en" field clearance was originally added to emphasize the functions semantics:
intel_eth_config_multi_msi() - config multi IRQ device, intel_eth_config_single_msi() - config single IRQ device.

So in your case there is no any reason of clearing the STMMAC_FLAG_MULTI_MSI_EN flag. Please, either drop it or move the change into a separate patch.

-Serge(y)

Quoted 106 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +2 -0
+	dev_info(&pdev->dev, "%s: Single IRQ enablement successful\n",
+		 __func__);

OK, drop it.

Quoted 20 lines
Quoted 20 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +13 -0
+
+	return 0;
+}
+
  static void loongson_default_data(struct pci_dev *pdev,
  				  struct plat_stmmacenet_data *plat)
  {
@@ -66,8 +104,21 @@ static int loongson_gmac_data(struct pci_dev *pdev,
  	return 0;
  }
+static int loongson_gmac_config(struct pci_dev *pdev,
+				struct plat_stmmacenet_data *plat,
+				struct stmmac_resources *res,
+				struct device_node *np)
+{
+	int ret;
+
+	ret = loongson_dwmac_config_legacy(pdev, plat, res, np);
+
Quoted 8 lines

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int loongson_gmac_data(struct pci_dev *pdev, · line 118

Quoted 3 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +3 -0
+	return ret;
+}
+

You introduce the config callback here and convert to a dummy method in
[PATCH 07/11] net: stmmac: dwmac-loongson: Add multi-channel supports for loongson It's just pointless. What about introducing the loongson_dwmac_config_legacy() method and call it directly?

OK, I will try.

Quoted 11 lines

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int loongson_dwmac_probe(struct pci_dev *pdev, · line 141

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +1 -1
  static struct stmmac_pci_info loongson_gmac_pci_info = {
  	.setup = loongson_gmac_data,
+	.config = loongson_gmac_config,
  };
  static int loongson_dwmac_probe(struct pci_dev *pdev,
@@ -139,44 +190,19 @@ static int loongson_dwmac_probe(struct pci_dev *pdev,
  		plat->phy_interface = phy_mode;
  	}
-	pci_enable_msi(pdev);

See my first note in this message.

OK.

Thanks,

Yanteng

Quoted 52 lines

-Serge(y)

Quoted 49 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +4 -29
  	memset(&res, 0, sizeof(res));
  	res.addr = pcim_iomap_table(pdev)[0];
-	if (np) {
-		res.irq = of_irq_get_byname(np, "macirq");
-		if (res.irq < 0) {
-			dev_err(&pdev->dev, "IRQ macirq not found\n");
-			ret = -ENODEV;
-			goto err_disable_msi;
-		}
-
-		res.wol_irq = of_irq_get_byname(np, "eth_wake_irq");
-		if (res.wol_irq < 0) {
-			dev_info(&pdev->dev,
-				 "IRQ eth_wake_irq not found, using macirq\n");
-			res.wol_irq = res.irq;
-		}
-
-		res.lpi_irq = of_irq_get_byname(np, "eth_lpi");
-		if (res.lpi_irq < 0) {
-			dev_err(&pdev->dev, "IRQ eth_lpi not found\n");
-			ret = -ENODEV;
-			goto err_disable_msi;
-		}
-	} else {
-		res.irq = pdev->irq;
-		res.wol_irq = pdev->irq;
-	}
+	ret = info->config(pdev, plat, &res, np);
+	if (ret)
+		goto err_disable_device;
  	ret = stmmac_dvr_probe(&pdev->dev, plat, &res);
  	if (ret)
-		goto err_disable_msi;
+		goto err_disable_device;
  	return ret;
-err_disable_msi:
-	pci_disable_msi(pdev);
  err_disable_device:
  	pci_disable_device(pdev);
  err_put_node:
@@ -200,7 +226,6 @@ static void loongson_dwmac_remove(struct pci_dev *pdev)
  		break;
  	}
-	pci_disable_msi(pdev);
  	pci_disable_device(pdev);
  }
Signature · 1 line
2.31.4
#11 lore raw

Re: [PATCH net-next v8 01/11] net: stmmac: Add multi-channel support

In reply to Yanteng Si
Quoted 1 line · Yanteng Si

Hi Serge

How come almost all of yours recent replies have been formatted as if with no inline messages? See
https://lore.kernel.org/netdev/[email protected]/
It's very-very-very hard to read. Please never do that.

Quoted 453 lines · Yanteng Si
Quoted 451 lines · Serge Semin
Quoted 216 lines

Hi Yanteng

Quoted 192 lines · Yanteng Si

Hi Serge

Quoted 69 lines · Serge Semin
Quoted 35 lines · Yanteng Si

DW GMAC v3.x multi-channels feature is implemented as multiple sets of the same CSRs. Here is only preliminary support, it will be useful for the driver further evolution and for the users having multi-channel DWGMAC v3.x devices.

---
   .../net/ethernet/stmicro/stmmac/dwmac-sun8i.c |  2 +-
   .../ethernet/stmicro/stmmac/dwmac1000_dma.c   | 36 ++++++++++---------
   .../net/ethernet/stmicro/stmmac/dwmac_dma.h   | 19 +++++++++-
   .../net/ethernet/stmicro/stmmac/dwmac_lib.c   | 32 ++++++++---------
   drivers/net/ethernet/stmicro/stmmac/hwif.h    |  2 +-
   .../net/ethernet/stmicro/stmmac/stmmac_main.c |  6 ++--
   6 files changed, 58 insertions(+), 39 deletions(-)
drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c +1 -1
index 137741b94122..7cdfa0bdb93a 100644
@@ -395,7 +395,7 @@ static void sun8i_dwmac_dma_start_tx(struct stmmac_priv *priv,
   	writel(v, ioaddr + EMAC_TX_CTL1);
   }
-static void sun8i_dwmac_enable_dma_transmission(void __iomem *ioaddr)
+static void sun8i_dwmac_enable_dma_transmission(void __iomem *ioaddr, u32 chan)
   {
   	u32 v;
drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c +0 -0
index daf79cdbd3ec..5f7b82ad3ec2 100644
@@ -70,15 +70,18 @@ static void dwmac1000_dma_axi(void __iomem *ioaddr, struct stmmac_axi *axi)
   	writel(value, ioaddr + DMA_AXI_BUS_MODE);
   }

drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c static void dwmac1000_dma_axi(void __iomem *ioaddr, struct stmmac_axi *axi) · line 78

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c +4 -3
-static void dwmac1000_dma_init(void __iomem *ioaddr,
-			       struct stmmac_dma_cfg *dma_cfg, int atds)
+static void dwmac1000_dma_init_channel(struct stmmac_priv *priv,
+				       void __iomem *ioaddr,
+				       struct stmmac_dma_cfg *dma_cfg, u32 chan)
   {
-	u32 value = readl(ioaddr + DMA_BUS_MODE);
+	u32 value;
   	int txpbl = dma_cfg->txpbl ?: dma_cfg->pbl;
   	int rxpbl = dma_cfg->rxpbl ?: dma_cfg->pbl;

Reverse xmas tree please.

drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c static void dwmac1000_dma_axi(void __iomem *ioaddr, struct stmmac_axi *axi) · line 79

Quoted 3 lines
drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c +1 -2
-	/*
-	 * Set the DMA PBL (Programmable Burst Length) mode.
+	/* common channel control register config */

Redundant comment. Please drop.

drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c static void dwmac1000_dma_init(void __iomem *ioaddr, · line 103

Quoted 12 lines
drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c +4 -2
+	value = readl(ioaddr + DMA_CHAN_BUS_MODE(chan));
+
+	/* Set the DMA PBL (Programmable Burst Length) mode.
   	 *
   	 * Note: before stmmac core 3.50 this mode bit was 4xPBL, and
   	 * post 3.5 mode bit acts as 8*PBL.
@@ -98,16 +101,15 @@ static void dwmac1000_dma_init(void __iomem *ioaddr,
   	if (dma_cfg->mixed_burst)
   		value |= DMA_BUS_MODE_MB;
-	if (atds)
-		value |= DMA_BUS_MODE_ATDS;
+	value |= DMA_BUS_MODE_ATDS;

No, just convert the stmmac_dma_ops.dma_init_channel() to accepting the atds flag as I suggested in v7:
https://lore.kernel.org/netdev/vxcfrxtbfu4pya56m22icnizsyjzqqha5blzb7zpexqcur56uh@uv6vsjf77npa/

Quoted 4 lines

In order to simplify this patch you can provide the stmmac_dma_ops.dma_init_channel() and stmmac_dma_ops.enable_dma_transmission() prototype updates in a pre-requisite/preparation patch.

Sorry to keep you waiting for so long, I finally got the machine again. Regarding atds, is this how it is implemented?

On the basis of applying PATCH v8:

drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c +2 -1
index 0323f0a5049c..ce99f4a1b320 100644
@@ -72,7 +72,8 @@ static void dwmac1000_dma_axi(void __iomem *ioaddr, struct
 stmmac_axi *axi)
 
  static void dwmac1000_dma_init_channel(struct stmmac_priv *priv,
                         void __iomem *ioaddr,
-                       struct stmmac_dma_cfg *dma_cfg, u32 chan)
+                       struct stmmac_dma_cfg *dma_cfg,
+                       int atds, u32 chan)
  {
      u32 value;
      int txpbl = dma_cfg->txpbl ?: dma_cfg->pbl;
drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c +2 -1
@@ -101,7 +102,8 @@ static void dwmac1000_dma_init_channel(struct
 stmmac_priv *priv,
      if (dma_cfg->mixed_burst)
          value |= DMA_BUS_MODE_MB;
 
-    value |= DMA_BUS_MODE_ATDS;
+    if (atds)
+        value |= DMA_BUS_MODE_ATDS;
 
      if (dma_cfg->aal)
          value |= DMA_BUS_MODE_AAL;
drivers/net/ethernet/stmicro/stmmac/dwmac4_dma.c +2 -1
index 84d3a8551b03..8a79c154b553 100644
@@ -117,7 +117,8 @@ static void dwmac4_dma_init_tx_chan(struct stmmac_priv
 *priv,
 
  static void dwmac4_dma_init_channel(struct stmmac_priv *priv,
                      void __iomem *ioaddr,
-                    struct stmmac_dma_cfg *dma_cfg, u32 chan)
+                    struct stmmac_dma_cfg *dma_cfg,
+                                    int atds, u32 chan)
  {
      const struct dwmac4_addrs *dwmac4_addrs = priv->plat->dwmac4_addrs;
      u32 value;
drivers/net/ethernet/stmicro/stmmac/dwmac4_dma.c +2 -1
@@ -135,7 +136,8 @@ static void dwmac4_dma_init_channel(struct stmmac_priv
 *priv,
 
  static void dwmac410_dma_init_channel(struct stmmac_priv *priv,
                        void __iomem *ioaddr,
-                      struct stmmac_dma_cfg *dma_cfg, u32 chan)
+                      struct stmmac_dma_cfg *dma_cfg,
+                                      int atds, u32 chan)
  {
      const struct dwmac4_addrs *dwmac4_addrs = priv->plat->dwmac4_addrs;
      u32 value;
drivers/net/ethernet/stmicro/stmmac/dwxgmac2_dma.c +2 -1
index dd2ab6185c40..d1627b2e50c8 100644
@@ -35,7 +35,8 @@ static void dwxgmac2_dma_init(void __iomem *ioaddr,
 
  static void dwxgmac2_dma_init_chan(struct stmmac_priv *priv,
                     void __iomem *ioaddr,
-                   struct stmmac_dma_cfg *dma_cfg, u32 chan)
+                   struct stmmac_dma_cfg *dma_cfg,
+                                   int atds, u32 chan)
  {
      u32 value = readl(ioaddr + XGMAC_DMA_CH_CONTROL(chan));
 
drivers/net/ethernet/stmicro/stmmac/hwif.h +1 -1
index b0db38396171..fb27ad0e97e8 100644
@@ -178,7 +178,7 @@ struct stmmac_dma_ops {
      void (*init)(void __iomem *ioaddr, struct stmmac_dma_cfg *dma_cfg,
               int atds);
      void (*init_chan)(struct stmmac_priv *priv, void __iomem *ioaddr,
-              struct stmmac_dma_cfg *dma_cfg, u32 chan);
+              struct stmmac_dma_cfg *dma_cfg, int atds, u32 chan);
      void (*init_rx_chan)(struct stmmac_priv *priv, void __iomem *ioaddr,
                   struct stmmac_dma_cfg *dma_cfg,
                   dma_addr_t phy, u32 chan);
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +1 -1
index 3eed202d1f1c..8705e04913d1 100644
@@ -3039,7 +3039,7 @@ static int stmmac_init_dma_engine(struct stmmac_priv
 *priv)
 
      /* DMA CSR Channel configuration */
      for (chan = 0; chan < dma_csr_ch; chan++) {
-        stmmac_init_chan(priv, priv->ioaddr, priv->plat->dma_cfg, chan);
+        stmmac_init_chan(priv, priv->ioaddr, priv->plat->dma_cfg, atds,
 chan);
          stmmac_disable_dma_irq(priv, priv->ioaddr, chan, 1, 1);
      }
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +1 -0
@@ -6963,6 +6963,7 @@ int stmmac_xdp_open(struct net_device *dev)
      u32 buf_size;
      bool sph_en;
      u32 chan;
+     int atds;
      int ret;
 
      ret = alloc_dma_desc_resources(priv, &priv->dma_conf);
@@ -6981,9 +6982,12 @@ int stmmac_xdp_open(struct net_device *dev)
 
      stmmac_reset_queues_param(priv);
 

drivers/net/ethernet/stmicro/stmmac/stmmac_main.c int stmmac_xdp_open(struct net_device *dev) · line 6993

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +4 -1
+    if (priv->extend_desc && (priv->mode == STMMAC_RING_MODE))
+        atds = 1;
+
      /* DMA CSR Channel configuration */
      for (chan = 0; chan < dma_csr_ch; chan++) {
-        stmmac_init_chan(priv, priv->ioaddr, priv->plat->dma_cfg, chan);
+        stmmac_init_chan(priv, priv->ioaddr, priv->plat->dma_cfg, atds,
 chan);
          stmmac_disable_dma_irq(priv, priv->ioaddr, chan, 1, 1);
      }

Looking more thoroughly at this part I suggest to act a bit differently. Let's move the atds flag to the stmmac_dma_cfg structure. Alternate Descriptor Size (ATDS) is a part of the DMA-configs together with the PBL, ALL, AEME, etc so the structure is the most suitable place for it. Here is what should be done for that:
1. Add stmmac_dma_cfg::atds boolean field.
2. Drop atds argument from the stmmac_dma_ops::init() callback and use the stmmac_dma_cfg::atds field in the callback implementations.
3. Alter stmmac_init_dma_engine() to updating the dma_cfg->atds field instead of the local variable.

Quoted 4 lines

Please implement that update in a pre-requisite/preparation patch.

After that you can freely use the stmmac_dma_cfg::atds field in the stmmac_init_chan() method too.

OK.

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +2 -3
index b57e1325ce62..dabd6a3772f2 100644
@@ -66,8 +66,7 @@ struct loongson_data {
 
   static void loongson_gnet_dma_init_channel(struct stmmac_priv *priv,
                        void __iomem *ioaddr,
-                     struct stmmac_dma_cfg *dma_cfg,
-                                     int atds, u32 chan)
+                     struct stmmac_dma_cfg *dma_cfg, u32 chan)
   {
       int txpbl = dma_cfg->txpbl ?: dma_cfg->pbl;
       int rxpbl = dma_cfg->rxpbl ?: dma_cfg->pbl;
@@ -96,7 +95,7 @@ static void loongson_gnet_dma_init_channel(struct stmmac_priv
 *priv,
       if (dma_cfg->mixed_burst)
           value |= DMA_BUS_MODE_MB;
 
-    if (atds)
+    if (dma_cfg->atds)
           value |= DMA_BUS_MODE_ATDS;
 
       if (dma_cfg->aal)
drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c +1 -1
index 7001a86425ea..ae9240736e64 100644
@@ -299,7 +299,7 @@ static int sun8i_dwmac_dma_reset(void __iomem *ioaddr)
    * Called from stmmac via stmmac_dma_ops->init
    */
   static void sun8i_dwmac_dma_init(void __iomem *ioaddr,
-                 struct stmmac_dma_cfg *dma_cfg, int atds)
+                 struct stmmac_dma_cfg *dma_cfg)
   {
       writel(EMAC_RX_INT | EMAC_TX_INT, ioaddr + EMAC_INT_EN);
       writel(0x1FFFFFF, ioaddr + EMAC_INT_STA);
drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c +1 -2
index fd5ecc043251..66c0c22908b1 100644
@@ -72,8 +72,7 @@ static void dwmac1000_dma_axi(void __iomem *ioaddr, struct
 stmmac_axi *axi)
 
   static void dwmac1000_dma_init_channel(struct stmmac_priv *priv,
                          void __iomem *ioaddr,
-                       struct stmmac_dma_cfg *dma_cfg,
-                       int atds, u32 chan)
+                       struct stmmac_dma_cfg *dma_cfg, u32 chan)
   {
       int txpbl = dma_cfg->txpbl ?: dma_cfg->pbl;
       int rxpbl = dma_cfg->rxpbl ?: dma_cfg->pbl;
drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c +1 -1
@@ -101,7 +100,7 @@ static void dwmac1000_dma_init_channel(struct stmmac_priv *priv,
       if (dma_cfg->mixed_burst)
           value |= DMA_BUS_MODE_MB;
 
-    if (atds)
+    if (dma_cfg->atds)
           value |= DMA_BUS_MODE_ATDS;
 
       if (dma_cfg->aal)
drivers/net/ethernet/stmicro/stmmac/dwmac100_dma.c +1 -1
index dea270f60cc3..f861babc06f9 100644
@@ -19,7 +19,7 @@
   #include "dwmac_dma.h"
 
   static void dwmac100_dma_init(void __iomem *ioaddr,
-                  struct stmmac_dma_cfg *dma_cfg, int atds)
+                  struct stmmac_dma_cfg *dma_cfg)
   {
       /* Enable Application Access by writing to DMA CSR0 */
       writel(DMA_BUS_MODE_DEFAULT | (dma_cfg->pbl << DMA_BUS_MODE_PBL_SHIFT),
drivers/net/ethernet/stmicro/stmmac/dwmac4_dma.c +3 -5
index 8a79c154b553..e0165358c4ac 100644
@@ -117,8 +117,7 @@ static void dwmac4_dma_init_tx_chan(struct stmmac_priv *priv,
 
   static void dwmac4_dma_init_channel(struct stmmac_priv *priv,
                       void __iomem *ioaddr,
-                    struct stmmac_dma_cfg *dma_cfg,
-                                    int atds, u32 chan)
+                    struct stmmac_dma_cfg *dma_cfg, u32 chan)
   {
       const struct dwmac4_addrs *dwmac4_addrs = priv->plat->dwmac4_addrs;
       u32 value;
@@ -136,8 +135,7 @@ static void dwmac4_dma_init_channel(struct stmmac_priv *priv,
 
   static void dwmac410_dma_init_channel(struct stmmac_priv *priv,
                         void __iomem *ioaddr,
-                      struct stmmac_dma_cfg *dma_cfg,
-                                      int atds, u32 chan)
+                      struct stmmac_dma_cfg *dma_cfg, u32 chan)
   {
       const struct dwmac4_addrs *dwmac4_addrs = priv->plat->dwmac4_addrs;
       u32 value;
@@ -155,7 +153,7 @@ static void dwmac410_dma_init_channel(struct stmmac_priv *priv,
   }
 
   static void dwmac4_dma_init(void __iomem *ioaddr,
-                struct stmmac_dma_cfg *dma_cfg, int atds)
+                struct stmmac_dma_cfg *dma_cfg)
   {
       u32 value = readl(ioaddr + DMA_SYS_BUS_MODE);
 
drivers/net/ethernet/stmicro/stmmac/dwxgmac2_dma.c +2 -3
index d1627b2e50c8..7840bc403788 100644
@@ -20,7 +20,7 @@ static int dwxgmac2_dma_reset(void __iomem *ioaddr)
   }
 
   static void dwxgmac2_dma_init(void __iomem *ioaddr,
-                  struct stmmac_dma_cfg *dma_cfg, int atds)
+                  struct stmmac_dma_cfg *dma_cfg)
   {
       u32 value = readl(ioaddr + XGMAC_DMA_SYSBUS_MODE);
 
@@ -35,8 +35,7 @@ static void dwxgmac2_dma_init(void __iomem *ioaddr,
 
   static void dwxgmac2_dma_init_chan(struct stmmac_priv *priv,
                      void __iomem *ioaddr,
-                   struct stmmac_dma_cfg *dma_cfg,
-                                   int atds, u32 chan)
+                   struct stmmac_dma_cfg *dma_cfg, u32 chan)
   {
       u32 value = readl(ioaddr + XGMAC_DMA_CH_CONTROL(chan));
 
drivers/net/ethernet/stmicro/stmmac/hwif.h +2 -3
index fb27ad0e97e8..3b20fb7f3a61 100644
@@ -175,10 +175,9 @@ struct dma_features;
   struct stmmac_dma_ops {
       /* DMA core initialization */
       int (*reset)(void __iomem *ioaddr);
-    void (*init)(void __iomem *ioaddr, struct stmmac_dma_cfg *dma_cfg,
-             int atds);
+    void (*init)(void __iomem *ioaddr, struct stmmac_dma_cfg *dma_cfg);
       void (*init_chan)(struct stmmac_priv *priv, void __iomem *ioaddr,
-              struct stmmac_dma_cfg *dma_cfg, int atds, u32 chan);
+              struct stmmac_dma_cfg *dma_cfg, u32 chan);
       void (*init_rx_chan)(struct stmmac_priv *priv, void __iomem *ioaddr,
                    struct stmmac_dma_cfg *dma_cfg,
                    dma_addr_t phy, u32 chan);
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +4 -9
index 7c656f970575..957dfabc663d 100644
@@ -3013,7 +3013,6 @@ static int stmmac_init_dma_engine(struct stmmac_priv *priv)
       struct stmmac_rx_queue *rx_q;
       struct stmmac_tx_queue *tx_q;
       u32 chan = 0;
-    int atds = 0;
       int ret = 0;
 
       if (!priv->plat->dma_cfg || !priv->plat->dma_cfg->pbl) {
@@ -3022,7 +3021,7 @@ static int stmmac_init_dma_engine(struct stmmac_priv *priv)
       }
 
       if (priv->extend_desc && (priv->mode == STMMAC_RING_MODE))
-        atds = 1;
+        priv->plat->dma_cfg->atds = 1;
 
       ret = stmmac_reset(priv, priv->ioaddr);
       if (ret) {
@@ -3031,14 +3030,14 @@ static int stmmac_init_dma_engine(struct stmmac_priv *priv)
       }
 
       /* DMA Configuration */
-    stmmac_dma_init(priv, priv->ioaddr, priv->plat->dma_cfg, atds);
+    stmmac_dma_init(priv, priv->ioaddr, priv->plat->dma_cfg);
 
       if (priv->plat->axi)
           stmmac_axi(priv, priv->ioaddr, priv->plat->axi);
 
       /* DMA CSR Channel configuration */
       for (chan = 0; chan < dma_csr_ch; chan++) {
-        stmmac_init_chan(priv, priv->ioaddr, priv->plat->dma_cfg, atds, chan);
+        stmmac_init_chan(priv, priv->ioaddr, priv->plat->dma_cfg, chan);
           stmmac_disable_dma_irq(priv, priv->ioaddr, chan, 1, 1);
       }
 
@@ -6962,7 +6961,6 @@ int stmmac_xdp_open(struct net_device *dev)
       u32 buf_size;
       bool sph_en;
       u32 chan;
-        int atds;
       int ret;
 
       ret = alloc_dma_desc_resources(priv, &priv->dma_conf);
@@ -6981,12 +6979,9 @@ int stmmac_xdp_open(struct net_device *dev)
 
       stmmac_reset_queues_param(priv);
 
-    if (priv->extend_desc && (priv->mode == STMMAC_RING_MODE))
-        atds = 1;
-
       /* DMA CSR Channel configuration */
       for (chan = 0; chan < dma_csr_ch; chan++) {
-        stmmac_init_chan(priv, priv->ioaddr, priv->plat->dma_cfg, atds, chan);
+        stmmac_init_chan(priv, priv->ioaddr, priv->plat->dma_cfg, chan);
           stmmac_disable_dma_irq(priv, priv->ioaddr, chan, 1, 1);
       }
 
include/linux/stmmac.h +1 -0
index 23bfe3c1465f..c827dc1213b9 100644
@@ -100,6 +100,7 @@ struct stmmac_dma_cfg {
       bool eame;
       bool multi_msi_en;
       bool dche;
+    bool atds;
   };
 
Quoted 2 lines

include/linux/stmmac.h struct stmmac_dma_cfg { · line 106

Quoted 2 lines
include/linux/stmmac.h +0 -0
   #define AXI_BLEN    7

Ok. Let's see how it looks in a separate patch of the v9 series.

-Serge(y)

Quoted 266 lines
Quoted 265 lines

Thanks,

Yanteng

Quoted 260 lines

-Serge(y)

Quoted 257 lines

Thanks,

Yanteng

Quoted 252 lines
Quoted 73 lines
drivers/net/ethernet/stmicro/stmmac/dwmac1000_dma.c +10 -10
   	if (dma_cfg->aal)
   		value |= DMA_BUS_MODE_AAL;
-	writel(value, ioaddr + DMA_BUS_MODE);
+	writel(value, ioaddr + DMA_CHAN_BUS_MODE(chan));
   	/* Mask interrupts by writing to CSR7 */
-	writel(DMA_INTR_DEFAULT_MASK, ioaddr + DMA_INTR_ENA);
+	writel(DMA_INTR_DEFAULT_MASK, ioaddr + DMA_CHAN_INTR_ENA(chan));
   }
   static void dwmac1000_dma_init_rx(struct stmmac_priv *priv,
@@ -116,7 +118,7 @@ static void dwmac1000_dma_init_rx(struct stmmac_priv *priv,
   				  dma_addr_t dma_rx_phy, u32 chan)
   {
   	/* RX descriptor base address list must be written into DMA CSR3 */
-	writel(lower_32_bits(dma_rx_phy), ioaddr + DMA_RCV_BASE_ADDR);
+	writel(lower_32_bits(dma_rx_phy), ioaddr + DMA_CHAN_RCV_BASE_ADDR(chan));
   }
   static void dwmac1000_dma_init_tx(struct stmmac_priv *priv,
@@ -125,7 +127,7 @@ static void dwmac1000_dma_init_tx(struct stmmac_priv *priv,
   				  dma_addr_t dma_tx_phy, u32 chan)
   {
   	/* TX descriptor base address list must be written into DMA CSR4 */
-	writel(lower_32_bits(dma_tx_phy), ioaddr + DMA_TX_BASE_ADDR);
+	writel(lower_32_bits(dma_tx_phy), ioaddr + DMA_CHAN_TX_BASE_ADDR(chan));
   }
   static u32 dwmac1000_configure_fc(u32 csr6, int rxfifosz)
@@ -153,7 +155,7 @@ static void dwmac1000_dma_operation_mode_rx(struct stmmac_priv *priv,
   					    void __iomem *ioaddr, int mode,
   					    u32 channel, int fifosz, u8 qmode)
   {
-	u32 csr6 = readl(ioaddr + DMA_CONTROL);
+	u32 csr6 = readl(ioaddr + DMA_CHAN_CONTROL(channel));
   	if (mode == SF_DMA_MODE) {
   		pr_debug("GMAC: enable RX store and forward mode\n");
@@ -175,14 +177,14 @@ static void dwmac1000_dma_operation_mode_rx(struct stmmac_priv *priv,
   	/* Configure flow control based on rx fifo size */
   	csr6 = dwmac1000_configure_fc(csr6, fifosz);
-	writel(csr6, ioaddr + DMA_CONTROL);
+	writel(csr6, ioaddr + DMA_CHAN_CONTROL(channel));
   }
   static void dwmac1000_dma_operation_mode_tx(struct stmmac_priv *priv,
   					    void __iomem *ioaddr, int mode,
   					    u32 channel, int fifosz, u8 qmode)
   {
-	u32 csr6 = readl(ioaddr + DMA_CONTROL);
+	u32 csr6 = readl(ioaddr + DMA_CHAN_CONTROL(channel));
   	if (mode == SF_DMA_MODE) {
   		pr_debug("GMAC: enable TX store and forward mode\n");
@@ -209,7 +211,7 @@ static void dwmac1000_dma_operation_mode_tx(struct stmmac_priv *priv,
   			csr6 |= DMA_CONTROL_TTC_256;
   	}
-	writel(csr6, ioaddr + DMA_CONTROL);
+	writel(csr6, ioaddr + DMA_CHAN_CONTROL(channel));
   }
   static void dwmac1000_dump_dma_regs(struct stmmac_priv *priv,
@@ -271,12 +273,12 @@ static int dwmac1000_get_hw_feature(void __iomem *ioaddr,
   static void dwmac1000_rx_watchdog(struct stmmac_priv *priv,
   				  void __iomem *ioaddr, u32 riwt, u32 queue)
   {
-	writel(riwt, ioaddr + DMA_RX_WATCHDOG);
+	writel(riwt, ioaddr + DMA_CHAN_RX_WATCHDOG(queue));
   }
   const struct stmmac_dma_ops dwmac1000_dma_ops = {
   	.reset = dwmac_dma_reset,
-	.init = dwmac1000_dma_init,
+	.init_chan = dwmac1000_dma_init_channel,
   	.init_rx_chan = dwmac1000_dma_init_rx,
   	.init_tx_chan = dwmac1000_dma_init_tx,
   	.axi = dwmac1000_dma_axi,
drivers/net/ethernet/stmicro/stmmac/dwmac_dma.h +0 -0
index 72672391675f..593be79c46e1 100644

drivers/net/ethernet/stmicro/stmmac/dwmac_dma.h line 152

Quoted 5 lines
drivers/net/ethernet/stmicro/stmmac/dwmac_dma.h +3 -0
@@ -148,11 +148,14 @@
   					 DMA_STATUS_TI | \
   					 DMA_STATUS_MSK_COMMON)
+/* Following DMA defines are chanels oriented */    \
+#define DMA_CHAN_OFFSET			0x100   |-------------+
+                                                    /              |
                                                                        |
Please move all of these ---------------------------------------------+-------------------------+
to being defined just below the DMA_MISSED_FRAME_CTR macros definition.                         |
The point is to keep a coherency between dwmac_dma.h and dwmac4_dma.h.                          |
The later header file has first generic DMA-related macros defined                              |
(CSR addresses and flags) and then the channel-specific ones (CSR                               |
addresses and flags). Since in case of the DW GMAC v3.x the                                     |
multi-channels are implemented as a copy of all the DMA CSRs let's                              |
preserve the logic of having all CSR address defined first, then the                            |
CSR flags.                                                                                      |
                                                                                                  |

drivers/net/ethernet/stmicro/stmmac/dwmac_dma.h int dwmac_dma_interrupt(struct stmmac_priv *priv, void __iomem *ioaddr, | · line 174

Quoted 13 lines
drivers/net/ethernet/stmicro/stmmac/dwmac_dma.h +1 -1
   #define NUM_DWMAC100_DMA_REGS	9                                                       |
   #define NUM_DWMAC1000_DMA_REGS	23                                                      |
   #define NUM_DWMAC4_DMA_REGS	27                                                              |
                                                                                                |
-void dwmac_enable_dma_transmission(void __iomem *ioaddr);                                    |
+void dwmac_enable_dma_transmission(void __iomem *ioaddr, u32 chan);                          |
   void dwmac_enable_dma_irq(struct stmmac_priv *priv, void __iomem *ioaddr,                    |
   			  u32 chan, bool rx, bool tx);                                          |
   void dwmac_disable_dma_irq(struct stmmac_priv *priv, void __iomem *ioaddr,                   |
@@ -169,4 +172,18 @@ int dwmac_dma_interrupt(struct stmmac_priv *priv, void __iomem *ioaddr,  |
   			struct stmmac_extra_stats *x, u32 chan, u32 dir);                       |
   int dwmac_dma_reset(void __iomem *ioaddr);                                                   |
                                                                                                |
                                                                                                  |
Quoted 96 lines
drivers/net/ethernet/stmicro/stmmac/dwmac_dma.h +14 -0
+static inline u32 dma_chan_base_addr(u32 base, u32 chan)                                  \  |
+{                                                                                          | |
+	return base + chan * DMA_CHAN_OFFSET;                                                 | |
+}                                                                                          | |
+                                                                                           | |
+#define DMA_CHAN_XMT_POLL_DEMAND(chan)	dma_chan_base_addr(DMA_XMT_POLL_DEMAND, chan) | |
+#define DMA_CHAN_INTR_ENA(chan)		dma_chan_base_addr(DMA_INTR_ENA, chan)        | |
+#define DMA_CHAN_CONTROL(chan)		dma_chan_base_addr(DMA_CONTROL, chan)         | |
+#define DMA_CHAN_STATUS(chan)		dma_chan_base_addr(DMA_STATUS, chan)          |-+
+#define DMA_CHAN_BUS_MODE(chan)		dma_chan_base_addr(DMA_BUS_MODE, chan)        |
+#define DMA_CHAN_RCV_BASE_ADDR(chan)	dma_chan_base_addr(DMA_RCV_BASE_ADDR, chan)           |
+#define DMA_CHAN_TX_BASE_ADDR(chan)	dma_chan_base_addr(DMA_TX_BASE_ADDR, chan)            |
+#define DMA_CHAN_RX_WATCHDOG(chan)	dma_chan_base_addr(DMA_RX_WATCHDOG, chan)             |
+                                                                                           /
   #endif /* __DWMAC_DMA_H__ */
drivers/net/ethernet/stmicro/stmmac/dwmac_lib.c +15 -15
index 7907d62d3437..b37368137810 100644
@@ -28,65 +28,65 @@ int dwmac_dma_reset(void __iomem *ioaddr)
   }
   /* CSR1 enables the transmit DMA to check for new descriptor */
-void dwmac_enable_dma_transmission(void __iomem *ioaddr)
+void dwmac_enable_dma_transmission(void __iomem *ioaddr, u32 chan)
   {
-	writel(1, ioaddr + DMA_XMT_POLL_DEMAND);
+	writel(1, ioaddr + DMA_CHAN_XMT_POLL_DEMAND(chan));
   }
   void dwmac_enable_dma_irq(struct stmmac_priv *priv, void __iomem *ioaddr,
   			  u32 chan, bool rx, bool tx)
   {
-	u32 value = readl(ioaddr + DMA_INTR_ENA);
+	u32 value = readl(ioaddr + DMA_CHAN_INTR_ENA(chan));
   	if (rx)
   		value |= DMA_INTR_DEFAULT_RX;
   	if (tx)
   		value |= DMA_INTR_DEFAULT_TX;
-	writel(value, ioaddr + DMA_INTR_ENA);
+	writel(value, ioaddr + DMA_CHAN_INTR_ENA(chan));
   }
   void dwmac_disable_dma_irq(struct stmmac_priv *priv, void __iomem *ioaddr,
   			   u32 chan, bool rx, bool tx)
   {
-	u32 value = readl(ioaddr + DMA_INTR_ENA);
+	u32 value = readl(ioaddr + DMA_CHAN_INTR_ENA(chan));
   	if (rx)
   		value &= ~DMA_INTR_DEFAULT_RX;
   	if (tx)
   		value &= ~DMA_INTR_DEFAULT_TX;
-	writel(value, ioaddr + DMA_INTR_ENA);
+	writel(value, ioaddr + DMA_CHAN_INTR_ENA(chan));
   }
   void dwmac_dma_start_tx(struct stmmac_priv *priv, void __iomem *ioaddr,
   			u32 chan)
   {
-	u32 value = readl(ioaddr + DMA_CONTROL);
+	u32 value = readl(ioaddr + DMA_CHAN_CONTROL(chan));
   	value |= DMA_CONTROL_ST;
-	writel(value, ioaddr + DMA_CONTROL);
+	writel(value, ioaddr + DMA_CHAN_CONTROL(chan));
   }
   void dwmac_dma_stop_tx(struct stmmac_priv *priv, void __iomem *ioaddr, u32 chan)
   {
-	u32 value = readl(ioaddr + DMA_CONTROL);
+	u32 value = readl(ioaddr + DMA_CHAN_CONTROL(chan));
   	value &= ~DMA_CONTROL_ST;
-	writel(value, ioaddr + DMA_CONTROL);
+	writel(value, ioaddr + DMA_CHAN_CONTROL(chan));
   }
   void dwmac_dma_start_rx(struct stmmac_priv *priv, void __iomem *ioaddr,
   			u32 chan)
   {
-	u32 value = readl(ioaddr + DMA_CONTROL);
+	u32 value = readl(ioaddr + DMA_CHAN_CONTROL(chan));
   	value |= DMA_CONTROL_SR;
-	writel(value, ioaddr + DMA_CONTROL);
+	writel(value, ioaddr + DMA_CHAN_CONTROL(chan));
   }
   void dwmac_dma_stop_rx(struct stmmac_priv *priv, void __iomem *ioaddr, u32 chan)
   {
-	u32 value = readl(ioaddr + DMA_CONTROL);
+	u32 value = readl(ioaddr + DMA_CHAN_CONTROL(chan));
   	value &= ~DMA_CONTROL_SR;
-	writel(value, ioaddr + DMA_CONTROL);
+	writel(value, ioaddr + DMA_CHAN_CONTROL(chan));
   }
   #ifdef DWMAC_DMA_DEBUG
@@ -166,7 +166,7 @@ int dwmac_dma_interrupt(struct stmmac_priv *priv, void __iomem *ioaddr,
   	struct stmmac_txq_stats *txq_stats = &priv->xstats.txq_stats[chan];
   	int ret = 0;
   	/* read the status register (CSR5) */
-	u32 intr_status = readl(ioaddr + DMA_STATUS);
+	u32 intr_status = readl(ioaddr + DMA_CHAN_STATUS(chan));
   #ifdef DWMAC_DMA_DEBUG
   	/* Enable it to monitor DMA rx/tx status in case of critical problems */

drivers/net/ethernet/stmicro/stmmac/dwmac_lib.c int dwmac_dma_interrupt(struct stmmac_priv *priv, void __iomem *ioaddr, · line 238

Quoted 4 lines
drivers/net/ethernet/stmicro/stmmac/dwmac_lib.c +1 -1
@@ -236,7 +236,7 @@ int dwmac_dma_interrupt(struct stmmac_priv *priv, void __iomem *ioaddr,
   		pr_warn("%s: unexpected status %08x\n", __func__, intr_status);
   	/* Clear the interrupt by writing a logic 1 to the CSR5[15-0] */
-	writel((intr_status & 0x1ffff), ioaddr + DMA_STATUS);
+	writel((intr_status & 0x7ffff), ioaddr + DMA_CHAN_STATUS(chan));

Isn't the mask change going to be implemented in the framework of the Loongson-specific DMA-interrupt handler in some of the further patches?

I'll get back to reviewing the series tomorrow (later today)...

-Serge(y)

Quoted 41 lines
drivers/net/ethernet/stmicro/stmmac/dwmac_lib.c +0 -0
   	return ret;
   }
drivers/net/ethernet/stmicro/stmmac/hwif.h +1 -1
index 7be04b54738b..b0db38396171 100644
@@ -198,7 +198,7 @@ struct stmmac_dma_ops {
   	/* To track extra statistic (if supported) */
   	void (*dma_diagnostic_fr)(struct stmmac_extra_stats *x,
   				  void __iomem *ioaddr);
-	void (*enable_dma_transmission) (void __iomem *ioaddr);
+	void (*enable_dma_transmission)(void __iomem *ioaddr, u32 chan);
   	void (*enable_dma_irq)(struct stmmac_priv *priv, void __iomem *ioaddr,
   			       u32 chan, bool rx, bool tx);
   	void (*disable_dma_irq)(struct stmmac_priv *priv, void __iomem *ioaddr,
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +3 -4
index b334eb16da23..5617b40abbe4 100644
@@ -2558,7 +2558,7 @@ static bool stmmac_xdp_xmit_zc(struct stmmac_priv *priv, u32 queue, u32 budget)
   				       true, priv->mode, true, true,
   				       xdp_desc.len);
-		stmmac_enable_dma_transmission(priv, priv->ioaddr);
+		stmmac_enable_dma_transmission(priv, priv->ioaddr, queue);
   		xsk_tx_metadata_to_compl(meta,
   					 &tx_q->tx_skbuff_dma[entry].xsk_meta);
@@ -4706,7 +4706,7 @@ static netdev_tx_t stmmac_xmit(struct sk_buff *skb, struct net_device *dev)
   	netdev_tx_sent_queue(netdev_get_tx_queue(dev, queue), skb->len);
-	stmmac_enable_dma_transmission(priv, priv->ioaddr);
+	stmmac_enable_dma_transmission(priv, priv->ioaddr, queue);
   	stmmac_flush_tx_descriptors(priv, queue);
   	stmmac_tx_timer_arm(priv, queue);
@@ -4926,7 +4926,7 @@ static int stmmac_xdp_xmit_xdpf(struct stmmac_priv *priv, int queue,
   		u64_stats_update_end_irqrestore(&txq_stats->syncp, flags);
   	}
-	stmmac_enable_dma_transmission(priv, priv->ioaddr);
+	stmmac_enable_dma_transmission(priv, priv->ioaddr, queue);
   	entry = STMMAC_GET_ENTRY(entry, priv->dma_conf.dma_tx_size);
   	tx_q->cur_tx = entry;
-- >>>> 2.31.4
 
#42 lore raw

Re: [PATCH net-next v8 06/11] net: stmmac: dwmac-loongson: Add GNET support

In reply to Yanteng Si
Quoted 15 lines · Yanteng Si
Quoted 12 lines · Yanteng Si
Quoted 11 lines · Serge Semin
Quoted 2 lines · Yanteng Si

Add Loongson GNET (GMAC with PHY) support, override stmmac_priv.synopsys_id with 0x37.

Please add more details of all the device capabilities: supported speeds, duplexness, IP-core version, DMA-descriptors type (normal/enhanced), MTL Tx/Rx FIFO size, Perfect and Hash-based MAC Filter tables size, L3/L4 filters availability, VLAN hash table filter, PHY-interface (GMII, RGMII, etc), EEE support, AV-feature/Multi-channels support, IEEE 1588 Timestamp support, Magic Frame support, Remote Wake-up support, IP Checksum, Tx/Rx TCP/IP Checksum, Mac Management Counters (MMC), SMA/MDIO interface,

Quoted 8 lines
Quoted 8 lines

The gnet (2k2000) of 0x10 supports full-duplex and half-duplex at 1000/100/10M. The gnet of 0x37 (i.e. the gnet of 7a2000) supports 1000/100/10M full duplex.

The gnet with 0x10 has 8 DMA channels, except for channel 0, which does not support sending hardware checksums.

Supported AV features are Qav, Qat, and Qas, and other features should be consistent with the 3.73 IP.

Just list all of these features in the commit message referring to the respective controller. Like this:
"There are two types of them Loongson GNET controllers:
Loongson 2k2000 GNET and the rest of the Loongson GNETs (like presented on the 7a2000 SoC). All of them of the DW GMAC 3.73a IP-core with the next features:
Speeds, DMA-descriptors type (normal/enhanced), MTL Tx/Rx FIFO size, Perfect and Hash-based MAC Filter tables size, L3/L4 filters availability, VLAN hash table filter, PHY-interface (GMII, RGMII, etc), EEE support, IEEE 1588 Timestamp support, Magic Frame support, Remote Wake-up support, IP Checksum, Tx/Rx TCP/IP Checksum, Mac Management Counters (MMC), SMA/MDIO interface.

The difference is that the Loongson 2k2000 GNET controller supports 8 DMA-channels, AV features (Qav, Qat, and Qas) and half-duplex link, meanwhile the rest of the GNETs don't have these capabilities available."

Quoted 24 lines
Quoted 23 lines
Quoted 22 lines
Quoted 14 lines
---
  .../ethernet/stmicro/stmmac/dwmac-loongson.c  | 44 +++++++++++++++++++
  1 file changed, 44 insertions(+)
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +0 -0
index 3b3578318cc1..584f7322bd3e 100644

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static struct mac_device_info *loongson_setup(void *apriv) · line 321

Quoted 4 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +1 -0
@@ -318,6 +318,8 @@ static struct mac_device_info *loongson_setup(void *apriv)
  	if (!mac)
  		return NULL;
  >> +	priv->synopsys_id = 0x37;	/*Overwrite custom IP*/
+

Please add a more descriptive comment _above_ the subjected line. In particular note why the override is needed, what is the real DW GMAC IP-core version and what is the original value the statement above overrides.

Quoted 8 lines
Quoted 8 lines

The IP-core version of the gnet device on the loongson 2k2000 is 0x10, which is a custom IP.

Compared to 0x37, we have split some of the dma registers into two (tx and rx). After overwriting stmmac_dma_ops.dma_interrupt() and stmmac_dma_ops.init_chan(), the logic is consistent with 0x37,

so we overwrite synopsys_id to 0x37.

Yeah, something like that:
/* The original IP-core version is 0x37 in all Loongson GNET
* (2k2000 and 7a2000), but the GNET HW designers have changed the
* GMAC_VERSION.SNPSVER field to the custom 0x10 value on the Loongson
* 2k2000 MAC to emphasize the differences: multiple DMA-channels, AV
* feature and GMAC_INT_STATUS CSR flags layout. Get back the
* original value so the correct HW-interface would be
* selected.
*/

Quoted 21 lines
Quoted 20 lines
Quoted 4 lines

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static struct mac_device_info *loongson_setup(void *apriv)

Quoted 4 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +0 -0
  	ld = priv->plat->bsp_priv;
  	mac->dma = &ld->dwlgmac_dma_ops;
  >> @@ -350,6 +352,46 @@ static struct mac_device_info

*loongson_setup(void *apriv)

Quoted 14 lines

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static struct mac_device_info *loongson_setup(void *apriv) · line 365

Quoted 13 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +10 -0
  	return mac;
  }
  >> +static int loongson_gnet_data(struct pci_dev *pdev,
+			      struct plat_stmmacenet_data *plat)
+{
+	loongson_default_data(pdev, plat);
+
+	plat->multicast_filter_bins = 256;
+
+	plat->mdio_bus_data->phy_mask =  ~(u32)BIT(2);
+
+	plat->phy_addr = 2;
+	plat->phy_interface = PHY_INTERFACE_MODE_INTERNAL;

Are you sure PHY-interface is supposed to be defined as "internal"?

Quoted 2 lines
Quoted 2 lines

Yes, because the gnet hardware has a integrated PHY, so we set it to internal,

Why do you need the phy_addr set to 2 then? Is PHY still discoverable on the subordinate MDIO-bus?

kdoc in "include/linux/phy.h" defines the PHY_INTERFACE_MODE_INTERNAL mode as for a case of the MAC and PHY being combined. IIUC it's reserved for a case when you can't determine actual interface between the MAC and PHY. Is it your case? Are you sure the interface between MAC and PHY isn't something like GMII/RGMII/etc?

-Serge(y)

Quoted 73 lines
Quoted 72 lines

Correspondingly, our gmac hardware PHY is external.

Quoted 15 lines
Quoted 15 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +15 -0
+
+	plat->bsp_priv = &pdev->dev;
+
+	plat->dma_cfg->pbl = 32;
+	plat->dma_cfg->pblx8 = true;
+
+	plat->clk_ref_rate = 125000000;
+	plat->clk_ptp_rate = 125000000;
+
+	return 0;
+}
+
+static int loongson_gnet_config(struct pci_dev *pdev,
+				struct plat_stmmacenet_data *plat,
+				struct stmmac_resources *res,
Quoted 8 lines

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static struct mac_device_info *loongson_setup(void *apriv) · line 385

Quoted 5 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +5 -0
+				struct device_node *np)
+{
+	int ret;
+
+	ret = loongson_dwmac_config_legacy(pdev, plat, res, np);

Again. This will be moved to the probe() method in one of the next patches leaving loongson_gnet_config() empty. What was the problem with doing that right away with no intermediate change?

No problem. My original intention is to break the patches down into smaller pieces.

In the next version, I will try to re-break them based on your comments.

Quoted 10 lines
Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +9 -0
+
+	return ret;
+}
+
+static struct stmmac_pci_info loongson_gnet_pci_info = {
+	.setup = loongson_gnet_data,
+	.config = loongson_gnet_config,
+};
+
Quoted 8 lines

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static SIMPLE_DEV_PM_OPS(loongson_dwmac_pm_ops, loongson_dwmac_suspend, · line 561

Quoted 8 lines

static int loongson_dwmac_probe(struct pci_dev *pdev,
const struct pci_device_id *id)
{

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +1 -0
@@ -516,9 +558,11 @@ static SIMPLE_DEV_PM_OPS(loongson_dwmac_pm_ops, loongson_dwmac_suspend,
  			 loongson_dwmac_resume);
  >>   #define PCI_DEVICE_ID_LOONGSON_GMAC	0x7a03
+#define PCI_DEVICE_ID_LOONGSON_GNET	0x7a13
  >>   static const struct pci_device_id loongson_dwmac_id_table[] =

{

Quoted 6 lines

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static SIMPLE_DEV_PM_OPS(loongson_dwmac_pm_ops, loongson_dwmac_suspend, · line 565

Quoted 2 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +1 -0
  	{ PCI_DEVICE_DATA(LOONGSON, GMAC, &loongson_gmac_pci_info) },
+	{ PCI_DEVICE_DATA(LOONGSON, GNET, &loongson_gnet_pci_info) },

After this the driver is supposed to correctly handle the Loongson GNET devices. Based on the patches introduced further it isn't. Please consider re-arranging the changes (see my comments in the further patches).

OK.

Thanks,

Yanteng

Quoted 8 lines

-Serge(y)

Quoted 5 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +0 -1
  	{}
  };
  MODULE_DEVICE_TABLE(pci, loongson_dwmac_id_table);
-- >> 2.31.4
 
#53 lore raw

Re: [PATCH net-next v8 07/11] net: stmmac: dwmac-loongson: Add multi-channel supports for loongson

In reply to Yanteng Si
Quoted 88 lines · Yanteng Si
Quoted 85 lines · Yanteng Si
Quoted 6 lines · Serge Semin
Quoted 2 lines · Yanteng Si

Request allocation for MSI for specific versions.

Please elaborate what is actually done in the patch. What device version it is dedicated for (Loongson GNET?), what IRQs the patch adds, etc.

gnet_device   core IP    IRQ
7a2000        0x37    legacy
2k2000        0x10    multi_msi
Quoted 4 lines

BTW will GNET device work without this patch? If no you need to either merge it into the patch introducing the GNET-device support or place it before that patch (6/11).

OK, GNET device work need this patch.

Quoted 4 lines
Quoted 3 lines
Quoted 1 line

Some features of Loongson platforms are bound to the GMAC_VERSION

register. We have to read its value in order to get the correct channel number.

This message seems misleading. I don't see you doing that in the patch below...

Because part of our gnet hardware (7a2000) core IP is 0x37

Quoted 16 lines
Quoted 16 lines
---
  .../ethernet/stmicro/stmmac/dwmac-loongson.c  | 57 +++++++++++++++----
  1 file changed, 46 insertions(+), 11 deletions(-)
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +0 -0
index 584f7322bd3e..60d0a122d7c9 100644
@@ -98,10 +98,10 @@ static void dwlgmac_dma_init_channel(struct stmmac_priv *priv,
  	if (dma_cfg->aal)
  		value |= DMA_BUS_MODE_AAL;
 
Quoted 9 lines

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static void dwlgmac_dma_init_channel(struct stmmac_priv *priv, · line 104

Quoted 5 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +2 -1
 > -	writel(value, ioaddr + DMA_BUS_MODE);
+	writel(value, ioaddr + DMA_CHAN_BUS_MODE(chan));
  >>   	/* Mask interrupts by writing to CSR7 */
-	writel(DMA_INTR_DEFAULT_MASK_LOONGSON, ioaddr + DMA_INTR_ENA);
+	writel(DMA_INTR_DEFAULT_MASK_LOONGSON, ioaddr + DMA_CHAN_INTR_ENA(chan));

Em, why is this here? There is a patch
[PATCH net-next v8 05/11] net: stmmac: dwmac-loongson: Add Loongson-specific register definitions in this series which was supposed to introduce the fully functional
GNET-specific callbacks. Move this change in there.

OK.

Quoted 3 lines

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static void dwlgmac_dma_init_channel(struct stmmac_priv *priv, · line 106

Quoted 3 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +0 -0
  }
  >>   static int dwlgmac_dma_interrupt(struct stmmac_priv *priv,

void __iomem *ioaddr,

Quoted 4 lines

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int loongson_dwmac_config_legacy(struct pci_dev *pdev, · line 240

Quoted 4 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +0 -0
@@ -238,6 +238,45 @@ static int loongson_dwmac_config_legacy(struct pci_dev *pdev,
  	return 0;
  }
  >> +static int loongson_dwmac_config_multi_msi(struct pci_dev

*pdev,

Quoted 2 lines

This method seems like the GNET-specific one. What about using the appropriate prefix then?

OK. loongson_gnet_config_multi_msi()

Quoted 8 lines

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int loongson_dwmac_config_legacy(struct pci_dev *pdev, · line 245

Quoted 5 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +4 -0
+					   struct plat_stmmacenet_data *plat,
+					   struct stmmac_resources *res,
+					   struct device_node *np,
+					   int channel_num)

Why do you need this parametrization? Since this method is GNET-specific what about defining a macro with the channels amount and using it here?

OK.

#define CHANNEL_NUM 8

Quoted 13 lines

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int loongson_dwmac_config_legacy(struct pci_dev *pdev, · line 254

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +9 -0
+{
+	int i, ret, vecs;
+
+	vecs = roundup_pow_of_two(channel_num * 2 + 1);
+	ret = pci_alloc_irq_vectors(pdev, vecs, vecs, PCI_IRQ_MSI);
+	if (ret < 0) {
+		dev_info(&pdev->dev,
+			 "MSI enable failed, Fallback to legacy interrupt\n");
+		return loongson_dwmac_config_legacy(pdev, plat, res, np);

In what conditions is this possible? Will the loongson_dwmac_config_legacy() method work in that case? Did you test it out?

Quoted 2 lines
Quoted 2 lines

Failed to apply for msi interrupt when the interrupt number is not enough,For example, there are a large number of devices。

Then those platforms will _require_ to have the DT-node specified. This will define the DT-bindings which I doubt you imply here. Am I wrong?

Once again have you tested the loongson_dwmac_config_legacy() method working in the case of the pci_alloc_irq_vectors() failure?

Quoted 9 lines
Quoted 9 lines
Quoted 6 lines

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int loongson_dwmac_config_legacy(struct pci_dev *pdev, · line 258

Quoted 4 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +4 -0
+	}
+
+	plat->rx_queues_to_use = channel_num;
+	plat->tx_queues_to_use = channel_num;

This is supposed to be initialized in the setup() methods. Please move it to the dedicated patch.

No, referring to my previous reply, only the 0x10 gnet device has 8 channels, and the 0x37 device has a single channel.

Yes. You have a perfectly suitable method for it. It's loongson_gnet_data(). Init the number of channels there based on the value read from the GMAC_VERSION.SNPSVER field. Thus the loongson_gnet_config_multi_msi() will get to be more coherent setting up the MSI IRQs only.

Am I missing something in the last two notes chunks regard? If yes, let's submit v9 as you see it. We'll get back to this part there then.

-Serge(y)

Quoted 87 lines
Quoted 86 lines
Quoted 6 lines

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int loongson_dwmac_config_legacy(struct pci_dev *pdev, · line 261

Quoted 4 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +3 -0
+
+	res->irq = pci_irq_vector(pdev, 0);
+	res->wol_irq = res->irq;

Once again. wol_irq is optional. If there is no dedicated WoL IRQ leave the field as zero.

OK.

res->wol_irq = 0;

Quoted 10 lines
Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +9 -0
+
+	/* INT NAME | MAC | CH7 rx | CH7 tx | ... | CH0 rx | CH0 tx |
+	 * --------- ----- -------- --------  ...  -------- --------
+	 * IRQ NUM  |  0  |   1    |   2    | ... |   15   |   16   |
+	 */
+	for (i = 0; i < channel_num; i++) {
+		res->rx_irq[channel_num - 1 - i] =
+			pci_irq_vector(pdev, 1 + i * 2);
+		res->tx_irq[channel_num - 1 - i] =
Quoted 8 lines

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int loongson_dwmac_config_legacy(struct pci_dev *pdev, · line 275

Quoted 5 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +5 -0
+			pci_irq_vector(pdev, 2 + i * 2);
+	}
+
+	plat->flags |= STMMAC_FLAG_MULTI_MSI_EN;
+	dev_info(&pdev->dev, "%s: multi MSI enablement successful\n", __func__);

What's the point in printing this message especially with the __func__ prefix? You'll always be able to figure out the allocated IRQs by means of procfs. I suggest to drop it.

OK.

Quoted 27 lines
Quoted 27 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +5 -7
+
+	return 0;
+}
+
  static void loongson_default_data(struct pci_dev *pdev,
  				  struct plat_stmmacenet_data *plat)
  {
@@ -296,11 +335,8 @@ static int loongson_gmac_config(struct pci_dev *pdev,
  				struct stmmac_resources *res,
  				struct device_node *np)
  {
-	int ret;
-
-	ret = loongson_dwmac_config_legacy(pdev, plat, res, np);
  >> -	return ret;
+	return 0;
  }
  >>   static struct stmmac_pci_info loongson_gmac_pci_info = {
@@ -380,11 +416,7 @@ static int loongson_gnet_config(struct pci_dev *pdev,
  				struct stmmac_resources *res,
  				struct device_node *np)
  {
-	int ret;
-
-	ret = loongson_dwmac_config_legacy(pdev, plat, res, np);
-
Quoted 8 lines

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int loongson_gmac_config(struct pci_dev *pdev, · line 340

Quoted 3 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +1 -1
-	return ret;
+	return 0;
  }

Here you are dropping the changes you just introduced leaving the config() methods empty... Why not to place the loongson_dwmac_config_legacy() invocation in the probe() method right at the patches introducing the config() functions and not to add the config() callback in the first place?

OK, I will try.

Thanks,

Yanteng

Quoted 14 lines

-Serge(y)

Quoted 11 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +3 -1
  >>   static struct stmmac_pci_info loongson_gnet_pci_info = {
@@ -483,6 +515,9 @@ static int loongson_dwmac_probe(struct pci_dev *pdev,
  		ld->dwlgmac_dma_ops.dma_interrupt = dwlgmac_dma_interrupt;
  >>   		plat->setup = loongson_setup;
+		ret = loongson_dwmac_config_multi_msi(pdev, plat, &res, np, 8);
+	} else {
+		ret = loongson_dwmac_config_legacy(pdev, plat, &res, np);
  	}
  >>   	plat->bsp_priv = ld;
-- >> 2.31.4
 
#64 lore raw

Re: [PATCH net-next v8 08/11] net: stmmac: dwmac-loongson: Fix MAC speed for GNET

In reply to Yanteng Si
Quoted 9 lines · Yanteng Si
Quoted 6 lines · Yanteng Si
Quoted 5 lines · Serge Semin
Quoted 2 lines · Yanteng Si

Current GNET on LS7A only supports ANE when speed is set to 1000M.

If so you need to merge it into the patch
[PATCH net-next v8 06/11] net: stmmac: dwmac-loongson: Add GNET support

Quoted 37 lines
Quoted 5 lines
Quoted 2 lines

Current GNET on LS7A only supports ANE when speed is set to 1000M.

If so you need to merge it into the patch
[PATCH net-next v8 06/11] net: stmmac: dwmac-loongson: Add GNET support

OK.

Quoted 29 lines
Quoted 10 lines
Quoted 10 lines
---
  .../ethernet/stmicro/stmmac/dwmac-loongson.c  | 19 +++++++++++++++++++
  .../ethernet/stmicro/stmmac/stmmac_ethtool.c  |  6 ++++++
  include/linux/stmmac.h                        |  1 +
  3 files changed, 26 insertions(+)
Quoted 8 lines

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static struct stmmac_pci_info loongson_gmac_pci_info = { · line 346

Quoted 8 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +0 -0
index 60d0a122d7c9..264c4c198d5a 100644
@@ -344,6 +344,21 @@ static struct stmmac_pci_info loongson_gmac_pci_info = {
  	.config = loongson_gmac_config,
  };
  >> +static void loongson_gnet_fix_speed(void *priv, unsigned int

speed, unsigned int mode)

Quoted 9 lines

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static struct stmmac_pci_info loongson_gmac_pci_info = { · line 353

Quoted 6 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +6 -0
+{
+	struct loongson_data *ld = (struct loongson_data *)priv;
+	struct net_device *ndev = dev_get_drvdata(ld->dev);
+	struct stmmac_priv *ptr = netdev_priv(ndev);
+
+	/* The controller and PHY don't work well together.

So there _is_ a PHY. What is the interface between MAC and PHY then?

GMAC only has a MAC chip inside the chip and needs an external PHY

chip; GNET > has the PHY chip inside the chip.

We are talking about GNETs in this method since it has the loongson_gnet_ prefix. You are referring to GMAC. I am getting confused about all of these. Based on the patch 06/11 of this series you call "Loongson GNET" of all the devices placed on the PCI devices with PCI ID 0x7a13. PCIe device with ID 0x7a03 is called "Loongson GMAC". Right?

Anyway no matter whether the PHY is placed externally or inside the chip. AFAIU as long as you know the interface type between MAC and PHY it would be better to have it specified.

Quoted 18 lines
Quoted 18 lines
Quoted 7 lines

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static struct stmmac_pci_info loongson_gmac_pci_info = { · line 359

Quoted 6 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +6 -0
+	 * We need to use the PS bit to check if the controller's status
+	 * is correct and reset PHY if necessary.
+	 */
+	if (speed == SPEED_1000)
+		if (readl(ptr->ioaddr + MAC_CTRL_REG) & (1 << 15) /* PS */)
+			phy_restart_aneg(ndev->phydev);

1. Please add curly braces for the outer if-statement.

OK,

Quoted 1 line

2. MAC_CTRL_REG.15 is defined by the GMAC_CONTROL_PS macro.

OK.

if(speed==SPEED_1000){
/*MAC_CTRL_REG.15 is defined by the GMAC_CONTROL_PS macro.*/ if(readl(ptr->ioaddr+MAC_CTRL_REG) &(1<<15)) phy_restart_aneg(ndev->phydev);
}

Quoted 8 lines
Quoted 8 lines
Quoted 4 lines

3. How is the AN-restart helps? PHY-reset is done in stmmac_init_phy()->phylink_connect_phy()->... a bit earlier than this is called in the framework of the stmmac_mac_link_up() callback. Wouldn't that restart AN too?

Due to a bug in the chip's internal PHY, the network is still not working after the first self-negotiation, and it needs to be self-negotiated again.

Then please describe the bug in more details then.

Getting back to the code you implemented here. In the in-situ comment you say: "We need to use the PS bit to check if the controller's status is correct and reset PHY if necessary." By calling phy_restart_aneg() you don't reset the PHY.

Moreover if "PS" flag is set, then the MAC has been pre-configured to work in the 10/100Mbps mode. Since 1000Mbps speed is requested, the MAC_CTRL_REG.PS flag will be cleared later in the stmmac_mac_link_up() method and then phylink_start() shall cause the link speed re-auto-negotiation. Why do you need the auto-negotiation started for the default MAC config which will be changed just in a moment later? All of that seems weird.

Most importantly I have doubts the networking subsystem maintainers will permit you calling the phy_restart_aneg() method from the MAC driver code.

Quoted 37 lines
Quoted 37 lines
Quoted 14 lines
Quoted 14 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +3 -0
+}
+
  static struct mac_device_info *loongson_setup(void *apriv)
  {
  	struct stmmac_priv *priv = apriv;
@@ -401,6 +416,7 @@ static int loongson_gnet_data(struct pci_dev *pdev,
  	plat->phy_interface = PHY_INTERFACE_MODE_INTERNAL;
  >>   	plat->bsp_priv = &pdev->dev;
+	plat->fix_mac_speed = loongson_gnet_fix_speed;
  >>   	plat->dma_cfg->pbl = 32;
  	plat->dma_cfg->pblx8 = true;
@@ -416,6 +432,9 @@ static int loongson_gnet_config(struct pci_dev *pdev,
Quoted 8 lines

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int loongson_gnet_config(struct pci_dev *pdev, · line 437

Quoted 6 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +3 -0
  				struct stmmac_resources *res,
  				struct device_node *np)
  {
+	if (pdev->revision == 0x00 || pdev->revision == 0x01)
+		plat->flags |= STMMAC_FLAG_DISABLE_FORCE_1000;
+

This should be in the patch
[PATCH net-next v8 06/11] net: stmmac: dwmac-loongson: Add GNET support

OK.

Quoted 4 lines

drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int loongson_gnet_config(struct pci_dev *pdev,

Quoted 4 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +0 -0
  	return 0;
  }
  >> diff --git

a/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c

Quoted 7 lines

drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c stmmac_ethtool_set_link_ksettings(struct net_device *dev, · line 424

Quoted 7 lines

index 42d27b97dd1d..31068fbc23c9 100644

drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c +0 -0
@@ -422,6 +422,12 @@ stmmac_ethtool_set_link_ksettings(struct net_device *dev,
  		return 0;
  	}
  >> +	if (FIELD_GET(STMMAC_FLAG_DISABLE_FORCE_1000,

priv->plat->flags)) {

Quoted 6 lines
Quoted 6 lines
Quoted 1 line

FIELD_GET()?

OK,

if (STMMAC_FLAG_DISABLE_FORCE_1000 & priv->plat->flags) {

it's better to change the order of the operands:

	if (priv->plat->flags & STMMAC_FLAG_DISABLE_FORCE_1000) {

-Serge(y)

Quoted 40 lines
Quoted 39 lines
Quoted 16 lines
Quoted 16 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c +5 -0
+		if (cmd->base.speed == SPEED_1000 &&
+		    cmd->base.autoneg != AUTONEG_ENABLE)
+			return -EOPNOTSUPP;
+	}
+
  	return phylink_ethtool_ksettings_set(priv->phylink, cmd);
  }
  >> diff --git a/include/linux/stmmac.h b/include/linux/stmmac.h

index dee5ad6e48c5..2810361e4048 100644

include/linux/stmmac.h +0 -0
@@ -221,6 +221,7 @@ struct dwmac4_addrs {
  #define STMMAC_FLAG_RX_CLK_RUNS_IN_LPI		BIT(10)
  #define STMMAC_FLAG_EN_TX_LPI_CLOCKGATING	BIT(11)
Quoted 8 lines

include/linux/stmmac.h struct dwmac4_addrs { · line 224

Quoted 2 lines
include/linux/stmmac.h +1 -0
  #define STMMAC_FLAG_HWTSTAMP_CORRECT_LATENCY	BIT(12)
+#define STMMAC_FLAG_DISABLE_FORCE_1000	BIT(13)

Detach the change introducing the STMMAC_FLAG_DISABLE_FORCE_1000 flag into a separate patch a place it before
[PATCH net-next v8 06/11] net: stmmac: dwmac-loongson: Add GNET support as a pre-requisite/preparation patch.
Don't forget a _detailed_ description of why it's necessary, what is wrong with GNET so 1G speed doesn't work without AN.

OK.

Thanks,

Yanteng

Quoted 7 lines

-Serge(y)

Quoted 4 lines
include/linux/stmmac.h +0 -1
  >>   struct plat_stmmacenet_data {
  	int bus_id;
-- >> 2.31.4