Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src Fix to cannnot be opened a nvme(4) namespace device file.
details: https://anonhg.NetBSD.org/src/rev/807b9d4a28d5
branches: trunk
changeset: 347644:807b9d4a28d5
user: nonaka <nonaka%NetBSD.org@localhost>
date: Thu Sep 08 15:00:08 2016 +0000
description:
Fix to cannnot be opened a nvme(4) namespace device file.
diffstat:
etc/MAKEDEV.tmpl | 6 +-
sys/conf/majors | 3 +-
sys/dev/ic/nvme.c | 149 +++++++++++++----------------------------------------
3 files changed, 42 insertions(+), 116 deletions(-)
diffs (250 lines):
diff -r dffba1fd9296 -r 807b9d4a28d5 etc/MAKEDEV.tmpl
--- a/etc/MAKEDEV.tmpl Thu Sep 08 14:44:44 2016 +0000
+++ b/etc/MAKEDEV.tmpl Thu Sep 08 15:00:08 2016 +0000
@@ -1,5 +1,5 @@
#!/bin/sh -
-# $NetBSD: MAKEDEV.tmpl,v 1.182 2016/07/23 06:48:27 kre Exp $
+# $NetBSD: MAKEDEV.tmpl,v 1.183 2016/09/08 15:00:08 nonaka Exp $
#
# Copyright (c) 2003,2007,2008 The NetBSD Foundation, Inc.
# All rights reserved.
@@ -2211,12 +2211,12 @@
warn "bad nsid for $i: $subunit"
break
fi
- mkdev nvme${unit}ns$subunit c %nvmens_chr% $(($unit * 65536 + $subunit))
+ mkdev nvme${unit}ns$subunit c %nvme_chr% $(($unit * 65536 + $subunit))
;;
nvme[0-9]*)
unit=${i#nvme}
- mkdev nvme$unit c %nvme_chr% $unit
+ mkdev nvme$unit c %nvme_chr% $(($unit * 65536))
;;
midevend)
diff -r dffba1fd9296 -r 807b9d4a28d5 sys/conf/majors
--- a/sys/conf/majors Thu Sep 08 14:44:44 2016 +0000
+++ b/sys/conf/majors Thu Sep 08 15:00:08 2016 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: majors,v 1.74 2016/06/04 16:11:50 nonaka Exp $
+# $NetBSD: majors,v 1.75 2016/09/08 15:00:08 nonaka Exp $
#
# Device majors for Machine-Independent drivers.
#
@@ -73,4 +73,3 @@
device-major hdmicec char 340 hdmicec
device-major nvme char 341 nvme
-device-major nvmens char 342 nvmens
diff -r dffba1fd9296 -r 807b9d4a28d5 sys/dev/ic/nvme.c
--- a/sys/dev/ic/nvme.c Thu Sep 08 14:44:44 2016 +0000
+++ b/sys/dev/ic/nvme.c Thu Sep 08 15:00:08 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: nvme.c,v 1.4 2016/09/08 04:41:16 nonaka Exp $ */
+/* $NetBSD: nvme.c,v 1.5 2016/09/08 15:00:08 nonaka 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.4 2016/09/08 04:41:16 nonaka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nvme.c,v 1.5 2016/09/08 15:00:08 nonaka Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -1436,7 +1436,6 @@
* ioctl
*/
-/* nvme */
dev_type_open(nvmeopen);
dev_type_close(nvmeclose);
dev_type_ioctl(nvmeioctl);
@@ -1465,16 +1464,29 @@
nvmeopen(dev_t dev, int flag, int mode, struct lwp *l)
{
struct nvme_softc *sc;
- int unit = minor(dev);
+ int unit = minor(dev) / 0x10000;
+ int nsid = minor(dev) & 0xffff;
+ int nsidx;
if ((sc = device_lookup_private(&nvme_cd, unit)) == NULL)
return ENXIO;
if ((sc->sc_flags & NVME_F_ATTACHED) == 0)
return ENXIO;
- if (ISSET(sc->sc_flags, NVME_F_OPEN))
- return EBUSY;
- SET(sc->sc_flags, NVME_F_OPEN);
+ if (nsid == 0) {
+ /* controller */
+ if (ISSET(sc->sc_flags, NVME_F_OPEN))
+ return EBUSY;
+ SET(sc->sc_flags, NVME_F_OPEN);
+ } else {
+ /* namespace */
+ nsidx = nsid - 1;
+ if (nsidx >= sc->sc_nn || sc->sc_namespaces[nsidx].dev == NULL)
+ return ENXIO;
+ if (ISSET(sc->sc_namespaces[nsidx].flags, NVME_NS_F_OPEN))
+ return EBUSY;
+ SET(sc->sc_namespaces[nsidx].flags, NVME_NS_F_OPEN);
+ }
return 0;
}
@@ -1485,13 +1497,25 @@
nvmeclose(dev_t dev, int flag, int mode, struct lwp *l)
{
struct nvme_softc *sc;
- int unit = minor(dev);
+ int unit = minor(dev) / 0x10000;
+ int nsid = minor(dev) & 0xffff;
+ int nsidx;
sc = device_lookup_private(&nvme_cd, unit);
if (sc == NULL)
return ENXIO;
- CLR(sc->sc_flags, NVME_F_OPEN);
+ if (nsid == 0) {
+ /* controller */
+ CLR(sc->sc_flags, NVME_F_OPEN);
+ } else {
+ /* namespace */
+ nsidx = nsid - 1;
+ if (nsidx >= sc->sc_nn)
+ return ENXIO;
+ CLR(sc->sc_namespaces[nsidx].flags, NVME_NS_F_OPEN);
+ }
+
return 0;
}
@@ -1502,8 +1526,9 @@
nvmeioctl(dev_t dev, u_long cmd, void *data, int flag, struct lwp *l)
{
struct nvme_softc *sc;
+ int unit = minor(dev) / 0x10000;
+ int nsid = minor(dev) & 0xffff;
struct nvme_pt_command *pt;
- int unit = minor(dev);
sc = device_lookup_private(&nvme_cd, unit);
if (sc == NULL)
@@ -1511,108 +1536,10 @@
switch (cmd) {
case NVME_PASSTHROUGH_CMD:
- pt = (struct nvme_pt_command *)data;
- return nvme_command_passthrough(sc, pt, pt->cmd.nsid, l, true);
+ pt = data;
+ return nvme_command_passthrough(sc, data,
+ nsid == 0 ? pt->cmd.nsid : nsid, l, nsid == 0);
}
return ENOTTY;
}
-
-/* nvmens */
-dev_type_open(nvmensopen);
-dev_type_close(nvmensclose);
-dev_type_ioctl(nvmensioctl);
-
-const struct cdevsw nvmens_cdevsw = {
- .d_open = nvmensopen,
- .d_close = nvmensclose,
- .d_read = noread,
- .d_write = nowrite,
- .d_ioctl = nvmensioctl,
- .d_stop = nostop,
- .d_tty = notty,
- .d_poll = nopoll,
- .d_mmap = nommap,
- .d_kqfilter = nokqfilter,
- .d_discard = nodiscard,
- .d_flag = D_OTHER,
-};
-
-extern struct cfdriver nvmens_cd;
-
-/*
- * Accept an open operation on the control device.
- */
-int
-nvmensopen(dev_t dev, int flag, int mode, struct lwp *l)
-{
- struct nvme_softc *sc;
- int unit = minor(dev) / 0x10000;
- int nsid = minor(dev) & 0xffff;
- int nsidx;
-
- if ((sc = device_lookup_private(&nvme_cd, unit)) == NULL)
- return ENXIO;
- if ((sc->sc_flags & NVME_F_ATTACHED) == 0)
- return ENXIO;
- if (nsid == 0)
- return ENXIO;
-
- nsidx = nsid - 1;
- if (nsidx >= sc->sc_nn || sc->sc_namespaces[nsidx].dev == NULL)
- return ENXIO;
- if (ISSET(sc->sc_namespaces[nsidx].flags, NVME_NS_F_OPEN))
- return EBUSY;
-
- SET(sc->sc_namespaces[nsidx].flags, NVME_NS_F_OPEN);
- return 0;
-}
-
-/*
- * Accept the last close on the control device.
- */
-int
-nvmensclose(dev_t dev, int flag, int mode, struct lwp *l)
-{
- struct nvme_softc *sc;
- int unit = minor(dev) / 0x10000;
- int nsid = minor(dev) & 0xffff;
- int nsidx;
-
- sc = device_lookup_private(&nvme_cd, unit);
- if (sc == NULL)
- return ENXIO;
- if (nsid == 0)
- return ENXIO;
-
- nsidx = nsid - 1;
- if (nsidx >= sc->sc_nn)
- return ENXIO;
-
- CLR(sc->sc_namespaces[nsidx].flags, NVME_NS_F_OPEN);
- return 0;
-}
-
-/*
- * Handle control operations.
- */
-int
-nvmensioctl(dev_t dev, u_long cmd, void *data, int flag, struct lwp *l)
-{
- struct nvme_softc *sc;
- int unit = minor(dev) / 0x10000;
- int nsid = minor(dev) & 0xffff;
-
- sc = device_lookup_private(&nvme_cd, unit);
- if (sc == NULL)
- return ENXIO;
- if (nsid == 0)
- return ENXIO;
-
- switch (cmd) {
- case NVME_PASSTHROUGH_CMD:
- return nvme_command_passthrough(sc, data, nsid, l, false);
- }
-
- return ENOTTY;
-}
Home |
Main Index |
Thread Index |
Old Index