nb_descs++;
if (++vq->vq_avail_idx >= vq->vq_nentries) {
vq->vq_avail_idx -= vq->vq_nentries;
- vq->vq_packed.cached_flags ^=
- VRING_DESC_F_AVAIL(1) | VRING_DESC_F_USED(1);
+ vq->vq_packed.cached_flags ^= VRING_PACKED_DESC_F_AVAIL_USED;
}
for (k = 0; k < pkt_num; k++) {
if (++vq->vq_avail_idx >= vq->vq_nentries) {
vq->vq_avail_idx -= vq->vq_nentries;
vq->vq_packed.cached_flags ^=
- VRING_DESC_F_AVAIL(1) | VRING_DESC_F_USED(1);
+ VRING_PACKED_DESC_F_AVAIL_USED;
}
}
nb_descs++;
if (++vq->vq_avail_idx >= vq->vq_nentries) {
vq->vq_avail_idx -= vq->vq_nentries;
- vq->vq_packed.cached_flags ^=
- VRING_DESC_F_AVAIL(1) | VRING_DESC_F_USED(1);
+ vq->vq_packed.cached_flags ^= VRING_PACKED_DESC_F_AVAIL_USED;
}
virtio_wmb(vq->hw->weak_barriers);
vq->vq_nentries = vq_size;
if (vtpci_packed_queue(hw)) {
vq->vq_packed.used_wrap_counter = 1;
- vq->vq_packed.cached_flags = VRING_DESC_F_AVAIL(1);
+ vq->vq_packed.cached_flags = VRING_PACKED_DESC_F_AVAIL;
vq->vq_packed.event_flags_shadow = 0;
if (queue_type == VTNET_RQ)
vq->vq_packed.cached_flags |= VRING_DESC_F_WRITE;
#define VRING_DESC_F_WRITE 2
/* This means the buffer contains a list of buffer descriptors. */
#define VRING_DESC_F_INDIRECT 4
+
/* This flag means the descriptor was made available by the driver */
-#define VRING_DESC_F_AVAIL(b) ((uint16_t)(b) << 7)
+#define VRING_PACKED_DESC_F_AVAIL (1 << 7)
/* This flag means the descriptor was used by the device */
-#define VRING_DESC_F_USED(b) ((uint16_t)(b) << 15)
+#define VRING_PACKED_DESC_F_USED (1 << 15)
+
+/* Frequently used combinations */
+#define VRING_PACKED_DESC_F_AVAIL_USED (VRING_PACKED_DESC_F_AVAIL | \
+ VRING_PACKED_DESC_F_USED)
/* The Host uses this in used->flags to advise the Guest: don't kick me
* when you add a buffer. It's unreliable, so it's simply an
if (++vq->vq_avail_idx >= vq->vq_nentries) {
vq->vq_avail_idx -= vq->vq_nentries;
vq->vq_packed.cached_flags ^=
- VRING_DESC_F_AVAIL(1) | VRING_DESC_F_USED(1);
+ VRING_PACKED_DESC_F_AVAIL_USED;
flags = vq->vq_packed.cached_flags;
}
}
if (++vq->vq_avail_idx >= vq->vq_nentries) {
vq->vq_avail_idx -= vq->vq_nentries;
- vq->vq_packed.cached_flags ^=
- VRING_DESC_F_AVAIL(1) | VRING_DESC_F_USED(1);
+ vq->vq_packed.cached_flags ^= VRING_PACKED_DESC_F_AVAIL_USED;
}
vq->vq_free_cnt--;
if (idx >= vq->vq_nentries) {
idx -= vq->vq_nentries;
vq->vq_packed.cached_flags ^=
- VRING_DESC_F_AVAIL(1) | VRING_DESC_F_USED(1);
+ VRING_PACKED_DESC_F_AVAIL_USED;
}
}
if (idx >= vq->vq_nentries) {
idx -= vq->vq_nentries;
vq->vq_packed.cached_flags ^=
- VRING_DESC_F_AVAIL(1) | VRING_DESC_F_USED(1);
+ VRING_PACKED_DESC_F_AVAIL_USED;
}
} while ((cookie = cookie->next) != NULL);
static inline int
desc_is_avail(struct vring_packed_desc *desc, bool wrap_counter)
{
- return wrap_counter == !!(desc->flags & VRING_DESC_F_AVAIL(1)) &&
- wrap_counter != !!(desc->flags & VRING_DESC_F_USED(1));
+ uint16_t flags = desc->flags;
+
+ return wrap_counter == !!(flags & VRING_PACKED_DESC_F_AVAIL) &&
+ wrap_counter != !!(flags & VRING_PACKED_DESC_F_USED);
}
static uint32_t
{
struct virtio_user_queue *vq = &dev->packed_queues[queue_idx];
struct vring_packed *vring = &dev->packed_vrings[queue_idx];
- uint16_t n_descs;
+ uint16_t n_descs, flags;
while (desc_is_avail(&vring->desc[vq->used_idx],
vq->used_wrap_counter)) {
n_descs = virtio_user_handle_ctrl_msg_packed(dev, vring,
vq->used_idx);
+ flags = VRING_DESC_F_WRITE;
+ if (vq->used_wrap_counter)
+ flags |= VRING_PACKED_DESC_F_AVAIL_USED;
+
rte_smp_wmb();
- vring->desc[vq->used_idx].flags =
- VRING_DESC_F_WRITE |
- VRING_DESC_F_AVAIL(vq->used_wrap_counter) |
- VRING_DESC_F_USED(vq->used_wrap_counter);
+ vring->desc[vq->used_idx].flags = flags;
vq->used_idx += n_descs;
if (vq->used_idx >= dev->queue_size) {
uint16_t used, avail, flags;
flags = desc->flags;
- used = !!(flags & VRING_DESC_F_USED(1));
- avail = !!(flags & VRING_DESC_F_AVAIL(1));
+ used = !!(flags & VRING_PACKED_DESC_F_USED);
+ avail = !!(flags & VRING_PACKED_DESC_F_AVAIL);
return avail == used && used == vq->vq_packed.used_wrap_counter;
}