Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev/ic on further thought, just remove the separately al...
details: https://anonhg.NetBSD.org/src/rev/f7e5ab4d8307
branches: trunk
changeset: 347860:f7e5ab4d8307
user: jdolecek <jdolecek%NetBSD.org@localhost>
date: Mon Sep 19 20:33:51 2016 +0000
description:
on further thought, just remove the separately allocated nvme_ns_context
altogether and fold into nvme_ccb; allocating this separately just isn't useful
diffstat:
sys/dev/ic/ld_nvme.c | 100 +++++++++++---------------------------------------
sys/dev/ic/nvme.c | 96 ++++++++++++++++++++++++------------------------
sys/dev/ic/nvmevar.h | 60 ++++++++++++-----------------
3 files changed, 95 insertions(+), 161 deletions(-)
diffs (truncated from 508 to 300 lines):
diff -r 48531e9d2645 -r f7e5ab4d8307 sys/dev/ic/ld_nvme.c
--- a/sys/dev/ic/ld_nvme.c Mon Sep 19 19:15:04 2016 +0000
+++ b/sys/dev/ic/ld_nvme.c Mon Sep 19 20:33:51 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ld_nvme.c,v 1.5 2016/09/18 21:52:36 jdolecek Exp $ */
+/* $NetBSD: ld_nvme.c,v 1.6 2016/09/19 20:33:51 jdolecek Exp $ */
/*-
* Copyright (C) 2016 NONAKA Kimihiro <nonaka%netbsd.org@localhost>
@@ -26,7 +26,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ld_nvme.c,v 1.5 2016/09/18 21:52:36 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ld_nvme.c,v 1.6 2016/09/19 20:33:51 jdolecek Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -46,7 +46,6 @@
struct nvme_softc *sc_nvme;
uint16_t sc_nsid;
- int sc_attaching;
};
static int ld_nvme_match(device_t, cfdata_t, void *);
@@ -60,11 +59,8 @@
static int ld_nvme_dump(struct ld_softc *, void *, int, int);
static int ld_nvme_flush(struct ld_softc *, int);
-static int ld_nvme_dobio(struct ld_nvme_softc *, void *, int, daddr_t,
- int, struct buf *);
-static void ld_nvme_biodone(struct nvme_ns_context *);
-static void ld_nvme_syncdone(struct nvme_ns_context *);
-
+static void ld_nvme_biodone(void *, struct buf *, uint16_t);
+static void ld_nvme_syncdone(void *, struct buf *, uint16_t);
static int
ld_nvme_match(device_t parent, cfdata_t match, void *aux)
@@ -92,7 +88,6 @@
ld->sc_dv = self;
sc->sc_nvme = nsc;
sc->sc_nsid = naa->naa_nsid;
- sc->sc_attaching = 1;
aprint_naive("\n");
aprint_normal("\n");
@@ -117,8 +112,6 @@
ld->sc_flush = ld_nvme_flush;
ld->sc_flags = LDF_ENABLED;
ldattach(ld, "fcfs");
-
- sc->sc_attaching = 0;
}
static int
@@ -142,8 +135,11 @@
{
struct ld_nvme_softc *sc = device_private(ld->sc_dv);
- return ld_nvme_dobio(sc, bp->b_data, bp->b_bcount, bp->b_rawblkno,
- BUF_ISWRITE(bp), bp);
+ return nvme_ns_dobio(sc->sc_nvme, sc->sc_nsid, sc,
+ bp, bp->b_data, bp->b_bcount,
+ sc->sc_ld.sc_secsize, bp->b_rawblkno,
+ BUF_ISWRITE(bp) ? 0 : NVME_NS_CTX_F_READ,
+ ld_nvme_biodone);
}
static int
@@ -151,51 +147,18 @@
{
struct ld_nvme_softc *sc = device_private(ld->sc_dv);
- return ld_nvme_dobio(sc, data, blkcnt * ld->sc_secsize, blkno, 1, NULL);
-}
-
-static int
-ld_nvme_dobio(struct ld_nvme_softc *sc, void *data, int datasize, daddr_t blkno,
- int dowrite, struct buf *bp)
-{
- struct nvme_ns_context *ctx;
- int error;
- int waitok = (bp != NULL && !cpu_softintr_p() && !cpu_intr_p()
- && !sc->sc_attaching);
-
- ctx = nvme_ns_get_ctx(sc, waitok ? PR_WAITOK : PR_NOWAIT);
- if (ctx == NULL)
- return EAGAIN;
-
- ctx->nnc_cookie = sc;
- ctx->nnc_nsid = sc->sc_nsid;
- ctx->nnc_done = ld_nvme_biodone;
- ctx->nnc_buf = bp;
- ctx->nnc_data = data;
- ctx->nnc_datasize = datasize;
- ctx->nnc_secsize = sc->sc_ld.sc_secsize;
- ctx->nnc_blkno = blkno;
- ctx->nnc_flags = dowrite ? 0 : NVME_NS_CTX_F_READ;
- if (bp == NULL)
- SET(ctx->nnc_flags, NVME_NS_CTX_F_POLL);
-
- error = nvme_ns_dobio(sc->sc_nvme, ctx);
- if (error)
- nvme_ns_put_ctx(sc, ctx);
-
- return error;
+ return nvme_ns_dobio(sc->sc_nvme, sc->sc_nsid, sc,
+ NULL, data, blkcnt * ld->sc_secsize,
+ sc->sc_ld.sc_secsize, blkno,
+ NVME_NS_CTX_F_POLL,
+ ld_nvme_biodone);
}
static void
-ld_nvme_biodone(struct nvme_ns_context *ctx)
+ld_nvme_biodone(void *xc, struct buf *bp, uint16_t cmd_status)
{
- struct ld_nvme_softc *sc = ctx->nnc_cookie;
- struct buf *bp = ctx->nnc_buf;
- int status = NVME_CQE_SC(ctx->nnc_status);
-
- /* free before processing to avoid starvation, lddone() could trigger
- * another i/o request */
- nvme_ns_put_ctx(sc, ctx);
+ struct ld_nvme_softc *sc = xc;
+ uint16_t status = NVME_CQE_SC(cmd_status);
if (bp != NULL) {
if (status != NVME_CQE_SC_SUCCESS) {
@@ -217,33 +180,14 @@
ld_nvme_flush(struct ld_softc *ld, int flags)
{
struct ld_nvme_softc *sc = device_private(ld->sc_dv);
- struct nvme_ns_context *ctx;
- int error;
- int waitok = (!ISSET(flags, LDFL_POLL)
- && !cpu_softintr_p() && !cpu_intr_p());
- ctx = nvme_ns_get_ctx(sc, waitok ? PR_WAITOK : PR_NOWAIT);
- if (ctx == NULL)
- return EAGAIN;
-
- ctx->nnc_cookie = sc;
- ctx->nnc_nsid = sc->sc_nsid;
- ctx->nnc_done = ld_nvme_syncdone;
- ctx->nnc_flags = 0;
- if (flags & LDFL_POLL)
- SET(ctx->nnc_flags, NVME_NS_CTX_F_POLL);
-
- error = nvme_ns_sync(sc->sc_nvme, ctx);
- if (error)
- nvme_ns_put_ctx(sc, ctx);
-
- return error;
+ return nvme_ns_sync(sc->sc_nvme, sc->sc_nsid, sc,
+ (flags & LDFL_POLL) ? NVME_NS_CTX_F_POLL : 0,
+ ld_nvme_syncdone);
}
static void
-ld_nvme_syncdone(struct nvme_ns_context *ctx)
+ld_nvme_syncdone(void *xc, struct buf *bp, uint16_t cmd_status)
{
- struct ld_nvme_softc *sc = ctx->nnc_cookie;
-
- nvme_ns_put_ctx(sc, ctx);
+ /* nothing to do */
}
diff -r 48531e9d2645 -r f7e5ab4d8307 sys/dev/ic/nvme.c
--- a/sys/dev/ic/nvme.c Mon Sep 19 19:15:04 2016 +0000
+++ b/sys/dev/ic/nvme.c Mon Sep 19 20:33:51 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: nvme.c,v 1.10 2016/09/19 19:06:57 jdolecek Exp $ */
+/* $NetBSD: nvme.c,v 1.11 2016/09/19 20:33:51 jdolecek Exp $ */
/* $OpenBSD: nvme.c,v 1.49 2016/04/18 05:59:50 dlg Exp $ */
/*
@@ -18,7 +18,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: nvme.c,v 1.10 2016/09/19 19:06:57 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nvme.c,v 1.11 2016/09/19 20:33:51 jdolecek Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -417,15 +417,6 @@
if (!sc->sc_use_mq)
nvme_write4(sc, NVME_INTMC, 1);
- snprintf(sc->sc_ctxpoolname, sizeof(sc->sc_ctxpoolname),
- "%s_ns_ctx", device_xname(sc->sc_dev));
- sc->sc_ctxpool = pool_cache_init(sizeof(struct nvme_ns_context),
- 0, 0, 0, sc->sc_ctxpoolname, NULL, IPL_BIO, NULL, NULL, NULL);
- if (sc->sc_ctxpool == NULL) {
- aprint_error_dev(sc->sc_dev, "unable to create ctx pool\n");
- goto free_q;
- }
-
/* probe subdevices */
sc->sc_namespaces = kmem_zalloc(sizeof(*sc->sc_namespaces) * sc->sc_nn,
KM_SLEEP);
@@ -484,8 +475,6 @@
return error;
/* from now on we are committed to detach, following will never fail */
- pool_cache_destroy(sc->sc_ctxpool);
-
for (i = 0; i < sc->sc_nq; i++)
nvme_q_free(sc, sc->sc_q[i]);
kmem_free(sc->sc_q, sizeof(*sc->sc_q) * sc->sc_nq);
@@ -565,8 +554,7 @@
KASSERT(nsid > 0);
ccb = nvme_ccb_get(sc->sc_admin_q);
- if (ccb == NULL)
- return EAGAIN;
+ KASSERT(ccb != NULL); /* it's a bug if we don't have spare ccb here */
mem = nvme_dmamem_alloc(sc, sizeof(*identify));
if (mem == NULL)
@@ -608,7 +596,9 @@
}
int
-nvme_ns_dobio(struct nvme_softc *sc, struct nvme_ns_context *ctx)
+nvme_ns_dobio(struct nvme_softc *sc, uint16_t nsid, void *cookie,
+ struct buf *bp, void *data, size_t datasize,
+ int secsize, daddr_t blkno, int flags, nvme_nnc_done nnc_done)
{
struct nvme_queue *q = nvme_get_q(sc);
struct nvme_ccb *ccb;
@@ -620,14 +610,23 @@
return EAGAIN;
ccb->ccb_done = nvme_ns_io_done;
- ccb->ccb_cookie = ctx;
+ ccb->ccb_cookie = cookie;
+
+ /* namespace context */
+ ccb->nnc_nsid = nsid;
+ ccb->nnc_flags = flags;
+ ccb->nnc_buf = bp;
+ ccb->nnc_datasize = datasize;
+ ccb->nnc_secsize = secsize;
+ ccb->nnc_blkno = blkno;
+ ccb->nnc_done = nnc_done;
dmap = ccb->ccb_dmamap;
- error = bus_dmamap_load(sc->sc_dmat, dmap, ctx->nnc_data,
- ctx->nnc_datasize, NULL,
- (ISSET(ctx->nnc_flags, NVME_NS_CTX_F_POLL) ?
+ error = bus_dmamap_load(sc->sc_dmat, dmap, data,
+ datasize, NULL,
+ (ISSET(flags, NVME_NS_CTX_F_POLL) ?
BUS_DMA_NOWAIT : BUS_DMA_WAITOK) |
- (ISSET(ctx->nnc_flags, NVME_NS_CTX_F_READ) ?
+ (ISSET(flags, NVME_NS_CTX_F_READ) ?
BUS_DMA_READ : BUS_DMA_WRITE));
if (error) {
nvme_ccb_put(q, ccb);
@@ -635,7 +634,7 @@
}
bus_dmamap_sync(sc->sc_dmat, dmap, 0, dmap->dm_mapsize,
- ISSET(ctx->nnc_flags, NVME_NS_CTX_F_READ) ?
+ ISSET(flags, NVME_NS_CTX_F_READ) ?
BUS_DMASYNC_PREREAD : BUS_DMASYNC_PREWRITE);
if (dmap->dm_nsegs > 2) {
@@ -650,7 +649,7 @@
BUS_DMASYNC_PREWRITE);
}
- if (ISSET(ctx->nnc_flags, NVME_NS_CTX_F_POLL)) {
+ if (ISSET(flags, NVME_NS_CTX_F_POLL)) {
if (nvme_poll(sc, q, ccb, nvme_ns_io_fill, NVME_TIMO_PT) != 0)
return EIO;
return 0;
@@ -664,12 +663,11 @@
nvme_ns_io_fill(struct nvme_queue *q, struct nvme_ccb *ccb, void *slot)
{
struct nvme_sqe_io *sqe = slot;
- struct nvme_ns_context *ctx = ccb->ccb_cookie;
bus_dmamap_t dmap = ccb->ccb_dmamap;
- sqe->opcode = ISSET(ctx->nnc_flags, NVME_NS_CTX_F_READ) ?
+ sqe->opcode = ISSET(ccb->nnc_flags, NVME_NS_CTX_F_READ) ?
NVM_CMD_READ : NVM_CMD_WRITE;
- htolem32(&sqe->nsid, ctx->nnc_nsid);
+ htolem32(&sqe->nsid, ccb->nnc_nsid);
htolem64(&sqe->entry.prp[0], dmap->dm_segs[0].ds_addr);
switch (dmap->dm_nsegs) {
@@ -684,8 +682,11 @@
break;
}
Home |
Main Index |
Thread Index |
Old Index