Commit 73c0be85 authored by Yankun Li's avatar Yankun Li Committed by Konrad Sztyber
Browse files

lib/accel: support multiple [de]compression algorithms



Change-Id: I4b070ccdcdddb684a72a354245d4d14ed63e6bbf
Signed-off-by: default avatarYankun Li <845245370@qq.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/24564


Community-CI: Mellanox Build Bot
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarGangCao <gang.cao@intel.com>
Reviewed-by: default avatarAleksey Marchuk <alexeymar@nvidia.com>
Reviewed-by: default avatarKonrad Sztyber <konrad.sztyber@intel.com>
Reviewed-by: default avatarJim Harris <jim.harris@samsung.com>
parent 445bf303
Loading
Loading
Loading
Loading
+80 −3
Original line number Diff line number Diff line
@@ -22,6 +22,10 @@ extern "C" {
#define SPDK_ACCEL_AES_XTS_128_KEY_SIZE 16
#define SPDK_ACCEL_AES_XTS_256_KEY_SIZE 32

enum spdk_accel_comp_algo {
	SPDK_ACCEL_COMP_ALGO_DEFLATE = 0,
};

/** Data Encryption Key identifier */
struct spdk_accel_crypto_key;

@@ -262,7 +266,7 @@ int spdk_accel_submit_copy_crc32cv(struct spdk_io_channel *ch, void *dst, struct
				   spdk_accel_completion_cb cb_fn, void *cb_arg);

/**
 * Build and submit a memory compress request.
 * Build and submit a memory compress request using the deflate algorithm.
 *
 * This function will build the compress descriptor and submit it.
 *
@@ -284,7 +288,7 @@ int spdk_accel_submit_compress(struct spdk_io_channel *ch, void *dst,
			       spdk_accel_completion_cb cb_fn, void *cb_arg);

/**
 * Build and submit a memory decompress request.
 * Build and submit a memory decompress request using the deflate algorithm.
 *
 * This function will build the decompress descriptor and submit it.
 *
@@ -305,6 +309,52 @@ int spdk_accel_submit_decompress(struct spdk_io_channel *ch, struct iovec *dst_i
				 size_t src_iovcnt, uint32_t *output_size,
				 spdk_accel_completion_cb cb_fn, void *cb_arg);

/**
 * Build and submit a memory compress request using the specified algorithm.
 *
 * This function will build the compress descriptor and submit it.
 *
 * \param ch I/O channel associated with this call
 * \param dst Destination to write the data to.
 * \param nbytes Length in bytes.
 * \param src_iovs The io vector array which stores the src data and len.
 * \param src_iovcnt The size of the src io vectors.
 * \param comp_algo The compression algorithm, enum spdk_accel_comp_algo value.
 * \param output_size The size of the compressed data (may be NULL if not desired)
 * \param cb_fn Callback function which will be called when the request is complete.
 * \param cb_arg Opaque value which will be passed back as the arg parameter in
 * the completion callback.
 *
 * \return 0 on success, negative errno on failure.
 */
int spdk_accel_submit_compress_ext(struct spdk_io_channel *ch, void *dst, uint64_t nbytes,
				   struct iovec *src_iovs, size_t src_iovcnt,
				   enum spdk_accel_comp_algo comp_algo, uint32_t *output_size,
				   spdk_accel_completion_cb cb_fn, void *cb_arg);

/**
 * Build and submit a memory decompress request using the specified algorithm.
 *
 * This function will build the decompress descriptor and submit it.
 *
 * \param ch I/O channel associated with this call
 * \param dst_iovs The io vector array which stores the dst data and len.
 * \param dst_iovcnt The size of the dst io vectors.
 * \param src_iovs The io vector array which stores the src data and len.
 * \param src_iovcnt The size of the src io vectors.
 * \param decomp_algo The decompression algorithm, enum spdk_accel_comp_algo value.
 * \param output_size The size of the compressed data (may be NULL if not desired)
 * \param cb_fn Callback function which will be called when the request is complete.
 * \param cb_arg Opaque value which will be passed back as the arg parameter in
 * the completion callback.
 *
 * \return 0 on success, negative errno on failure.
 */
int spdk_accel_submit_decompress_ext(struct spdk_io_channel *ch, struct iovec *dst_iovs,
				     size_t dst_iovcnt, struct iovec *src_iovs, size_t src_iovcnt,
				     enum spdk_accel_comp_algo decomp_algo, uint32_t *output_size,
				     spdk_accel_completion_cb cb_fn, void *cb_arg);

/**
 * Submit an xor request.
 *
@@ -601,7 +651,34 @@ int spdk_accel_append_fill(struct spdk_accel_sequence **seq, struct spdk_io_chan
			   spdk_accel_step_cb cb_fn, void *cb_arg);

/**
 * Append a decompress operation to a sequence.
 * Append a decompression operation using the specified algorithm to a sequence.
 *
 * \param pseq Sequence object.  If NULL, a new sequence object will be created.
 * \param ch I/O channel.
 * \param dst_iovs Destination I/O vector array.
 * \param dst_iovcnt Size of the `dst_iovs` array.
 * \param dst_domain Memory domain to which the destination buffers belong.
 * \param dst_domain_ctx Destination buffer domain context.
 * \param src_iovs Source I/O vector array.
 * \param src_iovcnt Size of the `src_iovs` array.
 * \param src_domain Memory domain to which the source buffers belong.
 * \param src_domain_ctx Source buffer domain context.
 * \param decomp_algo The decompression algorithm, enum spdk_accel_comp_algo value.
 * \param cb_fn Callback to be executed once this operation is completed.
 * \param cb_arg Argument to be passed to `cb_fn`.
 *
 * \return 0 if operation was successfully added to the sequence, negative errno otherwise.
 */
int spdk_accel_append_decompress_ext(struct spdk_accel_sequence **pseq, struct spdk_io_channel *ch,
				     struct iovec *dst_iovs, size_t dst_iovcnt,
				     struct spdk_memory_domain *dst_domain, void *dst_domain_ctx,
				     struct iovec *src_iovs, size_t src_iovcnt,
				     struct spdk_memory_domain *src_domain, void *src_domain_ctx,
				     enum spdk_accel_comp_algo decomp_algo,
				     spdk_accel_step_cb cb_fn, void *cb_arg);

/**
 * Append a decompression operation using the deflate algorithm to a sequence.
 *
 * \param seq Sequence object.  If NULL, a new sequence object will be created.
 * \param ch I/O channel.
+8 −0
Original line number Diff line number Diff line
@@ -143,6 +143,9 @@ struct spdk_accel_task {
			struct spdk_dif_error		*err;
			uint32_t	num_blocks;
		} dif;
		struct {
			enum spdk_accel_comp_algo       algo; /* compresssion/decompression algorithm */
		} comp;
	};
	union {
		uint32_t		*crc_dst;
@@ -231,6 +234,11 @@ struct spdk_accel_module_if {
	 */
	bool (*crypto_supports_cipher)(enum spdk_accel_cipher cipher, size_t key_size);

	/**
	 * Return true if compresssion algo is supported, false otherwise.
	 */
	bool (*compress_supports_algo)(enum spdk_accel_comp_algo algo);

	/**
	 * Returns memory domains supported by the module.  If NULL, the module does not support
	 * memory domains.  The `domains` array can be NULL, in which case this function only
+76 −7
Original line number Diff line number Diff line
@@ -665,13 +665,33 @@ spdk_accel_submit_copy_crc32cv(struct spdk_io_channel *ch, void *dst,
	return accel_submit_task(accel_ch, accel_task);
}

static int
_accel_check_comp_algo(enum spdk_accel_comp_algo comp_algo)
{
	struct spdk_accel_module_if *module = g_modules_opc[SPDK_ACCEL_OPC_COMPRESS].module;

	if (!module->compress_supports_algo || !module->compress_supports_algo(comp_algo)) {
		SPDK_ERRLOG("Module %s doesn't support compression algo %d\n", module->name, comp_algo);
		return -ENOTSUP;
	}

	return 0;
}

int
spdk_accel_submit_compress(struct spdk_io_channel *ch, void *dst, uint64_t nbytes,
			   struct iovec *src_iovs, size_t src_iovcnt, uint32_t *output_size,
spdk_accel_submit_compress_ext(struct spdk_io_channel *ch, void *dst, uint64_t nbytes,
			       struct iovec *src_iovs, size_t src_iovcnt,
			       enum spdk_accel_comp_algo comp_algo, uint32_t *output_size,
			       spdk_accel_completion_cb cb_fn, void *cb_arg)
{
	struct accel_io_channel *accel_ch = spdk_io_channel_get_ctx(ch);
	struct spdk_accel_task *accel_task;
	int rc;

	rc = _accel_check_comp_algo(comp_algo);
	if (spdk_unlikely(rc != 0)) {
		return rc;
	}

	accel_task = _get_task(accel_ch, cb_fn, cb_arg);
	if (spdk_unlikely(accel_task == NULL)) {
@@ -691,18 +711,25 @@ spdk_accel_submit_compress(struct spdk_io_channel *ch, void *dst, uint64_t nbyte
	accel_task->op_code = SPDK_ACCEL_OPC_COMPRESS;
	accel_task->src_domain = NULL;
	accel_task->dst_domain = NULL;
	accel_task->comp.algo = comp_algo;

	return accel_submit_task(accel_ch, accel_task);
}

int
spdk_accel_submit_decompress(struct spdk_io_channel *ch, struct iovec *dst_iovs,
spdk_accel_submit_decompress_ext(struct spdk_io_channel *ch, struct iovec *dst_iovs,
				 size_t dst_iovcnt, struct iovec *src_iovs, size_t src_iovcnt,
			     uint32_t *output_size, spdk_accel_completion_cb cb_fn,
			     void *cb_arg)
				 enum spdk_accel_comp_algo decomp_algo, uint32_t *output_size,
				 spdk_accel_completion_cb cb_fn, void *cb_arg)
{
	struct accel_io_channel *accel_ch = spdk_io_channel_get_ctx(ch);
	struct spdk_accel_task *accel_task;
	int rc;

	rc = _accel_check_comp_algo(decomp_algo);
	if (spdk_unlikely(rc != 0)) {
		return rc;
	}

	accel_task = _get_task(accel_ch, cb_fn, cb_arg);
	if (spdk_unlikely(accel_task == NULL)) {
@@ -718,10 +745,30 @@ spdk_accel_submit_decompress(struct spdk_io_channel *ch, struct iovec *dst_iovs,
	accel_task->op_code = SPDK_ACCEL_OPC_DECOMPRESS;
	accel_task->src_domain = NULL;
	accel_task->dst_domain = NULL;
	accel_task->comp.algo = decomp_algo;

	return accel_submit_task(accel_ch, accel_task);
}

int
spdk_accel_submit_compress(struct spdk_io_channel *ch, void *dst, uint64_t nbytes,
			   struct iovec *src_iovs, size_t src_iovcnt, uint32_t *output_size,
			   spdk_accel_completion_cb cb_fn, void *cb_arg)
{
	return spdk_accel_submit_compress_ext(ch, dst, nbytes, src_iovs, src_iovcnt,
					      SPDK_ACCEL_COMP_ALGO_DEFLATE, output_size, cb_fn, cb_arg);
}

int
spdk_accel_submit_decompress(struct spdk_io_channel *ch, struct iovec *dst_iovs,
			     size_t dst_iovcnt, struct iovec *src_iovs, size_t src_iovcnt,
			     uint32_t *output_size, spdk_accel_completion_cb cb_fn,
			     void *cb_arg)
{
	return spdk_accel_submit_decompress_ext(ch, dst_iovs, dst_iovcnt, src_iovs, src_iovcnt,
						SPDK_ACCEL_COMP_ALGO_DEFLATE, output_size, cb_fn, cb_arg);
}

int
spdk_accel_submit_encrypt(struct spdk_io_channel *ch, struct spdk_accel_crypto_key *key,
			  struct iovec *dst_iovs, uint32_t dst_iovcnt,
@@ -1204,10 +1251,31 @@ spdk_accel_append_decompress(struct spdk_accel_sequence **pseq, struct spdk_io_c
			     struct iovec *src_iovs, size_t src_iovcnt,
			     struct spdk_memory_domain *src_domain, void *src_domain_ctx,
			     spdk_accel_step_cb cb_fn, void *cb_arg)
{
	return spdk_accel_append_decompress_ext(pseq, ch, dst_iovs, dst_iovcnt, dst_domain,
						dst_domain_ctx, src_iovs, src_iovcnt, src_domain,
						src_domain_ctx, SPDK_ACCEL_COMP_ALGO_DEFLATE,
						cb_fn, cb_arg);
}

int
spdk_accel_append_decompress_ext(struct spdk_accel_sequence **pseq, struct spdk_io_channel *ch,
				 struct iovec *dst_iovs, size_t dst_iovcnt,
				 struct spdk_memory_domain *dst_domain, void *dst_domain_ctx,
				 struct iovec *src_iovs, size_t src_iovcnt,
				 struct spdk_memory_domain *src_domain, void *src_domain_ctx,
				 enum spdk_accel_comp_algo decomp_algo,
				 spdk_accel_step_cb cb_fn, void *cb_arg)
{
	struct accel_io_channel *accel_ch = spdk_io_channel_get_ctx(ch);
	struct spdk_accel_task *task;
	struct spdk_accel_sequence *seq = *pseq;
	int rc;

	rc = _accel_check_comp_algo(decomp_algo);
	if (spdk_unlikely(rc != 0)) {
		return rc;
	}

	if (seq == NULL) {
		seq = accel_sequence_get(accel_ch);
@@ -1238,6 +1306,7 @@ spdk_accel_append_decompress(struct spdk_accel_sequence **pseq, struct spdk_io_c
	task->s.iovcnt = src_iovcnt;
	task->nbytes = accel_get_iovlen(src_iovs, src_iovcnt);
	task->op_code = SPDK_ACCEL_OPC_DECOMPRESS;
	task->comp.algo = decomp_algo;

	TAILQ_INSERT_TAIL(&seq->tasks, task, seq_link);
	*pseq = seq;
+37 −2
Original line number Diff line number Diff line
@@ -167,7 +167,7 @@ _sw_accel_crc32cv(uint32_t *crc_dst, struct iovec *iov, uint32_t iovcnt, uint32_
}

static int
_sw_accel_compress(struct sw_accel_io_channel *sw_ch, struct spdk_accel_task *accel_task)
_sw_accel_compress_deflate(struct sw_accel_io_channel *sw_ch, struct spdk_accel_task *accel_task)
{
#ifdef SPDK_CONFIG_ISAL
	size_t last_seglen = accel_task->s.iovs[accel_task->s.iovcnt - 1].iov_len;
@@ -251,7 +251,7 @@ _sw_accel_compress(struct sw_accel_io_channel *sw_ch, struct spdk_accel_task *ac
}

static int
_sw_accel_decompress(struct sw_accel_io_channel *sw_ch, struct spdk_accel_task *accel_task)
_sw_accel_decompress_deflate(struct sw_accel_io_channel *sw_ch, struct spdk_accel_task *accel_task)
{
#ifdef SPDK_CONFIG_ISAL
	struct iovec *siov = accel_task->s.iovs;
@@ -305,6 +305,30 @@ _sw_accel_decompress(struct sw_accel_io_channel *sw_ch, struct spdk_accel_task *
#endif
}

static int
_sw_accel_compress(struct sw_accel_io_channel *sw_ch, struct spdk_accel_task *accel_task)
{
	switch (accel_task->comp.algo) {
	case SPDK_ACCEL_COMP_ALGO_DEFLATE:
		return _sw_accel_compress_deflate(sw_ch, accel_task);
	default:
		assert(0);
		return -EINVAL;
	}
}

static int
_sw_accel_decompress(struct sw_accel_io_channel *sw_ch, struct spdk_accel_task *accel_task)
{
	switch (accel_task->comp.algo) {
	case SPDK_ACCEL_COMP_ALGO_DEFLATE:
		return _sw_accel_decompress_deflate(sw_ch, accel_task);
	default:
		assert(0);
		return -EINVAL;
	}
}

static int
_sw_accel_crypto_operation(struct spdk_accel_task *accel_task, struct spdk_accel_crypto_key *key,
			   sw_accel_crypto_op op)
@@ -760,6 +784,16 @@ sw_accel_crypto_supports_cipher(enum spdk_accel_cipher cipher, size_t key_size)
	}
}

static bool
sw_accel_compress_supports_algo(enum spdk_accel_comp_algo algo)
{
	if (algo == SPDK_ACCEL_COMP_ALGO_DEFLATE) {
		return true;
	}

	return false;
}

static int
sw_accel_get_operation_info(enum spdk_accel_opcode opcode,
			    const struct spdk_accel_operation_exec_ctx *ctx,
@@ -784,6 +818,7 @@ static struct spdk_accel_module_if g_sw_module = {
	.crypto_key_deinit		= sw_accel_crypto_key_deinit,
	.crypto_supports_tweak_mode	= sw_accel_crypto_supports_tweak_mode,
	.crypto_supports_cipher		= sw_accel_crypto_supports_cipher,
	.compress_supports_algo         = sw_accel_compress_supports_algo,
	.get_operation_info		= sw_accel_get_operation_info,
};

+3 −0
Original line number Diff line number Diff line
@@ -54,6 +54,9 @@
	spdk_accel_get_buf_align;
	spdk_accel_get_opcode_name;
	spdk_accel_get_opc_memory_domains;
	spdk_accel_submit_compress_ext;
	spdk_accel_submit_decompress_ext;
	spdk_accel_append_decompress_ext;

	# functions needed by modules
	spdk_accel_module_list_add;
Loading