git: 500196c5c705 - main - cam: Add nvme error devctl publishing

From: Warner Losh <imp_at_FreeBSD.org>
Date: Mon, 06 Nov 2023 19:11:20 UTC
The branch main has been updated by imp:

URL: https://cgit.FreeBSD.org/src/commit/?id=500196c5c705f48e847ad8d568c7167fbef738b0

commit 500196c5c705f48e847ad8d568c7167fbef738b0
Author:     Warner Losh <imp@FreeBSD.org>
AuthorDate: 2023-11-06 19:09:31 +0000
Commit:     Warner Losh <imp@FreeBSD.org>
CommitDate: 2023-11-06 19:10:42 +0000

    cam: Add nvme error devctl publishing
    
    Start reporting nvme errors from devices, like we report ata and scsi
    errors.
    
    Sponsored by:           Netflix
    Reviewed by:            mav, jhb
    Differential Revision:  https://reviews.freebsd.org/D41086
---
 sys/cam/cam_periph.c | 34 ++++++++++++++++++++++++++++++++--
 1 file changed, 32 insertions(+), 2 deletions(-)

diff --git a/sys/cam/cam_periph.c b/sys/cam/cam_periph.c
index ebdda9ef449f..101abda5db25 100644
--- a/sys/cam/cam_periph.c
+++ b/sys/cam/cam_periph.c
@@ -2172,19 +2172,49 @@ cam_periph_devctl_notify(union ccb *ccb)
 		sbuf_printf(&sb, "\" ");
 		type = "error";
 		break;
+	case CAM_NVME_STATUS_ERROR:
+	{
+		struct ccb_nvmeio *n = &ccb->nvmeio;
+
+		sbuf_printf(&sb, "sc=\"%02x\" sct=\"%02x\" cdw0=\"%08x\" ",
+		    NVME_STATUS_GET_SC(n->cpl.status),
+		    NVME_STATUS_GET_SCT(n->cpl.status), n->cpl.cdw0);
+		type = "error";
+		break;
+	}
 	default:
 		type = "error";
 		break;
 	}
 
-	if (ccb->ccb_h.func_code == XPT_SCSI_IO) {
+
+	switch (ccb->ccb_h.func_code) {
+	case XPT_SCSI_IO:
 		sbuf_printf(&sb, "CDB=\"");
 		scsi_cdb_sbuf(scsiio_cdb_ptr(&ccb->csio), &sb);
 		sbuf_printf(&sb, "\" ");
-	} else if (ccb->ccb_h.func_code == XPT_ATA_IO) {
+		break;
+	case XPT_ATA_IO:
 		sbuf_printf(&sb, "ACB=\"");
 		ata_cmd_sbuf(&ccb->ataio.cmd, &sb);
 		sbuf_printf(&sb, "\" ");
+		break;
+	case XPT_NVME_IO:
+	case XPT_NVME_ADMIN:
+	{
+		struct ccb_nvmeio *n = &ccb->nvmeio;
+		struct nvme_command *cmd = &n->cmd;
+
+		// XXX Likely should be nvme_cmd_sbuf
+		sbuf_printf(&sb, "opc=\"%02x\" fuse=\"%02x\" cid=\"%04x\" "
+		    "nsid=\"%08x\" cdw10=\"%08x\" cdw11=\"%08x\" cdw12=\"%08x\" "
+		    "cdw13=\"%08x\" cdw14=\"%08x\" cdw15=\"%08x\" ",
+		    cmd->opc, cmd->fuse, cmd->cid, cmd->nsid, cmd->cdw10,
+		    cmd->cdw11, cmd->cdw12, cmd->cdw13, cmd->cdw14, cmd->cdw15);
+		break;
+	}
+	default:
+		break;
 	}
 
 	if (sbuf_finish(&sb) == 0)