xref: /spdk/module/accel/mlx5/accel_mlx5_rpc.c (revision 60241941e6cfa4fc04cfcf6840c79f941ccf85d0)
1 /*   SPDX-License-Identifier: BSD-3-Clause
2  *   Copyright (c) 2022-2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3  */
4 
5 #include "spdk/rpc.h"
6 #include "spdk/util.h"
7 #include "spdk/log.h"
8 
9 #include "accel_mlx5.h"
10 
11 static const struct spdk_json_object_decoder rpc_mlx5_module_decoder[] = {
12 	{"qp_size", offsetof(struct accel_mlx5_attr, qp_size), spdk_json_decode_uint16, true},
13 	{"num_requests", offsetof(struct accel_mlx5_attr, num_requests), spdk_json_decode_uint32, true},
14 	{"allowed_devs", offsetof(struct accel_mlx5_attr, allowed_devs), spdk_json_decode_string, true},
15 	{"crypto_split_blocks", offsetof(struct accel_mlx5_attr, crypto_split_blocks), spdk_json_decode_uint16, true},
16 };
17 
18 static void
19 rpc_mlx5_scan_accel_module(struct spdk_jsonrpc_request *request,
20 			   const struct spdk_json_val *params)
21 {
22 	struct accel_mlx5_attr attr;
23 	int rc;
24 
25 	accel_mlx5_get_default_attr(&attr);
26 
27 	if (params != NULL) {
28 		if (spdk_json_decode_object(params, rpc_mlx5_module_decoder,
29 					    SPDK_COUNTOF(rpc_mlx5_module_decoder),
30 					    &attr)) {
31 			SPDK_ERRLOG("spdk_json_decode_object() failed\n");
32 			spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_PARSE_ERROR,
33 							 "spdk_json_decode_object failed");
34 			return;
35 		}
36 	}
37 
38 	rc = accel_mlx5_enable(&attr);
39 	if (rc) {
40 		spdk_jsonrpc_send_error_response_fmt(request, rc, "mlx5 scan failed with %d", rc);
41 	} else {
42 		spdk_jsonrpc_send_bool_response(request, true);
43 	}
44 }
45 SPDK_RPC_REGISTER("mlx5_scan_accel_module", rpc_mlx5_scan_accel_module, SPDK_RPC_STARTUP)
46