Commit 4af9f06c authored by Ben Walker's avatar Ben Walker
Browse files

nvme: Rename discover_info to transport_id



This is a small step toward making discovery more like
scanning a local PCI bus.

Change-Id: Ie7149ad060f2eeb56939b1241187bdf09681f2aa
Signed-off-by: default avatarBen Walker <benjamin.walker@intel.com>
parent f74d64f0
Loading
Loading
Loading
Loading
+11 −11
Original line number Diff line number Diff line
@@ -69,7 +69,7 @@ static struct spdk_nvme_intel_marketing_description_page intel_md_page;

static bool g_hex_dump = false;

static struct spdk_nvme_discover_info info;
static struct spdk_nvme_transport_id trid;

static void
hex_dump(const void *data, size_t size)
@@ -874,7 +874,7 @@ parse_args(int argc, char **argv)
{
	int op, rc;

	info.subnqn = SPDK_NVMF_DISCOVERY_NQN;
	trid.subnqn = SPDK_NVMF_DISCOVERY_NQN;

	while ((op = getopt(argc, argv, "a:n:s:t:xH")) != -1) {
		switch (op) {
@@ -896,13 +896,13 @@ parse_args(int argc, char **argv)
#endif
			break;
		case 'a':
			info.traddr = optarg;
			trid.traddr = optarg;
			break;
		case 's':
			info.trsvcid = optarg;
			trid.trsvcid = optarg;
			break;
		case 'n':
			info.subnqn = optarg;
			trid.subnqn = optarg;
			break;
		case 'H':
		default:
@@ -911,21 +911,21 @@ parse_args(int argc, char **argv)
		}
	}

	if (!info.traddr || !info.trsvcid || !info.subnqn) {
	if (!trid.traddr || !trid.trsvcid || !trid.subnqn) {
		return 0;
	}

	if ((strlen(info.traddr) > 255)) {
	if ((strlen(trid.traddr) > 255)) {
		printf("The string len of traddr should <= 255\n");
		return 0;
	}

	if (strlen(info.subnqn) >= SPDK_NVMF_NQN_MAX_LEN) {
	if (strlen(trid.subnqn) >= SPDK_NVMF_NQN_MAX_LEN) {
		printf("NQN must be less than %d bytes long\n", SPDK_NVMF_NQN_MAX_LEN);
		return 0;
	}

	info.trtype = SPDK_NVMF_TRTYPE_RDMA;
	trid.trtype = SPDK_NVME_TRANSPORT_RDMA;
	optind = 1;

	return 0;
@@ -972,8 +972,8 @@ int main(int argc, char **argv)
	}

	rc = 0;
	if (info.trtype == SPDK_NVMF_TRTYPE_RDMA) {
		if (spdk_nvme_discover(&info, NULL, probe_cb, attach_cb, NULL) != 0) {
	if (trid.trtype == SPDK_NVME_TRANSPORT_RDMA) {
		if (spdk_nvme_discover(&trid, NULL, probe_cb, attach_cb, NULL) != 0) {
			fprintf(stderr, "spdk_nvme_probe() failed\n");
		}
	}
+6 −6
Original line number Diff line number Diff line
@@ -1009,7 +1009,7 @@ attach_cb(void *cb_ctx, const struct spdk_nvme_probe_info *probe_info,
static int
register_controllers(void)
{
	struct spdk_nvme_discover_info info;
	struct spdk_nvme_transport_id trid;
	char *p, *p1;
	int n;

@@ -1021,7 +1021,7 @@ register_controllers(void)

	/* The format of g_nvmf_discover_info should be: TRTYPE:TRADDR:TRVCSID */
	if (g_nvmf_discover_info) {
		info.subnqn = SPDK_NVMF_DISCOVERY_NQN;
		trid.subnqn = SPDK_NVMF_DISCOVERY_NQN;

		p = (char *)g_nvmf_discover_info;
		p1 = strchr(p, ':');
@@ -1041,7 +1041,7 @@ register_controllers(void)
			fprintf(stderr, "wrong transport type \n");
			return 0;
		}
		info.trtype = SPDK_NVMF_TRTYPE_RDMA;
		trid.trtype = SPDK_NVME_TRANSPORT_RDMA;

		p = (char *)p1 + 1;
		p1 = strchr(p, ':');
@@ -1056,11 +1056,11 @@ register_controllers(void)
			return 0;
		}
		p[n] = '\0';
		info.traddr = p;
		trid.traddr = p;

		p = (char *)p1 + 1;
		info.trsvcid = p;
		if (spdk_nvme_discover(&info, NULL, probe_cb, attach_cb, NULL) != 0) {
		trid.trsvcid = p;
		if (spdk_nvme_discover(&trid, NULL, probe_cb, attach_cb, NULL) != 0) {
			fprintf(stderr, "spdk_nvme_discover() failed\n");
		}
	}
+41 −16
Original line number Diff line number Diff line
@@ -110,32 +110,56 @@ struct spdk_nvme_ctrlr_opts {
};

/**
 * NVMe over Fabrics discovery parameters.
 * NVMe library transports
 *
 * This structure must be provided when connecting to remote NVMe controllers via NVMe over Fabrics.
 * NOTE: These are mapped directly to the NVMe over Fabrics TRTYPE values, except for PCIe,
 * which is a special case since NVMe over Fabrics does not define a TRTYPE for local PCIe.
 *
 * Currently, this uses 256 for PCIe which is intentionally outside of the 8-bit range of TRTYPE.
 * If the NVMe-oF specification ever defines a PCIe TRTYPE, this should be updated.
 */
struct spdk_nvme_discover_info {
enum spdk_nvme_transport_type {
	/**
	 * NVMe over Fabrics transport type.
	 * PCIe Transport (locally attached devices)
	 */
	enum spdk_nvmf_trtype trtype;
	SPDK_NVME_TRANSPORT_PCIE = 256,

	/**
	 * Subsystem NQN of the NVMe over Fabrics discovery service.
	 * RDMA Transport (RoCE, iWARP, etc.)
	 */
	const char *subnqn;
	SPDK_NVME_TRANSPORT_RDMA = SPDK_NVMF_TRTYPE_RDMA,
};

/**
	 * Transport address of the NVMe over Fabrics discovery service. For transports which use IP
	 * addressing (e.g. RDMA), this should be an IP-based address.
 * NVMe transport identifier.
 *
 * This identifies a unique endpoint on an NVMe fabric.
 */
struct spdk_nvme_transport_id {
	/**
	 * NVMe over Fabrics transport type.
	 */
	enum spdk_nvme_transport_type trtype;

	/**
	 * Transport address of the NVMe-oF endpoint. For transports which use IP
	 * addressing (e.g. RDMA), this should be an IP address. For PCIe, this
	 * can either be NULL (the whole bus) or a PCI address in the format
	 * DDDD:BB:DD.FF
	 */
	const char *traddr;

	/**
	 * Specifiy the transport service identifier.  For transports which use IP addressing
	 * (e.g. RDMA), this field shoud be the port number.
	 * Transport service id of the NVMe-oF endpoint.  For transports which use
	 * IP addressing (e.g. RDMA), this field shoud be the port number. For PCIe,
	 * this is always NULL.
	 */
	const char *trsvcid;

	/**
	 * Subsystem NQN of the NVMe over Fabrics endpoint. May be NULL.
	 */
	const char *subnqn;
};

/**
@@ -190,7 +214,7 @@ struct spdk_nvme_probe_info {
 *
 * \return true if trtype is supported or false if it is not supported.
 */
bool spdk_nvme_transport_available(enum spdk_nvmf_trtype trtype);
bool spdk_nvme_transport_available(enum spdk_nvme_transport_type trtype);

/**
 * Callback for spdk_nvme_probe() enumeration.
@@ -229,10 +253,10 @@ typedef void (*spdk_nvme_attach_cb)(void *cb_ctx, const struct spdk_nvme_probe_i
typedef void (*spdk_nvme_remove_cb)(void *cb_ctx, struct spdk_nvme_ctrlr *ctrlr);

/**
 * \brief discover the remote Controller via NVMe over fabrics protocol
 * \brief Perform a device discovery using the discovery service specified by trid.
 *
 * \param trid The address of the discovery service on which to perform the discovery.
 * \param cb_ctx Opaque value which will be passed back in cb_ctx parameter of the callbacks.
 * \param info which specifies the info used to discover the NVMe over fabrics target.
 * \param probe_cb will be called once per NVMe device found in the system.
 * \param attach_cb will be called for devices for which probe_cb returned true once that NVMe
 * controller has been attached to the userspace driver.
@@ -241,8 +265,9 @@ typedef void (*spdk_nvme_remove_cb)(void *cb_ctx, struct spdk_nvme_ctrlr *ctrlr)
 * desired.
 *
 */
int spdk_nvme_discover(const struct spdk_nvme_discover_info *info,
		       void *cb_ctx, spdk_nvme_probe_cb  probe_cb,
int spdk_nvme_discover(const struct spdk_nvme_transport_id *trid,
		       void *cb_ctx,
		       spdk_nvme_probe_cb  probe_cb,
		       spdk_nvme_attach_cb attach_cb,
		       spdk_nvme_remove_cb remove_cb);

+10 −9
Original line number Diff line number Diff line
@@ -410,7 +410,7 @@ nvme_attach_one(void *cb_ctx, spdk_nvme_probe_cb probe_cb, spdk_nvme_attach_cb a
}

static int
_spdk_nvme_probe(const struct spdk_nvme_discover_info *info, void *cb_ctx,
_spdk_nvme_probe(const struct spdk_nvme_transport_id *trid, void *cb_ctx,
		 spdk_nvme_probe_cb probe_cb, spdk_nvme_attach_cb attach_cb,
		 spdk_nvme_remove_cb remove_cb)
{
@@ -432,19 +432,19 @@ _spdk_nvme_probe(const struct spdk_nvme_discover_info *info, void *cb_ctx,
		}
	}

	if (!info) {
	if (!trid) {
		trtype = SPDK_NVME_TRANSPORT_PCIE;
	} else {
		if (!spdk_nvme_transport_available(info->trtype)) {
			SPDK_ERRLOG("NVMe over Fabrics trtype %u not available\n", info->trtype);
		if (!spdk_nvme_transport_available(trid->trtype)) {
			SPDK_ERRLOG("NVMe over Fabrics trtype %u not available\n", trid->trtype);
			nvme_robust_mutex_unlock(&g_spdk_nvme_driver->lock);
			return -1;
		}

		trtype = (uint8_t)info->trtype;
		trtype = (uint8_t)trid->trtype;
	}

	nvme_transport_ctrlr_scan(trtype, probe_cb, cb_ctx, (void *)info, NULL);
	nvme_transport_ctrlr_scan(trtype, probe_cb, cb_ctx, (void *)trid, NULL);

	if (!spdk_process_is_primary()) {
		TAILQ_FOREACH(ctrlr, &g_spdk_nvme_driver->attached_ctrlrs, tailq) {
@@ -474,16 +474,17 @@ _spdk_nvme_probe(const struct spdk_nvme_discover_info *info, void *cb_ctx,
	return rc;
}

int spdk_nvme_discover(const struct spdk_nvme_discover_info *info, void *cb_ctx,
int spdk_nvme_discover(const struct spdk_nvme_transport_id *trid,
		       void *cb_ctx,
		       spdk_nvme_probe_cb probe_cb,
		       spdk_nvme_attach_cb attach_cb,
		       spdk_nvme_remove_cb remove_cb)
{
	if (!info || !info->traddr || !info->trsvcid || !info->subnqn) {
	if (!trid || !trid->traddr || !trid->trsvcid || !trid->subnqn) {
		return -1;
	}

	return _spdk_nvme_probe(info, cb_ctx, probe_cb, attach_cb, remove_cb);
	return _spdk_nvme_probe(trid, cb_ctx, probe_cb, attach_cb, remove_cb);
}

static int
+0 −14
Original line number Diff line number Diff line
@@ -222,20 +222,6 @@ struct nvme_request {
	void				*user_buffer;
};

/*
 * NVMe library transports
 *
 * NOTE: These are mapped directly to the NVMe over Fabrics TRTYPE values, except for PCIe,
 * which is a special case since NVMe over Fabrics does not define a TRTYPE for local PCIe.
 *
 * Currently, this uses 0 for PCIe since it is reserved by NVMe-oF.  If 0 is ever assigned as a
 * valid TRTYPE, this would need to be changed.
 */
enum spdk_nvme_transport_type {
	SPDK_NVME_TRANSPORT_PCIE = 0,
	SPDK_NVME_TRANSPORT_RDMA = SPDK_NVMF_TRTYPE_RDMA,
};

struct nvme_completion_poll_status {
	struct spdk_nvme_cpl	cpl;
	bool			done;
Loading