xref: /spdk/module/accel/dsa/accel_dsa_rpc.c (revision 95d6c9fac17572b107042103439aafd696d60b0e)
1 /*   SPDX-License-Identifier: BSD-3-Clause
2  *   Copyright (C) 2022 Intel Corporation.
3  *   All rights reserved.
4  */
5 
6 #include "accel_dsa.h"
7 
8 #include "spdk/rpc.h"
9 #include "spdk/util.h"
10 #include "spdk/event.h"
11 #include "spdk/stdinc.h"
12 #include "spdk/env.h"
13 #include "spdk/string.h"
14 
15 struct rpc_dsa_scan_accel_module {
16 	bool config_kernel_mode;
17 };
18 
19 static const struct spdk_json_object_decoder rpc_dsa_scan_accel_module_decoder[] = {
20 	{"config_kernel_mode", offsetof(struct rpc_dsa_scan_accel_module, config_kernel_mode), spdk_json_decode_bool, true},
21 };
22 
23 static void
24 rpc_dsa_scan_accel_module(struct spdk_jsonrpc_request *request,
25 			  const struct spdk_json_val *params)
26 {
27 	struct rpc_dsa_scan_accel_module req = {};
28 	int rc;
29 
30 	if (params != NULL) {
31 		if (spdk_json_decode_object(params, rpc_dsa_scan_accel_module_decoder,
32 					    SPDK_COUNTOF(rpc_dsa_scan_accel_module_decoder),
33 					    &req)) {
34 			SPDK_ERRLOG("spdk_json_decode_object() failed\n");
35 			spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
36 							 "Invalid parameters");
37 			return;
38 		}
39 	}
40 
41 	rc = accel_dsa_enable_probe(req.config_kernel_mode);
42 	if (rc != 0) {
43 		spdk_jsonrpc_send_error_response(request, rc, spdk_strerror(-rc));
44 		return;
45 	}
46 
47 	if (req.config_kernel_mode) {
48 		SPDK_NOTICELOG("Enabled DSA kernel-mode\n");
49 	} else {
50 		SPDK_NOTICELOG("Enabled DSA user-mode\n");
51 	}
52 
53 	spdk_jsonrpc_send_bool_response(request, true);
54 }
55 SPDK_RPC_REGISTER("dsa_scan_accel_module", rpc_dsa_scan_accel_module, SPDK_RPC_STARTUP)
56 SPDK_RPC_REGISTER_ALIAS_DEPRECATED(dsa_scan_accel_module, dsa_scan_accel_engine)
57