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 = 0; \
130 (_r)->rsp_cons = 0; \
131 (_r)->nr_ents = __RING_SIZE(_s, __size); \
132 (_r)->sring = (_s); \
136 (_r)->rsp_prod_pvt = 0; \
137 (_r)->req_cons = 0; \
138 (_r)->nr_ents = __RING_SIZE(_s, __size); \
139 (_r)->sring = (_s); \
142 /* Initialize to existing shared indexes -- for recovery */
144 (_r)->sring = (_s); \
145 (_r)->req_prod_pvt = (_s)->req_prod; \
146 (_r)->rsp_cons = (_s)->rsp_prod; \
147 (_r)->nr_ents = __RING_SIZE(_s, __size); \
151 (_r)->sring = (_s); \
152 (_r)->rsp_prod_pvt = (_s)->rsp_prod; \
153 (_r)->req_cons = (_s)->req_prod; \
154 (_r)->nr_ents = __RING_SIZE(_s, __size); \
159 ((_r)->nr_ents)
161 /* Number of free requests (for use on front side only). */
163 (RING_SIZE(_r) - ((_r)->req_prod_pvt - (_r)->rsp_cons))
165 /* Test if there is an empty slot available on the front ring.
166 * (This is only meaningful from the front. )
173 ((_r)->sring->rsp_prod - (_r)->rsp_cons)
177 unsigned int req = (_r)->sring->req_prod - (_r)->req_cons; \
178 unsigned int rsp = RING_SIZE(_r) - \
179 ((_r)->req_cons - (_r)->rsp_prod_pvt); \
185 (&((_r)->sring->ring[((_idx) & (RING_SIZE(_r) - 1))].req))
191 * done on a local copy that cannot be modified by the other end.
202 (&((_r)->sring->ring[((_idx) & (RING_SIZE(_r) - 1))].rsp))
206 (((_cons) - (_r)->rsp_prod_pvt) >= RING_SIZE(_r))
208 /* Ill-behaved frontend determination: Can there be this many requests? */
210 (((_prod) - (_r)->rsp_prod_pvt) > RING_SIZE(_r))
215 (_r)->sring->req_prod = (_r)->req_prod_pvt; \
219 virt_wmb(); /* front sees responses /before/ updated producer index */ \
220 (_r)->sring->rsp_prod = (_r)->rsp_prod_pvt; \
224 * Notification hold-off (req_event and rsp_event):
227 * necessary to notify the remote end. For example, if requests are in flight
228 * in a backend, the front may be able to queue further requests without
254 RING_IDX __old = (_r)->sring->req_prod; \
255 RING_IDX __new = (_r)->req_prod_pvt; \
257 (_r)->sring->req_prod = __new; \
259 (_notify) = ((RING_IDX)(__new - (_r)->sring->req_event) < \
260 (RING_IDX)(__new - __old)); \
264 RING_IDX __old = (_r)->sring->rsp_prod; \
265 RING_IDX __new = (_r)->rsp_prod_pvt; \
266 virt_wmb(); /* front sees responses /before/ updated producer index */ \
267 (_r)->sring->rsp_prod = __new; \
268 virt_mb(); /* front sees new responses /before/ we check rsp_event */ \
269 (_notify) = ((RING_IDX)(__new - (_r)->sring->rsp_event) < \
270 (RING_IDX)(__new - __old)); \
276 (_r)->sring->req_event = (_r)->req_cons + 1; \
284 (_r)->sring->rsp_event = (_r)->rsp_cons + 1; \
306 * within the range [0-size].
327 * space is currently on the ring (XEN_FLEX_RING_SIZE() -
339 (1UL << ((order) + XEN_PAGE_SHIFT - 1))
344 return idx & (ring_size - 1); \
362 size <= ring_size - *masked_cons) { \
365 memcpy(opaque, buf + *masked_cons, ring_size - *masked_cons); \
366 memcpy((unsigned char *)opaque + ring_size - *masked_cons, buf, \
367 size - (ring_size - *masked_cons)); \
380 size <= ring_size - *masked_prod) { \
383 memcpy(buf + *masked_prod, opaque, ring_size - *masked_prod); \
384 memcpy(buf, (unsigned char *)opaque + (ring_size - *masked_prod), \
385 size - (ring_size - *masked_prod)); \
406 size = prod - cons; \
408 size = ring_size - (cons - prod); \