Commit ae7bf749 authored by Alexey Marchuk's avatar Alexey Marchuk Committed by Konrad Sztyber
Browse files

lib/dma: Add data transfer function



The new API allows async data transfer between
2 memory domains

Signed-off-by: default avatarAlexey Marchuk <alexeymar@nvidia.com>
Change-Id: Ib271f1f1888f8e337d18be4c95ae3ca8cd466411
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/24689


Community-CI: Mellanox Build Bot
Reviewed-by: default avatarShuhei Matsumoto <smatsumoto@nvidia.com>
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarJim Harris <jim.harris@samsung.com>
Community-CI: Broadcom CI <spdk-ci.pdl@broadcom.com>
parent d7c8bcf8
Loading
Loading
Loading
Loading
+59 −0
Original line number Diff line number Diff line
@@ -137,6 +137,32 @@ struct spdk_memory_domain_translation_ctx {
	};
};

/**
 * Definition of function which starts asynchronous operation to transfer data from the source to
 * destination memory domains.
 * Implementation of this function must call \b cpl_cb only when it returns 0. All other return codes mean failure.
 *
 * \param dst_domain Memory domain to which the data should be transferred
 * \param dst_domain_ctx Optional context passed by upper layer with IO request
 * \param dst_iov Iov vector in dst_domain space
 * \param dst_iovcnt dst_iov array size
 * \param src_domain Memory domain from which the data should be transferred
 * \param src_domain_ctx Optional context passed by the caller
 * \param src_iov Iov vector in local memory
 * \param src_iovcnt src_iov array size
 * \param src_translation Optional memory translation from the source to the destination memory domain
 * \param cpl_cb A callback to be called when push operation completes
 * \param cpl_cb_arg Optional argument to be passed to \b cpl_cb
 * \return 0 on success, negated errno on failure
 */
typedef int (*spdk_memory_domain_transfer_data_cb)(struct spdk_memory_domain *dst_domain,
		void *dst_domain_ctx,
		struct iovec *dst_iov, uint32_t dst_iovcnt,
		struct spdk_memory_domain *src_domain, void *src_domain_ctx,
		struct iovec *src_iov, uint32_t src_iovcnt,
		struct spdk_memory_domain_translation_result *src_translation,
		spdk_memory_domain_data_cpl_cb cpl_cb, void *cpl_cb_arg);

/**
 * Definition of function which translates data from src_domain to a form accessible by dst_domain.
 *
@@ -236,6 +262,15 @@ void spdk_memory_domain_set_pull(struct spdk_memory_domain *domain,
void spdk_memory_domain_set_push(struct spdk_memory_domain *domain,
				 spdk_memory_domain_push_data_cb push_cb);

/**
 * Set data transfer for memory domain. Overwrites existing function.
 *
 * \param domain Memory domain
 * \param transfer_cb Data transfer function
 */
void spdk_memory_domain_set_data_transfer(struct spdk_memory_domain *domain,
		spdk_memory_domain_transfer_data_cb transfer_cb);

/**
 * Set memzero function for memory domain. Overwrites existing memzero function.
 *
@@ -312,6 +347,30 @@ int spdk_memory_domain_push_data(struct spdk_memory_domain *dst_domain, void *ds
				 struct iovec *dst_iov, uint32_t dst_iovcnt, struct iovec *src_iov, uint32_t src_iovcnt,
				 spdk_memory_domain_data_cpl_cb cpl_cb, void *cpl_cb_arg);

/**
 * Asynchronously transfer data from the source memory domain to the destination memory domain
 *
 * \param dst_domain Memory domain to which the data should be transferred
 * \param dst_domain_ctx Optional context passed by upper layer with IO request
 * \param dst_iov Iov vector in dst_domain space
 * \param dst_iovcnt dst_iov array size
 * \param src_domain Memory domain from which the data should be transferred
 * \param src_domain_ctx Optional context passed by the caller
 * \param src_iov Iov vector in local memory
 * \param src_iovcnt src_iov array size
 * \param src_translation Optional memory translation from the source to the destination memory domain
 * \param cpl_cb A callback to be called when push operation completes
 * \param cpl_cb_arg Optional argument to be passed to \b cpl_cb
 * \return 0 on success, negated errno on failure. push_cb implementation must only call the callback when 0
 * is returned
 */
int spdk_memory_domain_transfer_data(struct spdk_memory_domain *dst_domain, void *dst_domain_ctx,
				     struct iovec *dst_iov, uint32_t dst_iovcnt,
				     struct spdk_memory_domain *src_domain, void *src_domain_ctx,
				     struct iovec *src_iov, uint32_t src_iovcnt,
				     struct spdk_memory_domain_translation_result *src_translation,
				     spdk_memory_domain_data_cpl_cb cpl_cb, void *cpl_cb_arg);

/**
 * Translate data located in \b src_domain space at address \b addr with size \b len into an equivalent
 * description of memory in dst_domain.
+1 −1
Original line number Diff line number Diff line
@@ -7,7 +7,7 @@ SPDK_ROOT_DIR := $(abspath $(CURDIR)/../..)
include $(SPDK_ROOT_DIR)/mk/spdk.common.mk

SO_VER := 4
SO_MINOR := 0
SO_MINOR := 1
SO_SUFFIX := $(SO_VER).$(SO_MINOR)

LIBNAME = dma
+31 −0
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@ struct spdk_memory_domain {
	enum spdk_dma_device_type type;
	spdk_memory_domain_pull_data_cb pull_cb;
	spdk_memory_domain_push_data_cb push_cb;
	spdk_memory_domain_transfer_data_cb transfer_cb;
	spdk_memory_domain_translate_memory_cb translate_cb;
	spdk_memory_domain_invalidate_data_cb invalidate_cb;
	spdk_memory_domain_memzero_cb memzero_cb;
@@ -133,6 +134,15 @@ spdk_memory_domain_set_push(struct spdk_memory_domain *domain,
	domain->push_cb = push_cb;
}

void
spdk_memory_domain_set_data_transfer(struct spdk_memory_domain *domain,
				     spdk_memory_domain_transfer_data_cb transfer_cb)
{
	assert(domain);

	domain->transfer_cb = transfer_cb;
}

void
spdk_memory_domain_set_memzero(struct spdk_memory_domain *domain,
			       spdk_memory_domain_memzero_cb memzero_cb)
@@ -221,6 +231,27 @@ spdk_memory_domain_push_data(struct spdk_memory_domain *dst_domain, void *dst_do
				   cpl_cb, cpl_cb_arg);
}

int
spdk_memory_domain_transfer_data(struct spdk_memory_domain *dst_domain, void *dst_domain_ctx,
				 struct iovec *dst_iov, uint32_t dst_iovcnt,
				 struct spdk_memory_domain *src_domain, void *src_domain_ctx,
				 struct iovec *src_iov, uint32_t src_iovcnt,
				 struct spdk_memory_domain_translation_result *src_translation,
				 spdk_memory_domain_data_cpl_cb cpl_cb, void *cpl_cb_arg)
{
	assert(dst_domain);
	assert(dst_iov);
	assert(src_iov);

	if (spdk_unlikely(!dst_domain->transfer_cb)) {
		return -ENOTSUP;
	}

	return dst_domain->transfer_cb(dst_domain, dst_domain_ctx, dst_iov, dst_iovcnt, src_domain,
				       src_domain_ctx, src_iov, src_iovcnt,
				       src_translation, cpl_cb, cpl_cb_arg);
}

int
spdk_memory_domain_translate_data(struct spdk_memory_domain *src_domain, void *src_domain_ctx,
				  struct spdk_memory_domain *dst_domain, struct spdk_memory_domain_translation_ctx *dst_domain_ctx,
+2 −0
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@
	spdk_memory_domain_set_invalidate;
	spdk_memory_domain_set_pull;
	spdk_memory_domain_set_push;
	spdk_memory_domain_set_data_transfer;
	spdk_memory_domain_set_memzero;
	spdk_memory_domain_get_context;
	spdk_memory_domain_get_dma_device_type;
@@ -16,6 +17,7 @@
	spdk_memory_domain_push_data;
	spdk_memory_domain_translate_data;
	spdk_memory_domain_invalidate_data;
	spdk_memory_domain_transfer_data;
	spdk_memory_domain_memzero;
	spdk_memory_domain_get_first;
	spdk_memory_domain_get_next;