Commit 4864545d authored by Konrad Sztyber's avatar Konrad Sztyber Committed by Tomasz Zawadzki
Browse files

accel: interface for getting buffer alignement requirements



This interface allows users to query accel for the minimum buffer
requirements to execute a given operation.

Signed-off-by: default avatarKonrad Sztyber <konrad.sztyber@intel.com>
Change-Id: I11ded02bca86f0979bcedef65fc2b75e56bca95a
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/19763


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarJim Harris <jim.harris@gmail.com>
Community-CI: Mellanox Build Bot
Reviewed-by: default avatarAleksey Marchuk <alexeymar@nvidia.com>
parent 247e9eb2
Loading
Loading
Loading
Loading
+24 −0
Original line number Diff line number Diff line
@@ -720,6 +720,30 @@ struct spdk_accel_opcode_stats {
void spdk_accel_get_opcode_stats(struct spdk_io_channel *ch, enum spdk_accel_opcode opcode,
				 struct spdk_accel_opcode_stats *stats, size_t size);

/**
 * Context for the `spdk_accel_get_buf_align()` function.  Depending on the operation, some of the
 * fields might be unused.
 */
struct spdk_accel_operation_exec_ctx {
	/** Size of this structure in bytes */
	size_t size;
	/** Block size in bytes, required for encrypt and decrypt */
	uint32_t block_size;
};

/**
 * Get minimum buffer alignment to execute a given operation.  It accounts for constraints of a
 * module assigned to execute a given operation and the driver (if set). The alignment is returned
 * as a power of 2.  The value of 0 means that the buffers don't need to be aligned.
 *
 * \param opcode Opcode.
 * \param ctx Context in which the operation will be executed.
 *
 * \return Minimum alignment.
 */
uint8_t spdk_accel_get_buf_align(enum spdk_accel_opcode opcode,
				 const struct spdk_accel_operation_exec_ctx *ctx);

#ifdef __cplusplus
}
#endif
+24 −0
Original line number Diff line number Diff line
@@ -135,6 +135,14 @@ struct spdk_accel_task {
	} bounce;
};

struct spdk_accel_opcode_info {
	/**
	 * Minimum buffer alignment required to execute the operation, expressed as power of 2.  The
	 * value of 0 means that the buffers don't need to be aligned.
	 */
	uint8_t required_alignment;
};

struct spdk_accel_module_if {
	/** Name of the module. */
	const char *name;
@@ -204,6 +212,14 @@ struct spdk_accel_module_if {
	 */
	int (*get_memory_domains)(struct spdk_memory_domain **domains, int num_domains);

	/**
	 * Returns information/constraints for a given operation.  If unimplemented, it is assumed
	 * that the module doens't have any constraints to execute any operation.
	 */
	int (*get_operation_info)(enum spdk_accel_opcode opcode,
				  const struct spdk_accel_operation_exec_ctx *ctx,
				  struct spdk_accel_opcode_info *info);

	TAILQ_ENTRY(spdk_accel_module_if)	tailq;
};

@@ -247,6 +263,14 @@ struct spdk_accel_driver {
	/** Returns IO channel that will be passed to `execute_sequence()`. */
	struct spdk_io_channel *(*get_io_channel)(void);

	/**
	 * Returns information/constraints for a given operation.  If unimplemented, it is assumed
	 * that the driver doesn't have any constraints to execute any operation.
	 */
	int (*get_operation_info)(enum spdk_accel_opcode opcode,
				  const struct spdk_accel_operation_exec_ctx *ctx,
				  struct spdk_accel_opcode_info *info);

	TAILQ_ENTRY(spdk_accel_driver)	tailq;
};

+22 −0
Original line number Diff line number Diff line
@@ -2890,4 +2890,26 @@ spdk_accel_get_opcode_stats(struct spdk_io_channel *ch, enum spdk_accel_opcode o
#undef SET_FIELD
}

uint8_t
spdk_accel_get_buf_align(enum spdk_accel_opcode opcode,
			 const struct spdk_accel_operation_exec_ctx *ctx)
{
	struct spdk_accel_module_if *module = g_modules_opc[opcode].module;
	struct spdk_accel_opcode_info modinfo = {}, drvinfo = {};

	if (g_accel_driver != NULL && g_accel_driver->get_operation_info != NULL) {
		g_accel_driver->get_operation_info(opcode, ctx, &drvinfo);
	}

	if (module->get_operation_info != NULL) {
		module->get_operation_info(opcode, ctx, &modinfo);
	}

	/* If a driver is set, it'll execute most of the operations, while the rest will usually
	 * fall back to accel_sw, which doesn't have any alignment requiremenets.  However, to be
	 * extra safe, return the max(driver, module) if a driver delegates some operations to a
	 * hardware module. */
	return spdk_max(modinfo.required_alignment, drvinfo.required_alignment);
}

SPDK_LOG_REGISTER_COMPONENT(accel)
+11 −0
Original line number Diff line number Diff line
@@ -659,6 +659,16 @@ sw_accel_crypto_supports_cipher(enum spdk_accel_cipher cipher, size_t key_size)
	}
}

static int
sw_accel_get_operation_info(enum spdk_accel_opcode opcode,
			    const struct spdk_accel_operation_exec_ctx *ctx,
			    struct spdk_accel_opcode_info *info)
{
	info->required_alignment = 0;

	return 0;
}

static struct spdk_accel_module_if g_sw_module = {
	.module_init			= sw_accel_module_init,
	.module_fini			= sw_accel_module_fini,
@@ -672,6 +682,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,
	.get_operation_info		= sw_accel_get_operation_info,
};

SPDK_ACCEL_MODULE_REGISTER(sw, &g_sw_module)
+1 −0
Original line number Diff line number Diff line
@@ -40,6 +40,7 @@
	spdk_accel_set_opts;
	spdk_accel_get_opts;
	spdk_accel_get_opcode_stats;
	spdk_accel_get_buf_align;

	# functions needed by modules
	spdk_accel_module_list_add;