[PATCH 2/3] staging: et131x: simplify tx dma code
ZHAO Gang
gamerh2o at gmail.com
Wed Nov 27 07:45:13 UTC 2013
combine two dma_alloc_coherent to one
Signed-off-by: ZHAO Gang <gamerh2o at gmail.com>
---
drivers/staging/et131x/et131x.c | 72 ++++++++++++-----------------------------
1 file changed, 20 insertions(+), 52 deletions(-)
diff --git a/drivers/staging/et131x/et131x.c b/drivers/staging/et131x/et131x.c
index 409949f..45bb681 100644
--- a/drivers/staging/et131x/et131x.c
+++ b/drivers/staging/et131x/et131x.c
@@ -2717,12 +2717,7 @@ static void et131x_handle_recv_interrupt(struct et131x_adapter *adapter)
adapter->rx_ring.unfinished_receives = false;
}
-/* et131x_tx_dma_memory_alloc
- * @adapter: pointer to our private adapter structure
- *
- * Returns 0 on success and errno on failure (as defined in errno.h).
- *
- * Allocates memory that will be visible both to the device and to the CPU.
+/* Allocates memory that will be visible both to the device and to the CPU.
* The OS will pass us packets, pointers to which we will insert in the Tx
* Descriptor queue. The device will read this queue to find the packets in
* memory. The device will update the "status" in memory each time it xmits a
@@ -2730,75 +2725,48 @@ static void et131x_handle_recv_interrupt(struct et131x_adapter *adapter)
*/
static int et131x_tx_dma_memory_alloc(struct et131x_adapter *adapter)
{
- int desc_size = 0;
+ int desc_size;
struct tx_ring *tx_ring = &adapter->tx_ring;
/* Allocate memory for the TCB's (Transmit Control Block) */
- adapter->tx_ring.tcb_ring = kcalloc(NUM_TCB, sizeof(struct tcb),
- GFP_ATOMIC | GFP_DMA);
- if (!adapter->tx_ring.tcb_ring)
+ tx_ring->tcb_ring = kcalloc(NUM_TCB, sizeof(struct tcb), GFP_KERNEL);
+ if (!tx_ring->tcb_ring)
return -ENOMEM;
- desc_size = (sizeof(struct tx_desc) * NUM_DESC_PER_RING_TX);
- tx_ring->tx_desc_ring =
- (struct tx_desc *)dma_alloc_coherent(&adapter->pdev->dev,
- desc_size,
- &tx_ring->tx_desc_ring_pa,
- GFP_KERNEL);
- if (!adapter->tx_ring.tx_desc_ring) {
+ desc_size = sizeof(struct tx_desc) * NUM_DESC_PER_RING_TX;
+ /* Allocate dma memory for Tx descriptors and Tx status block */
+ tx_ring->tx_desc_ring = dma_alloc_coherent(&adapter->pdev->dev,
+ desc_size + sizeof(u32),
+ &tx_ring->tx_desc_ring_pa,
+ GFP_KERNEL);
+
+ if (!tx_ring->tx_desc_ring) {
+ kfree(tx_ring->tcb_ring);
dev_err(&adapter->pdev->dev,
"Cannot alloc memory for Tx Ring\n");
- return -ENOMEM;
- }
- /* Save physical address
- *
- * NOTE: dma_alloc_coherent(), used above to alloc DMA regions,
- * ALWAYS returns SAC (32-bit) addresses. If DAC (64-bit) addresses
- * are ever returned, make sure the high part is retrieved here before
- * storing the adjusted address.
- */
- /* Allocate memory for the Tx status block */
- tx_ring->tx_status = dma_alloc_coherent(&adapter->pdev->dev,
- sizeof(u32),
- &tx_ring->tx_status_pa,
- GFP_KERNEL);
- if (!adapter->tx_ring.tx_status_pa) {
- dev_err(&adapter->pdev->dev,
- "Cannot alloc memory for Tx status block\n");
return -ENOMEM;
}
+
+ tx_ring->tx_status = (void *)tx_ring->tx_desc_ring + desc_size;
+ tx_ring->tx_status_pa = tx_ring->tx_desc_ring_pa + desc_size;
+
return 0;
}
-/* et131x_tx_dma_memory_free - Free all memory allocated within this module
- * @adapter: pointer to our private adapter structure
- *
- * Returns 0 on success and errno on failure (as defined in errno.h).
- */
static void et131x_tx_dma_memory_free(struct et131x_adapter *adapter)
{
- int desc_size = 0;
+ int desc_size;
if (adapter->tx_ring.tx_desc_ring) {
- /* Free memory relating to Tx rings here */
+ /* Free Tx descriptors and Tx status block memory */
desc_size = (sizeof(struct tx_desc) * NUM_DESC_PER_RING_TX);
dma_free_coherent(&adapter->pdev->dev,
- desc_size,
+ desc_size + sizeof(u32),
adapter->tx_ring.tx_desc_ring,
adapter->tx_ring.tx_desc_ring_pa);
- adapter->tx_ring.tx_desc_ring = NULL;
}
- /* Free memory for the Tx status block */
- if (adapter->tx_ring.tx_status) {
- dma_free_coherent(&adapter->pdev->dev,
- sizeof(u32),
- adapter->tx_ring.tx_status,
- adapter->tx_ring.tx_status_pa);
-
- adapter->tx_ring.tx_status = NULL;
- }
/* Free the memory for the tcb structures */
kfree(adapter->tx_ring.tcb_ring);
}
--
1.8.3.1
More information about the devel
mailing list