From 5e65a384e2bbe8e01cc1715a222e609514051f37 Mon Sep 17 00:00:00 2001 From: Alex Forencich Date: Fri, 10 Dec 2021 21:04:52 -0800 Subject: [PATCH] Track ring active state --- modules/mqnic/mqnic.h | 3 +++ modules/mqnic/mqnic_cq.c | 11 ++++++++++- modules/mqnic/mqnic_eq.c | 11 ++++++++++- modules/mqnic/mqnic_rx.c | 11 ++++++++++- modules/mqnic/mqnic_tx.c | 11 ++++++++++- 5 files changed, 43 insertions(+), 4 deletions(-) diff --git a/modules/mqnic/mqnic.h b/modules/mqnic/mqnic.h index df849fdef..a6c1d2eb5 100644 --- a/modules/mqnic/mqnic.h +++ b/modules/mqnic/mqnic.h @@ -200,6 +200,7 @@ struct mqnic_ring { struct net_device *ndev; struct mqnic_priv *priv; int ring_index; + int active; u32 hw_ptr_mask; u8 __iomem *hw_addr; @@ -225,6 +226,7 @@ struct mqnic_cq_ring { struct napi_struct napi; int ring_index; int eq_index; + int active; void (*handler)(struct mqnic_cq_ring *ring); @@ -251,6 +253,7 @@ struct mqnic_eq_ring { struct mqnic_priv *priv; int ring_index; int int_index; + int active; int irq; diff --git a/modules/mqnic/mqnic_cq.c b/modules/mqnic/mqnic_cq.c index f3edd5c24..21f66a43c 100644 --- a/modules/mqnic/mqnic_cq.c +++ b/modules/mqnic/mqnic_cq.c @@ -50,6 +50,7 @@ int mqnic_create_cq_ring(struct mqnic_priv *priv, struct mqnic_cq_ring **ring_pt ring->priv = priv; ring->ring_index = index; + ring->active = 0; ring->size = roundup_pow_of_two(size); ring->size_mask = ring->size - 1; @@ -98,7 +99,8 @@ void mqnic_destroy_cq_ring(struct mqnic_cq_ring **ring_ptr) struct mqnic_cq_ring *ring = *ring_ptr; *ring_ptr = NULL; - mqnic_deactivate_cq_ring(ring); + if (ring->active) + mqnic_deactivate_cq_ring(ring); dma_free_coherent(ring->priv->dev, ring->buf_size, ring->buf, ring->buf_dma_addr); kfree(ring); @@ -106,6 +108,9 @@ void mqnic_destroy_cq_ring(struct mqnic_cq_ring **ring_ptr) int mqnic_activate_cq_ring(struct mqnic_cq_ring *ring, int eq_index) { + if (ring->active) + mqnic_deactivate_cq_ring(ring); + ring->eq_index = eq_index; // deactivate queue @@ -122,6 +127,8 @@ int mqnic_activate_cq_ring(struct mqnic_cq_ring *ring, int eq_index) iowrite32(ilog2(ring->size) | MQNIC_CPL_QUEUE_ACTIVE_MASK, ring->hw_addr + MQNIC_CPL_QUEUE_ACTIVE_LOG_SIZE_REG); + ring->active = 1; + return 0; } @@ -131,6 +138,8 @@ void mqnic_deactivate_cq_ring(struct mqnic_cq_ring *ring) iowrite32(ilog2(ring->size), ring->hw_addr + MQNIC_CPL_QUEUE_ACTIVE_LOG_SIZE_REG); // disarm queue iowrite32(ring->eq_index, ring->hw_addr + MQNIC_CPL_QUEUE_INTERRUPT_INDEX_REG); + + ring->active = 0; } bool mqnic_is_cq_ring_empty(const struct mqnic_cq_ring *ring) diff --git a/modules/mqnic/mqnic_eq.c b/modules/mqnic/mqnic_eq.c index 7c3047398..4fd6b99d0 100644 --- a/modules/mqnic/mqnic_eq.c +++ b/modules/mqnic/mqnic_eq.c @@ -50,6 +50,7 @@ int mqnic_create_eq_ring(struct mqnic_priv *priv, struct mqnic_eq_ring **ring_pt ring->priv = priv; ring->ring_index = index; + ring->active = 0; ring->size = roundup_pow_of_two(size); ring->size_mask = ring->size - 1; @@ -101,7 +102,8 @@ void mqnic_destroy_eq_ring(struct mqnic_eq_ring **ring_ptr) struct device *dev = ring->priv->dev; *ring_ptr = NULL; - mqnic_deactivate_eq_ring(ring); + if (ring->active) + mqnic_deactivate_eq_ring(ring); dma_free_coherent(dev, ring->buf_size, ring->buf, ring->buf_dma_addr); kfree(ring); @@ -109,6 +111,9 @@ void mqnic_destroy_eq_ring(struct mqnic_eq_ring **ring_ptr) int mqnic_activate_eq_ring(struct mqnic_eq_ring *ring, int int_index) { + if (ring->active) + mqnic_deactivate_eq_ring(ring); + ring->int_index = int_index; // deactivate queue @@ -127,6 +132,8 @@ int mqnic_activate_eq_ring(struct mqnic_eq_ring *ring, int int_index) iowrite32(ilog2(ring->size) | MQNIC_EVENT_QUEUE_ACTIVE_MASK, ring->hw_addr + MQNIC_EVENT_QUEUE_ACTIVE_LOG_SIZE_REG); + ring->active = 1; + return 0; } @@ -136,6 +143,8 @@ void mqnic_deactivate_eq_ring(struct mqnic_eq_ring *ring) iowrite32(ilog2(ring->size), ring->hw_addr + MQNIC_EVENT_QUEUE_ACTIVE_LOG_SIZE_REG); // disarm queue iowrite32(ring->int_index, ring->hw_addr + MQNIC_EVENT_QUEUE_INTERRUPT_INDEX_REG); + + ring->active = 0; } bool mqnic_is_eq_ring_empty(const struct mqnic_eq_ring *ring) diff --git a/modules/mqnic/mqnic_rx.c b/modules/mqnic/mqnic_rx.c index 7194f3c89..4fdb58387 100644 --- a/modules/mqnic/mqnic_rx.c +++ b/modules/mqnic/mqnic_rx.c @@ -51,6 +51,7 @@ int mqnic_create_rx_ring(struct mqnic_priv *priv, struct mqnic_ring **ring_ptr, ring->priv = priv; ring->ring_index = index; + ring->active = 0; ring->size = roundup_pow_of_two(size); ring->size_mask = ring->size - 1; @@ -114,7 +115,8 @@ void mqnic_destroy_rx_ring(struct mqnic_ring **ring_ptr) struct mqnic_ring *ring = *ring_ptr; *ring_ptr = NULL; - mqnic_deactivate_rx_ring(ring); + if (ring->active) + mqnic_deactivate_rx_ring(ring); mqnic_free_rx_buf(ring); @@ -126,6 +128,9 @@ void mqnic_destroy_rx_ring(struct mqnic_ring **ring_ptr) int mqnic_activate_rx_ring(struct mqnic_ring *ring, int cpl_index) { + if (ring->active) + mqnic_deactivate_rx_ring(ring); + // deactivate queue iowrite32(0, ring->hw_addr + MQNIC_QUEUE_ACTIVE_LOG_SIZE_REG); // set base address @@ -140,6 +145,8 @@ int mqnic_activate_rx_ring(struct mqnic_ring *ring, int cpl_index) iowrite32(ilog2(ring->size) | (ring->log_desc_block_size << 8) | MQNIC_QUEUE_ACTIVE_MASK, ring->hw_addr + MQNIC_QUEUE_ACTIVE_LOG_SIZE_REG); + ring->active = 1; + mqnic_refill_rx_buffers(ring); return 0; @@ -150,6 +157,8 @@ void mqnic_deactivate_rx_ring(struct mqnic_ring *ring) // deactivate queue iowrite32(ilog2(ring->size) | (ring->log_desc_block_size << 8), ring->hw_addr + MQNIC_QUEUE_ACTIVE_LOG_SIZE_REG); + + ring->active = 0; } bool mqnic_is_rx_ring_empty(const struct mqnic_ring *ring) diff --git a/modules/mqnic/mqnic_tx.c b/modules/mqnic/mqnic_tx.c index 647820aa2..838be7fc4 100644 --- a/modules/mqnic/mqnic_tx.c +++ b/modules/mqnic/mqnic_tx.c @@ -52,6 +52,7 @@ int mqnic_create_tx_ring(struct mqnic_priv *priv, struct mqnic_ring **ring_ptr, ring->priv = priv; ring->ring_index = index; + ring->active = 0; ring->size = roundup_pow_of_two(size); ring->full_size = ring->size >> 1; @@ -116,7 +117,8 @@ void mqnic_destroy_tx_ring(struct mqnic_ring **ring_ptr) struct mqnic_ring *ring = *ring_ptr; *ring_ptr = NULL; - mqnic_deactivate_tx_ring(ring); + if (ring->active) + mqnic_deactivate_tx_ring(ring); mqnic_free_tx_buf(ring); @@ -128,6 +130,9 @@ void mqnic_destroy_tx_ring(struct mqnic_ring **ring_ptr) int mqnic_activate_tx_ring(struct mqnic_ring *ring, int cpl_index) { + if (ring->active) + mqnic_deactivate_tx_ring(ring); + // deactivate queue iowrite32(0, ring->hw_addr + MQNIC_QUEUE_ACTIVE_LOG_SIZE_REG); // set base address @@ -142,6 +147,8 @@ int mqnic_activate_tx_ring(struct mqnic_ring *ring, int cpl_index) iowrite32(ilog2(ring->size) | (ring->log_desc_block_size << 8) | MQNIC_QUEUE_ACTIVE_MASK, ring->hw_addr + MQNIC_QUEUE_ACTIVE_LOG_SIZE_REG); + ring->active = 1; + return 0; } @@ -150,6 +157,8 @@ void mqnic_deactivate_tx_ring(struct mqnic_ring *ring) // deactivate queue iowrite32(ilog2(ring->size) | (ring->log_desc_block_size << 8), ring->hw_addr + MQNIC_QUEUE_ACTIVE_LOG_SIZE_REG); + + ring->active = 0; } bool mqnic_is_tx_ring_empty(const struct mqnic_ring *ring)