svn commit: r322999 - in head/sys/cam: . nvme

Warner Losh imp at FreeBSD.org
Tue Aug 29 17:03:32 UTC 2017


Author: imp
Date: Tue Aug 29 17:03:30 2017
New Revision: 322999
URL: https://svnweb.freebsd.org/changeset/base/322999

Log:
  Fix NVMe's use of XPT_GDEV_TYPE
  
  This patch changes the way XPT_GDEV_TYPE works for NVMe. The current
  ccb_getdev structure includes pointers to the NVMe Identify Controller
  and Namespace structures, but these are kernel virtual addresses which
  are not accessible from user space.
  
  As an alternative, the patch changes the pointers into padding in
  ccb_getdev and adds two new types to ccb_dev_advinfo to retrieve the
  Identify Controller (CDAI_TYPE_NVME_CNTRL) and Namespace
  (CDAI_TYPE_NVME_NS) data structures.
  
  Reviewed By: rpokala, imp
  Differential Revision: https://reviews.freebsd.org/D10466
  Submitted by: Chuck Tuffli

Modified:
  head/sys/cam/cam_ccb.h
  head/sys/cam/cam_xpt.c
  head/sys/cam/nvme/nvme_all.c
  head/sys/cam/nvme/nvme_all.h
  head/sys/cam/nvme/nvme_da.c
  head/sys/cam/nvme/nvme_xpt.c

Modified: head/sys/cam/cam_ccb.h
==============================================================================
--- head/sys/cam/cam_ccb.h	Tue Aug 29 15:46:34 2017	(r322998)
+++ head/sys/cam/cam_ccb.h	Tue Aug 29 17:03:30 2017	(r322999)
@@ -366,8 +366,7 @@ struct ccb_getdev {
 	u_int8_t  serial_num[252];
 	u_int8_t  inq_flags;
 	u_int8_t  serial_num_len;
-	const struct nvme_controller_data	*nvme_cdata;
-	const struct nvme_namespace_data	*nvme_data;
+	void *padding[2];
 };
 
 /* Device Statistics CCB */
@@ -1267,6 +1266,8 @@ struct ccb_dev_advinfo {
 #define	CDAI_TYPE_PHYS_PATH	3
 #define	CDAI_TYPE_RCAPLONG	4
 #define	CDAI_TYPE_EXT_INQ	5
+#define	CDAI_TYPE_NVME_CNTRL	6	/* NVMe Identify Controller data */
+#define	CDAI_TYPE_NVME_NS	7	/* NVMe Identify Namespace data */
 	off_t bufsiz;			/* IN: Size of external buffer */
 #define	CAM_SCSI_DEVID_MAXLEN	65536	/* length in buffer is an uint16_t */
 	off_t provsiz;			/* OUT: Size required/used */

Modified: head/sys/cam/cam_xpt.c
==============================================================================
--- head/sys/cam/cam_xpt.c	Tue Aug 29 15:46:34 2017	(r322998)
+++ head/sys/cam/cam_xpt.c	Tue Aug 29 17:03:30 2017	(r322999)
@@ -2834,8 +2834,6 @@ call_sim:
 			cgd->inq_data = dev->inq_data;
 			cgd->ident_data = dev->ident_data;
 			cgd->inq_flags = dev->inq_flags;
-			cgd->nvme_data = dev->nvme_data;
-			cgd->nvme_cdata = dev->nvme_cdata;
 			cgd->ccb_h.status = CAM_REQ_CMP;
 			cgd->serial_num_len = dev->serial_num_len;
 			if ((dev->serial_num_len > 0)

Modified: head/sys/cam/nvme/nvme_all.c
==============================================================================
--- head/sys/cam/nvme/nvme_all.c	Tue Aug 29 15:46:34 2017	(r322998)
+++ head/sys/cam/nvme/nvme_all.c	Tue Aug 29 17:03:30 2017	(r322999)
@@ -35,6 +35,7 @@ __FBSDID("$FreeBSD$");
 #include <sys/systm.h>
 #include <sys/libkern.h>
 #include <sys/kernel.h>
+#include <sys/malloc.h>
 #include <sys/sysctl.h>
 #else
 #include <errno.h>
@@ -54,6 +55,13 @@ __FBSDID("$FreeBSD$");
 #include <sys/sbuf.h>
 #include <sys/endian.h>
 
+#ifdef _KERNEL
+#include <cam/cam_periph.h>
+#include <cam/cam_xpt_sim.h>
+#include <cam/cam_xpt_periph.h>
+#include <cam/cam_xpt_internal.h>
+#endif
+
 void
 nvme_ns_cmd(struct ccb_nvmeio *nvmeio, uint8_t cmd, uint32_t nsid,
     uint32_t cdw10, uint32_t cdw11, uint32_t cdw12, uint32_t cdw13,
@@ -121,4 +129,24 @@ nvme_cmd_string(const struct nvme_command *cmd, char *
 	    cmd->cdw10, cmd->cdw11, cmd->cdw12, cmd->cdw13, cmd->cdw14, cmd->cdw15);
 
 	return cmd_string;
+}
+
+const void *
+nvme_get_identify_cntrl(struct cam_periph *periph)
+{
+	struct cam_ed *device;
+
+	device = periph->path->device;
+
+	return device->nvme_cdata;
+}
+
+const void *
+nvme_get_identify_ns(struct cam_periph *periph)
+{
+	struct cam_ed *device;
+
+	device = periph->path->device;
+
+	return device->nvme_data;
 }

Modified: head/sys/cam/nvme/nvme_all.h
==============================================================================
--- head/sys/cam/nvme/nvme_all.h	Tue Aug 29 15:46:34 2017	(r322998)
+++ head/sys/cam/nvme/nvme_all.h	Tue Aug 29 17:03:30 2017	(r322999)
@@ -44,5 +44,7 @@ int	nvme_identify_match(caddr_t identbuffer, caddr_t t
 void	nvme_print_ident(const struct nvme_controller_data *, const struct nvme_namespace_data *);
 const char *nvme_op_string(const struct nvme_command *);
 const char *nvme_cmd_string(const struct nvme_command *, char *, size_t);
+const void *nvme_get_identify_cntrl(struct cam_periph *);
+const void *nvme_get_identify_ns(struct cam_periph *);
 
 #endif /* CAM_NVME_NVME_ALL_H */

Modified: head/sys/cam/nvme/nvme_da.c
==============================================================================
--- head/sys/cam/nvme/nvme_da.c	Tue Aug 29 15:46:34 2017	(r322998)
+++ head/sys/cam/nvme/nvme_da.c	Tue Aug 29 17:03:30 2017	(r322999)
@@ -684,21 +684,14 @@ ndaregister(struct cam_periph *periph, void *arg)
 	struct nda_softc *softc;
 	struct disk *disk;
 	struct ccb_pathinq cpi;
-	struct ccb_getdev *cgd;
 	const struct nvme_namespace_data *nsd;
 	const struct nvme_controller_data *cd;
 	char   announce_buf[80];
-//	caddr_t match;
 	u_int maxio;
 	int quirks;
 
-	cgd = (struct ccb_getdev *)arg;
-	if (cgd == NULL) {
-		printf("ndaregister: no getdev CCB, can't register device\n");
-		return(CAM_REQ_CMP_ERR);
-	}
-	nsd = cgd->nvme_data;
-	cd = cgd->nvme_cdata;
+	nsd = nvme_get_identify_ns(periph);
+	cd = nvme_get_identify_cntrl(periph);
 
 	softc = (struct nda_softc *)malloc(sizeof(*softc), M_DEVBUF,
 	    M_NOWAIT | M_ZERO);
@@ -719,19 +712,7 @@ ndaregister(struct cam_periph *periph, void *arg)
 
 	periph->softc = softc;
 
-#if 0
-	/*
-	 * See if this device has any quirks.
-	 */
-	match = cam_quirkmatch((caddr_t)&cgd->ident_data,
-			       (caddr_t)nda_quirk_table,
-			       sizeof(nda_quirk_table)/sizeof(*nda_quirk_table),
-			       sizeof(*nda_quirk_table), ata_identify_match);
-	if (match != NULL)
-		softc->quirks = ((struct nda_quirk_entry *)match)->quirks;
-	else
-#endif
-		softc->quirks = NDA_Q_NONE;
+	softc->quirks = NDA_Q_NONE;
 
 	bzero(&cpi, sizeof(cpi));
 	xpt_setup_ccb(&cpi.ccb_h, periph->path, CAM_PRIORITY_NONE);

Modified: head/sys/cam/nvme/nvme_xpt.c
==============================================================================
--- head/sys/cam/nvme/nvme_xpt.c	Tue Aug 29 15:46:34 2017	(r322998)
+++ head/sys/cam/nvme/nvme_xpt.c	Tue Aug 29 17:03:30 2017	(r322999)
@@ -538,6 +538,24 @@ nvme_dev_advinfo(union ccb *start_ccb)
 			memcpy(cdai->buf, device->physpath, amt);
 		}
 		break;
+	case CDAI_TYPE_NVME_CNTRL:
+		if (cdai->flags & CDAI_FLAG_STORE)
+			return;
+		amt = sizeof(struct nvme_controller_data);
+		cdai->provsiz = amt;
+		if (amt > cdai->bufsiz)
+			amt = cdai->bufsiz;
+		memcpy(cdai->buf, device->nvme_cdata, amt);
+		break;
+	case CDAI_TYPE_NVME_NS:
+		if (cdai->flags & CDAI_FLAG_STORE)
+			return;
+		amt = sizeof(struct nvme_namespace_data);
+		cdai->provsiz = amt;
+		if (amt > cdai->bufsiz)
+			amt = cdai->bufsiz;
+		memcpy(cdai->buf, device->nvme_data, amt);
+		break;
 	default:
 		return;
 	}


More information about the svn-src-all mailing list