Skip to content

Commit 6b3da0b

Browse files
Peter UjfalusiSantoshShilimkar
authored andcommitted
soc: ti: k3-ringacc: Move state tracking variables under a struct
Move the free, occ, windex and rindex under a struct. We can use memset to zero them and it will allow a cleaner way to extend driver functionality in the future, Signed-off-by: Peter Ujfalusi <[email protected]> Signed-off-by: Grygorii Strashko <[email protected]> Signed-off-by: Santosh Shilimkar <[email protected]>
1 parent 19e3b58 commit 6b3da0b

File tree

1 file changed

+51
-48
lines changed

1 file changed

+51
-48
lines changed

drivers/soc/ti/k3-ringacc.c

Lines changed: 51 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,21 @@ struct k3_ring_ops {
108108
int (*pop_head)(struct k3_ring *ring, void *elm);
109109
};
110110

111+
/**
112+
* struct k3_ring_state - Internal state tracking structure
113+
*
114+
* @free: Number of free entries
115+
* @occ: Occupancy
116+
* @windex: Write index
117+
* @rindex: Read index
118+
*/
119+
struct k3_ring_state {
120+
u32 free;
121+
u32 occ;
122+
u32 windex;
123+
u32 rindex;
124+
};
125+
111126
/**
112127
* struct k3_ring - RA Ring descriptor
113128
*
@@ -121,10 +136,6 @@ struct k3_ring_ops {
121136
* @elm_size: Size of the ring element
122137
* @mode: Ring mode
123138
* @flags: flags
124-
* @free: Number of free elements
125-
* @occ: Ring occupancy
126-
* @windex: Write index (only for @K3_RINGACC_RING_MODE_RING)
127-
* @rindex: Read index (only for @K3_RINGACC_RING_MODE_RING)
128139
* @ring_id: Ring Id
129140
* @parent: Pointer on struct @k3_ringacc
130141
* @use_count: Use count for shared rings
@@ -143,10 +154,7 @@ struct k3_ring {
143154
u32 flags;
144155
#define K3_RING_FLAG_BUSY BIT(1)
145156
#define K3_RING_FLAG_SHARED BIT(2)
146-
u32 free;
147-
u32 occ;
148-
u32 windex;
149-
u32 rindex;
157+
struct k3_ring_state state;
150158
u32 ring_id;
151159
struct k3_ringacc *parent;
152160
u32 use_count;
@@ -339,10 +347,7 @@ void k3_ringacc_ring_reset(struct k3_ring *ring)
339347
if (!ring || !(ring->flags & K3_RING_FLAG_BUSY))
340348
return;
341349

342-
ring->occ = 0;
343-
ring->free = 0;
344-
ring->rindex = 0;
345-
ring->windex = 0;
350+
memset(&ring->state, 0, sizeof(ring->state));
346351

347352
k3_ringacc_ring_reset_sci(ring);
348353
}
@@ -590,10 +595,7 @@ int k3_ringacc_ring_cfg(struct k3_ring *ring, struct k3_ring_cfg *cfg)
590595
ring->size = cfg->size;
591596
ring->elm_size = cfg->elm_size;
592597
ring->mode = cfg->mode;
593-
ring->occ = 0;
594-
ring->free = 0;
595-
ring->rindex = 0;
596-
ring->windex = 0;
598+
memset(&ring->state, 0, sizeof(ring->state));
597599

598600
if (ring->proxy_id != K3_RINGACC_PROXY_NOT_USED)
599601
ring->proxy = ringacc->proxy_target_base +
@@ -664,10 +666,10 @@ u32 k3_ringacc_ring_get_free(struct k3_ring *ring)
664666
if (!ring || !(ring->flags & K3_RING_FLAG_BUSY))
665667
return -EINVAL;
666668

667-
if (!ring->free)
668-
ring->free = ring->size - readl(&ring->rt->occ);
669+
if (!ring->state.free)
670+
ring->state.free = ring->size - readl(&ring->rt->occ);
669671

670-
return ring->free;
672+
return ring->state.free;
671673
}
672674
EXPORT_SYMBOL_GPL(k3_ringacc_ring_get_free);
673675

@@ -738,22 +740,22 @@ static int k3_ringacc_ring_access_proxy(struct k3_ring *ring, void *elem,
738740
"proxy:memcpy_fromio(x): --> ptr(%p), mode:%d\n", ptr,
739741
access_mode);
740742
memcpy_fromio(elem, ptr, (4 << ring->elm_size));
741-
ring->occ--;
743+
ring->state.occ--;
742744
break;
743745
case K3_RINGACC_ACCESS_MODE_PUSH_TAIL:
744746
case K3_RINGACC_ACCESS_MODE_PUSH_HEAD:
745747
dev_dbg(ring->parent->dev,
746748
"proxy:memcpy_toio(x): --> ptr(%p), mode:%d\n", ptr,
747749
access_mode);
748750
memcpy_toio(ptr, elem, (4 << ring->elm_size));
749-
ring->free--;
751+
ring->state.free--;
750752
break;
751753
default:
752754
return -EINVAL;
753755
}
754756

755-
dev_dbg(ring->parent->dev, "proxy: free%d occ%d\n", ring->free,
756-
ring->occ);
757+
dev_dbg(ring->parent->dev, "proxy: free%d occ%d\n", ring->state.free,
758+
ring->state.occ);
757759
return 0;
758760
}
759761

@@ -808,22 +810,23 @@ static int k3_ringacc_ring_access_io(struct k3_ring *ring, void *elem,
808810
"memcpy_fromio(x): --> ptr(%p), mode:%d\n", ptr,
809811
access_mode);
810812
memcpy_fromio(elem, ptr, (4 << ring->elm_size));
811-
ring->occ--;
813+
ring->state.occ--;
812814
break;
813815
case K3_RINGACC_ACCESS_MODE_PUSH_TAIL:
814816
case K3_RINGACC_ACCESS_MODE_PUSH_HEAD:
815817
dev_dbg(ring->parent->dev,
816818
"memcpy_toio(x): --> ptr(%p), mode:%d\n", ptr,
817819
access_mode);
818820
memcpy_toio(ptr, elem, (4 << ring->elm_size));
819-
ring->free--;
821+
ring->state.free--;
820822
break;
821823
default:
822824
return -EINVAL;
823825
}
824826

825-
dev_dbg(ring->parent->dev, "free%d index%d occ%d index%d\n", ring->free,
826-
ring->windex, ring->occ, ring->rindex);
827+
dev_dbg(ring->parent->dev, "free%d index%d occ%d index%d\n",
828+
ring->state.free, ring->state.windex, ring->state.occ,
829+
ring->state.rindex);
827830
return 0;
828831
}
829832

@@ -855,16 +858,16 @@ static int k3_ringacc_ring_push_mem(struct k3_ring *ring, void *elem)
855858
{
856859
void *elem_ptr;
857860

858-
elem_ptr = k3_ringacc_get_elm_addr(ring, ring->windex);
861+
elem_ptr = k3_ringacc_get_elm_addr(ring, ring->state.windex);
859862

860863
memcpy(elem_ptr, elem, (4 << ring->elm_size));
861864

862-
ring->windex = (ring->windex + 1) % ring->size;
863-
ring->free--;
865+
ring->state.windex = (ring->state.windex + 1) % ring->size;
866+
ring->state.free--;
864867
writel(1, &ring->rt->db);
865868

866869
dev_dbg(ring->parent->dev, "ring_push_mem: free%d index%d\n",
867-
ring->free, ring->windex);
870+
ring->state.free, ring->state.windex);
868871

869872
return 0;
870873
}
@@ -873,16 +876,16 @@ static int k3_ringacc_ring_pop_mem(struct k3_ring *ring, void *elem)
873876
{
874877
void *elem_ptr;
875878

876-
elem_ptr = k3_ringacc_get_elm_addr(ring, ring->rindex);
879+
elem_ptr = k3_ringacc_get_elm_addr(ring, ring->state.rindex);
877880

878881
memcpy(elem, elem_ptr, (4 << ring->elm_size));
879882

880-
ring->rindex = (ring->rindex + 1) % ring->size;
881-
ring->occ--;
883+
ring->state.rindex = (ring->state.rindex + 1) % ring->size;
884+
ring->state.occ--;
882885
writel(-1, &ring->rt->db);
883886

884887
dev_dbg(ring->parent->dev, "ring_pop_mem: occ%d index%d pos_ptr%p\n",
885-
ring->occ, ring->rindex, elem_ptr);
888+
ring->state.occ, ring->state.rindex, elem_ptr);
886889
return 0;
887890
}
888891

@@ -893,8 +896,8 @@ int k3_ringacc_ring_push(struct k3_ring *ring, void *elem)
893896
if (!ring || !(ring->flags & K3_RING_FLAG_BUSY))
894897
return -EINVAL;
895898

896-
dev_dbg(ring->parent->dev, "ring_push: free%d index%d\n", ring->free,
897-
ring->windex);
899+
dev_dbg(ring->parent->dev, "ring_push: free%d index%d\n",
900+
ring->state.free, ring->state.windex);
898901

899902
if (k3_ringacc_ring_is_full(ring))
900903
return -ENOMEM;
@@ -914,7 +917,7 @@ int k3_ringacc_ring_push_head(struct k3_ring *ring, void *elem)
914917
return -EINVAL;
915918

916919
dev_dbg(ring->parent->dev, "ring_push_head: free%d index%d\n",
917-
ring->free, ring->windex);
920+
ring->state.free, ring->state.windex);
918921

919922
if (k3_ringacc_ring_is_full(ring))
920923
return -ENOMEM;
@@ -933,13 +936,13 @@ int k3_ringacc_ring_pop(struct k3_ring *ring, void *elem)
933936
if (!ring || !(ring->flags & K3_RING_FLAG_BUSY))
934937
return -EINVAL;
935938

936-
if (!ring->occ)
937-
ring->occ = k3_ringacc_ring_get_occ(ring);
939+
if (!ring->state.occ)
940+
ring->state.occ = k3_ringacc_ring_get_occ(ring);
938941

939-
dev_dbg(ring->parent->dev, "ring_pop: occ%d index%d\n", ring->occ,
940-
ring->rindex);
942+
dev_dbg(ring->parent->dev, "ring_pop: occ%d index%d\n", ring->state.occ,
943+
ring->state.rindex);
941944

942-
if (!ring->occ)
945+
if (!ring->state.occ)
943946
return -ENODATA;
944947

945948
if (ring->ops && ring->ops->pop_head)
@@ -956,13 +959,13 @@ int k3_ringacc_ring_pop_tail(struct k3_ring *ring, void *elem)
956959
if (!ring || !(ring->flags & K3_RING_FLAG_BUSY))
957960
return -EINVAL;
958961

959-
if (!ring->occ)
960-
ring->occ = k3_ringacc_ring_get_occ(ring);
962+
if (!ring->state.occ)
963+
ring->state.occ = k3_ringacc_ring_get_occ(ring);
961964

962-
dev_dbg(ring->parent->dev, "ring_pop_tail: occ%d index%d\n", ring->occ,
963-
ring->rindex);
965+
dev_dbg(ring->parent->dev, "ring_pop_tail: occ%d index%d\n",
966+
ring->state.occ, ring->state.rindex);
964967

965-
if (!ring->occ)
968+
if (!ring->state.occ)
966969
return -ENODATA;
967970

968971
if (ring->ops && ring->ops->pop_tail)

0 commit comments

Comments
 (0)