git: 07c6a62bab69 - main - cam: Add a XPORT_NVMF for NVMe over Fabrics sims

From: John Baldwin <jhb_at_FreeBSD.org>
Date: Fri, 03 May 2024 00:15:48 UTC
The branch main has been updated by jhb:

URL: https://cgit.FreeBSD.org/src/commit/?id=07c6a62bab69296f2514dc99046ac701c4392f78

commit 07c6a62bab69296f2514dc99046ac701c4392f78
Author:     John Baldwin <jhb@FreeBSD.org>
AuthorDate: 2024-05-02 23:29:26 +0000
Commit:     John Baldwin <jhb@FreeBSD.org>
CommitDate: 2024-05-02 23:29:26 +0000

    cam: Add a XPORT_NVMF for NVMe over Fabrics sims
    
    Reviewed by:    ken, imp
    Sponsored by:   Chelsio Communications
    Differential Revision:  https://reviews.freebsd.org/D44713
---
 rescue/rescue/Makefile       |  1 +
 sbin/camcontrol/Makefile     |  3 ++-
 sbin/camcontrol/camcontrol.c | 37 ++++++++++++++++++++++++++-----------
 sys/cam/cam_ccb.h            | 18 +++++++++++++++++-
 sys/cam/nvme/nvme_xpt.c      |  1 +
 5 files changed, 47 insertions(+), 13 deletions(-)

diff --git a/rescue/rescue/Makefile b/rescue/rescue/Makefile
index 6dceea6f5077..2c31323c2507 100644
--- a/rescue/rescue/Makefile
+++ b/rescue/rescue/Makefile
@@ -144,6 +144,7 @@ CRUNCH_PROGS_usr.sbin+= zdb
 # CRUNCH_PROGS+= devd
 
 CRUNCH_LIBS+= -l80211 -lalias -lcam -lncursesw -ldevstat -lipsec -llzma
+CRUNCH_LIBS_camcontrol+= ${LIBNVMF}
 .if ${MK_ZFS} != "no"
 CRUNCH_LIBS+= -lavl -lpthread -luutil -lumem -ltpool -lspl -lrt
 CRUNCH_LIBS_zfs+=	${LIBBE} \
diff --git a/sbin/camcontrol/Makefile b/sbin/camcontrol/Makefile
index b04eb5614c62..64703f656a89 100644
--- a/sbin/camcontrol/Makefile
+++ b/sbin/camcontrol/Makefile
@@ -24,7 +24,8 @@ SRCS+=	nvme_util.c
 .if ${MACHINE_CPUARCH} == "arm"
 WARNS?= 3
 .endif
-LIBADD=	cam sbuf util
+CFLAGS+= -I${SRCTOP}/lib/libnvmf
+LIBADD=	cam nvmf sbuf util
 MAN=	camcontrol.8
 
 .include <bsd.prog.mk>
diff --git a/sbin/camcontrol/camcontrol.c b/sbin/camcontrol/camcontrol.c
index db26b45ac508..3aa91eb00ecf 100644
--- a/sbin/camcontrol/camcontrol.c
+++ b/sbin/camcontrol/camcontrol.c
@@ -44,6 +44,7 @@
 #include <fcntl.h>
 #include <ctype.h>
 #include <err.h>
+#include <libnvmf.h>
 #include <libutil.h>
 #include <limits.h>
 #include <inttypes.h>
@@ -5378,6 +5379,26 @@ cts_print(struct cam_device *device, struct ccb_trans_settings *cts)
 				sata->caps);
 		}
 	}
+	if (cts->transport == XPORT_NVME) {
+		struct ccb_trans_settings_nvme *nvme =
+		    &cts->xport_specific.nvme;
+
+		if (nvme->valid & CTS_NVME_VALID_LINK) {
+			fprintf(stdout, "%sPCIe lanes: %d (%d max)\n", pathstr,
+			    nvme->lanes, nvme->max_lanes);
+			fprintf(stdout, "%sPCIe Generation: %d (%d max)\n", pathstr,
+			    nvme->speed, nvme->max_speed);
+		}
+	}
+	if (cts->transport == XPORT_NVMF) {
+		struct ccb_trans_settings_nvmf *nvmf =
+		    &cts->xport_specific.nvmf;
+
+		if (nvmf->valid & CTS_NVMF_VALID_TRTYPE) {
+			fprintf(stdout, "%sTransport: %s\n", pathstr,
+			    nvmf_transport_type(nvmf->trtype));
+		}
+	}
 	if (cts->protocol == PROTO_ATA) {
 		struct ccb_trans_settings_ata *ata=
 		    &cts->proto_specific.ata;
@@ -5399,19 +5420,13 @@ cts_print(struct cam_device *device, struct ccb_trans_settings *cts)
 		}
 	}
 	if (cts->protocol == PROTO_NVME) {
-		struct ccb_trans_settings_nvme *nvmex =
-		    &cts->xport_specific.nvme;
+		struct ccb_trans_settings_nvme *nvme =
+		    &cts->proto_specific.nvme;
 
-		if (nvmex->valid & CTS_NVME_VALID_SPEC) {
+		if (nvme->valid & CTS_NVME_VALID_SPEC) {
 			fprintf(stdout, "%sNVMe Spec: %d.%d\n", pathstr,
-			    NVME_MAJOR(nvmex->spec),
-			    NVME_MINOR(nvmex->spec));
-		}
-		if (nvmex->valid & CTS_NVME_VALID_LINK) {
-			fprintf(stdout, "%sPCIe lanes: %d (%d max)\n", pathstr,
-			    nvmex->lanes, nvmex->max_lanes);
-			fprintf(stdout, "%sPCIe Generation: %d (%d max)\n", pathstr,
-			    nvmex->speed, nvmex->max_speed);
+			    NVME_MAJOR(nvme->spec),
+			    NVME_MINOR(nvme->spec));
 		}
 	}
 }
diff --git a/sys/cam/cam_ccb.h b/sys/cam/cam_ccb.h
index 66b374008aa5..15e136e8a072 100644
--- a/sys/cam/cam_ccb.h
+++ b/sys/cam/cam_ccb.h
@@ -297,9 +297,10 @@ typedef enum {
 	XPORT_SRP,	/* SCSI RDMA Protocol */
 	XPORT_NVME,	/* NVMe over PCIe */
 	XPORT_MMCSD,	/* MMC, SD, SDIO card */
+	XPORT_NVMF,	/* NVMe over Fabrics */
 } cam_xport;
 
-#define XPORT_IS_NVME(t)	((t) == XPORT_NVME)
+#define XPORT_IS_NVME(t)	((t) == XPORT_NVME || (t) == XPORT_NVMF)
 #define XPORT_IS_ATA(t)		((t) == XPORT_ATA || (t) == XPORT_SATA)
 #define XPORT_IS_SCSI(t)	((t) != XPORT_UNKNOWN && \
 				 (t) != XPORT_UNSPECIFIED && \
@@ -653,6 +654,12 @@ struct ccb_pathinq_settings_nvme {
 _Static_assert(sizeof(struct ccb_pathinq_settings_nvme) == 64,
     "ccb_pathinq_settings_nvme too big");
 
+struct ccb_pathinq_settings_nvmf {
+	uint32_t nsid;		/* Namespace ID for this path */
+	uint8_t  trtype;
+	char	 dev_name[NVME_DEV_NAME_LEN]; /* nvme controller dev name for this device */
+};
+
 #define	PATHINQ_SETTINGS_SIZE	128
 
 struct ccb_pathinq {
@@ -684,6 +691,7 @@ struct ccb_pathinq {
 		struct ccb_pathinq_settings_fc fc;
 		struct ccb_pathinq_settings_sas sas;
 		struct ccb_pathinq_settings_nvme nvme;
+		struct ccb_pathinq_settings_nvmf nvmf;
 		char ccb_pathinq_settings_opaque[PATHINQ_SETTINGS_SIZE];
 	} xport_specific;
 	u_int		maxio;		/* Max supported I/O size, in bytes. */
@@ -1050,6 +1058,13 @@ struct ccb_trans_settings_nvme
 	uint8_t		max_speed;	/* PCIe generation for each lane */
 };
 
+struct ccb_trans_settings_nvmf
+{
+	u_int     	valid;		/* Which fields to honor */
+#define CTS_NVMF_VALID_TRTYPE	0x01
+	uint8_t		trtype;
+};
+
 #include <cam/mmc/mmc_bus.h>
 struct ccb_trans_settings_mmc {
 	struct mmc_ios ios;
@@ -1122,6 +1137,7 @@ struct ccb_trans_settings {
 		struct ccb_trans_settings_pata ata;
 		struct ccb_trans_settings_sata sata;
 		struct ccb_trans_settings_nvme nvme;
+		struct ccb_trans_settings_nvmf nvmf;
 	} xport_specific;
 };
 
diff --git a/sys/cam/nvme/nvme_xpt.c b/sys/cam/nvme/nvme_xpt.c
index 86127aca7b0f..d2cb6ff11fd4 100644
--- a/sys/cam/nvme/nvme_xpt.c
+++ b/sys/cam/nvme/nvme_xpt.c
@@ -175,6 +175,7 @@ static struct xpt_xport nvme_xport_ ## x = {	\
 CAM_XPT_XPORT(nvme_xport_ ## x);
 
 NVME_XPT_XPORT(nvme, NVME);
+NVME_XPT_XPORT(nvmf, NVMF);
 
 #undef NVME_XPT_XPORT