Commit 47bd10d1 authored by Guo-Fu Tseng's avatar Guo-Fu Tseng Committed by David S. Miller

jme: Change bufinf memory location

Instead of using a large chunk of memory space preserved for
for modules, using kmalloc to obtain the needed memory.
Signed-off-by: default avatarGuo-Fu Tseng <cooldavid@cooldavid.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 44d8d2e9
...@@ -522,12 +522,8 @@ jme_setup_tx_resources(struct jme_adapter *jme) ...@@ -522,12 +522,8 @@ jme_setup_tx_resources(struct jme_adapter *jme)
&(txring->dmaalloc), &(txring->dmaalloc),
GFP_ATOMIC); GFP_ATOMIC);
if (!txring->alloc) { if (!txring->alloc)
txring->desc = NULL; goto err_set_null;
txring->dmaalloc = 0;
txring->dma = 0;
return -ENOMEM;
}
/* /*
* 16 Bytes align * 16 Bytes align
...@@ -539,6 +535,11 @@ jme_setup_tx_resources(struct jme_adapter *jme) ...@@ -539,6 +535,11 @@ jme_setup_tx_resources(struct jme_adapter *jme)
atomic_set(&txring->next_to_clean, 0); atomic_set(&txring->next_to_clean, 0);
atomic_set(&txring->nr_free, jme->tx_ring_size); atomic_set(&txring->nr_free, jme->tx_ring_size);
txring->bufinf = kmalloc(sizeof(struct jme_buffer_info) *
jme->tx_ring_size, GFP_ATOMIC);
if (unlikely(!(txring->bufinf)))
goto err_free_txring;
/* /*
* Initialize Transmit Descriptors * Initialize Transmit Descriptors
*/ */
...@@ -547,6 +548,20 @@ jme_setup_tx_resources(struct jme_adapter *jme) ...@@ -547,6 +548,20 @@ jme_setup_tx_resources(struct jme_adapter *jme)
sizeof(struct jme_buffer_info) * jme->tx_ring_size); sizeof(struct jme_buffer_info) * jme->tx_ring_size);
return 0; return 0;
err_free_txring:
dma_free_coherent(&(jme->pdev->dev),
TX_RING_ALLOC_SIZE(jme->tx_ring_size),
txring->alloc,
txring->dmaalloc);
err_set_null:
txring->desc = NULL;
txring->dmaalloc = 0;
txring->dma = 0;
txring->bufinf = NULL;
return -ENOMEM;
} }
static void static void
...@@ -557,16 +572,19 @@ jme_free_tx_resources(struct jme_adapter *jme) ...@@ -557,16 +572,19 @@ jme_free_tx_resources(struct jme_adapter *jme)
struct jme_buffer_info *txbi; struct jme_buffer_info *txbi;
if (txring->alloc) { if (txring->alloc) {
for (i = 0 ; i < jme->tx_ring_size ; ++i) { if (txring->bufinf) {
txbi = txring->bufinf + i; for (i = 0 ; i < jme->tx_ring_size ; ++i) {
if (txbi->skb) { txbi = txring->bufinf + i;
dev_kfree_skb(txbi->skb); if (txbi->skb) {
txbi->skb = NULL; dev_kfree_skb(txbi->skb);
txbi->skb = NULL;
}
txbi->mapping = 0;
txbi->len = 0;
txbi->nr_desc = 0;
txbi->start_xmit = 0;
} }
txbi->mapping = 0; kfree(txring->bufinf);
txbi->len = 0;
txbi->nr_desc = 0;
txbi->start_xmit = 0;
} }
dma_free_coherent(&(jme->pdev->dev), dma_free_coherent(&(jme->pdev->dev),
...@@ -578,11 +596,11 @@ jme_free_tx_resources(struct jme_adapter *jme) ...@@ -578,11 +596,11 @@ jme_free_tx_resources(struct jme_adapter *jme)
txring->desc = NULL; txring->desc = NULL;
txring->dmaalloc = 0; txring->dmaalloc = 0;
txring->dma = 0; txring->dma = 0;
txring->bufinf = NULL;
} }
txring->next_to_use = 0; txring->next_to_use = 0;
atomic_set(&txring->next_to_clean, 0); atomic_set(&txring->next_to_clean, 0);
atomic_set(&txring->nr_free, 0); atomic_set(&txring->nr_free, 0);
} }
static inline void static inline void
...@@ -720,8 +738,11 @@ jme_free_rx_resources(struct jme_adapter *jme) ...@@ -720,8 +738,11 @@ jme_free_rx_resources(struct jme_adapter *jme)
struct jme_ring *rxring = &(jme->rxring[0]); struct jme_ring *rxring = &(jme->rxring[0]);
if (rxring->alloc) { if (rxring->alloc) {
for (i = 0 ; i < jme->rx_ring_size ; ++i) if (rxring->bufinf) {
jme_free_rx_buf(jme, i); for (i = 0 ; i < jme->rx_ring_size ; ++i)
jme_free_rx_buf(jme, i);
kfree(rxring->bufinf);
}
dma_free_coherent(&(jme->pdev->dev), dma_free_coherent(&(jme->pdev->dev),
RX_RING_ALLOC_SIZE(jme->rx_ring_size), RX_RING_ALLOC_SIZE(jme->rx_ring_size),
...@@ -731,6 +752,7 @@ jme_free_rx_resources(struct jme_adapter *jme) ...@@ -731,6 +752,7 @@ jme_free_rx_resources(struct jme_adapter *jme)
rxring->desc = NULL; rxring->desc = NULL;
rxring->dmaalloc = 0; rxring->dmaalloc = 0;
rxring->dma = 0; rxring->dma = 0;
rxring->bufinf = NULL;
} }
rxring->next_to_use = 0; rxring->next_to_use = 0;
atomic_set(&rxring->next_to_clean, 0); atomic_set(&rxring->next_to_clean, 0);
...@@ -746,12 +768,8 @@ jme_setup_rx_resources(struct jme_adapter *jme) ...@@ -746,12 +768,8 @@ jme_setup_rx_resources(struct jme_adapter *jme)
RX_RING_ALLOC_SIZE(jme->rx_ring_size), RX_RING_ALLOC_SIZE(jme->rx_ring_size),
&(rxring->dmaalloc), &(rxring->dmaalloc),
GFP_ATOMIC); GFP_ATOMIC);
if (!rxring->alloc) { if (!rxring->alloc)
rxring->desc = NULL; goto err_set_null;
rxring->dmaalloc = 0;
rxring->dma = 0;
return -ENOMEM;
}
/* /*
* 16 Bytes align * 16 Bytes align
...@@ -762,9 +780,16 @@ jme_setup_rx_resources(struct jme_adapter *jme) ...@@ -762,9 +780,16 @@ jme_setup_rx_resources(struct jme_adapter *jme)
rxring->next_to_use = 0; rxring->next_to_use = 0;
atomic_set(&rxring->next_to_clean, 0); atomic_set(&rxring->next_to_clean, 0);
rxring->bufinf = kmalloc(sizeof(struct jme_buffer_info) *
jme->rx_ring_size, GFP_ATOMIC);
if (unlikely(!(rxring->bufinf)))
goto err_free_rxring;
/* /*
* Initiallize Receive Descriptors * Initiallize Receive Descriptors
*/ */
memset(rxring->bufinf, 0,
sizeof(struct jme_buffer_info) * jme->rx_ring_size);
for (i = 0 ; i < jme->rx_ring_size ; ++i) { for (i = 0 ; i < jme->rx_ring_size ; ++i) {
if (unlikely(jme_make_new_rx_buf(jme, i))) { if (unlikely(jme_make_new_rx_buf(jme, i))) {
jme_free_rx_resources(jme); jme_free_rx_resources(jme);
...@@ -775,6 +800,19 @@ jme_setup_rx_resources(struct jme_adapter *jme) ...@@ -775,6 +800,19 @@ jme_setup_rx_resources(struct jme_adapter *jme)
} }
return 0; return 0;
err_free_rxring:
dma_free_coherent(&(jme->pdev->dev),
RX_RING_ALLOC_SIZE(jme->rx_ring_size),
rxring->alloc,
rxring->dmaalloc);
err_set_null:
rxring->desc = NULL;
rxring->dmaalloc = 0;
rxring->dma = 0;
rxring->bufinf = NULL;
return -ENOMEM;
} }
static inline void static inline void
......
...@@ -372,7 +372,6 @@ struct jme_buffer_info { ...@@ -372,7 +372,6 @@ struct jme_buffer_info {
/* /*
* The structure holding buffer information and ring descriptors all together. * The structure holding buffer information and ring descriptors all together.
*/ */
#define MAX_RING_DESC_NR 1024
struct jme_ring { struct jme_ring {
void *alloc; /* pointer to allocated memory */ void *alloc; /* pointer to allocated memory */
void *desc; /* pointer to ring memory */ void *desc; /* pointer to ring memory */
...@@ -380,7 +379,7 @@ struct jme_ring { ...@@ -380,7 +379,7 @@ struct jme_ring {
dma_addr_t dma; /* phys address for ring dma */ dma_addr_t dma; /* phys address for ring dma */
/* Buffer information corresponding to each descriptor */ /* Buffer information corresponding to each descriptor */
struct jme_buffer_info bufinf[MAX_RING_DESC_NR]; struct jme_buffer_info *bufinf;
int next_to_use; int next_to_use;
atomic_t next_to_clean; atomic_t next_to_clean;
......
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