Spdk/lib/accel/accel_engine_rpc.c
paul luse c6ecddcc1c lib/accel: add RPC to get list of OP codes per module
In prep for upcoming patch that will provide an RPC to override
and automatic assignment of an op code to an engine.

Signed-off-by: paul luse <paul.e.luse@intel.com>
Change-Id: I17d4b962fb376a77f97ce051a513679d0fba698e
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/12829
Community-CI: Mellanox Build Bot
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-by: Aleksey Marchuk <alexeymar@nvidia.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
2022-08-03 07:53:21 +00:00

74 lines
1.8 KiB
C

/* SPDX-License-Identifier: BSD-3-Clause
* Copyright (c) Intel Corporation.
* All rights reserved.
*/
#include "spdk_internal/accel_engine.h"
#include "spdk/rpc.h"
#include "spdk/util.h"
#include "spdk/event.h"
#include "spdk/stdinc.h"
#include "spdk/env.h"
const char *g_opcode_strings[ACCEL_OPC_LAST] = {
"copy", "fill", "dualcast", "compare", "crc32c", "copy_crc32c",
"compress", "decompress"
};
static int
_get_opc_name(enum accel_opcode opcode, const char **opcode_name)
{
int rc = 0;
if (opcode < ACCEL_OPC_LAST) {
*opcode_name = g_opcode_strings[opcode];
} else {
/* invalid opcode */
rc = -EINVAL;
}
return rc;
}
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;
const char *name, *engine_name;
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++) {
rc = _get_opc_name(opcode, &name);
if (rc == 0) {
rc = spdk_accel_get_opc_engine_name(opcode, &engine_name);
if (rc != 0) {
/* This isn't fatal but throw an informational message if we
* cant get an engine name right now */
SPDK_NOTICELOG("FYI error (%d) getting engine name.\n", rc);
}
spdk_json_write_named_string(w, name, engine_name);
} 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);
}
SPDK_RPC_REGISTER("accel_get_opc_assignments", rpc_accel_get_opc_assignments,
SPDK_RPC_STARTUP | SPDK_RPC_RUNTIME)