From owner-svn-src-head@freebsd.org Tue Sep 3 14:06:12 2019 Return-Path: Delivered-To: svn-src-head@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id B4C95DC330; Tue, 3 Sep 2019 14:06:05 +0000 (UTC) (envelope-from yuripv@freebsd.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2610:1c1:1:6074::16:84]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "freefall.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 46N7z12164z4PB9; Tue, 3 Sep 2019 14:06:05 +0000 (UTC) (envelope-from yuripv@freebsd.org) Received: by freefall.freebsd.org (Postfix, from userid 1452) id 83A581A0DD; Tue, 3 Sep 2019 14:05:57 +0000 (UTC) X-Original-To: yuripv@localmail.freebsd.org Delivered-To: yuripv@localmail.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [96.47.72.80]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client CN "mx1.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by freefall.freebsd.org (Postfix) with ESMTPS id 602AB7D76; Tue, 2 Apr 2019 19:37:57 +0000 (UTC) (envelope-from owner-src-committers@freebsd.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2610:1c1:1:6074::16:84]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "freefall.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 2D242745AD; Tue, 2 Apr 2019 19:37:57 +0000 (UTC) (envelope-from owner-src-committers@freebsd.org) Received: by freefall.freebsd.org (Postfix, from userid 538) id 1BEC67D75; Tue, 2 Apr 2019 19:37:57 +0000 (UTC) Delivered-To: src-committers@localmail.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client CN "mx1.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by freefall.freebsd.org (Postfix) with ESMTPS id 637997D73 for ; Tue, 2 Apr 2019 19:37:54 +0000 (UTC) (envelope-from mav@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 30FC6745A8; Tue, 2 Apr 2019 19:37:54 +0000 (UTC) (envelope-from mav@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 0A9BF2A79; Tue, 2 Apr 2019 19:37:54 +0000 (UTC) (envelope-from mav@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x32JbrFY067925; Tue, 2 Apr 2019 19:37:53 GMT (envelope-from mav@FreeBSD.org) Received: (from mav@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x32JbrRk067921; Tue, 2 Apr 2019 19:37:53 GMT (envelope-from mav@FreeBSD.org) Message-Id: <201904021937.x32JbrRk067921@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mav set sender to mav@FreeBSD.org using -f From: Alexander Motin 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 X-SVN-Group: head X-SVN-Commit-Author: mav X-SVN-Commit-Paths: in head: lib/libcam sys/cam sys/cam/nvme X-SVN-Commit-Revision: 345815 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk X-Loop: FreeBSD.org Sender: owner-src-committers@freebsd.org X-Rspamd-Queue-Id: 2D242745AD X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.95 / 15.00]; local_wl_from(0.00)[freebsd.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.999,0]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; NEURAL_HAM_SHORT(-0.95)[-0.947,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US] Status: O X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.29 List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Date: Tue, 03 Sep 2019 14:06:12 -0000 X-Original-Date: Tue, 2 Apr 2019 19:37:53 +0000 (UTC) X-List-Received-Date: Tue, 03 Sep 2019 14:06:12 -0000 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)))); }