From bfc8e959bf408c8c9def1c8da6b2cb5615f01ac5 Mon Sep 17 00:00:00 2001 From: Alex Forencich Date: Sun, 12 Dec 2021 01:52:24 -0800 Subject: [PATCH] Split ring buffer allocation from ring creation --- modules/mqnic/mqnic.h | 16 ++++++-- modules/mqnic/mqnic_cq.c | 69 +++++++++++++++++++++------------- modules/mqnic/mqnic_eq.c | 72 ++++++++++++++++++++++-------------- modules/mqnic/mqnic_netdev.c | 40 +++++++++++++++----- modules/mqnic/mqnic_rx.c | 70 +++++++++++++++++++++++------------ modules/mqnic/mqnic_tx.c | 70 +++++++++++++++++++++++------------ 6 files changed, 224 insertions(+), 113 deletions(-) diff --git a/modules/mqnic/mqnic.h b/modules/mqnic/mqnic.h index 8e13726f8..7033c11be 100644 --- a/modules/mqnic/mqnic.h +++ b/modules/mqnic/mqnic.h @@ -374,8 +374,10 @@ void mqnic_board_deinit(struct mqnic_dev *mqnic); // mqnic_eq.c int mqnic_create_eq_ring(struct mqnic_priv *priv, struct mqnic_eq_ring **ring_ptr, - int size, int stride, int index, u8 __iomem *hw_addr); + int index, u8 __iomem *hw_addr); void mqnic_destroy_eq_ring(struct mqnic_eq_ring **ring_ptr); +int mqnic_alloc_eq_ring(struct mqnic_eq_ring *ring, int size, int stride); +void mqnic_free_eq_ring(struct mqnic_eq_ring *ring); int mqnic_activate_eq_ring(struct mqnic_eq_ring *ring, int int_index); void mqnic_deactivate_eq_ring(struct mqnic_eq_ring *ring); bool mqnic_is_eq_ring_empty(const struct mqnic_eq_ring *ring); @@ -387,8 +389,10 @@ void mqnic_process_eq(struct mqnic_eq_ring *eq_ring); // mqnic_cq.c int mqnic_create_cq_ring(struct mqnic_priv *priv, struct mqnic_cq_ring **ring_ptr, - int size, int stride, int index, u8 __iomem *hw_addr); + int index, u8 __iomem *hw_addr); void mqnic_destroy_cq_ring(struct mqnic_cq_ring **ring_ptr); +int mqnic_alloc_cq_ring(struct mqnic_cq_ring *ring, int size, int stride); +void mqnic_free_cq_ring(struct mqnic_cq_ring *ring); int mqnic_activate_cq_ring(struct mqnic_cq_ring *ring, int eq_index); void mqnic_deactivate_cq_ring(struct mqnic_cq_ring *ring); bool mqnic_is_cq_ring_empty(const struct mqnic_cq_ring *ring); @@ -399,8 +403,10 @@ void mqnic_arm_cq(struct mqnic_cq_ring *ring); // mqnic_tx.c int mqnic_create_tx_ring(struct mqnic_priv *priv, struct mqnic_ring **ring_ptr, - int size, int stride, int index, u8 __iomem *hw_addr); + int index, u8 __iomem *hw_addr); void mqnic_destroy_tx_ring(struct mqnic_ring **ring_ptr); +int mqnic_alloc_tx_ring(struct mqnic_ring *ring, int size, int stride); +void mqnic_free_tx_ring(struct mqnic_ring *ring); int mqnic_activate_tx_ring(struct mqnic_ring *ring, int cpl_index); void mqnic_deactivate_tx_ring(struct mqnic_ring *ring); bool mqnic_is_tx_ring_empty(const struct mqnic_ring *ring); @@ -416,8 +422,10 @@ netdev_tx_t mqnic_start_xmit(struct sk_buff *skb, struct net_device *dev); // mqnic_rx.c int mqnic_create_rx_ring(struct mqnic_priv *priv, struct mqnic_ring **ring_ptr, - int size, int stride, int index, u8 __iomem *hw_addr); + int index, u8 __iomem *hw_addr); void mqnic_destroy_rx_ring(struct mqnic_ring **ring_ptr); +int mqnic_alloc_rx_ring(struct mqnic_ring *ring, int size, int stride); +void mqnic_free_rx_ring(struct mqnic_ring *ring); int mqnic_activate_rx_ring(struct mqnic_ring *ring, int cpl_index); void mqnic_deactivate_rx_ring(struct mqnic_ring *ring); bool mqnic_is_rx_ring_empty(const struct mqnic_ring *ring); diff --git a/modules/mqnic/mqnic_cq.c b/modules/mqnic/mqnic_cq.c index 17b4d14bc..72aab7fb9 100644 --- a/modules/mqnic/mqnic_cq.c +++ b/modules/mqnic/mqnic_cq.c @@ -36,11 +36,9 @@ #include "mqnic.h" int mqnic_create_cq_ring(struct mqnic_priv *priv, struct mqnic_cq_ring **ring_ptr, - int size, int stride, int index, u8 __iomem *hw_addr) + int index, u8 __iomem *hw_addr) { - struct device *dev = priv->dev; struct mqnic_cq_ring *ring; - int ret; ring = kzalloc(sizeof(*ring), GFP_KERNEL); if (!ring) @@ -52,22 +50,43 @@ int mqnic_create_cq_ring(struct mqnic_priv *priv, struct mqnic_cq_ring **ring_pt ring->ring_index = index; ring->active = 0; + ring->hw_addr = hw_addr; + ring->hw_ptr_mask = 0xffff; + ring->hw_head_ptr = hw_addr + MQNIC_CPL_QUEUE_HEAD_PTR_REG; + ring->hw_tail_ptr = hw_addr + MQNIC_CPL_QUEUE_TAIL_PTR_REG; + + ring->head_ptr = 0; + ring->tail_ptr = 0; + + // deactivate queue + iowrite32(0, ring->hw_addr + MQNIC_CPL_QUEUE_ACTIVE_LOG_SIZE_REG); + + *ring_ptr = ring; + return 0; +} + +void mqnic_destroy_cq_ring(struct mqnic_cq_ring **ring_ptr) +{ + struct mqnic_cq_ring *ring = *ring_ptr; + *ring_ptr = NULL; + + mqnic_free_cq_ring(ring); + + kfree(ring); +} + +int mqnic_alloc_cq_ring(struct mqnic_cq_ring *ring, int size, int stride) +{ + struct device *dev = ring->priv->dev; + ring->size = roundup_pow_of_two(size); ring->size_mask = ring->size - 1; ring->stride = roundup_pow_of_two(stride); ring->buf_size = ring->size * ring->stride; - ring->buf = dma_alloc_coherent(dev, ring->buf_size, - &ring->buf_dma_addr, GFP_KERNEL); - if (!ring->buf) { - ret = -ENOMEM; - goto fail_ring; - } - - ring->hw_addr = hw_addr; - ring->hw_ptr_mask = 0xffff; - ring->hw_head_ptr = hw_addr + MQNIC_CPL_QUEUE_HEAD_PTR_REG; - ring->hw_tail_ptr = hw_addr + MQNIC_CPL_QUEUE_TAIL_PTR_REG; + ring->buf = dma_alloc_coherent(dev, ring->buf_size, &ring->buf_dma_addr, GFP_KERNEL); + if (!ring->buf) + return -ENOMEM; ring->head_ptr = 0; ring->tail_ptr = 0; @@ -85,30 +104,30 @@ int mqnic_create_cq_ring(struct mqnic_priv *priv, struct mqnic_cq_ring **ring_pt // set size iowrite32(ilog2(ring->size), ring->hw_addr + MQNIC_CPL_QUEUE_ACTIVE_LOG_SIZE_REG); - *ring_ptr = ring; return 0; - -fail_ring: - kfree(ring); - *ring_ptr = NULL; - return ret; } -void mqnic_destroy_cq_ring(struct mqnic_cq_ring **ring_ptr) +void mqnic_free_cq_ring(struct mqnic_cq_ring *ring) { - struct mqnic_cq_ring *ring = *ring_ptr; - *ring_ptr = NULL; + struct device *dev = ring->priv->dev; mqnic_deactivate_cq_ring(ring); - dma_free_coherent(ring->priv->dev, ring->buf_size, ring->buf, ring->buf_dma_addr); - kfree(ring); + if (!ring->buf) + return; + + dma_free_coherent(dev, ring->buf_size, ring->buf, ring->buf_dma_addr); + ring->buf = NULL; + ring->buf_dma_addr = 0; } int mqnic_activate_cq_ring(struct mqnic_cq_ring *ring, int eq_index) { mqnic_deactivate_cq_ring(ring); + if (!ring->buf) + return -EINVAL; + ring->eq_index = eq_index; // deactivate queue diff --git a/modules/mqnic/mqnic_eq.c b/modules/mqnic/mqnic_eq.c index d45e2c5b7..0427fd55c 100644 --- a/modules/mqnic/mqnic_eq.c +++ b/modules/mqnic/mqnic_eq.c @@ -46,11 +46,9 @@ static int mqnic_eq_int(struct notifier_block *nb, unsigned long action, void *d } int mqnic_create_eq_ring(struct mqnic_priv *priv, struct mqnic_eq_ring **ring_ptr, - int size, int stride, int index, u8 __iomem *hw_addr) + int index, u8 __iomem *hw_addr) { - struct device *dev = priv->dev; struct mqnic_eq_ring *ring; - int ret; ring = kzalloc(sizeof(*ring), GFP_KERNEL); if (!ring) @@ -64,22 +62,43 @@ int mqnic_create_eq_ring(struct mqnic_priv *priv, struct mqnic_eq_ring **ring_pt ring->irq_nb.notifier_call = mqnic_eq_int; + ring->hw_addr = hw_addr; + ring->hw_ptr_mask = 0xffff; + ring->hw_head_ptr = hw_addr + MQNIC_EVENT_QUEUE_HEAD_PTR_REG; + ring->hw_tail_ptr = hw_addr + MQNIC_EVENT_QUEUE_TAIL_PTR_REG; + + ring->head_ptr = 0; + ring->tail_ptr = 0; + + // deactivate queue + iowrite32(0, ring->hw_addr + MQNIC_EVENT_QUEUE_ACTIVE_LOG_SIZE_REG); + + *ring_ptr = ring; + return 0; +} + +void mqnic_destroy_eq_ring(struct mqnic_eq_ring **ring_ptr) +{ + struct mqnic_eq_ring *ring = *ring_ptr; + *ring_ptr = NULL; + + mqnic_free_eq_ring(ring); + + kfree(ring); +} + +int mqnic_alloc_eq_ring(struct mqnic_eq_ring *ring, int size, int stride) +{ + struct device *dev = ring->priv->dev; + ring->size = roundup_pow_of_two(size); ring->size_mask = ring->size - 1; ring->stride = roundup_pow_of_two(stride); ring->buf_size = ring->size * ring->stride; - ring->buf = dma_alloc_coherent(dev, ring->buf_size, - &ring->buf_dma_addr, GFP_KERNEL); - if (!ring->buf) { - ret = -ENOMEM; - goto fail_ring; - } - - ring->hw_addr = hw_addr; - ring->hw_ptr_mask = 0xffff; - ring->hw_head_ptr = hw_addr + MQNIC_EVENT_QUEUE_HEAD_PTR_REG; - ring->hw_tail_ptr = hw_addr + MQNIC_EVENT_QUEUE_TAIL_PTR_REG; + ring->buf = dma_alloc_coherent(dev, ring->buf_size, &ring->buf_dma_addr, GFP_KERNEL); + if (!ring->buf) + return -ENOMEM; ring->head_ptr = 0; ring->tail_ptr = 0; @@ -92,32 +111,26 @@ int mqnic_create_eq_ring(struct mqnic_priv *priv, struct mqnic_eq_ring **ring_pt // set interrupt index iowrite32(0, ring->hw_addr + MQNIC_EVENT_QUEUE_INTERRUPT_INDEX_REG); // set pointers - iowrite32(ring->head_ptr & ring->hw_ptr_mask, - ring->hw_addr + MQNIC_EVENT_QUEUE_HEAD_PTR_REG); - iowrite32(ring->tail_ptr & ring->hw_ptr_mask, - ring->hw_addr + MQNIC_EVENT_QUEUE_TAIL_PTR_REG); + iowrite32(ring->head_ptr & ring->hw_ptr_mask, ring->hw_addr + MQNIC_EVENT_QUEUE_HEAD_PTR_REG); + iowrite32(ring->tail_ptr & ring->hw_ptr_mask, ring->hw_addr + MQNIC_EVENT_QUEUE_TAIL_PTR_REG); // set size iowrite32(ilog2(ring->size), ring->hw_addr + MQNIC_EVENT_QUEUE_ACTIVE_LOG_SIZE_REG); - *ring_ptr = ring; return 0; - -fail_ring: - kfree(ring); - *ring_ptr = NULL; - return ret; } -void mqnic_destroy_eq_ring(struct mqnic_eq_ring **ring_ptr) +void mqnic_free_eq_ring(struct mqnic_eq_ring *ring) { - struct mqnic_eq_ring *ring = *ring_ptr; struct device *dev = ring->priv->dev; - *ring_ptr = NULL; mqnic_deactivate_eq_ring(ring); + if (!ring->buf) + return; + dma_free_coherent(dev, ring->buf_size, ring->buf, ring->buf_dma_addr); - kfree(ring); + ring->buf = NULL; + ring->buf_dma_addr = 0; } int mqnic_activate_eq_ring(struct mqnic_eq_ring *ring, int int_index) @@ -126,6 +139,9 @@ int mqnic_activate_eq_ring(struct mqnic_eq_ring *ring, int int_index) mqnic_deactivate_eq_ring(ring); + if (!ring->buf) + return -EINVAL; + if (int_index < 0 || int_index >= ring->priv->mdev->irq_count) return -EINVAL; diff --git a/modules/mqnic/mqnic_netdev.c b/modules/mqnic/mqnic_netdev.c index 6d2d4030e..22ceace3e 100644 --- a/modules/mqnic/mqnic_netdev.c +++ b/modules/mqnic/mqnic_netdev.c @@ -478,36 +478,56 @@ int mqnic_create_netdev(struct mqnic_dev *mdev, struct net_device **ndev_ptr, // allocate rings for (k = 0; k < priv->event_queue_count; k++) { - ret = mqnic_create_eq_ring(priv, &priv->event_ring[k], 1024, MQNIC_EVENT_SIZE, k, - hw_addr + priv->event_queue_offset + k * MQNIC_EVENT_QUEUE_STRIDE); // TODO configure/constant + ret = mqnic_create_eq_ring(priv, &priv->event_ring[k], k, + hw_addr + priv->event_queue_offset + k * MQNIC_EVENT_QUEUE_STRIDE); + if (ret) + goto fail; + + ret = mqnic_alloc_eq_ring(priv->event_ring[k], 1024, MQNIC_EVENT_SIZE); // TODO configure/constant if (ret) goto fail; } for (k = 0; k < priv->tx_queue_count; k++) { - ret = mqnic_create_tx_ring(priv, &priv->tx_ring[k], 1024, MQNIC_DESC_SIZE * desc_block_size, k, - hw_addr + priv->tx_queue_offset + k * MQNIC_QUEUE_STRIDE); // TODO configure/constant + ret = mqnic_create_tx_ring(priv, &priv->tx_ring[k], k, + hw_addr + priv->tx_queue_offset + k * MQNIC_QUEUE_STRIDE); + if (ret) + goto fail; + + ret = mqnic_alloc_tx_ring(priv->tx_ring[k], 1024, MQNIC_DESC_SIZE * desc_block_size); // TODO configure/constant if (ret) goto fail; } for (k = 0; k < priv->tx_cpl_queue_count; k++) { - ret = mqnic_create_cq_ring(priv, &priv->tx_cpl_ring[k], 1024, MQNIC_CPL_SIZE, k, - hw_addr + priv->tx_cpl_queue_offset + k * MQNIC_CPL_QUEUE_STRIDE); // TODO configure/constant + ret = mqnic_create_cq_ring(priv, &priv->tx_cpl_ring[k], k, + hw_addr + priv->tx_cpl_queue_offset + k * MQNIC_CPL_QUEUE_STRIDE); + if (ret) + goto fail; + + ret = mqnic_alloc_cq_ring(priv->tx_cpl_ring[k], 1024, MQNIC_CPL_SIZE); // TODO configure/constant if (ret) goto fail; } for (k = 0; k < priv->rx_queue_count; k++) { - ret = mqnic_create_rx_ring(priv, &priv->rx_ring[k], 1024, MQNIC_DESC_SIZE, k, - hw_addr + priv->rx_queue_offset + k * MQNIC_QUEUE_STRIDE); // TODO configure/constant + ret = mqnic_create_rx_ring(priv, &priv->rx_ring[k], k, + hw_addr + priv->rx_queue_offset + k * MQNIC_QUEUE_STRIDE); + if (ret) + goto fail; + + ret = mqnic_alloc_rx_ring(priv->rx_ring[k], 1024, MQNIC_DESC_SIZE); // TODO configure/constant if (ret) goto fail; } for (k = 0; k < priv->rx_cpl_queue_count; k++) { - ret = mqnic_create_cq_ring(priv, &priv->rx_cpl_ring[k], 1024, MQNIC_CPL_SIZE, k, - hw_addr + priv->rx_cpl_queue_offset + k * MQNIC_CPL_QUEUE_STRIDE); // TODO configure/constant + ret = mqnic_create_cq_ring(priv, &priv->rx_cpl_ring[k], k, + hw_addr + priv->rx_cpl_queue_offset + k * MQNIC_CPL_QUEUE_STRIDE); + if (ret) + goto fail; + + ret = mqnic_alloc_cq_ring(priv->rx_cpl_ring[k], 1024, MQNIC_CPL_SIZE); // TODO configure/constant if (ret) goto fail; } diff --git a/modules/mqnic/mqnic_rx.c b/modules/mqnic/mqnic_rx.c index a9547d44a..a03ebaaba 100644 --- a/modules/mqnic/mqnic_rx.c +++ b/modules/mqnic/mqnic_rx.c @@ -36,11 +36,9 @@ #include "mqnic.h" int mqnic_create_rx_ring(struct mqnic_priv *priv, struct mqnic_ring **ring_ptr, - int size, int stride, int index, u8 __iomem *hw_addr) + int index, u8 __iomem *hw_addr) { - struct device *dev = priv->dev; struct mqnic_ring *ring; - int ret; ring = kzalloc(sizeof(*ring), GFP_KERNEL); if (!ring) @@ -53,6 +51,39 @@ int mqnic_create_rx_ring(struct mqnic_priv *priv, struct mqnic_ring **ring_ptr, ring->ring_index = index; ring->active = 0; + ring->hw_addr = hw_addr; + ring->hw_ptr_mask = 0xffff; + ring->hw_head_ptr = hw_addr + MQNIC_QUEUE_HEAD_PTR_REG; + ring->hw_tail_ptr = hw_addr + MQNIC_QUEUE_TAIL_PTR_REG; + + ring->head_ptr = 0; + ring->tail_ptr = 0; + ring->clean_tail_ptr = 0; + + // deactivate queue + iowrite32(0, ring->hw_addr + MQNIC_QUEUE_ACTIVE_LOG_SIZE_REG); + + *ring_ptr = ring; + return 0; +} + +void mqnic_destroy_rx_ring(struct mqnic_ring **ring_ptr) +{ + struct mqnic_ring *ring = *ring_ptr; + *ring_ptr = NULL; + + mqnic_free_rx_ring(ring); + + kfree(ring); +} + +int mqnic_alloc_rx_ring(struct mqnic_ring *ring, int size, int stride) +{ + int ret; + + if (ring->active || ring->buf) + return -EINVAL; + ring->size = roundup_pow_of_two(size); ring->size_mask = ring->size - 1; ring->stride = roundup_pow_of_two(stride); @@ -62,24 +93,16 @@ int mqnic_create_rx_ring(struct mqnic_priv *priv, struct mqnic_ring **ring_ptr, ring->desc_block_size = 1 << ring->log_desc_block_size; ring->rx_info = kvzalloc(sizeof(*ring->rx_info) * ring->size, GFP_KERNEL); - if (!ring->rx_info) { - ret = -ENOMEM; - goto fail_ring; - } + if (!ring->rx_info) + return -ENOMEM; ring->buf_size = ring->size * ring->stride; - ring->buf = dma_alloc_coherent(dev, ring->buf_size, - &ring->buf_dma_addr, GFP_KERNEL); + ring->buf = dma_alloc_coherent(ring->dev, ring->buf_size, &ring->buf_dma_addr, GFP_KERNEL); if (!ring->buf) { ret = -ENOMEM; goto fail_info; } - ring->hw_addr = hw_addr; - ring->hw_ptr_mask = 0xffff; - ring->hw_head_ptr = hw_addr + MQNIC_QUEUE_HEAD_PTR_REG; - ring->hw_tail_ptr = hw_addr + MQNIC_QUEUE_TAIL_PTR_REG; - ring->head_ptr = 0; ring->tail_ptr = 0; ring->clean_tail_ptr = 0; @@ -98,37 +121,38 @@ int mqnic_create_rx_ring(struct mqnic_priv *priv, struct mqnic_ring **ring_ptr, iowrite32(ilog2(ring->size) | (ring->log_desc_block_size << 8), ring->hw_addr + MQNIC_QUEUE_ACTIVE_LOG_SIZE_REG); - *ring_ptr = ring; return 0; fail_info: kvfree(ring->rx_info); ring->rx_info = NULL; -fail_ring: - kfree(ring); - *ring_ptr = NULL; return ret; } -void mqnic_destroy_rx_ring(struct mqnic_ring **ring_ptr) +void mqnic_free_rx_ring(struct mqnic_ring *ring) { - struct mqnic_ring *ring = *ring_ptr; - *ring_ptr = NULL; - mqnic_deactivate_rx_ring(ring); + if (!ring->buf) + return; + mqnic_free_rx_buf(ring); dma_free_coherent(ring->dev, ring->buf_size, ring->buf, ring->buf_dma_addr); + ring->buf = NULL; + ring->buf_dma_addr = 0; + kvfree(ring->rx_info); ring->rx_info = NULL; - kfree(ring); } int mqnic_activate_rx_ring(struct mqnic_ring *ring, int cpl_index) { mqnic_deactivate_rx_ring(ring); + if (!ring->buf) + return -EINVAL; + // deactivate queue iowrite32(0, ring->hw_addr + MQNIC_QUEUE_ACTIVE_LOG_SIZE_REG); // set base address diff --git a/modules/mqnic/mqnic_tx.c b/modules/mqnic/mqnic_tx.c index 27fdeef55..71950062f 100644 --- a/modules/mqnic/mqnic_tx.c +++ b/modules/mqnic/mqnic_tx.c @@ -37,11 +37,9 @@ #include "mqnic.h" int mqnic_create_tx_ring(struct mqnic_priv *priv, struct mqnic_ring **ring_ptr, - int size, int stride, int index, u8 __iomem *hw_addr) + int index, u8 __iomem *hw_addr) { - struct device *dev = priv->dev; struct mqnic_ring *ring; - int ret; ring = kzalloc(sizeof(*ring), GFP_KERNEL); if (!ring) @@ -54,6 +52,39 @@ int mqnic_create_tx_ring(struct mqnic_priv *priv, struct mqnic_ring **ring_ptr, ring->ring_index = index; ring->active = 0; + ring->hw_addr = hw_addr; + ring->hw_ptr_mask = 0xffff; + ring->hw_head_ptr = hw_addr + MQNIC_QUEUE_HEAD_PTR_REG; + ring->hw_tail_ptr = hw_addr + MQNIC_QUEUE_TAIL_PTR_REG; + + ring->head_ptr = 0; + ring->tail_ptr = 0; + ring->clean_tail_ptr = 0; + + // deactivate queue + iowrite32(0, ring->hw_addr + MQNIC_QUEUE_ACTIVE_LOG_SIZE_REG); + + *ring_ptr = ring; + return 0; +} + +void mqnic_destroy_tx_ring(struct mqnic_ring **ring_ptr) +{ + struct mqnic_ring *ring = *ring_ptr; + *ring_ptr = NULL; + + mqnic_free_tx_ring(ring); + + kfree(ring); +} + +int mqnic_alloc_tx_ring(struct mqnic_ring *ring, int size, int stride) +{ + int ret; + + if (ring->active || ring->buf) + return -EINVAL; + ring->size = roundup_pow_of_two(size); ring->full_size = ring->size >> 1; ring->size_mask = ring->size - 1; @@ -64,24 +95,16 @@ int mqnic_create_tx_ring(struct mqnic_priv *priv, struct mqnic_ring **ring_ptr, ring->desc_block_size = 1 << ring->log_desc_block_size; ring->tx_info = kvzalloc(sizeof(*ring->tx_info) * ring->size, GFP_KERNEL); - if (!ring->tx_info) { - ret = -ENOMEM; - goto fail_ring; - } + if (!ring->tx_info) + return -ENOMEM; ring->buf_size = ring->size * ring->stride; - ring->buf = dma_alloc_coherent(dev, ring->buf_size, - &ring->buf_dma_addr, GFP_KERNEL); + ring->buf = dma_alloc_coherent(ring->dev, ring->buf_size, &ring->buf_dma_addr, GFP_KERNEL); if (!ring->buf) { ret = -ENOMEM; goto fail_info; } - ring->hw_addr = hw_addr; - ring->hw_ptr_mask = 0xffff; - ring->hw_head_ptr = hw_addr + MQNIC_QUEUE_HEAD_PTR_REG; - ring->hw_tail_ptr = hw_addr + MQNIC_QUEUE_TAIL_PTR_REG; - ring->head_ptr = 0; ring->tail_ptr = 0; ring->clean_tail_ptr = 0; @@ -100,37 +123,38 @@ int mqnic_create_tx_ring(struct mqnic_priv *priv, struct mqnic_ring **ring_ptr, iowrite32(ilog2(ring->size) | (ring->log_desc_block_size << 8), ring->hw_addr + MQNIC_QUEUE_ACTIVE_LOG_SIZE_REG); - *ring_ptr = ring; return 0; fail_info: kvfree(ring->tx_info); ring->tx_info = NULL; -fail_ring: - kfree(ring); - *ring_ptr = NULL; return ret; } -void mqnic_destroy_tx_ring(struct mqnic_ring **ring_ptr) +void mqnic_free_tx_ring(struct mqnic_ring *ring) { - struct mqnic_ring *ring = *ring_ptr; - *ring_ptr = NULL; - mqnic_deactivate_tx_ring(ring); + if (!ring->buf) + return; + mqnic_free_tx_buf(ring); dma_free_coherent(ring->dev, ring->buf_size, ring->buf, ring->buf_dma_addr); + ring->buf = NULL; + ring->buf_dma_addr = 0; + kvfree(ring->tx_info); ring->tx_info = NULL; - kfree(ring); } int mqnic_activate_tx_ring(struct mqnic_ring *ring, int cpl_index) { mqnic_deactivate_tx_ring(ring); + if (!ring->buf) + return -EINVAL; + // deactivate queue iowrite32(0, ring->hw_addr + MQNIC_QUEUE_ACTIVE_LOG_SIZE_REG); // set base address