2022-05-26 23:46:01 +00:00
|
|
|
/* SPDX-License-Identifier: BSD-3-Clause
|
2022-11-01 20:26:26 +00:00
|
|
|
* Copyright (C) 2020 Intel Corporation.
|
2022-10-04 18:50:44 +00:00
|
|
|
* Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES.
|
2022-05-26 23:46:01 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*/
|
|
|
|
|
2022-08-05 19:32:35 +00:00
|
|
|
#include "accel_internal.h"
|
2022-10-04 19:16:21 +00:00
|
|
|
#include "spdk_internal/accel_module.h"
|
2022-05-26 23:46:01 +00:00
|
|
|
|
|
|
|
#include "spdk/rpc.h"
|
|
|
|
#include "spdk/util.h"
|
|
|
|
#include "spdk/event.h"
|
|
|
|
#include "spdk/stdinc.h"
|
|
|
|
#include "spdk/env.h"
|
2022-10-04 19:16:21 +00:00
|
|
|
#include "spdk/util.h"
|
2022-05-26 23:46:01 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
rpc_accel_get_opc_assignments(struct spdk_jsonrpc_request *request,
|
|
|
|
const struct spdk_json_val *params)
|
|
|
|
{
|
|
|
|
struct spdk_json_write_ctx *w;
|
|
|
|
enum accel_opcode opcode;
|
2022-10-04 13:11:02 +00:00
|
|
|
const char *name, *module_name = NULL;
|
2022-05-26 23:46:01 +00:00
|
|
|
int rc;
|
|
|
|
|
|
|
|
if (params != NULL) {
|
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
|
|
|
"accel_get_opc_assignments requires no parameters");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
w = spdk_jsonrpc_begin_result(request);
|
|
|
|
|
|
|
|
spdk_json_write_object_begin(w);
|
|
|
|
for (opcode = 0; opcode < ACCEL_OPC_LAST; opcode++) {
|
2022-10-04 18:50:44 +00:00
|
|
|
rc = _accel_get_opc_name(opcode, &name);
|
2022-05-26 23:46:01 +00:00
|
|
|
if (rc == 0) {
|
2022-08-08 21:43:24 +00:00
|
|
|
rc = spdk_accel_get_opc_module_name(opcode, &module_name);
|
2022-11-10 15:09:30 +00:00
|
|
|
if (rc == 0) {
|
|
|
|
spdk_json_write_named_string(w, name, module_name);
|
|
|
|
} else {
|
2022-05-26 23:46:01 +00:00
|
|
|
/* This isn't fatal but throw an informational message if we
|
2022-08-08 21:43:24 +00:00
|
|
|
* cant get an module name right now */
|
|
|
|
SPDK_NOTICELOG("FYI error (%d) getting module name.\n", rc);
|
2022-05-26 23:46:01 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* this should never happen */
|
|
|
|
SPDK_ERRLOG("Invalid opcode (%d)).\n", opcode);
|
|
|
|
assert(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
spdk_json_write_object_end(w);
|
|
|
|
|
|
|
|
spdk_jsonrpc_end_result(request, w);
|
|
|
|
}
|
2022-11-10 15:09:30 +00:00
|
|
|
SPDK_RPC_REGISTER("accel_get_opc_assignments", rpc_accel_get_opc_assignments, SPDK_RPC_RUNTIME)
|
2022-07-21 21:15:09 +00:00
|
|
|
|
|
|
|
static void
|
2022-08-08 21:43:24 +00:00
|
|
|
rpc_dump_module_info(struct module_info *info)
|
2022-07-21 21:15:09 +00:00
|
|
|
{
|
|
|
|
struct spdk_json_write_ctx *w = info->w;
|
|
|
|
const char *name;
|
|
|
|
uint32_t i;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
spdk_json_write_object_begin(w);
|
|
|
|
|
2022-08-08 21:43:24 +00:00
|
|
|
spdk_json_write_named_string(w, "module", info->name);
|
|
|
|
spdk_json_write_named_array_begin(w, "supported ops");
|
2022-07-21 21:15:09 +00:00
|
|
|
|
|
|
|
for (i = 0; i < info->num_ops; i++) {
|
2022-10-04 18:50:44 +00:00
|
|
|
rc = _accel_get_opc_name(i, &name);
|
2022-07-21 21:15:09 +00:00
|
|
|
if (rc == 0) {
|
|
|
|
spdk_json_write_string(w, name);
|
|
|
|
} else {
|
|
|
|
/* this should never happen */
|
|
|
|
SPDK_ERRLOG("Invalid opcode (%d)).\n", i);
|
|
|
|
assert(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
spdk_json_write_array_end(w);
|
|
|
|
spdk_json_write_object_end(w);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-08-08 21:43:24 +00:00
|
|
|
rpc_accel_get_module_info(struct spdk_jsonrpc_request *request,
|
2022-07-21 21:15:09 +00:00
|
|
|
const struct spdk_json_val *params)
|
|
|
|
{
|
2022-08-08 21:43:24 +00:00
|
|
|
struct module_info info;
|
2022-07-21 21:15:09 +00:00
|
|
|
|
|
|
|
if (params != NULL) {
|
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
2022-08-08 21:43:24 +00:00
|
|
|
"accel_get_module_info requires no parameters");
|
2022-07-21 21:15:09 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
info.w = spdk_jsonrpc_begin_result(request);
|
|
|
|
spdk_json_write_array_begin(info.w);
|
|
|
|
|
2022-08-08 21:43:24 +00:00
|
|
|
_accel_for_each_module(&info, rpc_dump_module_info);
|
2022-07-21 21:15:09 +00:00
|
|
|
|
|
|
|
spdk_json_write_array_end(info.w);
|
|
|
|
spdk_jsonrpc_end_result(request, info.w);
|
|
|
|
}
|
2022-11-10 15:09:30 +00:00
|
|
|
SPDK_RPC_REGISTER("accel_get_module_info", rpc_accel_get_module_info, SPDK_RPC_RUNTIME)
|
2022-08-08 21:43:24 +00:00
|
|
|
SPDK_RPC_REGISTER_ALIAS_DEPRECATED(accel_get_module_info, accel_get_engine_info)
|
2022-06-01 00:13:04 +00:00
|
|
|
|
|
|
|
struct rpc_accel_assign_opc {
|
|
|
|
char *opname;
|
2022-08-08 21:43:24 +00:00
|
|
|
char *module;
|
2022-06-01 00:13:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const struct spdk_json_object_decoder rpc_accel_assign_opc_decoders[] = {
|
|
|
|
{"opname", offsetof(struct rpc_accel_assign_opc, opname), spdk_json_decode_string},
|
2022-08-08 21:43:24 +00:00
|
|
|
{"module", offsetof(struct rpc_accel_assign_opc, module), spdk_json_decode_string},
|
2022-06-01 00:13:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
free_accel_assign_opc(struct rpc_accel_assign_opc *r)
|
|
|
|
{
|
|
|
|
free(r->opname);
|
2022-08-08 21:43:24 +00:00
|
|
|
free(r->module);
|
2022-06-01 00:13:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
rpc_accel_assign_opc(struct spdk_jsonrpc_request *request,
|
|
|
|
const struct spdk_json_val *params)
|
|
|
|
{
|
|
|
|
struct rpc_accel_assign_opc req = {};
|
2022-10-04 18:50:44 +00:00
|
|
|
const char *opcode_str;
|
2022-06-01 00:13:04 +00:00
|
|
|
enum accel_opcode opcode;
|
|
|
|
bool found = false;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
if (spdk_json_decode_object(params, rpc_accel_assign_opc_decoders,
|
|
|
|
SPDK_COUNTOF(rpc_accel_assign_opc_decoders),
|
|
|
|
&req)) {
|
|
|
|
SPDK_DEBUGLOG(accel, "spdk_json_decode_object failed\n");
|
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_PARSE_ERROR,
|
|
|
|
"spdk_json_decode_object failed");
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (opcode = 0; opcode < ACCEL_OPC_LAST; opcode++) {
|
2022-10-04 18:50:44 +00:00
|
|
|
rc = _accel_get_opc_name(opcode, &opcode_str);
|
|
|
|
assert(!rc);
|
|
|
|
if (strcmp(opcode_str, req.opname) == 0) {
|
2022-06-01 00:13:04 +00:00
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (found == false) {
|
|
|
|
SPDK_DEBUGLOG(accel, "Invalid operation name\n");
|
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
|
|
|
"spdk_json_decode_object failed");
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2022-08-08 21:43:24 +00:00
|
|
|
rc = spdk_accel_assign_opc(opcode, req.module);
|
2022-06-01 00:13:04 +00:00
|
|
|
if (rc) {
|
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
|
|
|
"error assigning opcode");
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2022-08-08 21:43:24 +00:00
|
|
|
SPDK_NOTICELOG("Operation %s will be assigned to module %s\n", req.opname, req.module);
|
2022-06-01 00:13:04 +00:00
|
|
|
spdk_jsonrpc_send_bool_response(request, true);
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
free_accel_assign_opc(&req);
|
|
|
|
|
|
|
|
}
|
|
|
|
SPDK_RPC_REGISTER("accel_assign_opc", rpc_accel_assign_opc, SPDK_RPC_STARTUP)
|
2022-10-04 19:16:21 +00:00
|
|
|
|
|
|
|
struct rpc_accel_crypto_key_create {
|
|
|
|
struct spdk_accel_crypto_key_create_param param;
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct spdk_json_object_decoder rpc_accel_dek_create_decoders[] = {
|
|
|
|
{"cipher", offsetof(struct rpc_accel_crypto_key_create, param.cipher), spdk_json_decode_string},
|
|
|
|
{"key", offsetof(struct rpc_accel_crypto_key_create, param.hex_key), spdk_json_decode_string},
|
|
|
|
{"key2", offsetof(struct rpc_accel_crypto_key_create, param.hex_key2), spdk_json_decode_string, true},
|
|
|
|
{"name", offsetof(struct rpc_accel_crypto_key_create, param.key_name), spdk_json_decode_string},
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
rpc_accel_crypto_key_create(struct spdk_jsonrpc_request *request,
|
|
|
|
const struct spdk_json_val *params)
|
|
|
|
{
|
|
|
|
struct rpc_accel_crypto_key_create req = {};
|
|
|
|
size_t key_size;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
if (spdk_json_decode_object(params, rpc_accel_dek_create_decoders,
|
|
|
|
SPDK_COUNTOF(rpc_accel_dek_create_decoders),
|
|
|
|
&req)) {
|
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_PARSE_ERROR,
|
|
|
|
"spdk_json_decode_object failed");
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = spdk_accel_crypto_key_create(&req.param);
|
|
|
|
if (rc) {
|
|
|
|
spdk_jsonrpc_send_error_response_fmt(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
|
|
|
"failed to create DEK, rc %d", rc);
|
|
|
|
} else {
|
|
|
|
spdk_jsonrpc_send_bool_response(request, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
free(req.param.cipher);
|
|
|
|
if (req.param.hex_key) {
|
|
|
|
key_size = strnlen(req.param.hex_key, SPDK_ACCEL_CRYPTO_KEY_MAX_HEX_LENGTH);
|
|
|
|
spdk_memset_s(req.param.hex_key, key_size, 0, key_size);
|
|
|
|
free(req.param.hex_key);
|
|
|
|
}
|
|
|
|
if (req.param.hex_key2) {
|
|
|
|
key_size = strnlen(req.param.hex_key2, SPDK_ACCEL_CRYPTO_KEY_MAX_HEX_LENGTH);
|
|
|
|
spdk_memset_s(req.param.hex_key2, key_size, 0, key_size);
|
|
|
|
free(req.param.hex_key2);
|
|
|
|
}
|
|
|
|
free(req.param.key_name);
|
|
|
|
}
|
|
|
|
SPDK_RPC_REGISTER("accel_crypto_key_create", rpc_accel_crypto_key_create, SPDK_RPC_RUNTIME)
|
|
|
|
|
|
|
|
struct rpc_accel_crypto_keys_get_ctx {
|
|
|
|
char *key_name;
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct spdk_json_object_decoder rpc_accel_crypto_keys_get_decoders[] = {
|
2022-08-31 15:26:12 +00:00
|
|
|
{"key_name", offsetof(struct rpc_accel_crypto_keys_get_ctx, key_name), spdk_json_decode_string},
|
2022-10-04 19:16:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
rpc_accel_crypto_keys_get(struct spdk_jsonrpc_request *request,
|
|
|
|
const struct spdk_json_val *params)
|
|
|
|
{
|
|
|
|
struct rpc_accel_crypto_keys_get_ctx req = {};
|
|
|
|
struct spdk_accel_crypto_key *key = NULL;
|
|
|
|
struct spdk_json_write_ctx *w;
|
|
|
|
|
|
|
|
if (params && spdk_json_decode_object(params, rpc_accel_crypto_keys_get_decoders,
|
|
|
|
SPDK_COUNTOF(rpc_accel_crypto_keys_get_decoders),
|
|
|
|
&req)) {
|
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_PARSE_ERROR,
|
|
|
|
"spdk_json_decode_object failed");
|
|
|
|
free(req.key_name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (req.key_name) {
|
|
|
|
key = spdk_accel_crypto_key_get(req.key_name);
|
|
|
|
free(req.key_name);
|
|
|
|
if (!key) {
|
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, "key was not found\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
w = spdk_jsonrpc_begin_result(request);
|
|
|
|
spdk_json_write_array_begin(w);
|
|
|
|
|
|
|
|
if (key) {
|
|
|
|
_accel_crypto_key_dump_param(w, key);
|
|
|
|
} else {
|
|
|
|
_accel_crypto_keys_dump_param(w);
|
|
|
|
}
|
|
|
|
|
|
|
|
spdk_json_write_array_end(w);
|
|
|
|
spdk_jsonrpc_end_result(request, w);
|
|
|
|
}
|
|
|
|
SPDK_RPC_REGISTER("accel_crypto_keys_get", rpc_accel_crypto_keys_get, SPDK_RPC_RUNTIME)
|
2022-08-31 15:26:12 +00:00
|
|
|
|
|
|
|
static const struct spdk_json_object_decoder rpc_accel_crypto_key_destroy_decoders[] = {
|
|
|
|
{"key_name", offsetof(struct rpc_accel_crypto_keys_get_ctx, key_name), spdk_json_decode_string, true},
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
rpc_accel_crypto_key_destroy(struct spdk_jsonrpc_request *request,
|
|
|
|
const struct spdk_json_val *params)
|
|
|
|
{
|
|
|
|
struct rpc_accel_crypto_keys_get_ctx req = {};
|
|
|
|
struct spdk_accel_crypto_key *key = NULL;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
if (params && spdk_json_decode_object(params, rpc_accel_crypto_key_destroy_decoders,
|
|
|
|
SPDK_COUNTOF(rpc_accel_crypto_key_destroy_decoders),
|
|
|
|
&req)) {
|
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_PARSE_ERROR,
|
|
|
|
"spdk_json_decode_object failed");
|
|
|
|
free(req.key_name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
key = spdk_accel_crypto_key_get(req.key_name);
|
|
|
|
if (!key) {
|
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
|
|
|
"No key object found");
|
|
|
|
free(req.key_name);
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
rc = spdk_accel_crypto_key_destroy(key);
|
|
|
|
if (rc) {
|
|
|
|
spdk_jsonrpc_send_error_response_fmt(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
|
|
|
"Failed to destroy key, rc %d\n", rc);
|
|
|
|
} else {
|
|
|
|
spdk_jsonrpc_send_bool_response(request, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
free(req.key_name);
|
|
|
|
}
|
|
|
|
SPDK_RPC_REGISTER("accel_crypto_key_destroy", rpc_accel_crypto_key_destroy, SPDK_RPC_RUNTIME)
|