Commit 24aaed0c authored by Jose Abreu's avatar Jose Abreu Committed by David S. Miller

net: stmmac: Uniformize the use of dma_init_* callbacks

Instead of relying on the GMAC version for choosing if we need to use
dma_init or dma_init_{rx/tx}_chan callback, lets uniformize this and
always use the dma_init_{rx/tx}_chan callbacks.

While at it, fix the use of dma_init_chan callback, which shall be
called for as many channels as the max of rx/tx channels.
Signed-off-by: default avatarJose Abreu <joabreu@synopsys.com>
Cc: David S. Miller <davem@davemloft.net>
Cc: Joao Pinto <jpinto@synopsys.com>
Cc: Vitor Soares <soares@synopsys.com>
Cc: Giuseppe Cavallaro <peppe.cavallaro@st.com>
Cc: Alexandre Torgue <alexandre.torgue@st.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 758d5c73
...@@ -276,17 +276,28 @@ static int sun8i_dwmac_dma_reset(void __iomem *ioaddr) ...@@ -276,17 +276,28 @@ static int sun8i_dwmac_dma_reset(void __iomem *ioaddr)
* Called from stmmac via stmmac_dma_ops->init * Called from stmmac via stmmac_dma_ops->init
*/ */
static void sun8i_dwmac_dma_init(void __iomem *ioaddr, static void sun8i_dwmac_dma_init(void __iomem *ioaddr,
struct stmmac_dma_cfg *dma_cfg, struct stmmac_dma_cfg *dma_cfg, int atds)
u32 dma_tx, u32 dma_rx, int atds)
{ {
/* Write TX and RX descriptors address */
writel(dma_rx, ioaddr + EMAC_RX_DESC_LIST);
writel(dma_tx, ioaddr + EMAC_TX_DESC_LIST);
writel(EMAC_RX_INT | EMAC_TX_INT, ioaddr + EMAC_INT_EN); writel(EMAC_RX_INT | EMAC_TX_INT, ioaddr + EMAC_INT_EN);
writel(0x1FFFFFF, ioaddr + EMAC_INT_STA); writel(0x1FFFFFF, ioaddr + EMAC_INT_STA);
} }
static void sun8i_dwmac_dma_init_rx(void __iomem *ioaddr,
struct stmmac_dma_cfg *dma_cfg,
u32 dma_rx_phy, u32 chan)
{
/* Write RX descriptors address */
writel(dma_rx_phy, ioaddr + EMAC_RX_DESC_LIST);
}
static void sun8i_dwmac_dma_init_tx(void __iomem *ioaddr,
struct stmmac_dma_cfg *dma_cfg,
u32 dma_tx_phy, u32 chan)
{
/* Write TX descriptors address */
writel(dma_tx_phy, ioaddr + EMAC_TX_DESC_LIST);
}
/* sun8i_dwmac_dump_regs() - Dump EMAC address space /* sun8i_dwmac_dump_regs() - Dump EMAC address space
* Called from stmmac_dma_ops->dump_regs * Called from stmmac_dma_ops->dump_regs
* Used for ethtool * Used for ethtool
...@@ -492,6 +503,8 @@ static void sun8i_dwmac_dma_operation_mode_tx(void __iomem *ioaddr, int mode, ...@@ -492,6 +503,8 @@ static void sun8i_dwmac_dma_operation_mode_tx(void __iomem *ioaddr, int mode,
static const struct stmmac_dma_ops sun8i_dwmac_dma_ops = { static const struct stmmac_dma_ops sun8i_dwmac_dma_ops = {
.reset = sun8i_dwmac_dma_reset, .reset = sun8i_dwmac_dma_reset,
.init = sun8i_dwmac_dma_init, .init = sun8i_dwmac_dma_init,
.init_rx_chan = sun8i_dwmac_dma_init_rx,
.init_tx_chan = sun8i_dwmac_dma_init_tx,
.dump_regs = sun8i_dwmac_dump_regs, .dump_regs = sun8i_dwmac_dump_regs,
.dma_rx_mode = sun8i_dwmac_dma_operation_mode_rx, .dma_rx_mode = sun8i_dwmac_dma_operation_mode_rx,
.dma_tx_mode = sun8i_dwmac_dma_operation_mode_tx, .dma_tx_mode = sun8i_dwmac_dma_operation_mode_tx,
......
...@@ -81,8 +81,7 @@ static void dwmac1000_dma_axi(void __iomem *ioaddr, struct stmmac_axi *axi) ...@@ -81,8 +81,7 @@ static void dwmac1000_dma_axi(void __iomem *ioaddr, struct stmmac_axi *axi)
} }
static void dwmac1000_dma_init(void __iomem *ioaddr, static void dwmac1000_dma_init(void __iomem *ioaddr,
struct stmmac_dma_cfg *dma_cfg, struct stmmac_dma_cfg *dma_cfg, int atds)
u32 dma_tx, u32 dma_rx, int atds)
{ {
u32 value = readl(ioaddr + DMA_BUS_MODE); u32 value = readl(ioaddr + DMA_BUS_MODE);
int txpbl = dma_cfg->txpbl ?: dma_cfg->pbl; int txpbl = dma_cfg->txpbl ?: dma_cfg->pbl;
...@@ -119,12 +118,22 @@ static void dwmac1000_dma_init(void __iomem *ioaddr, ...@@ -119,12 +118,22 @@ static void dwmac1000_dma_init(void __iomem *ioaddr,
/* Mask interrupts by writing to CSR7 */ /* Mask interrupts by writing to CSR7 */
writel(DMA_INTR_DEFAULT_MASK, ioaddr + DMA_INTR_ENA); writel(DMA_INTR_DEFAULT_MASK, ioaddr + DMA_INTR_ENA);
}
/* RX/TX descriptor base address lists must be written into static void dwmac1000_dma_init_rx(void __iomem *ioaddr,
* DMA CSR3 and CSR4, respectively struct stmmac_dma_cfg *dma_cfg,
*/ u32 dma_rx_phy, u32 chan)
writel(dma_tx, ioaddr + DMA_TX_BASE_ADDR); {
writel(dma_rx, ioaddr + DMA_RCV_BASE_ADDR); /* RX descriptor base address list must be written into DMA CSR3 */
writel(dma_rx_phy, ioaddr + DMA_RCV_BASE_ADDR);
}
static void dwmac1000_dma_init_tx(void __iomem *ioaddr,
struct stmmac_dma_cfg *dma_cfg,
u32 dma_tx_phy, u32 chan)
{
/* TX descriptor base address list must be written into DMA CSR4 */
writel(dma_tx_phy, ioaddr + DMA_TX_BASE_ADDR);
} }
static u32 dwmac1000_configure_fc(u32 csr6, int rxfifosz) static u32 dwmac1000_configure_fc(u32 csr6, int rxfifosz)
...@@ -264,6 +273,8 @@ static void dwmac1000_rx_watchdog(void __iomem *ioaddr, u32 riwt, ...@@ -264,6 +273,8 @@ static void dwmac1000_rx_watchdog(void __iomem *ioaddr, u32 riwt,
const struct stmmac_dma_ops dwmac1000_dma_ops = { const struct stmmac_dma_ops dwmac1000_dma_ops = {
.reset = dwmac_dma_reset, .reset = dwmac_dma_reset,
.init = dwmac1000_dma_init, .init = dwmac1000_dma_init,
.init_rx_chan = dwmac1000_dma_init_rx,
.init_tx_chan = dwmac1000_dma_init_tx,
.axi = dwmac1000_dma_axi, .axi = dwmac1000_dma_axi,
.dump_regs = dwmac1000_dump_dma_regs, .dump_regs = dwmac1000_dump_dma_regs,
.dma_rx_mode = dwmac1000_dma_operation_mode_rx, .dma_rx_mode = dwmac1000_dma_operation_mode_rx,
......
...@@ -29,8 +29,7 @@ ...@@ -29,8 +29,7 @@
#include "dwmac_dma.h" #include "dwmac_dma.h"
static void dwmac100_dma_init(void __iomem *ioaddr, static void dwmac100_dma_init(void __iomem *ioaddr,
struct stmmac_dma_cfg *dma_cfg, struct stmmac_dma_cfg *dma_cfg, int atds)
u32 dma_tx, u32 dma_rx, int atds)
{ {
/* Enable Application Access by writing to DMA CSR0 */ /* Enable Application Access by writing to DMA CSR0 */
writel(DMA_BUS_MODE_DEFAULT | (dma_cfg->pbl << DMA_BUS_MODE_PBL_SHIFT), writel(DMA_BUS_MODE_DEFAULT | (dma_cfg->pbl << DMA_BUS_MODE_PBL_SHIFT),
...@@ -38,12 +37,22 @@ static void dwmac100_dma_init(void __iomem *ioaddr, ...@@ -38,12 +37,22 @@ static void dwmac100_dma_init(void __iomem *ioaddr,
/* Mask interrupts by writing to CSR7 */ /* Mask interrupts by writing to CSR7 */
writel(DMA_INTR_DEFAULT_MASK, ioaddr + DMA_INTR_ENA); writel(DMA_INTR_DEFAULT_MASK, ioaddr + DMA_INTR_ENA);
}
/* RX/TX descriptor base addr lists must be written into static void dwmac100_dma_init_rx(void __iomem *ioaddr,
* DMA CSR3 and CSR4, respectively struct stmmac_dma_cfg *dma_cfg,
*/ u32 dma_rx_phy, u32 chan)
writel(dma_tx, ioaddr + DMA_TX_BASE_ADDR); {
writel(dma_rx, ioaddr + DMA_RCV_BASE_ADDR); /* RX descriptor base addr lists must be written into DMA CSR3 */
writel(dma_rx_phy, ioaddr + DMA_RCV_BASE_ADDR);
}
static void dwmac100_dma_init_tx(void __iomem *ioaddr,
struct stmmac_dma_cfg *dma_cfg,
u32 dma_tx_phy, u32 chan)
{
/* TX descriptor base addr lists must be written into DMA CSR4 */
writel(dma_tx_phy, ioaddr + DMA_TX_BASE_ADDR);
} }
/* Store and Forward capability is not used at all. /* Store and Forward capability is not used at all.
...@@ -112,6 +121,8 @@ static void dwmac100_dma_diagnostic_fr(void *data, struct stmmac_extra_stats *x, ...@@ -112,6 +121,8 @@ static void dwmac100_dma_diagnostic_fr(void *data, struct stmmac_extra_stats *x,
const struct stmmac_dma_ops dwmac100_dma_ops = { const struct stmmac_dma_ops dwmac100_dma_ops = {
.reset = dwmac_dma_reset, .reset = dwmac_dma_reset,
.init = dwmac100_dma_init, .init = dwmac100_dma_init,
.init_rx_chan = dwmac100_dma_init_rx,
.init_tx_chan = dwmac100_dma_init_tx,
.dump_regs = dwmac100_dump_dma_regs, .dump_regs = dwmac100_dump_dma_regs,
.dma_tx_mode = dwmac100_dma_operation_mode_tx, .dma_tx_mode = dwmac100_dma_operation_mode_tx,
.dma_diagnostic_fr = dwmac100_dma_diagnostic_fr, .dma_diagnostic_fr = dwmac100_dma_diagnostic_fr,
......
...@@ -120,8 +120,7 @@ static void dwmac4_dma_init_channel(void __iomem *ioaddr, ...@@ -120,8 +120,7 @@ static void dwmac4_dma_init_channel(void __iomem *ioaddr,
} }
static void dwmac4_dma_init(void __iomem *ioaddr, static void dwmac4_dma_init(void __iomem *ioaddr,
struct stmmac_dma_cfg *dma_cfg, struct stmmac_dma_cfg *dma_cfg, int atds)
u32 dma_tx, u32 dma_rx, int atds)
{ {
u32 value = readl(ioaddr + DMA_SYS_BUS_MODE); u32 value = readl(ioaddr + DMA_SYS_BUS_MODE);
......
...@@ -140,7 +140,7 @@ struct stmmac_dma_ops { ...@@ -140,7 +140,7 @@ struct stmmac_dma_ops {
/* DMA core initialization */ /* DMA core initialization */
int (*reset)(void __iomem *ioaddr); int (*reset)(void __iomem *ioaddr);
void (*init)(void __iomem *ioaddr, struct stmmac_dma_cfg *dma_cfg, void (*init)(void __iomem *ioaddr, struct stmmac_dma_cfg *dma_cfg,
u32 dma_tx, u32 dma_rx, int atds); int atds);
void (*init_chan)(void __iomem *ioaddr, void (*init_chan)(void __iomem *ioaddr,
struct stmmac_dma_cfg *dma_cfg, u32 chan); struct stmmac_dma_cfg *dma_cfg, u32 chan);
void (*init_rx_chan)(void __iomem *ioaddr, void (*init_rx_chan)(void __iomem *ioaddr,
......
...@@ -2138,10 +2138,9 @@ static int stmmac_init_dma_engine(struct stmmac_priv *priv) ...@@ -2138,10 +2138,9 @@ static int stmmac_init_dma_engine(struct stmmac_priv *priv)
{ {
u32 rx_channels_count = priv->plat->rx_queues_to_use; u32 rx_channels_count = priv->plat->rx_queues_to_use;
u32 tx_channels_count = priv->plat->tx_queues_to_use; u32 tx_channels_count = priv->plat->tx_queues_to_use;
u32 dma_csr_ch = max(rx_channels_count, tx_channels_count);
struct stmmac_rx_queue *rx_q; struct stmmac_rx_queue *rx_q;
struct stmmac_tx_queue *tx_q; struct stmmac_tx_queue *tx_q;
u32 dummy_dma_rx_phy = 0;
u32 dummy_dma_tx_phy = 0;
u32 chan = 0; u32 chan = 0;
int atds = 0; int atds = 0;
int ret = 0; int ret = 0;
...@@ -2160,48 +2159,39 @@ static int stmmac_init_dma_engine(struct stmmac_priv *priv) ...@@ -2160,48 +2159,39 @@ static int stmmac_init_dma_engine(struct stmmac_priv *priv)
return ret; return ret;
} }
if (priv->synopsys_id >= DWMAC_CORE_4_00) { /* DMA RX Channel Configuration */
/* DMA Configuration */ for (chan = 0; chan < rx_channels_count; chan++) {
stmmac_dma_init(priv, priv->ioaddr, priv->plat->dma_cfg, rx_q = &priv->rx_queue[chan];
dummy_dma_tx_phy, dummy_dma_rx_phy, atds);
/* DMA RX Channel Configuration */
for (chan = 0; chan < rx_channels_count; chan++) {
rx_q = &priv->rx_queue[chan];
stmmac_init_rx_chan(priv, priv->ioaddr,
priv->plat->dma_cfg, rx_q->dma_rx_phy,
chan);
rx_q->rx_tail_addr = rx_q->dma_rx_phy +
(DMA_RX_SIZE * sizeof(struct dma_desc));
stmmac_set_rx_tail_ptr(priv, priv->ioaddr,
rx_q->rx_tail_addr, chan);
}
/* DMA TX Channel Configuration */
for (chan = 0; chan < tx_channels_count; chan++) {
tx_q = &priv->tx_queue[chan];
stmmac_init_chan(priv, priv->ioaddr, stmmac_init_rx_chan(priv, priv->ioaddr, priv->plat->dma_cfg,
priv->plat->dma_cfg, chan); rx_q->dma_rx_phy, chan);
stmmac_init_tx_chan(priv, priv->ioaddr, rx_q->rx_tail_addr = rx_q->dma_rx_phy +
priv->plat->dma_cfg, tx_q->dma_tx_phy, (DMA_RX_SIZE * sizeof(struct dma_desc));
chan); stmmac_set_rx_tail_ptr(priv, priv->ioaddr,
rx_q->rx_tail_addr, chan);
}
tx_q->tx_tail_addr = tx_q->dma_tx_phy + /* DMA TX Channel Configuration */
(DMA_TX_SIZE * sizeof(struct dma_desc)); for (chan = 0; chan < tx_channels_count; chan++) {
stmmac_set_tx_tail_ptr(priv, priv->ioaddr,
tx_q->tx_tail_addr, chan);
}
} else {
rx_q = &priv->rx_queue[chan];
tx_q = &priv->tx_queue[chan]; tx_q = &priv->tx_queue[chan];
stmmac_dma_init(priv, priv->ioaddr, priv->plat->dma_cfg,
tx_q->dma_tx_phy, rx_q->dma_rx_phy, atds); stmmac_init_tx_chan(priv, priv->ioaddr, priv->plat->dma_cfg,
tx_q->dma_tx_phy, chan);
tx_q->tx_tail_addr = tx_q->dma_tx_phy +
(DMA_TX_SIZE * sizeof(struct dma_desc));
stmmac_set_tx_tail_ptr(priv, priv->ioaddr,
tx_q->tx_tail_addr, chan);
} }
/* DMA CSR Channel configuration */
for (chan = 0; chan < dma_csr_ch; chan++)
stmmac_init_chan(priv, priv->ioaddr, priv->plat->dma_cfg, chan);
/* DMA Configuration */
stmmac_dma_init(priv, priv->ioaddr, priv->plat->dma_cfg, atds);
if (priv->plat->axi) if (priv->plat->axi)
stmmac_axi(priv, priv->ioaddr, priv->plat->axi); stmmac_axi(priv, priv->ioaddr, priv->plat->axi);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment