@@ -108,6 +108,21 @@ struct k3_ring_ops {
108
108
int (* pop_head )(struct k3_ring * ring , void * elm );
109
109
};
110
110
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
+
111
126
/**
112
127
* struct k3_ring - RA Ring descriptor
113
128
*
@@ -121,10 +136,6 @@ struct k3_ring_ops {
121
136
* @elm_size: Size of the ring element
122
137
* @mode: Ring mode
123
138
* @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)
128
139
* @ring_id: Ring Id
129
140
* @parent: Pointer on struct @k3_ringacc
130
141
* @use_count: Use count for shared rings
@@ -143,10 +154,7 @@ struct k3_ring {
143
154
u32 flags ;
144
155
#define K3_RING_FLAG_BUSY BIT(1)
145
156
#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 ;
150
158
u32 ring_id ;
151
159
struct k3_ringacc * parent ;
152
160
u32 use_count ;
@@ -339,10 +347,7 @@ void k3_ringacc_ring_reset(struct k3_ring *ring)
339
347
if (!ring || !(ring -> flags & K3_RING_FLAG_BUSY ))
340
348
return ;
341
349
342
- ring -> occ = 0 ;
343
- ring -> free = 0 ;
344
- ring -> rindex = 0 ;
345
- ring -> windex = 0 ;
350
+ memset (& ring -> state , 0 , sizeof (ring -> state ));
346
351
347
352
k3_ringacc_ring_reset_sci (ring );
348
353
}
@@ -590,10 +595,7 @@ int k3_ringacc_ring_cfg(struct k3_ring *ring, struct k3_ring_cfg *cfg)
590
595
ring -> size = cfg -> size ;
591
596
ring -> elm_size = cfg -> elm_size ;
592
597
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 ));
597
599
598
600
if (ring -> proxy_id != K3_RINGACC_PROXY_NOT_USED )
599
601
ring -> proxy = ringacc -> proxy_target_base +
@@ -664,10 +666,10 @@ u32 k3_ringacc_ring_get_free(struct k3_ring *ring)
664
666
if (!ring || !(ring -> flags & K3_RING_FLAG_BUSY ))
665
667
return - EINVAL ;
666
668
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 );
669
671
670
- return ring -> free ;
672
+ return ring -> state . free ;
671
673
}
672
674
EXPORT_SYMBOL_GPL (k3_ringacc_ring_get_free );
673
675
@@ -738,22 +740,22 @@ static int k3_ringacc_ring_access_proxy(struct k3_ring *ring, void *elem,
738
740
"proxy:memcpy_fromio(x): --> ptr(%p), mode:%d\n" , ptr ,
739
741
access_mode );
740
742
memcpy_fromio (elem , ptr , (4 << ring -> elm_size ));
741
- ring -> occ -- ;
743
+ ring -> state . occ -- ;
742
744
break ;
743
745
case K3_RINGACC_ACCESS_MODE_PUSH_TAIL :
744
746
case K3_RINGACC_ACCESS_MODE_PUSH_HEAD :
745
747
dev_dbg (ring -> parent -> dev ,
746
748
"proxy:memcpy_toio(x): --> ptr(%p), mode:%d\n" , ptr ,
747
749
access_mode );
748
750
memcpy_toio (ptr , elem , (4 << ring -> elm_size ));
749
- ring -> free -- ;
751
+ ring -> state . free -- ;
750
752
break ;
751
753
default :
752
754
return - EINVAL ;
753
755
}
754
756
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 );
757
759
return 0 ;
758
760
}
759
761
@@ -808,22 +810,23 @@ static int k3_ringacc_ring_access_io(struct k3_ring *ring, void *elem,
808
810
"memcpy_fromio(x): --> ptr(%p), mode:%d\n" , ptr ,
809
811
access_mode );
810
812
memcpy_fromio (elem , ptr , (4 << ring -> elm_size ));
811
- ring -> occ -- ;
813
+ ring -> state . occ -- ;
812
814
break ;
813
815
case K3_RINGACC_ACCESS_MODE_PUSH_TAIL :
814
816
case K3_RINGACC_ACCESS_MODE_PUSH_HEAD :
815
817
dev_dbg (ring -> parent -> dev ,
816
818
"memcpy_toio(x): --> ptr(%p), mode:%d\n" , ptr ,
817
819
access_mode );
818
820
memcpy_toio (ptr , elem , (4 << ring -> elm_size ));
819
- ring -> free -- ;
821
+ ring -> state . free -- ;
820
822
break ;
821
823
default :
822
824
return - EINVAL ;
823
825
}
824
826
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 );
827
830
return 0 ;
828
831
}
829
832
@@ -855,16 +858,16 @@ static int k3_ringacc_ring_push_mem(struct k3_ring *ring, void *elem)
855
858
{
856
859
void * elem_ptr ;
857
860
858
- elem_ptr = k3_ringacc_get_elm_addr (ring , ring -> windex );
861
+ elem_ptr = k3_ringacc_get_elm_addr (ring , ring -> state . windex );
859
862
860
863
memcpy (elem_ptr , elem , (4 << ring -> elm_size ));
861
864
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 -- ;
864
867
writel (1 , & ring -> rt -> db );
865
868
866
869
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 );
868
871
869
872
return 0 ;
870
873
}
@@ -873,16 +876,16 @@ static int k3_ringacc_ring_pop_mem(struct k3_ring *ring, void *elem)
873
876
{
874
877
void * elem_ptr ;
875
878
876
- elem_ptr = k3_ringacc_get_elm_addr (ring , ring -> rindex );
879
+ elem_ptr = k3_ringacc_get_elm_addr (ring , ring -> state . rindex );
877
880
878
881
memcpy (elem , elem_ptr , (4 << ring -> elm_size ));
879
882
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 -- ;
882
885
writel (-1 , & ring -> rt -> db );
883
886
884
887
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 );
886
889
return 0 ;
887
890
}
888
891
@@ -893,8 +896,8 @@ int k3_ringacc_ring_push(struct k3_ring *ring, void *elem)
893
896
if (!ring || !(ring -> flags & K3_RING_FLAG_BUSY ))
894
897
return - EINVAL ;
895
898
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 );
898
901
899
902
if (k3_ringacc_ring_is_full (ring ))
900
903
return - ENOMEM ;
@@ -914,7 +917,7 @@ int k3_ringacc_ring_push_head(struct k3_ring *ring, void *elem)
914
917
return - EINVAL ;
915
918
916
919
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 );
918
921
919
922
if (k3_ringacc_ring_is_full (ring ))
920
923
return - ENOMEM ;
@@ -933,13 +936,13 @@ int k3_ringacc_ring_pop(struct k3_ring *ring, void *elem)
933
936
if (!ring || !(ring -> flags & K3_RING_FLAG_BUSY ))
934
937
return - EINVAL ;
935
938
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 );
938
941
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 );
941
944
942
- if (!ring -> occ )
945
+ if (!ring -> state . occ )
943
946
return - ENODATA ;
944
947
945
948
if (ring -> ops && ring -> ops -> pop_head )
@@ -956,13 +959,13 @@ int k3_ringacc_ring_pop_tail(struct k3_ring *ring, void *elem)
956
959
if (!ring || !(ring -> flags & K3_RING_FLAG_BUSY ))
957
960
return - EINVAL ;
958
961
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 );
961
964
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 );
964
967
965
- if (!ring -> occ )
968
+ if (!ring -> state . occ )
966
969
return - ENODATA ;
967
970
968
971
if (ring -> ops && ring -> ops -> pop_tail )
0 commit comments