-/* $OpenBSD: vioblk.c,v 1.6 2017/05/30 17:47:11 krw Exp $ */
+/* $OpenBSD: vioblk.c,v 1.7 2017/05/30 19:28:09 sf Exp $ */
/*
* Copyright (c) 2012 Stefan Fritsch.
#include <sys/device.h>
#include <sys/stat.h>
#include <sys/buf.h>
+#include <sys/mutex.h>
#include <dev/pv/virtioreg.h>
#include <dev/pv/virtiovar.h>
#include <dev/pv/vioblkreg.h>
return 0;
}
-#if VIRTIO_DEBUG > 0
-#define DPRINTF(x...) printf(x)
-#else
-#define DPRINTF(x...) do {} while (0)
-#endif
+#define DNPRINTF(n,x...) \
+ do { if (VIRTIO_DEBUG >= n) printf(x); } while(0)
void
vioblk_attach(struct device *parent, struct device *self, void *aux)
sc->sc_link.adapter_buswidth = 2;
sc->sc_link.luns = 1;
sc->sc_link.adapter_target = 2;
- DPRINTF("%s: qsize: %d\n", __func__, qsize);
+ DNPRINTF(1, "%s: qsize: %d\n", __func__, qsize);
if (features & VIRTIO_BLK_F_RO)
sc->sc_link.flags |= SDEV_READONLY;
SLIST_REMOVE_HEAD(&sc->sc_freelist, vr_list);
mtx_leave(&sc->sc_vr_mtx);
- DPRINTF("%s: %p\n", __func__, vr);
+ DNPRINTF(2, "%s: %p\n", __func__, vr);
return vr;
}
struct vioblk_softc *sc = cookie;
struct virtio_blk_req *vr = io;
- DPRINTF("%s: %p\n", __func__, vr);
+ DNPRINTF(2, "%s: %p\n", __func__, vr);
mtx_enter(&sc->sc_vr_mtx);
/*
if (vr->vr_status != VIRTIO_BLK_S_OK) {
- DPRINTF("%s: EIO\n", __func__);
+ DNPRINTF(1, "%s: EIO\n", __func__);
xs->error = XS_DRIVER_STUFFUP;
xs->resid = xs->datalen;
} else {
*/
vd = &vq->vq_desc[slot];
for (r = 0; r < ALLOC_SEGS - 1; r++) {
- DPRINTF("%s: vd[%d].next = %d should be %d\n",
- __func__, r, vd[r].next, (slot + r + 1));
+ DNPRINTF(2, "%s: vd[%d].next = %d should be "
+ "%d\n", __func__, r, vd[r].next,
+ (slot + r + 1));
if (vd[r].next != (slot + r + 1))
return i;
}
if (r == (ALLOC_SEGS -1) && vd[r].next != 0)
return i;
- DPRINTF("%s: reserved slots are contiguous (good!)\n",
- __func__);
+ DNPRINTF(2, "%s: reserved slots are contiguous "
+ "(good!)\n", __func__);
}
vr->vr_qe_index = slot;
-/* $OpenBSD: vioscsi.c,v 1.10 2017/05/30 12:47:47 krw Exp $ */
+/* $OpenBSD: vioscsi.c,v 1.11 2017/05/30 19:28:09 sf Exp $ */
/*
* Copyright (c) 2013 Google Inc.
*
#include <sys/types.h>
#include <sys/systm.h>
#include <sys/device.h>
+#include <sys/mutex.h>
#include <machine/bus.h>
#include <machine/intr.h>
-/* $OpenBSD: virtio.c,v 1.8 2017/05/30 12:47:47 krw Exp $ */
+/* $OpenBSD: virtio.c,v 1.9 2017/05/30 19:28:09 sf Exp $ */
/* $NetBSD: virtio.c,v 1.3 2011/11/02 23:05:52 njoly Exp $ */
/*
* - command blocks (in dmamem) should be pre-allocated and mapped
* - dmamaps for command blocks should be pre-allocated and loaded
* - dmamaps for payload should be pre-allocated
- * r = virtio_enqueue_prep(sc, vq, &slot); // allocate a slot
+ * r = virtio_enqueue_prep(sc, vq, &slot); // allocate a slot
* if (r) // currently 0 or EAGAIN
* return r;
* r = bus_dmamap_load(dmat, dmamap_payload[slot], data, count, ..);
* virtio_enqueue(sc, vq, slot, dmamap_cmd[slot], 0);
* virtio_enqueue(sc, vq, slot, dmamap_payload[slot], iswrite);
* virtio_enqueue_commit(sc, vq, slot, 1);
+ *
+ * Alternative usage with statically allocated slots:
+ * <during initialization>
+ * // while not out of slots, do
+ * virtio_enqueue_prep(sc, vq, &slot); // allocate a slot
+ * virtio_enqueue_reserve(sc, vq, slot, max_segs); // reserve all slots
+ * that may ever be needed
+ *
+ * <when enqueing a request>
+ * // Don't call virtio_enqueue_prep()
+ * bus_dmamap_load(dmat, dmamap_payload[slot], data, count, ..);
+ * bus_dmamap_sync(dmat, dmamap_cmd[slot],... BUS_DMASYNC_PREWRITE);
+ * bus_dmamap_sync(dmat, dmamap_payload[slot],...);
+ * virtio_enqueue_trim(sc, vq, slot, num_segs_needed);
+ * virtio_enqueue(sc, vq, slot, dmamap_cmd[slot], 0);
+ * virtio_enqueue(sc, vq, slot, dmamap_payload[slot], iswrite);
+ * virtio_enqueue_commit(sc, vq, slot, 1);
+ *
+ * <when dequeuing>
+ * // don't call virtio_dequeue_commit()
*/
/*
/*
* dequeue_commit: complete dequeue; the slot is recycled for future use.
* if you forget to call this the slot will be leaked.
+ *
+ * Don't call this if you use statically allocated slots
+ * and virtio_dequeue_trim().
*/
int
virtio_dequeue_commit(struct virtqueue *vq, int slot)