stmmac: Add Loongson platform support
Subsystems (5)
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
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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
Simon Horman
reviewerRe: [PATCH net-next v8 01/11] net: stmmac: Add multi-channel support
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.
Signed-off-by Yanteng Si <[email protected]>Signed-off-by Feiyang Chen <[email protected]>Signed-off-by Yinggang Gu <[email protected]>
...
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@@ -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.
...
Re: [PATCH net-next v8 01/11] net: stmmac: Add multi-channel support
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.
Signed-off-by Yanteng Si <[email protected]>Signed-off-by Feiyang Chen <[email protected]>Signed-off-by Yinggang Gu <[email protected]>...
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@@ -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
...
Re: [PATCH net-next v8 01/11] net: stmmac: Add multi-channel support
In reply to Yanteng SiQuoted 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.
Signed-off-by Yanteng Si <[email protected]>Signed-off-by Feiyang Chen <[email protected]>Signed-off-by Yinggang Gu <[email protected]>--- .../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@@ -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@@ -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
-10if (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
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@@ -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
-0return ret; }drivers/net/ethernet/stmicro/stmmac/hwif.h +1
-1@@ -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@@ -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
Re: [PATCH net-next v8 01/11] net: stmmac: Add multi-channel support
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.
Signed-off-by Yanteng Si <[email protected]>Signed-off-by Feiyang Chen <[email protected]>Signed-off-by Yinggang Gu <[email protected]>--- .../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@@ -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@@ -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()andstmmac_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
-10if (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
-0drivers/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@@ -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
-0return ret; }drivers/net/ethernet/stmicro/stmmac/hwif.h +1
-1@@ -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@@ -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
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.
Signed-off-by Yanteng Si <[email protected]>Signed-off-by Feiyang Chen <[email protected]>Signed-off-by Yinggang Gu <[email protected]>--- .../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@@ -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@@ -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()andstmmac_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
-10if (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
-0drivers/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@@ -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
-0return ret; }drivers/net/ethernet/stmicro/stmmac/hwif.h +1
-1@@ -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@@ -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
Re: [PATCH net-next v8 01/11] net: stmmac: Add multi-channel support
In reply to Serge SeminHi 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.
Signed-off-by Yanteng Si <[email protected]>Signed-off-by Feiyang Chen <[email protected]>Signed-off-by Yinggang Gu <[email protected]>--- .../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@@ -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@@ -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()andstmmac_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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
-10if (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
-0drivers/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@@ -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
-0return ret; }drivers/net/ethernet/stmicro/stmmac/hwif.h +1
-1@@ -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@@ -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
Re: [PATCH net-next v8 01/11] net: stmmac: Add multi-channel support
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.
Signed-off-by Yanteng Si <[email protected]>Signed-off-by Feiyang Chen <[email protected]>Signed-off-by Yinggang Gu <[email protected]>--- .../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@@ -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@@ -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()andstmmac_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@@ -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@@ -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@@ -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@@ -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@@ -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
-10if (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
-0drivers/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@@ -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
-0return ret; }drivers/net/ethernet/stmicro/stmmac/hwif.h +1
-1@@ -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@@ -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
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [PATCH net-next v8 01/11] net: stmmac: Add multi-channel support
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.
Signed-off-by Yanteng Si<[email protected]>Signed-off-by Feiyang Chen<[email protected]>Signed-off-by Yinggang Gu<[email protected]>--- .../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@@ -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@@ -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()andstmmac_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@@ -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@@ -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@@ -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@@ -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@@ -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_cfgstructure. 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. Addstmmac_dma_cfg::atdsboolean field.
2. Drop atds argument from thestmmac_dma_ops::init()callback and use thestmmac_dma_cfg::atdsfield in the callback implementations.
3. Alterstmmac_init_dma_engine()to updating thedma_cfg->atdsfield 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::atdsfield in thestmmac_init_chan()method too.OK.
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +2
-3@@ -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@@ -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@@ -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@@ -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@@ -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@@ -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@@ -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@@ -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@@ -100,6 +100,7 @@ struct stmmac_dma_cfg {bool eame;bool multi_msi_en;bool dche; +bool atds; };#define AXI_BLEN 7Thanks,
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
-10if (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
-0drivers/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@@ -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
-0return ret; }drivers/net/ethernet/stmicro/stmmac/hwif.h +1
-1@@ -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@@ -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
Re: [PATCH net-next v8 01/11] net: stmmac: Add multi-channel support
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.
Signed-off-by Yanteng Si<[email protected]>Signed-off-by Feiyang Chen<[email protected]>Signed-off-by Yinggang Gu<[email protected]>--- .../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@@ -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@@ -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()andstmmac_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@@ -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@@ -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@@ -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@@ -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@@ -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_cfgstructure. 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. Addstmmac_dma_cfg::atdsboolean field.
2. Drop atds argument from thestmmac_dma_ops::init()callback and use thestmmac_dma_cfg::atdsfield in the callback implementations.
3. Alterstmmac_init_dma_engine()to updating thedma_cfg->atdsfield 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::atdsfield in thestmmac_init_chan()method too.OK.
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +2
-3@@ -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@@ -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@@ -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@@ -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@@ -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@@ -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@@ -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@@ -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@@ -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.
267 lines not shown · raw message
Part of this message is not shown here. View the raw message.
Re: [PATCH net-next v8 01/11] net: stmmac: Add multi-channel support
Quoted 6 lines · Serge Semin
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.
Sorry, maybe I made a mistake in the email client.
Thanks,
Yanteng
Quoted 720 lines
Quoted 452 lines · Yanteng Si
Quoted 450 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.
Signed-off-by Yanteng Si<[email protected]>Signed-off-by Feiyang Chen<[email protected]>Signed-off-by Yinggang Gu<[email protected]>--- .../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@@ -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@@ -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()andstmmac_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@@ -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@@ -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@@ -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@@ -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@@ -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_cfgstructure. 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. Addstmmac_dma_cfg::atdsboolean field.
2. Drop atds argument from thestmmac_dma_ops::init()callback and use thestmmac_dma_cfg::atdsfield in the callback implementations.
3. Alterstmmac_init_dma_engine()to updating thedma_cfg->atdsfield 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::atdsfield in thestmmac_init_chan()method too.OK.
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +2
-3@@ -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@@ -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@@ -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@@ -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@@ -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@@ -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@@ -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@@ -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@@ -100,6 +100,7 @@ struct stmmac_dma_cfg {bool eame;bool multi_msi_en;bool dche; +bool atds; };Quoted 2 lines
2 lines not shown · raw message
264 lines not shown · raw message
Part of this message is not shown here. View the raw message.
Re: [PATCH net-next v8 01/11] net: stmmac: Add multi-channel support
In reply to Serge SeminQuoted 4 lines · Serge Semin
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.
Please also trim appropriately your replies (that goes for both of you.) I tried to work out whether you'd provided any content apart from the above, but I really couldn't be bothered to page through the message.
https://subspace.kernel.org/etiquette.html#trim-your-quotes-when-replying
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!
Re: [PATCH net-next v8 01/11] net: stmmac: Add multi-channel support
Quoted 3 lines · Russell King (Oracle)
Please also trim appropriately your replies (that goes for both of you.) I tried to work out whether you'd provided any content apart from the above, but I really couldn't be bothered to page through the message.
Sorry, I will. I'm sorry to have caused you trouble. I just saw this comment.
Thanks,
Yanteng
Re: [PATCH net-next v8 01/11] net: stmmac: Add multi-channel support
In reply to Yanteng SiQuoted 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.
Signed-off-by Yanteng Si <[email protected]>Signed-off-by Feiyang Chen <[email protected]>Signed-off-by Yinggang Gu <[email protected]>--- .../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@@ -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@@ -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
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@@ -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@@ -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@@ -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
PATCH v8 2/11 net: stmmac: dwmac-loongson: Refactor code for loongson_dwmac_probe()
In reply to Yanteng SiThe 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
@@ -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_idif (!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_idbreak ; } - 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
Simon Horman
reviewerRe: [PATCH net-next v8 02/11] net: stmmac: dwmac-loongson: Refactor code for loongson_dwmac_probe()
Quoted 6 lines · Yanteng Si
The driver function is not changed, but the code location is adjusted to prepare for adding more loongson drivers.
Signed-off-by Yanteng Si <[email protected]>Signed-off-by Feiyang Chen <[email protected]>Signed-off-by Yinggang Gu <[email protected]>
...
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
...
Re: [PATCH net-next v8 02/11] net: stmmac: dwmac-loongson: Refactor code for loongson_dwmac_probe()
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.
Signed-off-by Yanteng Si <[email protected]>Signed-off-by Feiyang Chen <[email protected]>Signed-off-by Yinggang Gu <[email protected]>...
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
...
Re: [PATCH net-next v8 02/11] net: stmmac: dwmac-loongson: Refactor code for loongson_dwmac_probe()
In reply to Yanteng SiQuoted 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
Signed-off-by Yanteng Si <[email protected]>Signed-off-by Feiyang Chen <[email protected]>Signed-off-by Yinggang Gu <[email protected]>--- .../ethernet/stmicro/stmmac/dwmac-loongson.c | 61 +++++++++++++------ 1 file changed, 42 insertions(+), 19 deletions(-)drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +6
-1@@ -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
-0plat->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
-2plat->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
-0np =dev_of_node (&pdev->dev);@@ -69,18 +88,17 @@ static int loongson_dwmac_probe(struct pci_dev *pdev, const struct pci_device_idif (!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
-6plat->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
-0if (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_idbreak ; } - 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
-0if (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
Re: [PATCH net-next v8 02/11] net: stmmac: dwmac-loongson: Refactor code for loongson_dwmac_probe()
Hi Serge,
Sorry, I seem to have forgotten to reply to the comments on this patch.
Quoted 14 lines · Serge Semin
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.
OK. I will resplit it.
Quoted 27 lines
Quoted 27 lines
Signed-off-by Yanteng Si <[email protected]>Signed-off-by Feiyang Chen <[email protected]>Signed-off-by Yinggang Gu <[email protected]>--- .../ethernet/stmicro/stmmac/dwmac-loongson.c | 61 +++++++++++++------ 1 file changed, 42 insertions(+), 19 deletions(-)drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +6
-1@@ -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)
Quoted 11 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int loongson_default_data(struct plat_stmmacenet_data *plat) · line 49
Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +8
-0/* 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 ;Why do you need to move this here from the function tail?
OK, restore it.
Quoted 4 lines
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?
OK, drop it.
Quoted 4 lines
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?
Sorry, restore it.
Quoted 10 lines
Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +0
-1plat->phy_addr =-1 ; plat->dma_cfg->pbl =32 ; plat->dma_cfg->pblx8 = true; - plat->multicast_filter_bins =256 ;return 0 ; }
Quoted 15 lines
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;Reverse xmas tree order please.
OK.
Quoted 8 lines
Quoted 8 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +0
-0np =dev_of_node (&pdev->dev);@@ -69,18 +88,17 @@ static int loongson_dwmac_probe(struct pci_dev *pdev, const struct pci_device_idif (!plat->mdio_bus_data)return -ENOMEM ;
Quoted 7 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int loongson_dwmac_probe(struct pci_dev *pdev, const struct pci_device_id · line 95
Quoted 5 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +5
-0+ 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_nodegetting procedure? They seem independent.
Sorry, restore it.
Quoted 20 lines
Quoted 20 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +0
-6plat->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_idbreak ; }
Quoted 6 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int loongson_dwmac_probe(struct pci_dev *pdev, const struct pci_device_id · line 103
Quoted 3 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +0
-3- 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_idis no longer initialized by thepci_dev_id()method as a fallback case. If you are sure this is required please unpin to a separate patch and explain.
Hmm, I will merge it into [PATCH net-next 03/11] .
Quoted 12 lines
Quoted 12 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;
Quoted 8 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int loongson_dwmac_probe(struct pci_dev *pdev, const struct pci_device_id · line 113
Quoted 7 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +0
-1phy_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 ;This is just dropped. Are you sure that the driver will work correctly
Yes, We only need to set phy_interface.
Quoted 5 lines
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.
OK.
Quoted 12 lines
Quoted 12 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 ];@@ -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);
Quoted 11 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int __maybe_unused loongson_dwmac_resume(struct device *dev) · line 239
Quoted 5 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +3
-1+#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. UsePCI_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
OK, I will.
Thanks,
Yanteng
PATCH v8 3/11 net: stmmac: dwmac-loongson: Add full PCI support
In reply to Yanteng SiCurrent 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
@@ -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
Re: [PATCH net-next v8 03/11] net: stmmac: dwmac-loongson: Add full PCI support
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
Signed-off-by Yanteng Si <[email protected]>Signed-off-by Feiyang Chen <[email protected]>Signed-off-by Yinggang Gu <[email protected]>--- .../ethernet/stmicro/stmmac/dwmac-loongson.c | 79 +++++++++++-------- 1 file changed, 44 insertions(+), 35 deletions(-)drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +4
-0@@ -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
-0plat->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
-7return 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
Re: [PATCH net-next v8 03/11] net: stmmac: dwmac-loongson: Add full PCI support
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
Signed-off-by Yanteng Si <[email protected]>Signed-off-by Feiyang Chen <[email protected]>Signed-off-by Yinggang Gu <[email protected]>--- .../ethernet/stmicro/stmmac/dwmac-loongson.c | 79 +++++++++++-------- 1 file changed, 44 insertions(+), 35 deletions(-)drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +5
-0@@ -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
-0plat->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
-7return 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_nodesetup 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_irqit won't be used (seestmmac_request_irq_multi_msi()andstmmac_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
PATCH v8 4/11 net: stmmac: dwmac-loongson: Move irq config to loongson_gmac_config
In reply to Yanteng SiAdd 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
@@ -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
Re: [PATCH net-next v8 04/11] net: stmmac: dwmac-loongson: Move irq config to loongson_gmac_config
Quoted 6 lines · Yanteng Si
Add
loongson_dwmac_configand moving irq config related code toloongson_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
Signed-off-by Yanteng Si <[email protected]>Signed-off-by Feiyang Chen <[email protected]>Signed-off-by Yinggang Gu <[email protected]>--- .../ethernet/stmicro/stmmac/dwmac-loongson.c | 85 ++++++++++++------- 1 file changed, 55 insertions(+), 30 deletions(-)drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +25
-0@@ -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
-0static 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
-28memset (&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
Re: [PATCH net-next v8 04/11] net: stmmac: dwmac-loongson: Move irq config to loongson_gmac_config
Quoted 8 lines · Serge Semin
Quoted 5 lines · Yanteng Si
Add
loongson_dwmac_configand moving irq config related code toloongson_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
Signed-off-by Yanteng Si <[email protected]>Signed-off-by Feiyang Chen <[email protected]>Signed-off-by Yinggang Gu <[email protected]>--- .../ethernet/stmicro/stmmac/dwmac-loongson.c | 85 ++++++++++++------- 1 file changed, 55 insertions(+), 30 deletions(-)drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +29
-0@@ -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 theloongson_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
-0static 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
-1static 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
-29memset (&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
Re: [PATCH net-next v8 04/11] net: stmmac: dwmac-loongson: Move irq config to loongson_gmac_config
Quoted 67 lines · Yanteng Si
Quoted 8 lines · Serge Semin
Quoted 5 lines · Yanteng Si
Add
loongson_dwmac_configand moving irq config related code toloongson_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
Signed-off-by Yanteng Si <[email protected]>Signed-off-by Feiyang Chen <[email protected]>Signed-off-by Yinggang Gu <[email protected]>--- .../ethernet/stmicro/stmmac/dwmac-loongson.c | 85 ++++++++++++------- 1 file changed, 55 insertions(+), 30 deletions(-)drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +24
-0@@ -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 theloongson_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
-1static 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
-29memset (&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
Re: [PATCH net-next v8 04/11] net: stmmac: dwmac-loongson: Move irq config to loongson_gmac_config
Quoted 79 lines · Serge Semin
Quoted 63 lines · Yanteng Si
Quoted 8 lines · Serge Semin
Quoted 5 lines · Yanteng Si
Add
loongson_dwmac_configand moving irq config related code toloongson_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 52 lines
Quoted 39 lines
Signed-off-by Yanteng Si <[email protected]>Signed-off-by Feiyang Chen <[email protected]>Signed-off-by Yinggang Gu <[email protected]>--- .../ethernet/stmicro/stmmac/dwmac-loongson.c | 85 ++++++++++++------- 1 file changed, 55 insertions(+), 30 deletions(-)drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +24
-0@@ -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
(quoted diff) +0
-1- plat->multi_msi_en = 0;to
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +1
-0+ 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.
Quoted 3 lines
So in your case there is no any reason of clearing the
STMMAC_FLAG_MULTI_MSI_ENflag. Please, either drop it or move the change into a separate patch.
OK, you are right. drop it.
Thanks,
Yanteng
Quoted 104 lines
-Serge(y)
Quoted 101 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 19 lines
Quoted 19 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 theloongson_dwmac_config_legacy()method and call it directly?OK, I will try.
Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int loongson_dwmac_probe(struct pci_dev *pdev, · line 141
Quoted 9 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +1
-1static 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 51 lines
-Serge(y)
Quoted 49 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +4
-29memset (&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
PATCH v8 5/11 net: stmmac: dwmac-loongson: Add Loongson-specific register definitions
In reply to Yanteng SiThere 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
@@ -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
Re: [PATCH net-next v8 05/11] net: stmmac: dwmac-loongson: Add Loongson-specific register definitions
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-specificstmmac_dma_ops.dma_interrupt()stmmac_dma_ops.init_chan()
methods in thedwmac-loongson.cdriver. Adding all the Loongson-specific macros2. Create a Loongson GNET-specific platform setup method with the next semantics:
+ allocatestmmac_dma_opsinstance and initialize it withdwmac1000_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.Signed-off-by Yanteng Si <[email protected]>Signed-off-by Feiyang Chen <[email protected]>Signed-off-by Yinggang Gu <[email protected]>--- .../ethernet/stmicro/stmmac/dwmac-loongson.c | 248 ++++++++++++++++++ 1 file changed, 248 insertions(+)drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +21
-0@@ -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
-0plat =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
-0if (ret) goto err_disable_device;Signature · 1 line
2.31.4
Re: [PATCH net-next v8 05/11] net: stmmac: dwmac-loongson: Add Loongson-specific register definitions
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-specificstmmac_dma_ops.dma_interrupt()stmmac_dma_ops.init_chan()
methods in thedwmac-loongson.cdriver. Adding all the Loongson-specific macros2. Create a Loongson GNET-specific platform setup method with the next semantics:
+ allocatestmmac_dma_opsinstance and initialize it withdwmac1000_dma_ops.
+ override the stmmac_dma_ops.{dma_interrupt,init_chan} with the pointers to the methods defined in 2.
+ allocatemac_device_infoinstance and initialize the mac_device_info.dma field with a pointer to the newstmmac_dma_opsinstance.
+ initializemac_device_infoin a way it's done indwmac1000_setup().3. Initialize
plat_stmmacenet_data.setup()with the pointer to the method created in 2.Signed-off-by Yanteng Si <[email protected]>Signed-off-by Feiyang Chen <[email protected]>Signed-off-by Yinggang Gu <[email protected]>--- .../ethernet/stmicro/stmmac/dwmac-loongson.c | 248 ++++++++++++++++++ 1 file changed, 248 insertions(+)drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +24
-0@@ -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_DEBUGis 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_opsinstance 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
-0plat =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_versionis unused in out of theprobe()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
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-specificstmmac_dma_ops.dma_interrupt()stmmac_dma_ops.init_chan()
methods in thedwmac-loongson.cdriver. Adding all the Loongson-specific macros2. Create a Loongson GNET-specific platform setup method with the next semantics:
+ allocatestmmac_dma_opsinstance and initialize it withdwmac1000_dma_ops.
+ override the stmmac_dma_ops.{dma_interrupt,init_chan} with the pointers to the methods defined in 2.
+ allocatemac_device_infoinstance and initialize the mac_device_info.dma field with a pointer to the newstmmac_dma_opsinstance.
+ initializemac_device_infoin a way it's done indwmac1000_setup().3. Initialize
plat_stmmacenet_data.setup()with the pointer to the method created in 2.Signed-off-by Yanteng Si <[email protected]>Signed-off-by Feiyang Chen <[email protected]>Signed-off-by Yinggang Gu <[email protected]>--- .../ethernet/stmicro/stmmac/dwmac-loongson.c | 248 ++++++++++++++++++ 1 file changed, 248 insertions(+)drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +24
-0@@ -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_DEBUGis 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_opsinstance 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
-0plat =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
-0if (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_versionis unused in out of theprobe()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
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-specificstmmac_dma_ops.dma_interrupt()stmmac_dma_ops.init_chan()
methods in thedwmac-loongson.cdriver. Adding all the Loongson-specific macros2. Create a Loongson GNET-specific platform setup method with the next semantics:
+ allocatestmmac_dma_opsinstance and initialize it withdwmac1000_dma_ops.
+ override the stmmac_dma_ops.{dma_interrupt,init_chan} with the pointers to the methods defined in 2.
+ allocatemac_device_infoinstance and initialize the mac_device_info.dma field with a pointer to the newstmmac_dma_opsinstance.
+ initializemac_device_infoin a way it's done indwmac1000_setup().3. Initialize
plat_stmmacenet_data.setup()with the pointer to the method created in 2.Signed-off-by Yanteng Si <[email protected]>Signed-off-by Feiyang Chen <[email protected]>Signed-off-by Yinggang Gu <[email protected]>--- .../ethernet/stmicro/stmmac/dwmac-loongson.c | 248 ++++++++++++++++++ 1 file changed, 248 insertions(+)drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +24
-0@@ -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_DEBUGis 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_opsinstance 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
-0plat =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
-0if (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_versionis unused in out of theprobe()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()expectspriv->plat->setup(priv)returning NULL if something wrong. As I suggested above just return NULL then ifmac_device_infocouldn'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
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-specificstmmac_dma_ops.dma_interrupt()stmmac_dma_ops.init_chan()
methods in thedwmac-loongson.cdriver. Adding all the Loongson-specific macros2. Create a Loongson GNET-specific platform setup method with the next semantics:
+ allocatestmmac_dma_opsinstance and initialize it withdwmac1000_dma_ops.
+ override the stmmac_dma_ops.{dma_interrupt,init_chan} with the pointers to the methods defined in 2.
+ allocatemac_device_infoinstance and initialize the mac_device_info.dma field with a pointer to the newstmmac_dma_opsinstance.
+ initializemac_device_infoin a way it's done indwmac1000_setup().3. Initialize
plat_stmmacenet_data.setup()with the pointer to the method created in 2.Signed-off-by Yanteng Si <[email protected]>Signed-off-by Feiyang Chen <[email protected]>Signed-off-by Yinggang Gu <[email protected]>--- .../ethernet/stmicro/stmmac/dwmac-loongson.c | 248 ++++++++++++++++++ 1 file changed, 248 insertions(+)drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +24
-0@@ -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_DEBUGis 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_opsinstance 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,
YantengQuoted 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
-0plat =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
-0if (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_versionis unused in out of theprobe()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()expectspriv->plat->setup(priv)returning NULL if something wrong. As I suggested above just return NULL then ifmac_device_infocouldn'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
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-specificstmmac_dma_ops.dma_interrupt()stmmac_dma_ops.init_chan()
methods in thedwmac-loongson.cdriver. Adding all the Loongson-specific macros2. Create a Loongson GNET-specific platform setup method with the next semantics:
+ allocatestmmac_dma_opsinstance and initialize it withdwmac1000_dma_ops.
+ override the stmmac_dma_ops.{dma_interrupt,init_chan} with the pointers to the methods defined in 2.
+ allocatemac_device_infoinstance and initialize the mac_device_info.dma field with a pointer to the newstmmac_dma_opsinstance.
+ initializemac_device_infoin a way it's done indwmac1000_setup().3. Initialize
plat_stmmacenet_data.setup()with the pointer to the method created in 2.Signed-off-by Yanteng Si <[email protected]>Signed-off-by Feiyang Chen <[email protected]>Signed-off-by Yinggang Gu <[email protected]>--- .../ethernet/stmicro/stmmac/dwmac-loongson.c | 248 ++++++++++++++++++ 1 file changed, 248 insertions(+)drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +24
-0@@ -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_DEBUGis 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_opsinstance 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,
YantengQuoted 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
-0plat =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
-0if (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_versionis unused in out of theprobe()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()expectspriv->plat->setup(priv)returning NULL if something wrong. As I suggested above just return NULL then ifmac_device_infocouldn'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
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-specificstmmac_dma_ops.dma_interrupt()stmmac_dma_ops.init_chan()
methods in thedwmac-loongson.cdriver. Adding all the Loongson-specific macros2. Create a Loongson GNET-specific platform setup method with the next semantics:
+ allocatestmmac_dma_opsinstance and initialize it withdwmac1000_dma_ops.
+ override the stmmac_dma_ops.{dma_interrupt,init_chan} with the pointers to the methods defined in 2.
+ allocatemac_device_infoinstance and initialize the mac_device_info.dma field with a pointer to the newstmmac_dma_opsinstance.
+ initializemac_device_infoin a way it's done indwmac1000_setup().3. Initialize
plat_stmmacenet_data.setup()with the pointer to the method created in 2.Signed-off-by Yanteng Si <[email protected]>Signed-off-by Feiyang Chen <[email protected]>Signed-off-by Yinggang Gu <[email protected]>--- .../ethernet/stmicro/stmmac/dwmac-loongson.c | 248 ++++++++++++++++++ 1 file changed, 248 insertions(+)drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +24
-0@@ -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_DEBUGis 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_opsinstance 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,
YantengQuoted 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
-0plat =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
-0if (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_versionis unused in out of theprobe()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()expectspriv->plat->setup(priv)returning NULL if something wrong. As I suggested above just return NULL then ifmac_device_infocouldn'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
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-specificstmmac_dma_ops.dma_interrupt()stmmac_dma_ops.init_chan()
methods in thedwmac-loongson.cdriver. Adding all the Loongson-specific macros2. Create a Loongson GNET-specific platform setup method with the next semantics:
+ allocatestmmac_dma_opsinstance and initialize it withdwmac1000_dma_ops.
+ override the stmmac_dma_ops.{dma_interrupt,init_chan} with the pointers to the methods defined in 2.
+ allocatemac_device_infoinstance and initialize the mac_device_info.dma field with a pointer to the newstmmac_dma_opsinstance.
+ initializemac_device_infoin a way it's done indwmac1000_setup().3. Initialize
plat_stmmacenet_data.setup()with the pointer to the method created in 2.Signed-off-by Yanteng Si <[email protected]>Signed-off-by Feiyang Chen <[email protected]>Signed-off-by Yinggang Gu <[email protected]>--- .../ethernet/stmicro/stmmac/dwmac-loongson.c | 248 ++++++++++++++++++ 1 file changed, 248 insertions(+)drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +24
-0@@ -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_DEBUGis 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_opsinstance 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,
YantengQuoted 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
-0plat =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
-0if (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_versionis unused in out of theprobe()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()expectspriv->plat->setup(priv)returning NULL if something wrong. As I suggested above just return NULL then ifmac_device_infocouldn'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
PATCH v8 6/11 net: stmmac: dwmac-loongson: Add GNET support
In reply to Yanteng SiAdd 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
@@ -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 0x7a13static 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
Re: [PATCH net-next v8 06/11] net: stmmac: dwmac-loongson: Add GNET support
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
Signed-off-by Yanteng Si <[email protected]>Signed-off-by Feiyang Chen <[email protected]>Signed-off-by Yinggang Gu <[email protected]>--- .../ethernet/stmicro/stmmac/dwmac-loongson.c | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+)drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +0
-0
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
-0ld = 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
-0const 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 0x7a13static 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
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [PATCH net-next v8 06/11] net: stmmac: dwmac-loongson: Add GNET support
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
0x10supports full-duplex and half-duplex at 1000/100/10M. The gnet of0x37(i.e. the gnet of 7a2000) supports 1000/100/10M full duplex.The gnet with
0x10has 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
Signed-off-by Yanteng Si<[email protected]>Signed-off-by Feiyang Chen<[email protected]>Signed-off-by Yinggang Gu<[email protected]>--- .../ethernet/stmicro/stmmac/dwmac-loongson.c | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+)drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +0
-0@@ -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 overwritingstmmac_dma_ops.dma_interrupt()andstmmac_dma_ops.init_chan(), the logic is consistent with0x37,so we overwrite
synopsys_idto0x37.Quoted 7 lines
Quoted 7 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +0
-0ld = 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 leavingloongson_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 0x7a13Quoted 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
-0static 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
Re: [PATCH net-next v8 06/11] net: stmmac: dwmac-loongson: Add GNET support
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
0x10supports full-duplex and half-duplex at 1000/100/10M. The gnet of0x37(i.e. the gnet of 7a2000) supports 1000/100/10M full duplex.The gnet with
0x10has 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
Signed-off-by Yanteng Si<[email protected]>Signed-off-by Feiyang Chen<[email protected]>Signed-off-by Yinggang Gu<[email protected]>--- .../ethernet/stmicro/stmmac/dwmac-loongson.c | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+)drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +0
-0drivers/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 overwritingstmmac_dma_ops.dma_interrupt()andstmmac_dma_ops.init_chan(), the logic is consistent with0x37,so we overwrite
synopsys_idto0x37.
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
-0ld = 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
-0return 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 leavingloongson_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 structpci_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
Re: [PATCH net-next v8 06/11] net: stmmac: dwmac-loongson: Add GNET support
Quoted 35 lines · Serge Semin
Quoted 13 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
0x10supports full-duplex and half-duplex at 1000/100/10M. The gnet of0x37(i.e. the gnet of 7a2000) supports 1000/100/10M full duplex.The gnet with
0x10has 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.
Quoted 4 lines
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."
OK, Thanks!
Quoted 29 lines
Quoted 21 lines
Quoted 21 lines
Quoted 21 lines
Quoted 13 lines
Signed-off-by Yanteng Si<[email protected]>Signed-off-by Feiyang Chen<[email protected]>Signed-off-by Yinggang Gu<[email protected]>--- .../ethernet/stmicro/stmmac/dwmac-loongson.c | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+)drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +0
-0drivers/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 overwritingstmmac_dma_ops.dma_interrupt()andstmmac_dma_ops.init_chan(), the logic is consistent with0x37,so we overwrite
synopsys_idto0x37.
Quoted 9 lines
Yeah, something like that:
/* The original IP-core version is0x37in all Loongson GNET
* (2k2000 and 7a2000), but the GNET HW designers have changed the
* GMAC_VERSION.SNPSVER field to the custom0x10value on the Loongson
* 2k2000 MAC to emphasize the differences: multiple DMA-channels, AV
* feature andGMAC_INT_STATUSCSR flags layout. Get back the
* original value so the correct HW-interface would be
* selected.
*/
OK, Thanks!
Quoted 20 lines
Quoted 18 lines
Quoted 18 lines
Quoted 3 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static struct mac_device_info *loongson_setup(void *apriv)
Quoted 3 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +0
-0ld = 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
-0return 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,
Quoted 8 lines
Why do you need the
phy_addrset to 2 then? Is PHY still discoverable on the subordinate MDIO-bus?kdoc in "
include/linux/phy.h" defines thePHY_INTERFACE_MODE_INTERNALmode 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?
Please allow me to consult with our hardware engineers before replying to you. :)
Thanks,
Yanteng
Quoted 71 lines
-Serge(y)
Quoted 68 lines
Quoted 68 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 leavingloongson_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 9 lines
Quoted 9 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 structpci_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 7 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
Re: [PATCH net-next v8 06/11] net: stmmac: dwmac-loongson: Add GNET support
Quoted 37 lines · Yanteng Si
Quoted 35 lines · Serge Semin
Quoted 13 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
0x10supports full-duplex and half-duplex at 1000/100/10M. The gnet of0x37(i.e. the gnet of 7a2000) supports 1000/100/10M full duplex.The gnet with
0x10has 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.
Quoted 6 lines
Quoted 4 lines
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."
OK, Thanks!
Please don't forget to replace the next text:
"... 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."
with the actual device capabilities, like:
Speeds - 10/100/1000Mbps,
DMA-descriptors type - Normal DMA descriptors or Enhanced DMA descriptors, MTL Tx/Rx FIFO size - X Kb MTL Tx FIFO, Y Kb MTL Rx FIFO, Perfect and Hash-based MAC Filter tables size - X MAC addresses, X-entries hash address filter,
etc
-Serge(y)
Quoted 148 lines
Quoted 29 lines
Quoted 21 lines
Quoted 21 lines
Quoted 21 lines
Quoted 13 lines
Signed-off-by Yanteng Si<[email protected]>Signed-off-by Feiyang Chen<[email protected]>Signed-off-by Yinggang Gu<[email protected]>--- .../ethernet/stmicro/stmmac/dwmac-loongson.c | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+)drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +0
-0drivers/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 overwritingstmmac_dma_ops.dma_interrupt()andstmmac_dma_ops.init_chan(), the logic is consistent with0x37,so we overwrite
synopsys_idto0x37.Quoted 9 lines
Yeah, something like that:
/* The original IP-core version is0x37in all Loongson GNET
* (2k2000 and 7a2000), but the GNET HW designers have changed the
* GMAC_VERSION.SNPSVER field to the custom0x10value on the Loongson
* 2k2000 MAC to emphasize the differences: multiple DMA-channels, AV
* feature andGMAC_INT_STATUSCSR flags layout. Get back the
* original value so the correct HW-interface would be
* selected.
*/OK, Thanks!
Quoted 20 lines
Quoted 18 lines
Quoted 18 lines
Quoted 3 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static struct mac_device_info *loongson_setup(void *apriv)
Quoted 3 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +0
-0ld = 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
-0return 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,
Quoted 8 lines
Why do you need the
phy_addrset to 2 then? Is PHY still discoverable on the subordinate MDIO-bus?kdoc in "
include/linux/phy.h" defines thePHY_INTERFACE_MODE_INTERNALmode 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?Please allow me to consult with our hardware engineers before replying to you. :)
Thanks,
Yanteng
Quoted 71 lines
-Serge(y)
Quoted 68 lines
Quoted 68 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 leavingloongson_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 9 lines
Quoted 9 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 structpci_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 7 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
Re: [PATCH net-next v8 06/11] net: stmmac: dwmac-loongson: Add GNET support
In reply to Serge SeminQuoted 12 lines · Serge Semin
Quoted 12 lines
Quoted 12 lines
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
Quoted 1 line
Quoted 1 line
+static int loongson_gnet_data(struct
pci_dev*pdev,drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +10
-0+ 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 4 lines
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_addrset to 2 then? Is PHY still discoverable on the subordinate MDIO-bus?
Because the default return value of gnet's mdio is 0xffff, when scanning for phy,
if the return value is not 0, it will be assumed that the phy for that address exists.
Not specifying an address will cause all addresses' phy to be detected, and the
lowest address' phy will be selected by default. so then, the network is unavailable.
Quoted 6 lines
kdoc in "
include/linux/phy.h" defines thePHY_INTERFACE_MODE_INTERNALmode 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?
Hmmm. the interface between MAC and PHY is GMII, so let's use
PHY_INTERFACE_MODE_GMII?
Thanks,
Yanteng
Re: [PATCH net-next v8 06/11] net: stmmac: dwmac-loongson: Add GNET support
Quoted 5 lines
Because the default return value of gnet's mdio is
0xffff, when scanning for phy,if the return value is not 0, it will be assumed that the phy for that address exists.
That is not correct. The MDIO bus has a pull up on the data line. If there is no device at a given address, that pull up results in 0xffff being read. phylib understands this, it knows that a read with the value of 0xffff probably means there is no device at that address. So it will not create a device.
Quoted 5 lines
Not specifying an address will cause all addresses' phy to be detected, and the
lowest address' phy will be selected by default. so then, the network is unavailable.
Do you have multiple PHYs on the bus? If there is only one PHY the first PHY should be the PHY you want, and phy_find_first() will do what you need. However, if there are multiple PHYs on the bus, you really should use a phandle in DT to point to the correct PHY.
Andrew
Re: [PATCH net-next v8 06/11] net: stmmac: dwmac-loongson: Add GNET support
Quoted 10 lines · Andrew Lunn
Quoted 5 lines
Because the default return value of gnet's mdio is
0xffff, when scanning for phy,if the return value is not 0, it will be assumed that the phy for that address exists.
That is not correct. The MDIO bus has a pull up on the data line. If there is no device at a given address, that pull up results in
0xffffbeing read. phylib understands this, it knows that a read with the value of0xffffprobably means there is no device at that address. So it will not create a device.
OK. I've got it.
Quoted 7 lines
Quoted 6 lines
Not specifying an address will cause all addresses' phy to be detected, and
thelowest address' phy will be selected by default. so then, the network is unavailable.
Do you have multiple PHYs on the bus? If there is only one PHY the
Only one.
Quoted 1 line
first PHY should be the PHY you want, and
phy_find_first()will do
static int loongson_gnet_data(struct pci_dev *pdev, struct plat_stmmacenet_data *plat) {
struct net_device *ndev = dev_get_drvdata(&pdev->dev); struct stmmac_priv *priv = netdev_priv(ndev); struct phy_device *phydev;
phydev = phy_find_first(priv->mii);
plat->phy_addr = phydev->mdio.addr;
If I understand your comment correctly, this doesn't seem to work
because the mii hasn't been initialized at this point.
So, how about plat->phy_addr = -1; ?
Thanks,
Yanteng
Re: [PATCH net-next v8 06/11] net: stmmac: dwmac-loongson: Add GNET support
In reply to Yanteng SiQuoted 22 lines · Yanteng Si
Quoted 14 lines · Serge Semin
Quoted 14 lines
Quoted 14 lines
Quoted 4 lines
Quoted 4 lines
Quoted 1 line
Quoted 1 line
+static int loongson_gnet_data(struct
pci_dev*pdev,drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +3
-0+ struct plat_stmmacenet_data *plat) +{ +loongson_default_data (pdev, plat);Quoted 8 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static struct mac_device_info *loongson_setup(void *apriv) · line 365
Quoted 7 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +7
-0+ + 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,
...
Quoted 5 lines
kdoc in "
include/linux/phy.h" defines thePHY_INTERFACE_MODE_INTERNALmode 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?
Quoted 4 lines
Hmmm. the interface between MAC and PHY is GMII, so let's use
PHY_INTERFACE_MODE_GMII?
If MAC<->PHY interface is GMII, then PHY_INTERFACE_MODE_GMII should be used to indicate that.
-Serge(y)
Quoted 6 lines
Thanks,
Yanteng
PATCH v8 7/11 net: stmmac: dwmac-loongson: Add multi-channel supports for loongson
In reply to Yanteng SiRequest 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
@@ -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
Re: [PATCH net-next v8 07/11] net: stmmac: dwmac-loongson: Add multi-channel supports for loongson
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_VERSIONregister. 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
Signed-off-by Yanteng Si <[email protected]>Signed-off-by Feiyang Chen <[email protected]>Signed-off-by Yinggang Gu <[email protected]>--- .../ethernet/stmicro/stmmac/dwmac-loongson.c | 57 +++++++++++++++---- 1 file changed, 46 insertions(+), 11 deletions(-)drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +0
-0
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
-0static 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
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [PATCH net-next v8 07/11] net: stmmac: dwmac-loongson: Add multi-channel supports for loongson
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_msiQuoted 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_VERSIONregister. 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
0x37Quoted 20 lines
Quoted 20 lines
Signed-off-by Yanteng Si<[email protected]>Signed-off-by Feiyang Chen<[email protected]>Signed-off-by Yinggang Gu<[email protected]>--- .../ethernet/stmicro/stmmac/dwmac-loongson.c | 57 +++++++++++++++---- 1 file changed, 46 insertions(+), 11 deletions(-)drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +1
-1@@ -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_NUM8Quoted 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
0x10gnet device has 8 channels, and the0x37device 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_irqis 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 theloongson_dwmac_config_legacy()invocation in theprobe()method right at the patches introducing theconfig()functions and not to add theconfig()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
-0static 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
Re: [PATCH net-next v8 07/11] net: stmmac: dwmac-loongson: Add multi-channel supports for loongson
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_msiQuoted 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_VERSIONregister. 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
0x37Quoted 16 lines
Quoted 16 lines
Signed-off-by Yanteng Si<[email protected]>Signed-off-by Feiyang Chen<[email protected]>Signed-off-by Yinggang Gu<[email protected]>--- .../ethernet/stmicro/stmmac/dwmac-loongson.c | 57 +++++++++++++++---- 1 file changed, 46 insertions(+), 11 deletions(-)drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +0
-0@@ -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_NUM8Quoted 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
0x10gnet device has 8 channels, and the0x37device 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_irqis 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 theloongson_dwmac_config_legacy()invocation in theprobe()method right at the patches introducing theconfig()functions and not to add theconfig()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
Re: [PATCH net-next v8 07/11] net: stmmac: dwmac-loongson: Add multi-channel supports for loongson
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +4
-0+{ +int i, ret, vecs; + + vecs =roundup_pow_of_two (channel_num *2 +1 );
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int loongson_dwmac_config_legacy(struct pci_dev *pdev, · line 254
Quoted 5 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +5
-0+ 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?
I need to wait for special hardware and PMON for this. Please give me some time.
Quoted 5 lines
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 thepci_alloc_irq_vectors()failure?
Yes! I have tested it, it works in single channel mode.
dmesg:
[ 3.935203] mdio_bus stmmac-18:02: attached PHY driver [unbound] (mii_bus:phy_addr=stmmac-18:02, irq=POLL) [ 3.945625] dwmac-loongson-pci 0000:00:03.1: MSI enable failed, Fallback to legacy interrupt [ 3.954175] dwmac-loongson-pci 0000:00:03.1: User ID: 0xd1, Synopsys ID: 0x10 [ 3.973676] dwmac-loongson-pci 0000:00:03.1: DMA HW capability register supported [ 3.981135] dwmac-loongson-pci 0000:00:03.1: RX Checksum Offload Engine supported
cat /proc/interrupt:
43: 0 0 PCH PIC 16 ahci[0000:00:08.0]
44: 0 0 PCH PIC 12 enp0s3f0 45: 0 0 PCH PIC 14 enp0s3f1 46: 16233 0 PCH PIC 17 enp0s3f2 47: 12698 0 PCH PIC 48 xhci-hcd:usb1
the irq number 46 is the falkback legacy irq.
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int loongson_dwmac_config_legacy(struct pci_dev *pdev, · line 258
Quoted 6 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.
Quoted 7 lines
Quoted 2 lines
Quoted 2 lines
No, referring to my previous reply, only the
0x10gnet device has 8 channels, and the0x37device 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 theloongson_gnet_config_multi_msi()will get to be more coherent setting up the MSI IRQs only.
You are right! it works well.
Thanks,
Yanteng
Re: [PATCH net-next v8 07/11] net: stmmac: dwmac-loongson: Add multi-channel supports for loongson
Quoted 35 lines · Yanteng Si
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +4
-0+{ +int i, ret, vecs; + + vecs =roundup_pow_of_two (channel_num *2 +1 );Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int loongson_dwmac_config_legacy(struct pci_dev *pdev, · line 254
Quoted 5 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +5
-0+ 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?I need to wait for special hardware and PMON for this. Please give me some time.
Quoted 5 lines
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 thepci_alloc_irq_vectors()failure?Yes! I have tested it, it works in single channel mode.
dmesg:
[ 3.935203] mdio_bus stmmac-18:02: attached PHY driver [unbound] (mii_bus:phy_addr=stmmac-18:02, irq=POLL) [ 3.945625] dwmac-loongson-pci 0000:00:03.1: MSI enable failed, Fallback to legacy interrupt [ 3.954175] dwmac-loongson-pci 0000:00:03.1: User ID: 0xd1, Synopsys ID: 0x10 [ 3.973676] dwmac-loongson-pci 0000:00:03.1: DMA HW capability register supported [ 3.981135] dwmac-loongson-pci 0000:00:03.1: RX Checksum Offload Engine supportedcat
/proc/interrupt:
Quoted 8 lines
43: 0 0 PCH PIC 16 ahci[0000:00:08.0]
44: 0 0 PCH PIC 12 enp0s3f0 45: 0 0 PCH PIC 14 enp0s3f1 46: 16233 0 PCH PIC 17 enp0s3f2 47: 12698 0 PCH PIC 48 xhci-hcd:usb1the irq number 46 is the falkback legacy irq.
Ok. Thanks. You can do that in a bit more clever manner. Like this:
+static int loongson_dwmac_config_multi_msi(struct pci_dev *pdev,
+ struct plat_stmmacenet_data *plat,
+ struct stmmac_resources *res)
+{
+ int i, ret, vecs;
+
+ /* INT NAME | MAC | CH7 rx | CH7 tx | ... | CH0 rx | CH0 tx |
+ * --------- ----- -------- -------- ... -------- --------
+ * IRQ NUM | 0 | 1 | 2 | ... | 15 | 16 |
+ */
+ vecs = plat->rx_queues_to_use + plat->tx_queues_to_use + 1;
+ ret = pci_alloc_irq_vectors(pdev, 1, vecs, PCI_IRQ_MSI | PCI_IRQ_LEGACY);
+ if (ret < 0) {
+ dev_err(&pdev->dev, "Failed to allocate PCI IRQs\n");
+ return ret;
+ } else if (ret >= vecs) {
+ for (i = 0; i < plat->rx_queues_to_use; i++) {
+ res->rx_irq[CHANNELS_NUM - 1 - i] =
+ pci_irq_vector(pdev, 1 + i * 2);
+ }
+ for (i = 0; i < plat->tx_queues_to_use; i++) {
+ res->tx_irq[CHANNELS_NUM - 1 - i] =
+ pci_irq_vector(pdev, 2 + i * 2);
+ }
+
+ plat->flags |= STMMAC_FLAG_MULTI_MSI_EN;
+ }
+
+ res->irq = pci_irq_vector(pdev, 0);
+
+ return 0;
+}
Thus in case if for some reason you were able to allocate less MSI IRQs than required you'll still be able to use them. The legacy IRQ will be also available in case if MSI failed to be allocated.
-Serge(y)
Quoted 24 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c static int loongson_dwmac_config_legacy(struct pci_dev *pdev, · line 258
Quoted 7 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.Quoted 7 lines
Quoted 2 lines
Quoted 2 lines
No, referring to my previous reply, only the
0x10gnet device has 8 channels, and the0x37device 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 theloongson_gnet_config_multi_msi()will get to be more coherent setting up the MSI IRQs only.You are right! it works well.
Thanks,
Yanteng
Re: [PATCH net-next v8 07/11] net: stmmac: dwmac-loongson: Add multi-channel supports for loongson
Quoted 33 lines · Serge Semin
(quoted diff) +32
-0+static int loongson_dwmac_config_multi_msi(struct pci_dev *pdev, + struct plat_stmmacenet_data *plat, + struct stmmac_resources *res) +{ + int i, ret, vecs; + + /* INT NAME | MAC | CH7 rx | CH7 tx | ... | CH0 rx | CH0 tx | + * --------- ----- -------- -------- ... -------- -------- + * IRQ NUM | 0 | 1 | 2 | ... | 15 | 16 | + */ + vecs = plat->rx_queues_to_use + plat->tx_queues_to_use + 1; + ret = pci_alloc_irq_vectors(pdev, 1, vecs, PCI_IRQ_MSI | PCI_IRQ_LEGACY); + if (ret < 0) { + dev_err(&pdev->dev, "Failed to allocate PCI IRQs\n"); + return ret; + } else if (ret >= vecs) { + for (i = 0; i < plat->rx_queues_to_use; i++) { + res->rx_irq[CHANNELS_NUM - 1 - i] = + pci_irq_vector(pdev, 1 + i * 2); + } + for (i = 0; i < plat->tx_queues_to_use; i++) { + res->tx_irq[CHANNELS_NUM - 1 - i] = + pci_irq_vector(pdev, 2 + i * 2); + } + + plat->flags |= STMMAC_FLAG_MULTI_MSI_EN; + } + + res->irq = pci_irq_vector(pdev, 0); + + return 0; +}
Quoted 3 lines
Thus in case if for some reason you were able to allocate less MSI IRQs than required you'll still be able to use them. The legacy IRQ will be also available in case if MSI failed to be allocated.
Great, we will consider doing this in the future, but at this stage, we don't want to add too much complexity.
Thanks,
Yanteng
Re: [PATCH net-next v8 07/11] net: stmmac: dwmac-loongson: Add multi-channel supports for loongson
Quoted 35 lines · Yanteng Si
Quoted 33 lines · Serge Semin
(quoted diff) +32
-0+static int loongson_dwmac_config_multi_msi(struct pci_dev *pdev, + struct plat_stmmacenet_data *plat, + struct stmmac_resources *res) +{ + int i, ret, vecs; + + /* INT NAME | MAC | CH7 rx | CH7 tx | ... | CH0 rx | CH0 tx | + * --------- ----- -------- -------- ... -------- -------- + * IRQ NUM | 0 | 1 | 2 | ... | 15 | 16 | + */ + vecs = plat->rx_queues_to_use + plat->tx_queues_to_use + 1; + ret = pci_alloc_irq_vectors(pdev, 1, vecs, PCI_IRQ_MSI | PCI_IRQ_LEGACY); + if (ret < 0) { + dev_err(&pdev->dev, "Failed to allocate PCI IRQs\n"); + return ret; + } else if (ret >= vecs) { + for (i = 0; i < plat->rx_queues_to_use; i++) { + res->rx_irq[CHANNELS_NUM - 1 - i] = + pci_irq_vector(pdev, 1 + i * 2); + } + for (i = 0; i < plat->tx_queues_to_use; i++) { + res->tx_irq[CHANNELS_NUM - 1 - i] = + pci_irq_vector(pdev, 2 + i * 2); + } + + plat->flags |= STMMAC_FLAG_MULTI_MSI_EN; + } + + res->irq = pci_irq_vector(pdev, 0); + + return 0; +}
Quoted 6 lines
Quoted 3 lines
Thus in case if for some reason you were able to allocate less MSI IRQs than required you'll still be able to use them. The legacy IRQ will be also available in case if MSI failed to be allocated.
Great, we will consider doing this in the future, but at this stage, we don't want to add too much complexity.
This comment isn't about complexity. Moreover the code in my comment is simpler since the function is more coherent and doesn't have the redundant dependencies from the node-pointer and the loongson_dwmac_config_legacy() function. In addition it provides more flexible solution in case if there were less MSI vectors allocated then required.
-Serge(y)
Quoted 6 lines
Thanks,
Yanteng
Re: [PATCH net-next v8 07/11] net: stmmac: dwmac-loongson: Add multi-channel supports for loongson
Quoted 40 lines · Serge Semin
Quoted 34 lines · Yanteng Si
Quoted 33 lines · Serge Semin
(quoted diff) +32
-0+static int loongson_dwmac_config_multi_msi(struct pci_dev *pdev, + struct plat_stmmacenet_data *plat, + struct stmmac_resources *res) +{ + int i, ret, vecs; + + /* INT NAME | MAC | CH7 rx | CH7 tx | ... | CH0 rx | CH0 tx | + * --------- ----- -------- -------- ... -------- -------- + * IRQ NUM | 0 | 1 | 2 | ... | 15 | 16 | + */ + vecs = plat->rx_queues_to_use + plat->tx_queues_to_use + 1; + ret = pci_alloc_irq_vectors(pdev, 1, vecs, PCI_IRQ_MSI | PCI_IRQ_LEGACY); + if (ret < 0) { + dev_err(&pdev->dev, "Failed to allocate PCI IRQs\n"); + return ret; + } else if (ret >= vecs) { + for (i = 0; i < plat->rx_queues_to_use; i++) { + res->rx_irq[CHANNELS_NUM - 1 - i] = + pci_irq_vector(pdev, 1 + i * 2); + } + for (i = 0; i < plat->tx_queues_to_use; i++) { + res->tx_irq[CHANNELS_NUM - 1 - i] = + pci_irq_vector(pdev, 2 + i * 2); + } + + plat->flags |= STMMAC_FLAG_MULTI_MSI_EN; + } + + res->irq = pci_irq_vector(pdev, 0); + + return 0; +}Quoted 5 lines
Quoted 3 lines
Thus in case if for some reason you were able to allocate less MSI IRQs than required you'll still be able to use them. The legacy IRQ will be also available in case if MSI failed to be allocated.
Great, we will consider doing this in the future, but at this stage, we don't want to add too much complexity.
Quoted 6 lines
This comment isn't about complexity. Moreover the code in my comment is simpler since the function is more coherent and doesn't have the redundant dependencies from the node-pointer and the
loongson_dwmac_config_legacy()function. In addition it provides more flexible solution in case if there were less MSI vectors allocated then required.
I just tried it, the network card doesn't work, the reason is not clear.
Considering that the overall change is a little big, I want to send the current
working state as the patch v9.
However, I will continue to analyze the reasons for the failure and submit them
as a separate patch in the future. Is that OK?
Thanks,
Yanteng
Re: [PATCH net-next v8 07/11] net: stmmac: dwmac-loongson: Add multi-channel supports for loongson
In reply to Serge SeminQuoted 2 lines · Serge Semin
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?
yes,dt-node has specified irq information,and this driver also work with ACPI configuration.
Thanks,
Yanteng
PATCH v8 8/11 net: stmmac: dwmac-loongson: Fix MAC speed for GNET
In reply to Yanteng SiCurrent 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
@@ -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
@@ -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
@@ -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
Re: [PATCH net-next v8 08/11] net: stmmac: dwmac-loongson: Fix MAC speed for GNET
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
Signed-off-by Yanteng Si <[email protected]>Signed-off-by Feiyang Chen <[email protected]>Signed-off-by Yinggang Gu <[email protected]>--- .../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@@ -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
-0struct 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
-0return 0 ; }drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c +1
-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)) {
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
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
-0struct plat_stmmacenet_data {int bus_id;Signature · 1 line
2.31.4
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [PATCH net-next v8 08/11] net: stmmac: dwmac-loongson: Fix MAC speed for GNET
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 supportCurrent 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
Signed-off-by Yanteng Si<[email protected]>Signed-off-by Feiyang Chen<[email protected]>Signed-off-by Yinggang Gu<[email protected]>--- .../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
-0drivers/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_PSmacro.OK.
if(speed==SPEED_1000){
/*MAC_CTRL_REG.15 is defined by theGMAC_CONTROL_PSmacro.*/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
-0plat->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 supportOK.
Quoted 12 lines
Quoted 12 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +0
-0return 0 ; }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 ; }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@@ -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_1000flag 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
-0struct plat_stmmacenet_data {int bus_id;Signature · 1 line
2.31.4
Re: [PATCH net-next v8 08/11] net: stmmac: dwmac-loongson: Fix MAC speed for GNET
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 supportOK.
Quoted 29 lines
Quoted 10 lines
Quoted 10 lines
Signed-off-by Yanteng Si<[email protected]>Signed-off-by Feiyang Chen<[email protected]>Signed-off-by Yinggang Gu<[email protected]>--- .../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@@ -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 intspeed, 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_PSmacro.OK.
if(speed==SPEED_1000){
/*MAC_CTRL_REG.15 is defined by theGMAC_CONTROL_PSmacro.*/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
-0struct 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 supportOK.
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
-0return 0 ; } >> diff --git
a/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.cb/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.cQuoted 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..31068fbc23c9100644drivers/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.hindex
dee5ad6e48c5..2810361e4048100644include/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_1000flag 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