• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * bcm_ring.h : Ring context abstraction
3  * The ring context tracks the WRITE and READ indices where elements may be
4  * produced and consumed respectively. All elements in the ring need to be
5  * fixed size.
6  *
7  * NOTE: A ring of size N, may only hold N-1 elements.
8  *
9  * Copyright (C) 1999-2019, Broadcom.
10  *
11  *      Unless you and Broadcom execute a separate written software license
12  * agreement governing use of this software, this software is licensed to you
13  * under the terms of the GNU General Public License version 2 (the "GPL"),
14  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
15  * following added to such license:
16  *
17  *      As a special exception, the copyright holders of this software give you
18  * permission to link this software with independent modules, and to copy and
19  * distribute the resulting executable under terms of your choice, provided that
20  * you also meet, for each linked independent module, the terms and conditions
21  * of the license of that module.  An independent module is a module which is
22  * not derived from this software.  The special exception does not apply to any
23  * modifications of the software.
24  *
25  *      Notwithstanding the above, under no circumstances may you combine this
26  * software in any way with any other Broadcom software provided under a license
27  * other than the GPL, without Broadcom's express prior written consent.
28  *
29  *
30  * <<Broadcom-WL-IPTag/Open:>>
31  *
32  * $Id: bcm_ring.h 700321 2017-05-18 16:09:07Z $
33  */
34 #ifndef __bcm_ring_included__
35 #define __bcm_ring_included__
36 /*
37  * API Notes:
38  *
39  * Ring manipulation API allows for:
40  *  Pending operations: Often before some work can be completed, it may be
41  *  desired that several resources are available, e.g. space for production in
42  *  a ring. Approaches such as, #1) reserve resources one by one and return them
43  *  if another required resource is not available, or #2) employ a two pass
44  *  algorithm of first testing whether all resources are available, have a
45  *  an impact on performance critical code. The approach taken here is more akin
46  *  to approach #2, where a test for resource availability essentially also
47  *  provides the index for production in an un-committed state.
48  *  The same approach is taken for the consumer side.
49  *
50  *  - Pending production: Fetch the next index where a ring element may be
51  *    produced. The caller may not commit the WRITE of the element.
52  *  - Pending consumption: Fetch the next index where a ring element may be
53  *    consumed. The caller may not commut the READ of the element.
54  *
55  *  Producer side API:
56  *  - bcm_ring_is_full  : Test whether ring is full
57  *  - bcm_ring_prod     : Fetch index where an element may be produced (commit)
58  *  - bcm_ring_prod_pend: Fetch index where an element may be produced (pending)
59  *  - bcm_ring_prod_done: Commit a previous pending produce fetch
60  *  - bcm_ring_prod_avail: Fetch total number free slots eligible for production
61  *
62  * Consumer side API:
63  *  - bcm_ring_is_empty : Test whether ring is empty
64  *  - bcm_ring_cons     : Fetch index where an element may be consumed (commit)
65  *  - bcm_ring_cons_pend: Fetch index where an element may be consumed (pending)
66  *  - bcm_ring_cons_done: Commit a previous pending consume fetch
67  *  - bcm_ring_cons_avail: Fetch total number elements eligible for consumption
68  *
69  *  - bcm_ring_sync_read: Sync read offset in peer ring, from local ring
70  *  - bcm_ring_sync_write: Sync write offset in peer ring, from local ring
71  *
72  * +----------------------------------------------------------------------------
73  *
74  * Design Notes:
75  * Following items are not tracked in a ring context (design decision)
76  *  - width of a ring element.
77  *  - depth of the ring.
78  *  - base of the buffer, where the elements are stored.
79  *  - count of number of free slots in the ring
80  *
81  * Implementation Notes:
82  *  - When BCM_RING_DEBUG is enabled, need explicit bcm_ring_init().
83  *  - BCM_RING_EMPTY and BCM_RING_FULL are (-1)
84  *
85  * +----------------------------------------------------------------------------
86  *
87  * Usage Notes:
88  * An application may incarnate a ring of some fixed sized elements, by defining
89  *  - a ring data buffer to store the ring elements.
90  *  - depth of the ring (max number of elements managed by ring context).
91  *    Preferrably, depth may be represented as a constant.
92  *  - width of a ring element: to be used in pointer arithmetic with the ring's
93  *    data buffer base and an index to fetch the ring element.
94  *
95  * Use bcm_workq_t to instantiate a pair of workq constructs, one for the
96  * producer and the other for the consumer, both pointing to the same circular
97  * buffer. The producer may operate on it's own local workq and flush the write
98  * index to the consumer. Likewise the consumer may use its local workq and
99  * flush the read index to the producer. This way we do not repeatedly access
100  * the peer's context. The two peers may reside on different CPU cores with a
101  * private L1 data cache.
102  * +----------------------------------------------------------------------------
103  *
104  * Copyright (C) 1999-2019, Broadcom.
105  *
106  *      Unless you and Broadcom execute a separate written software license
107  * agreement governing use of this software, this software is licensed to you
108  * under the terms of the GNU General Public License version 2 (the "GPL"),
109  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
110  * following added to such license:
111  *
112  *      As a special exception, the copyright holders of this software give you
113  * permission to link this software with independent modules, and to copy and
114  * distribute the resulting executable under terms of your choice, provided that
115  * you also meet, for each linked independent module, the terms and conditions
116  * of the license of that module.  An independent module is a module which is
117  * not derived from this software.  The special exception does not apply to any
118  * modifications of the software.
119  *
120  *      Notwithstanding the above, under no circumstances may you combine this
121  * software in any way with any other Broadcom software provided under a license
122  * other than the GPL, without Broadcom's express prior written consent.
123  *
124  * $Id: bcm_ring.h 700321 2017-05-18 16:09:07Z $
125  *
126  * -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*-
127  * vim: set ts=4 noet sw=4 tw=80:
128  *
129  * +----------------------------------------------------------------------------
130  */
131 
132 #ifdef ____cacheline_aligned
133 #define __ring_aligned ____cacheline_aligned
134 #else
135 #define __ring_aligned
136 #endif // endif
137 
138 #define BCM_RING_EMPTY (-1)
139 #define BCM_RING_FULL (-1)
140 #define BCM_RING_NULL ((bcm_ring_t *)NULL)
141 
142 #if defined(BCM_RING_DEBUG)
143 #define RING_ASSERT(exp) ASSERT(exp)
144 #define BCM_RING_IS_VALID(ring)                                                \
145     (((ring) != BCM_RING_NULL) && ((ring)->self == (ring)))
146 #else /* ! BCM_RING_DEBUG */
147 #define RING_ASSERT(exp)                                                       \
148     do {                                                                       \
149     } while (0)
150 #define BCM_RING_IS_VALID(ring) ((ring) != BCM_RING_NULL)
151 #endif /* ! BCM_RING_DEBUG */
152 
153 #define BCM_RING_SIZE_IS_VALID(ring_size) ((ring_size) > 0)
154 
155 /*
156  * +----------------------------------------------------------------------------
157  * Ring Context
158  * +----------------------------------------------------------------------------
159  */
160 typedef struct bcm_ring { /* Ring context */
161 #if defined(BCM_RING_DEBUG)
162     struct bcm_ring *self;    /* ptr to self for IS VALID test */
163 #endif                        /* BCM_RING_DEBUG */
164     int write __ring_aligned; /* WRITE index in a circular ring */
165     int read __ring_aligned;  /* READ index in a circular ring */
166 } bcm_ring_t;
167 
168 static INLINE void bcm_ring_init(bcm_ring_t *ring);
169 static INLINE void bcm_ring_copy(bcm_ring_t *to, bcm_ring_t *from);
170 static INLINE bool bcm_ring_is_empty(bcm_ring_t *ring);
171 
172 static INLINE int __bcm_ring_next_write(bcm_ring_t *ring, const int ring_size);
173 
174 static INLINE bool __bcm_ring_full(bcm_ring_t *ring, int next_write);
175 static INLINE bool bcm_ring_is_full(bcm_ring_t *ring, const int ring_size);
176 
177 static INLINE void bcm_ring_prod_done(bcm_ring_t *ring, int write);
178 static INLINE int bcm_ring_prod_pend(bcm_ring_t *ring, int *pend_write,
179                                      const int ring_size);
180 static INLINE int bcm_ring_prod(bcm_ring_t *ring, const int ring_size);
181 
182 static INLINE void bcm_ring_cons_done(bcm_ring_t *ring, int read);
183 static INLINE int bcm_ring_cons_pend(bcm_ring_t *ring, int *pend_read,
184                                      const int ring_size);
185 static INLINE int bcm_ring_cons(bcm_ring_t *ring, const int ring_size);
186 
187 static INLINE void bcm_ring_sync_read(bcm_ring_t *peer, const bcm_ring_t *self);
188 static INLINE void bcm_ring_sync_write(bcm_ring_t *peer,
189                                        const bcm_ring_t *self);
190 
191 static INLINE int bcm_ring_prod_avail(const bcm_ring_t *ring,
192                                       const int ring_size);
193 static INLINE int bcm_ring_cons_avail(const bcm_ring_t *ring,
194                                       const int ring_size);
195 static INLINE void bcm_ring_cons_all(bcm_ring_t *ring);
196 
197 /**
198  * bcm_ring_init - initialize a ring context.
199  * @ring: pointer to a ring context
200  */
bcm_ring_init(bcm_ring_t * ring)201 static INLINE void bcm_ring_init(bcm_ring_t *ring)
202 {
203     ASSERT(ring != (bcm_ring_t *)NULL);
204 #if defined(BCM_RING_DEBUG)
205     ring->self = ring;
206 #endif /* BCM_RING_DEBUG */
207     ring->write = 0;
208     ring->read = 0;
209 }
210 
211 /**
212  * bcm_ring_copy - copy construct a ring
213  * @to: pointer to the new ring context
214  * @from: pointer to orig ring context
215  */
bcm_ring_copy(bcm_ring_t * to,bcm_ring_t * from)216 static INLINE void bcm_ring_copy(bcm_ring_t *to, bcm_ring_t *from)
217 {
218     bcm_ring_init(to);
219 
220     to->write = from->write;
221     to->read = from->read;
222 }
223 
224 /**
225  * bcm_ring_is_empty - "Boolean" test whether ring is empty.
226  * @ring: pointer to a ring context
227  *
228  * PS. does not return BCM_RING_EMPTY value.
229  */
bcm_ring_is_empty(bcm_ring_t * ring)230 static INLINE bool bcm_ring_is_empty(bcm_ring_t *ring)
231 {
232     RING_ASSERT(BCM_RING_IS_VALID(ring));
233     return (ring->read == ring->write);
234 }
235 
236 /**
237  * __bcm_ring_next_write - determine the index where the next write may occur
238  *                         (with wrap-around).
239  * @ring: pointer to a ring context
240  * @ring_size: size of the ring
241  *
242  * PRIVATE INTERNAL USE ONLY.
243  */
__bcm_ring_next_write(bcm_ring_t * ring,const int ring_size)244 static INLINE int __bcm_ring_next_write(bcm_ring_t *ring, const int ring_size)
245 {
246     RING_ASSERT(BCM_RING_IS_VALID(ring) && BCM_RING_SIZE_IS_VALID(ring_size));
247     return ((ring->write + 1) % ring_size);
248 }
249 
250 /**
251  * __bcm_ring_full - support function for ring full test.
252  * @ring: pointer to a ring context
253  * @next_write: next location in ring where an element is to be produced
254  *
255  * PRIVATE INTERNAL USE ONLY.
256  */
__bcm_ring_full(bcm_ring_t * ring,int next_write)257 static INLINE bool __bcm_ring_full(bcm_ring_t *ring, int next_write)
258 {
259     return (next_write == ring->read);
260 }
261 
262 /**
263  * bcm_ring_is_full - "Boolean" test whether a ring is full.
264  * @ring: pointer to a ring context
265  * @ring_size: size of the ring
266  *
267  * PS. does not return BCM_RING_FULL value.
268  */
bcm_ring_is_full(bcm_ring_t * ring,const int ring_size)269 static INLINE bool bcm_ring_is_full(bcm_ring_t *ring, const int ring_size)
270 {
271     int next_write;
272     RING_ASSERT(BCM_RING_IS_VALID(ring) && BCM_RING_SIZE_IS_VALID(ring_size));
273     next_write = __bcm_ring_next_write(ring, ring_size);
274     return __bcm_ring_full(ring, next_write);
275 }
276 
277 /**
278  * bcm_ring_prod_done - commit a previously pending index where production
279  * was requested.
280  * @ring: pointer to a ring context
281  * @write: index into ring upto where production was done.
282  * +----------------------------------------------------------------------------
283  */
bcm_ring_prod_done(bcm_ring_t * ring,int write)284 static INLINE void bcm_ring_prod_done(bcm_ring_t *ring, int write)
285 {
286     RING_ASSERT(BCM_RING_IS_VALID(ring));
287     ring->write = write;
288 }
289 
290 /**
291  * bcm_ring_prod_pend - Fetch in "pend" mode, the index where an element may be
292  * produced.
293  * @ring: pointer to a ring context
294  * @pend_write: next index, after the returned index
295  * @ring_size: size of the ring
296  */
bcm_ring_prod_pend(bcm_ring_t * ring,int * pend_write,const int ring_size)297 static INLINE int bcm_ring_prod_pend(bcm_ring_t *ring, int *pend_write,
298                                      const int ring_size)
299 {
300     int rtn;
301     RING_ASSERT(BCM_RING_IS_VALID(ring) && BCM_RING_SIZE_IS_VALID(ring_size));
302     *pend_write = __bcm_ring_next_write(ring, ring_size);
303     if (__bcm_ring_full(ring, *pend_write)) {
304         *pend_write = BCM_RING_FULL;
305         rtn = BCM_RING_FULL;
306     } else {
307         /* production is not committed, caller needs to explicitly commit */
308         rtn = ring->write;
309     }
310     return rtn;
311 }
312 
313 /**
314  * bcm_ring_prod - Fetch and "commit" the next index where a ring element may
315  * be produced.
316  * @ring: pointer to a ring context
317  * @ring_size: size of the ring
318  */
bcm_ring_prod(bcm_ring_t * ring,const int ring_size)319 static INLINE int bcm_ring_prod(bcm_ring_t *ring, const int ring_size)
320 {
321     int next_write, prod_write;
322     RING_ASSERT(BCM_RING_IS_VALID(ring) && BCM_RING_SIZE_IS_VALID(ring_size));
323 
324     next_write = __bcm_ring_next_write(ring, ring_size);
325     if (__bcm_ring_full(ring, next_write)) {
326         prod_write = BCM_RING_FULL;
327     } else {
328         prod_write = ring->write;
329         bcm_ring_prod_done(ring, next_write); /* "commit" production */
330     }
331     return prod_write;
332 }
333 
334 /**
335  * bcm_ring_cons_done - commit a previously pending read
336  * @ring: pointer to a ring context
337  * @read: index upto which elements have been consumed.
338  */
bcm_ring_cons_done(bcm_ring_t * ring,int read)339 static INLINE void bcm_ring_cons_done(bcm_ring_t *ring, int read)
340 {
341     RING_ASSERT(BCM_RING_IS_VALID(ring));
342     ring->read = read;
343 }
344 
345 /**
346  * bcm_ring_cons_pend - fetch in "pend" mode, the next index where a ring
347  * element may be consumed.
348  * @ring: pointer to a ring context
349  * @pend_read: index into ring upto which elements may be consumed.
350  * @ring_size: size of the ring
351  */
bcm_ring_cons_pend(bcm_ring_t * ring,int * pend_read,const int ring_size)352 static INLINE int bcm_ring_cons_pend(bcm_ring_t *ring, int *pend_read,
353                                      const int ring_size)
354 {
355     int rtn;
356     RING_ASSERT(BCM_RING_IS_VALID(ring) && BCM_RING_SIZE_IS_VALID(ring_size));
357     if (bcm_ring_is_empty(ring)) {
358         *pend_read = BCM_RING_EMPTY;
359         rtn = BCM_RING_EMPTY;
360     } else {
361         *pend_read = (ring->read + 1) % ring_size;
362         /* production is not committed, caller needs to explicitly commit */
363         rtn = ring->read;
364     }
365     return rtn;
366 }
367 
368 /**
369  * bcm_ring_cons - fetch and "commit" the next index where a ring element may
370  * be consumed.
371  * @ring: pointer to a ring context
372  * @ring_size: size of the ring
373  */
bcm_ring_cons(bcm_ring_t * ring,const int ring_size)374 static INLINE int bcm_ring_cons(bcm_ring_t *ring, const int ring_size)
375 {
376     int cons_read;
377     RING_ASSERT(BCM_RING_IS_VALID(ring) && BCM_RING_SIZE_IS_VALID(ring_size));
378     if (bcm_ring_is_empty(ring)) {
379         cons_read = BCM_RING_EMPTY;
380     } else {
381         cons_read = ring->read;
382         ring->read = (ring->read + 1) % ring_size; /* read is committed */
383     }
384     return cons_read;
385 }
386 
387 /**
388  * bcm_ring_sync_read - on consumption, update peer's read index.
389  * @peer: pointer to peer's producer ring context
390  * @self: pointer to consumer's ring context
391  */
bcm_ring_sync_read(bcm_ring_t * peer,const bcm_ring_t * self)392 static INLINE void bcm_ring_sync_read(bcm_ring_t *peer, const bcm_ring_t *self)
393 {
394     RING_ASSERT(BCM_RING_IS_VALID(peer));
395     RING_ASSERT(BCM_RING_IS_VALID(self));
396     peer->read = self->read; /* flush read update to peer producer */
397 }
398 
399 /**
400  * bcm_ring_sync_write - on consumption, update peer's write index.
401  * @peer: pointer to peer's consumer ring context
402  * @self: pointer to producer's ring context
403  */
bcm_ring_sync_write(bcm_ring_t * peer,const bcm_ring_t * self)404 static INLINE void bcm_ring_sync_write(bcm_ring_t *peer, const bcm_ring_t *self)
405 {
406     RING_ASSERT(BCM_RING_IS_VALID(peer));
407     RING_ASSERT(BCM_RING_IS_VALID(self));
408     peer->write = self->write; /* flush write update to peer consumer */
409 }
410 
411 /**
412  * bcm_ring_prod_avail - fetch total number of available empty slots in the
413  * ring for production.
414  * @ring: pointer to a ring context
415  * @ring_size: size of the ring
416  */
bcm_ring_prod_avail(const bcm_ring_t * ring,const int ring_size)417 static INLINE int bcm_ring_prod_avail(const bcm_ring_t *ring,
418                                       const int ring_size)
419 {
420     int prod_avail;
421     RING_ASSERT(BCM_RING_IS_VALID(ring) && BCM_RING_SIZE_IS_VALID(ring_size));
422     if (ring->write >= ring->read) {
423         prod_avail = (ring_size - (ring->write - ring->read) - 1);
424     } else {
425         prod_avail = (ring->read - (ring->write + 1));
426     }
427     ASSERT(prod_avail < ring_size);
428     return prod_avail;
429 }
430 
431 /**
432  * bcm_ring_cons_avail - fetch total number of available elements for
433  * consumption.
434  * @ring: pointer to a ring context
435  * @ring_size: size of the ring
436  */
bcm_ring_cons_avail(const bcm_ring_t * ring,const int ring_size)437 static INLINE int bcm_ring_cons_avail(const bcm_ring_t *ring,
438                                       const int ring_size)
439 {
440     int cons_avail;
441     RING_ASSERT(BCM_RING_IS_VALID(ring) && BCM_RING_SIZE_IS_VALID(ring_size));
442     if (ring->read == ring->write) {
443         cons_avail = 0;
444     } else if (ring->read > ring->write) {
445         cons_avail = ((ring_size - ring->read) + ring->write);
446     } else {
447         cons_avail = ring->write - ring->read;
448     }
449     ASSERT(cons_avail < ring_size);
450     return cons_avail;
451 }
452 
453 /**
454  * bcm_ring_cons_all - set ring in state where all elements are consumed.
455  * @ring: pointer to a ring context
456  */
bcm_ring_cons_all(bcm_ring_t * ring)457 static INLINE void bcm_ring_cons_all(bcm_ring_t *ring)
458 {
459     ring->read = ring->write;
460 }
461 
462 /**
463  * Work Queue
464  * A work Queue is composed of a ring of work items, of a specified depth.
465  * It HAS-A bcm_ring object, comprising of a RD and WR offset, to implement a
466  * producer/consumer circular ring.
467  */
468 
469 struct bcm_workq {
470     bcm_ring_t ring;        /* Ring context abstraction */
471     struct bcm_workq *peer; /* Peer workq context */
472     void *buffer;           /* Buffer storage for work items in workQ */
473     int ring_size;          /* Depth of workQ */
474 } __ring_aligned;
475 
476 typedef struct bcm_workq bcm_workq_t;
477 
478 #if defined(BCM_WORKQ_DEBUG)
479 #define WORKQ_ASSERT(exp) ASSERT(exp)
480 #else /* ! BCM_WORKQ_DEBUG */
481 #define WORKQ_ASSERT(exp)                                                      \
482     do {                                                                       \
483     } while (0)
484 #endif /* ! BCM_WORKQ_DEBUG */
485 
486 #define WORKQ_AUDIT(workq)                                                     \
487     WORKQ_ASSERT((workq) != BCM_WORKQ_NULL);                                   \
488     WORKQ_ASSERT(WORKQ_PEER(workq) != BCM_WORKQ_NULL);                         \
489     WORKQ_ASSERT((workq)->buffer == WORKQ_PEER(workq)->buffer);                \
490     WORKQ_ASSERT((workq)->ring_size == WORKQ_PEER(workq)->ring_size);
491 
492 #define BCM_WORKQ_NULL ((bcm_workq_t *)NULL)
493 
494 #define WORKQ_PEER(workq) ((workq)->peer)
495 #define WORKQ_RING(workq) (&((workq)->ring))
496 #define WORKQ_PEER_RING(workq) (&((workq)->peer->ring))
497 
498 #define WORKQ_ELEMENT(__elem_type, __workq, __index)                           \
499     ( {                                                                        \
500         WORKQ_ASSERT((__workq) != BCM_WORKQ_NULL);                             \
501         WORKQ_ASSERT((__index) < ((__workq)->ring_size));                      \
502         ((__elem_type *)((__workq)->buffer)) + (__index);                      \
503     })
504 
505 static INLINE void bcm_workq_init(bcm_workq_t *workq, bcm_workq_t *workq_peer,
506                                   void *buffer, int ring_size);
507 
508 static INLINE bool bcm_workq_is_empty(bcm_workq_t *workq_prod);
509 
510 static INLINE void bcm_workq_prod_sync(bcm_workq_t *workq_prod);
511 static INLINE void bcm_workq_cons_sync(bcm_workq_t *workq_cons);
512 
513 static INLINE void bcm_workq_prod_refresh(bcm_workq_t *workq_prod);
514 static INLINE void bcm_workq_cons_refresh(bcm_workq_t *workq_cons);
515 
516 /**
517  * bcm_workq_init - initialize a workq
518  * @workq: pointer to a workq context
519  * @buffer: pointer to a pre-allocated circular buffer to serve as a ring
520  * @ring_size: size of the ring in terms of max number of elements.
521  */
bcm_workq_init(bcm_workq_t * workq,bcm_workq_t * workq_peer,void * buffer,int ring_size)522 static INLINE void bcm_workq_init(bcm_workq_t *workq, bcm_workq_t *workq_peer,
523                                   void *buffer, int ring_size)
524 {
525     ASSERT(workq != BCM_WORKQ_NULL);
526     ASSERT(workq_peer != BCM_WORKQ_NULL);
527     ASSERT(buffer != NULL);
528     ASSERT(ring_size > 0);
529 
530     WORKQ_PEER(workq) = workq_peer;
531     WORKQ_PEER(workq_peer) = workq;
532 
533     bcm_ring_init(WORKQ_RING(workq));
534     bcm_ring_init(WORKQ_RING(workq_peer));
535 
536     workq->buffer = workq_peer->buffer = buffer;
537     workq->ring_size = workq_peer->ring_size = ring_size;
538 }
539 
540 /**
541  * bcm_workq_empty - test whether there is work
542  * @workq_prod: producer's workq
543  */
bcm_workq_is_empty(bcm_workq_t * workq_prod)544 static INLINE bool bcm_workq_is_empty(bcm_workq_t *workq_prod)
545 {
546     return bcm_ring_is_empty(WORKQ_RING(workq_prod));
547 }
548 
549 /**
550  * bcm_workq_prod_sync - Commit the producer write index to peer workq's ring
551  * @workq_prod: producer's workq whose write index must be synced to peer
552  */
bcm_workq_prod_sync(bcm_workq_t * workq_prod)553 static INLINE void bcm_workq_prod_sync(bcm_workq_t *workq_prod)
554 {
555     WORKQ_AUDIT(workq_prod);
556 
557     /* cons::write <--- prod::write */
558     bcm_ring_sync_write(WORKQ_PEER_RING(workq_prod), WORKQ_RING(workq_prod));
559 }
560 
561 /**
562  * bcm_workq_cons_sync - Commit the consumer read index to the peer workq's ring
563  * @workq_cons: consumer's workq whose read index must be synced to peer
564  */
bcm_workq_cons_sync(bcm_workq_t * workq_cons)565 static INLINE void bcm_workq_cons_sync(bcm_workq_t *workq_cons)
566 {
567     WORKQ_AUDIT(workq_cons);
568 
569     /* prod::read <--- cons::read */
570     bcm_ring_sync_read(WORKQ_PEER_RING(workq_cons), WORKQ_RING(workq_cons));
571 }
572 
573 /**
574  * bcm_workq_prod_refresh - Fetch the updated consumer's read index
575  * @workq_prod: producer's workq whose read index must be refreshed from peer
576  */
bcm_workq_prod_refresh(bcm_workq_t * workq_prod)577 static INLINE void bcm_workq_prod_refresh(bcm_workq_t *workq_prod)
578 {
579     WORKQ_AUDIT(workq_prod);
580 
581     /* prod::read <--- cons::read */
582     bcm_ring_sync_read(WORKQ_RING(workq_prod), WORKQ_PEER_RING(workq_prod));
583 }
584 
585 /**
586  * bcm_workq_cons_refresh - Fetch the updated producer's write index
587  * @workq_cons: consumer's workq whose write index must be refreshed from peer
588  */
bcm_workq_cons_refresh(bcm_workq_t * workq_cons)589 static INLINE void bcm_workq_cons_refresh(bcm_workq_t *workq_cons)
590 {
591     WORKQ_AUDIT(workq_cons);
592 
593     /* cons::write <--- prod::write */
594     bcm_ring_sync_write(WORKQ_RING(workq_cons), WORKQ_PEER_RING(workq_cons));
595 }
596 
597 #endif /* ! __bcm_ring_h_included__ */
598