Lines Matching +full:front +full:- +full:end
1 /* SPDX-License-Identifier: GPL-2.0 */
5 * Shared producer-consumer ring macros.
17 /* Round a 32-bit unsigned constant down to the nearest power of two. */
28 * power of two (so we can mask with (size-1) to loop around).
31 (__RD32(((_sz) - offsetof(struct _s##_sring, ring)) / \
32 sizeof(((struct _s##_sring *)0)->ring[0])))
38 (__RD32(((_sz) - (long)&(_s)->ring + (long)(_s)) / sizeof((_s)->ring[0])))
53 * struct mytag_sring - The shared ring.
54 * struct mytag_front_ring - The 'front' half of the ring.
55 * struct mytag_back_ring - The 'back' half of the ring.
59 * the front half:
66 * Initializing the back follows similarly (note that only the front
87 union __name##_sring_entry ring[1]; /* variable-length */ \
90 /* "Front" end's private variables */ \
98 /* "Back" end's private variables */ \
109 * FRONT_RING_whatever works on the "front end" of a ring: here
112 * BACK_RING_whatever works on the "back end" of a ring: here
116 * This is OK in 1-for-1 request-response situations where the
117 * requestor (front end) never has more than RING_SIZE()-1
123 (_s)->req_prod = (_s)->rsp_prod = 0; \
124 (_s)->req_event = (_s)->rsp_event = 1; \
125 memset((_s)->pad, 0, sizeof((_s)->pad)); \
129 (_r)->req_prod_pvt = (_i); \
130 (_r)->rsp_cons = (_i); \
131 (_r)->nr_ents = __RING_SIZE(_s, __size); \
132 (_r)->sring = (_s); \
138 (_r)->rsp_prod_pvt = (_i); \
139 (_r)->req_cons = (_i); \
140 (_r)->nr_ents = __RING_SIZE(_s, __size); \
141 (_r)->sring = (_s); \
148 ((_r)->nr_ents)
150 /* Number of free requests (for use on front side only). */
152 (RING_SIZE(_r) - ((_r)->req_prod_pvt - (_r)->rsp_cons))
154 /* Test if there is an empty slot available on the front ring.
155 * (This is only meaningful from the front. )
162 ((_r)->sring->rsp_prod - (_r)->rsp_cons)
166 unsigned int req = (_r)->sring->req_prod - (_r)->req_cons; \
167 unsigned int rsp = RING_SIZE(_r) - \
168 ((_r)->req_cons - (_r)->rsp_prod_pvt); \
174 (&((_r)->sring->ring[((_idx) & (RING_SIZE(_r) - 1))].req))
180 * done on a local copy that cannot be modified by the other end.
191 (&((_r)->sring->ring[((_idx) & (RING_SIZE(_r) - 1))].rsp))
195 (((_cons) - (_r)->rsp_prod_pvt) >= RING_SIZE(_r))
197 /* Ill-behaved frontend determination: Can there be this many requests? */
199 (((_prod) - (_r)->rsp_prod_pvt) > RING_SIZE(_r))
204 (_r)->sring->req_prod = (_r)->req_prod_pvt; \
208 virt_wmb(); /* front sees responses /before/ updated producer index */ \
209 (_r)->sring->rsp_prod = (_r)->rsp_prod_pvt; \
213 * Notification hold-off (req_event and rsp_event):
216 * necessary to notify the remote end. For example, if requests are in flight
217 * in a backend, the front may be able to queue further requests without
243 RING_IDX __old = (_r)->sring->req_prod; \
244 RING_IDX __new = (_r)->req_prod_pvt; \
246 (_r)->sring->req_prod = __new; \
248 (_notify) = ((RING_IDX)(__new - (_r)->sring->req_event) < \
249 (RING_IDX)(__new - __old)); \
253 RING_IDX __old = (_r)->sring->rsp_prod; \
254 RING_IDX __new = (_r)->rsp_prod_pvt; \
255 virt_wmb(); /* front sees responses /before/ updated producer index */ \
256 (_r)->sring->rsp_prod = __new; \
257 virt_mb(); /* front sees new responses /before/ we check rsp_event */ \
258 (_notify) = ((RING_IDX)(__new - (_r)->sring->rsp_event) < \
259 (RING_IDX)(__new - __old)); \
265 (_r)->sring->req_event = (_r)->req_cons + 1; \
273 (_r)->sring->rsp_event = (_r)->rsp_cons + 1; \
295 * within the range [0-size].
316 * space is currently on the ring (XEN_FLEX_RING_SIZE() -
328 (1UL << ((order) + XEN_PAGE_SHIFT - 1))
333 return idx & (ring_size - 1); \
351 size <= ring_size - *masked_cons) { \
354 memcpy(opaque, buf + *masked_cons, ring_size - *masked_cons); \
355 memcpy((unsigned char *)opaque + ring_size - *masked_cons, buf, \
356 size - (ring_size - *masked_cons)); \
369 size <= ring_size - *masked_prod) { \
372 memcpy(buf + *masked_prod, opaque, ring_size - *masked_prod); \
373 memcpy(buf, (unsigned char *)opaque + (ring_size - *masked_prod), \
374 size - (ring_size - *masked_prod)); \
395 size = prod - cons; \
397 size = ring_size - (cons - prod); \