Skip to content

Commit b6a5293

Browse files
committed
RM 6641: Temporary implementation of dma_alloc_coherent() on STM32H7 SOM
1 parent 2a2514d commit b6a5293

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

drivers/net/ethernet/stmicro/stmmac/stmmac_main.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,12 @@ int stmmac_bus_clks_config(struct stmmac_priv *priv, bool enabled)
173173
}
174174
EXPORT_SYMBOL_GPL(stmmac_bus_clks_config);
175175

176+
/* temporary implementation of dma_alloc_coherent() on STM32H7 SOM */
177+
#define STM32H7_SOM_DMA
178+
#ifdef STM32H7_SOM_DMA
179+
static const char dma_rx_phy[16384] __attribute__ ((aligned (16)));
180+
static const char dma_tx_phy[16384] __attribute__ ((aligned (16)));
181+
#endif
176182
/**
177183
* stmmac_verify_args - verify the driver parameters.
178184
* Description: it checks the driver parameters and set a default in case of
@@ -1908,6 +1914,7 @@ static void __free_dma_rx_desc_resources(struct stmmac_priv *priv, u32 queue)
19081914
rx_q->buf_alloc_num = 0;
19091915
rx_q->xsk_pool = NULL;
19101916

1917+
#ifndef STM32H7_SOM_DMA
19111918
/* Free DMA regions of consistent memory previously allocated */
19121919
if (!priv->extend_desc)
19131920
dma_free_coherent(priv->device, priv->dma_rx_size *
@@ -1917,6 +1924,7 @@ static void __free_dma_rx_desc_resources(struct stmmac_priv *priv, u32 queue)
19171924
dma_free_coherent(priv->device, priv->dma_rx_size *
19181925
sizeof(struct dma_extended_desc),
19191926
rx_q->dma_erx, rx_q->dma_rx_phy);
1927+
#endif
19201928

19211929
if (xdp_rxq_info_is_reg(&rx_q->xdp_rxq))
19221930
xdp_rxq_info_unreg(&rx_q->xdp_rxq);
@@ -1963,7 +1971,9 @@ static void __free_dma_tx_desc_resources(struct stmmac_priv *priv, u32 queue)
19631971

19641972
size *= priv->dma_tx_size;
19651973

1974+
#ifndef STM32H7_SOM_DMA
19661975
dma_free_coherent(priv->device, size, addr, tx_q->dma_tx_phy);
1976+
#endif
19671977

19681978
kfree(tx_q->tx_skbuff_dma);
19691979
kfree(tx_q->tx_skbuff);
@@ -2025,22 +2035,36 @@ static int __alloc_dma_rx_desc_resources(struct stmmac_priv *priv, u32 queue)
20252035
return -ENOMEM;
20262036

20272037
if (priv->extend_desc) {
2038+
#ifdef STM32H7_SOM_DMA
2039+
rx_q->dma_erx = (void*) dma_rx_phy;
2040+
rx_q->dma_rx_phy = (dma_addr_t) dma_rx_phy;
2041+
if ((u32)dma_rx_phy > 0xd03f0000)
2042+
return -ENOMEM;
2043+
#else
20282044
rx_q->dma_erx = dma_alloc_coherent(priv->device,
20292045
priv->dma_rx_size *
20302046
sizeof(struct dma_extended_desc),
20312047
&rx_q->dma_rx_phy,
20322048
GFP_KERNEL);
20332049
if (!rx_q->dma_erx)
20342050
return -ENOMEM;
2051+
#endif
20352052

20362053
} else {
2054+
#ifdef STM32H7_SOM_DMA
2055+
rx_q->dma_rx = (void*) dma_rx_phy;
2056+
rx_q->dma_rx_phy = (dma_addr_t) dma_rx_phy;
2057+
if ((u32)dma_rx_phy > 0xd03f0000)
2058+
return -ENOMEM;
2059+
#else
20372060
rx_q->dma_rx = dma_alloc_coherent(priv->device,
20382061
priv->dma_rx_size *
20392062
sizeof(struct dma_desc),
20402063
&rx_q->dma_rx_phy,
20412064
GFP_KERNEL);
20422065
if (!rx_q->dma_rx)
20432066
return -ENOMEM;
2067+
#endif
20442068
}
20452069

20462070
if (stmmac_xdp_is_enabled(priv) &&
@@ -2120,10 +2144,17 @@ static int __alloc_dma_tx_desc_resources(struct stmmac_priv *priv, u32 queue)
21202144

21212145
size *= priv->dma_tx_size;
21222146

2147+
#ifdef STM32H7_SOM_DMA
2148+
addr = (void*) dma_tx_phy;
2149+
tx_q->dma_tx_phy = (dma_addr_t) dma_tx_phy;
2150+
if ((u32)dma_tx_phy > 0xd03f0000)
2151+
return -ENOMEM;
2152+
#else
21232153
addr = dma_alloc_coherent(priv->device, size,
21242154
&tx_q->dma_tx_phy, GFP_KERNEL);
21252155
if (!addr)
21262156
return -ENOMEM;
2157+
#endif
21272158

21282159
if (priv->extend_desc)
21292160
tx_q->dma_etx = addr;

0 commit comments

Comments
 (0)