Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 03 Sep 2019 14:06:12 -0000
From:      Alexander Motin <mav@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r345815 - in head: lib/libcam sys/cam sys/cam/nvme
Message-ID:  <201904021937.x32JbrRk067921@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: mav
Date: Tue Apr  2 19:37:52 2019
New Revision: 345815
URL: https://svnweb.freebsd.org/changeset/base/345815

Log:
  Make cam_error_print() decode NVMe commands.
  
  MFC after:	2 weeks

Modified:
  head/lib/libcam/Makefile
  head/sys/cam/cam.c
  head/sys/cam/nvme/nvme_all.c
  head/sys/cam/nvme/nvme_all.h
  head/sys/cam/nvme/nvme_xpt.c

Modified: head/lib/libcam/Makefile
==============================================================================
--- head/lib/libcam/Makefile	Tue Apr  2 19:20:55 2019	(r345814)
+++ head/lib/libcam/Makefile	Tue Apr  2 19:37:52 2019	(r345815)
@@ -4,7 +4,7 @@ PACKAGE=	lib${LIB}
 LIB=		cam
 SHLIBDIR?=	/lib
 SRCS=		camlib.c scsi_cmdparse.c scsi_all.c scsi_da.c scsi_sa.c cam.c \
-		ata_all.c smp_all.c
+		ata_all.c nvme_all.c smp_all.c
 INCS=		camlib.h
 
 LIBADD=		sbuf
@@ -38,6 +38,7 @@ MLINKS+=	cam.3 cam_open_device.3 \
 
 .PATH:		${SRCTOP}/sys/cam \
 		${SRCTOP}/sys/cam/ata \
+		${SRCTOP}/sys/cam/nvme \
 		${SRCTOP}/sys/cam/mmc \
 		${SRCTOP}/sys/cam/scsi
 

Modified: head/sys/cam/cam.c
==============================================================================
--- head/sys/cam/cam.c	Tue Apr  2 19:20:55 2019	(r345814)
+++ head/sys/cam/cam.c	Tue Apr  2 19:37:52 2019	(r345815)
@@ -415,7 +415,6 @@ cam_error_string(struct cam_device *device, union ccb 
 		switch (ccb->ccb_h.func_code) {
 		case XPT_ATA_IO:
 			ata_command_sbuf(&ccb->ataio, &sb);
-			sbuf_printf(&sb, "\n");
 			break;
 		case XPT_SCSI_IO:
 #ifdef _KERNEL
@@ -423,17 +422,22 @@ cam_error_string(struct cam_device *device, union ccb 
 #else /* !_KERNEL */
 			scsi_command_string(device, &ccb->csio, &sb);
 #endif /* _KERNEL/!_KERNEL */
-			sbuf_printf(&sb, "\n");
 			break;
 		case XPT_SMP_IO:
 			smp_command_sbuf(&ccb->smpio, &sb, path_str, 79 -
 					 strlen(path_str), (proto_flags &
 					 CAM_ESMF_PRINT_FULL_CMD) ? 79 : 0);
-			sbuf_printf(&sb, "\n");
 			break;
+		case XPT_NVME_IO:
+		case XPT_NVME_ADMIN:
+			nvme_command_sbuf(&ccb->nvmeio, &sb);
+			break;
 		default:
+			sbuf_printf(&sb, "CAM func %#x",
+			    ccb->ccb_h.func_code);
 			break;
 		}
+		sbuf_printf(&sb, "\n");
 	}
 
 	if (flags & CAM_ESF_CAM_STATUS) {

Modified: head/sys/cam/nvme/nvme_all.c
==============================================================================
--- head/sys/cam/nvme/nvme_all.c	Tue Apr  2 19:20:55 2019	(r345814)
+++ head/sys/cam/nvme/nvme_all.c	Tue Apr  2 19:37:52 2019	(r345815)
@@ -111,37 +111,84 @@ nvme_opc2str[] = {
 	"COMPARE",
 	"RSVD-6",
 	"RSVD-7",
-	"DATASET_MANAGEMENT"
+	"WRITE_ZEROES",
+	"DATASET_MANAGEMENT",
+	"RSVD-a",
+	"RSVD-b",
+	"RSVD-c",
+	"RESERVATION_REGISTER",
+	"RESERVATION_REPORT",
+	"RSVD-f",
+	"RSVD-10",
+	"RESERVATION_ACQUIRE",
+	"RSVD-12",
+	"RSVD-13",
+	"RSVD-14",
+	"RESERVATION_RELEASE",
 };
 
 const char *
-nvme_op_string(const struct nvme_command *cmd)
+nvme_op_string(const struct nvme_command *cmd, int admin)
 {
 
-	if (cmd->opc >= nitems(nvme_opc2str))
-		return "UNKNOWN";
-
-	return nvme_opc2str[cmd->opc];
+	if (admin) {
+		return "ADMIN";
+	} else {
+		if (cmd->opc >= nitems(nvme_opc2str))
+			return "UNKNOWN";
+		return nvme_opc2str[cmd->opc];
+	}
 }
 
 const char *
 nvme_cmd_string(const struct nvme_command *cmd, char *cmd_string, size_t len)
 {
+	struct sbuf sb;
+	int error;
 
+	if (len == 0)
+		return ("");
+
+	sbuf_new(&sb, cmd_string, len, SBUF_FIXEDLEN);
+	nvme_cmd_sbuf(cmd, &sb);
+
+	error = sbuf_finish(&sb);
+	if (error != 0 && error != ENOMEM)
+		return ("");
+
+	return(sbuf_data(&sb));
+}
+
+void
+nvme_cmd_sbuf(const struct nvme_command *cmd, struct sbuf *sb)
+{
+
 	/*
 	 * cid, rsvd areas and mptr not printed, since they are used
 	 * only internally by the SIM.
 	 */
-	snprintf(cmd_string, len,
+	sbuf_printf(sb,
 	    "opc=%x fuse=%x nsid=%x prp1=%llx prp2=%llx cdw=%x %x %x %x %x %x",
 	    cmd->opc, cmd->fuse, cmd->nsid,
 	    (unsigned long long)cmd->prp1, (unsigned long long)cmd->prp2,
 	    cmd->cdw10, cmd->cdw11, cmd->cdw12,
 	    cmd->cdw13, cmd->cdw14, cmd->cdw15);
+}
 
-	return cmd_string;
+/*
+ * nvme_command_sbuf() returns 0 for success and -1 for failure.
+ */
+int
+nvme_command_sbuf(struct ccb_nvmeio *nvmeio, struct sbuf *sb)
+{
+
+	sbuf_printf(sb, "%s. NCB: ", nvme_op_string(&nvmeio->cmd,
+	    nvmeio->ccb_h.func_code == XPT_NVME_ADMIN));
+	nvme_cmd_sbuf(&nvmeio->cmd, sb);
+	return(0);
 }
 
+#ifdef _KERNEL
 const void *
 nvme_get_identify_cntrl(struct cam_periph *periph)
 {
@@ -161,3 +208,4 @@ nvme_get_identify_ns(struct cam_periph *periph)
 
 	return device->nvme_data;
 }
+#endif

Modified: head/sys/cam/nvme/nvme_all.h
==============================================================================
--- head/sys/cam/nvme/nvme_all.h	Tue Apr  2 19:20:55 2019	(r345814)
+++ head/sys/cam/nvme/nvme_all.h	Tue Apr  2 19:37:52 2019	(r345815)
@@ -42,8 +42,10 @@ int	nvme_identify_match(caddr_t identbuffer, caddr_t t
 
 struct sbuf;
 void	nvme_print_ident(const struct nvme_controller_data *, const struct nvme_namespace_data *, struct sbuf *);
-const char *nvme_op_string(const struct nvme_command *);
+const char *nvme_op_string(const struct nvme_command *, int admin);
 const char *nvme_cmd_string(const struct nvme_command *, char *, size_t);
+void nvme_cmd_sbuf(const struct nvme_command *, struct sbuf *sb);
+int nvme_command_sbuf(struct ccb_nvmeio *nvmeio, struct sbuf *sb);
 const void *nvme_get_identify_cntrl(struct cam_periph *);
 const void *nvme_get_identify_ns(struct cam_periph *);
 

Modified: head/sys/cam/nvme/nvme_xpt.c
==============================================================================
--- head/sys/cam/nvme/nvme_xpt.c	Tue Apr  2 19:20:55 2019	(r345814)
+++ head/sys/cam/nvme/nvme_xpt.c	Tue Apr  2 19:37:52 2019	(r345815)
@@ -769,11 +769,13 @@ nvme_proto_debug_out(union ccb *ccb)
 {
 	char cdb_str[(sizeof(struct nvme_command) * 3) + 1];
 
-	if (ccb->ccb_h.func_code != XPT_NVME_IO)
+	if (ccb->ccb_h.func_code != XPT_NVME_IO ||
+	    ccb->ccb_h.func_code != XPT_NVME_ADMIN)
 		return;
 
 	CAM_DEBUG(ccb->ccb_h.path,
-	    CAM_DEBUG_CDB,("%s. NCB: %s\n", nvme_op_string(&ccb->nvmeio.cmd),
+	    CAM_DEBUG_CDB,("%s. NCB: %s\n", nvme_op_string(&ccb->nvmeio.cmd,
+		ccb->ccb_h.func_code == XPT_NVME_ADMIN),
 		nvme_cmd_string(&ccb->nvmeio.cmd, cdb_str, sizeof(cdb_str))));
 }
 





Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201904021937.x32JbrRk067921>