Move the free, occ, windex and rinfex under a struct.
We can use memset to zero them and it will allow a cleaner way to extend
the variables for duplex rings.

Signed-off-by: Vignesh Raghavendra <vigne...@ti.com>
---
 drivers/soc/ti/k3-navss-ringacc.c | 89 ++++++++++++++++---------------
 1 file changed, 46 insertions(+), 43 deletions(-)

diff --git a/drivers/soc/ti/k3-navss-ringacc.c 
b/drivers/soc/ti/k3-navss-ringacc.c
index ecc4b8b5a0..f31ffaf5ae 100644
--- a/drivers/soc/ti/k3-navss-ringacc.c
+++ b/drivers/soc/ti/k3-navss-ringacc.c
@@ -126,6 +126,22 @@ struct k3_nav_ring_ops {
        int (*pop_head)(struct k3_nav_ring *ring, void *elm);
 };
 
+/**
+ * struct k3_nav_ring_state - Internal state tracking structure
+ *
+ * @free: Number of free entries
+ * @occ: Occupancy
+ * @windex: Write index
+ * @rindex: Read index
+ */
+struct k3_nav_ring_state {
+       u32 free;
+       u32 occ;
+       u32 windex;
+       u32 rindex;
+       u32 tdown_complete:1;
+};
+
 /**
  * struct k3_nav_ring - RA Ring descriptor
  *
@@ -139,10 +155,6 @@ struct k3_nav_ring_ops {
  * @elm_size - Size of the ring element
  * @mode - Ring mode
  * @flags - flags
- * @free - Number of free elements
- * @occ - Ring occupancy
- * @windex - Write index (only for @K3_NAV_RINGACC_RING_MODE_RING)
- * @rindex - Read index (only for @K3_NAV_RINGACC_RING_MODE_RING)
  * @ring_id - Ring Id
  * @parent - Pointer on struct @k3_nav_ringacc
  * @use_count - Use count for shared rings
@@ -161,10 +173,7 @@ struct k3_nav_ring {
        u32             flags;
 #define KNAV_RING_FLAG_BUSY    BIT(1)
 #define K3_NAV_RING_FLAG_SHARED        BIT(2)
-       u32             free;
-       u32             occ;
-       u32             windex;
-       u32             rindex;
+       struct k3_nav_ring_state state;
        u32             ring_id;
        struct k3_nav_ringacc   *parent;
        u32             use_count;
@@ -338,10 +347,7 @@ void k3_nav_ringacc_ring_reset(struct k3_nav_ring *ring)
        if (!ring || !(ring->flags & KNAV_RING_FLAG_BUSY))
                return;
 
-       ring->occ = 0;
-       ring->free = 0;
-       ring->rindex = 0;
-       ring->windex = 0;
+       memset(&ring->state, 0, sizeof(ring->state));
 
        k3_ringacc_ring_reset_sci(ring);
 }
@@ -546,10 +552,7 @@ int k3_nav_ringacc_ring_cfg(struct k3_nav_ring *ring,
        ring->size = cfg->size;
        ring->elm_size = cfg->elm_size;
        ring->mode = cfg->mode;
-       ring->occ = 0;
-       ring->free = 0;
-       ring->rindex = 0;
-       ring->windex = 0;
+       memset(&ring->state, 0, sizeof(ring->state));
 
        if (ring->proxy_id != K3_RINGACC_PROXY_NOT_USED)
                ring->proxy = ringacc->proxy_target_base +
@@ -625,10 +628,10 @@ u32 k3_nav_ringacc_ring_get_free(struct k3_nav_ring *ring)
        if (!ring || !(ring->flags & KNAV_RING_FLAG_BUSY))
                return -EINVAL;
 
-       if (!ring->free)
-               ring->free = ring->size - ringacc_readl(&ring->rt->occ);
+       if (!ring->state.free)
+               ring->state.free = ring->size - ringacc_readl(&ring->rt->occ);
 
-       return ring->free;
+       return ring->state.free;
 }
 
 u32 k3_nav_ringacc_ring_get_occ(struct k3_nav_ring *ring)
@@ -694,21 +697,21 @@ static int k3_nav_ringacc_ring_access_proxy(
                pr_debug("proxy:memcpy_fromio(x): --> ptr(%p), mode:%d\n",
                         ptr, access_mode);
                memcpy_fromio(elem, ptr, (4 << ring->elm_size));
-               ring->occ--;
+               ring->state.occ--;
                break;
        case K3_RINGACC_ACCESS_MODE_PUSH_TAIL:
        case K3_RINGACC_ACCESS_MODE_PUSH_HEAD:
                pr_debug("proxy:memcpy_toio(x): --> ptr(%p), mode:%d\n",
                         ptr, access_mode);
                memcpy_toio(ptr, elem, (4 << ring->elm_size));
-               ring->free--;
+               ring->state.free--;
                break;
        default:
                return -EINVAL;
        }
 
        pr_debug("proxy: free%d occ%d\n",
-                ring->free, ring->occ);
+                ring->state.free, ring->state.occ);
        return 0;
 }
 
@@ -763,21 +766,21 @@ static int k3_nav_ringacc_ring_access_io(
                pr_debug("memcpy_fromio(x): --> ptr(%p), mode:%d\n",
                         ptr, access_mode);
                memcpy_fromio(elem, ptr, (4 << ring->elm_size));
-               ring->occ--;
+               ring->state.occ--;
                break;
        case K3_RINGACC_ACCESS_MODE_PUSH_TAIL:
        case K3_RINGACC_ACCESS_MODE_PUSH_HEAD:
                pr_debug("memcpy_toio(x): --> ptr(%p), mode:%d\n",
                         ptr, access_mode);
                memcpy_toio(ptr, elem, (4 << ring->elm_size));
-               ring->free--;
+               ring->state.free--;
                break;
        default:
                return -EINVAL;
        }
 
        pr_debug("free%d index%d occ%d index%d\n",
-                ring->free, ring->windex, ring->occ, ring->rindex);
+                ring->state.free, ring->state.windex, ring->state.occ, 
ring->state.rindex);
        return 0;
 }
 
@@ -810,7 +813,7 @@ static int k3_nav_ringacc_ring_push_mem(struct k3_nav_ring 
*ring, void *elem)
 {
        void *elem_ptr;
 
-       elem_ptr = k3_nav_ringacc_get_elm_addr(ring, ring->windex);
+       elem_ptr = k3_nav_ringacc_get_elm_addr(ring, ring->state.windex);
 
        memcpy(elem_ptr, elem, (4 << ring->elm_size));
 
@@ -819,12 +822,12 @@ static int k3_nav_ringacc_ring_push_mem(struct 
k3_nav_ring *ring, void *elem)
                                 ring->size * (4 << ring->elm_size),
                                 ARCH_DMA_MINALIGN));
 
-       ring->windex = (ring->windex + 1) % ring->size;
-       ring->free--;
+       ring->state.windex = (ring->state.windex + 1) % ring->size;
+       ring->state.free--;
        ringacc_writel(1, &ring->rt->db);
 
        pr_debug("ring_push_mem: free%d index%d\n",
-                ring->free, ring->windex);
+                ring->state.free, ring->state.windex);
 
        return 0;
 }
@@ -833,7 +836,7 @@ static int k3_nav_ringacc_ring_pop_mem(struct k3_nav_ring 
*ring, void *elem)
 {
        void *elem_ptr;
 
-       elem_ptr = k3_nav_ringacc_get_elm_addr(ring, ring->rindex);
+       elem_ptr = k3_nav_ringacc_get_elm_addr(ring, ring->state.rindex);
 
        invalidate_dcache_range((unsigned long)ring->ring_mem_virt,
                                ALIGN((unsigned long)ring->ring_mem_virt +
@@ -842,12 +845,12 @@ static int k3_nav_ringacc_ring_pop_mem(struct k3_nav_ring 
*ring, void *elem)
 
        memcpy(elem, elem_ptr, (4 << ring->elm_size));
 
-       ring->rindex = (ring->rindex + 1) % ring->size;
-       ring->occ--;
+       ring->state.rindex = (ring->state.rindex + 1) % ring->size;
+       ring->state.occ--;
        ringacc_writel(-1, &ring->rt->db);
 
        pr_debug("ring_pop_mem: occ%d index%d pos_ptr%p\n",
-                ring->occ, ring->rindex, elem_ptr);
+                ring->state.occ, ring->state.rindex, elem_ptr);
        return 0;
 }
 
@@ -859,7 +862,7 @@ int k3_nav_ringacc_ring_push(struct k3_nav_ring *ring, void 
*elem)
                return -EINVAL;
 
        pr_debug("ring_push%d: free%d index%d\n",
-                ring->ring_id, ring->free, ring->windex);
+                ring->ring_id, ring->state.free, ring->state.windex);
 
        if (k3_nav_ringacc_ring_is_full(ring))
                return -ENOMEM;
@@ -878,7 +881,7 @@ int k3_nav_ringacc_ring_push_head(struct k3_nav_ring *ring, 
void *elem)
                return -EINVAL;
 
        pr_debug("ring_push_head: free%d index%d\n",
-                ring->free, ring->windex);
+                ring->state.free, ring->state.windex);
 
        if (k3_nav_ringacc_ring_is_full(ring))
                return -ENOMEM;
@@ -896,13 +899,13 @@ int k3_nav_ringacc_ring_pop(struct k3_nav_ring *ring, 
void *elem)
        if (!ring || !(ring->flags & KNAV_RING_FLAG_BUSY))
                return -EINVAL;
 
-       if (!ring->occ)
-               ring->occ = k3_nav_ringacc_ring_get_occ(ring);
+       if (!ring->state.occ)
+               ring->state.occ = k3_nav_ringacc_ring_get_occ(ring);
 
        pr_debug("ring_pop%d: occ%d index%d\n",
-                ring->ring_id, ring->occ, ring->rindex);
+                ring->ring_id, ring->state.occ, ring->state.rindex);
 
-       if (!ring->occ)
+       if (!ring->state.occ && !ring->state.tdown_complete)
                return -ENODATA;
 
        if (ring->ops && ring->ops->pop_head)
@@ -918,13 +921,13 @@ int k3_nav_ringacc_ring_pop_tail(struct k3_nav_ring 
*ring, void *elem)
        if (!ring || !(ring->flags & KNAV_RING_FLAG_BUSY))
                return -EINVAL;
 
-       if (!ring->occ)
-               ring->occ = k3_nav_ringacc_ring_get_occ(ring);
+       if (!ring->state.occ)
+               ring->state.occ = k3_nav_ringacc_ring_get_occ(ring);
 
        pr_debug("ring_pop_tail: occ%d index%d\n",
-                ring->occ, ring->rindex);
+                ring->state.occ, ring->state.rindex);
 
-       if (!ring->occ)
+       if (!ring->state.occ)
                return -ENODATA;
 
        if (ring->ops && ring->ops->pop_tail)
-- 
2.27.0

Reply via email to