1 From 09f8d6960b69e474eef9d2aebdd0d536d00af0c8 Mon Sep 17 00:00:00 2001
2 From: Srinivas Kandagatla <srinivas.kandagatla@st.com>
3 Date: Thu, 16 Jan 2014 10:52:06 +0000
4 Subject: [PATCH] net: stmmac: move dma allocation to new function
6 This patch moves dma resource allocation to a new function
7 alloc_dma_desc_resources, the reason for moving this to a new function
8 is to keep the memory allocations in a separate function. One more reason
9 it to get suspend and hibernation cases working without releasing and
10 allocating these resources during suspend-resume and freeze-restore
13 Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@st.com>
14 Acked-by: Giuseppe Cavallaro <peppe.cavallaro@st.com>
15 Signed-off-by: David S. Miller <davem@davemloft.net>
17 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 169 +++++++++++-----------
18 1 file changed, 85 insertions(+), 84 deletions(-)
20 diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
21 index 15192c0..532f2b4 100644
22 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
23 +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
24 @@ -996,66 +996,6 @@ static int init_dma_desc_rings(struct net_device *dev)
25 pr_debug("%s: txsize %d, rxsize %d, bfsize %d\n", __func__,
26 txsize, rxsize, bfsize);
28 - if (priv->extend_desc) {
29 - priv->dma_erx = dma_alloc_coherent(priv->device, rxsize *
37 - priv->dma_etx = dma_alloc_coherent(priv->device, txsize *
42 - if (!priv->dma_etx) {
43 - dma_free_coherent(priv->device, priv->dma_rx_size *
44 - sizeof(struct dma_extended_desc),
45 - priv->dma_erx, priv->dma_rx_phy);
49 - priv->dma_rx = dma_alloc_coherent(priv->device, rxsize *
50 - sizeof(struct dma_desc),
56 - priv->dma_tx = dma_alloc_coherent(priv->device, txsize *
57 - sizeof(struct dma_desc),
60 - if (!priv->dma_tx) {
61 - dma_free_coherent(priv->device, priv->dma_rx_size *
62 - sizeof(struct dma_desc),
63 - priv->dma_rx, priv->dma_rx_phy);
68 - priv->rx_skbuff_dma = kmalloc_array(rxsize, sizeof(dma_addr_t),
70 - if (!priv->rx_skbuff_dma)
71 - goto err_rx_skbuff_dma;
73 - priv->rx_skbuff = kmalloc_array(rxsize, sizeof(struct sk_buff *),
75 - if (!priv->rx_skbuff)
78 - priv->tx_skbuff_dma = kmalloc_array(txsize, sizeof(dma_addr_t),
80 - if (!priv->tx_skbuff_dma)
81 - goto err_tx_skbuff_dma;
83 - priv->tx_skbuff = kmalloc_array(txsize, sizeof(struct sk_buff *),
85 - if (!priv->tx_skbuff)
88 if (netif_msg_probe(priv)) {
89 pr_debug("(%s) dma_rx_phy=0x%08x dma_tx_phy=0x%08x\n", __func__,
90 (u32) priv->dma_rx_phy, (u32) priv->dma_tx_phy);
91 @@ -1123,30 +1063,6 @@ static int init_dma_desc_rings(struct net_device *dev)
94 stmmac_free_rx_buffers(priv, i);
95 - kfree(priv->tx_skbuff);
97 - kfree(priv->tx_skbuff_dma);
99 - kfree(priv->rx_skbuff);
101 - kfree(priv->rx_skbuff_dma);
103 - if (priv->extend_desc) {
104 - dma_free_coherent(priv->device, priv->dma_tx_size *
105 - sizeof(struct dma_extended_desc),
106 - priv->dma_etx, priv->dma_tx_phy);
107 - dma_free_coherent(priv->device, priv->dma_rx_size *
108 - sizeof(struct dma_extended_desc),
109 - priv->dma_erx, priv->dma_rx_phy);
111 - dma_free_coherent(priv->device,
112 - priv->dma_tx_size * sizeof(struct dma_desc),
113 - priv->dma_tx, priv->dma_tx_phy);
114 - dma_free_coherent(priv->device,
115 - priv->dma_rx_size * sizeof(struct dma_desc),
116 - priv->dma_rx, priv->dma_rx_phy);
122 @@ -1182,6 +1098,85 @@ static void dma_free_tx_skbufs(struct stmmac_priv *priv)
126 +static int alloc_dma_desc_resources(struct stmmac_priv *priv)
128 + unsigned int txsize = priv->dma_tx_size;
129 + unsigned int rxsize = priv->dma_rx_size;
132 + priv->rx_skbuff_dma = kmalloc_array(rxsize, sizeof(dma_addr_t),
134 + if (!priv->rx_skbuff_dma)
137 + priv->rx_skbuff = kmalloc_array(rxsize, sizeof(struct sk_buff *),
139 + if (!priv->rx_skbuff)
140 + goto err_rx_skbuff;
142 + priv->tx_skbuff_dma = kmalloc_array(txsize, sizeof(dma_addr_t),
144 + if (!priv->tx_skbuff_dma)
145 + goto err_tx_skbuff_dma;
147 + priv->tx_skbuff = kmalloc_array(txsize, sizeof(struct sk_buff *),
149 + if (!priv->tx_skbuff)
150 + goto err_tx_skbuff;
152 + if (priv->extend_desc) {
153 + priv->dma_erx = dma_alloc_coherent(priv->device, rxsize *
155 + dma_extended_desc),
158 + if (!priv->dma_erx)
161 + priv->dma_etx = dma_alloc_coherent(priv->device, txsize *
163 + dma_extended_desc),
166 + if (!priv->dma_etx) {
167 + dma_free_coherent(priv->device, priv->dma_rx_size *
168 + sizeof(struct dma_extended_desc),
169 + priv->dma_erx, priv->dma_rx_phy);
173 + priv->dma_rx = dma_alloc_coherent(priv->device, rxsize *
174 + sizeof(struct dma_desc),
180 + priv->dma_tx = dma_alloc_coherent(priv->device, txsize *
181 + sizeof(struct dma_desc),
184 + if (!priv->dma_tx) {
185 + dma_free_coherent(priv->device, priv->dma_rx_size *
186 + sizeof(struct dma_desc),
187 + priv->dma_rx, priv->dma_rx_phy);
195 + kfree(priv->tx_skbuff);
197 + kfree(priv->tx_skbuff_dma);
199 + kfree(priv->rx_skbuff);
201 + kfree(priv->rx_skbuff_dma);
205 static void free_dma_desc_resources(struct stmmac_priv *priv)
207 /* Release the DMA TX/RX socket buffers */
208 @@ -1623,6 +1618,12 @@ static int stmmac_open(struct net_device *dev)
209 priv->dma_rx_size = STMMAC_ALIGN(dma_rxsize);
210 priv->dma_buf_sz = STMMAC_ALIGN(buf_sz);
212 + alloc_dma_desc_resources(priv);
214 + pr_err("%s: DMA descriptors allocation failed\n", __func__);
215 + goto dma_desc_error;
218 ret = init_dma_desc_rings(dev);
220 pr_err("%s: DMA descriptors initialization failed\n", __func__);