xref: /spdk/module/accel/mlx5/accel_mlx5_rpc.c (revision 57fd99b91e71a4baa5543e19ff83958dc99d4dac)
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 };
16 
17 static void
18 rpc_mlx5_scan_accel_module(struct spdk_jsonrpc_request *request,
19 			   const struct spdk_json_val *params)
20 {
21 	struct accel_mlx5_attr attr;
22 	int rc;
23 
24 	accel_mlx5_get_default_attr(&attr);
25 
26 	if (params != NULL) {
27 		if (spdk_json_decode_object(params, rpc_mlx5_module_decoder,
28 					    SPDK_COUNTOF(rpc_mlx5_module_decoder),
29 					    &attr)) {
30 			SPDK_ERRLOG("spdk_json_decode_object() failed\n");
31 			spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_PARSE_ERROR,
32 							 "spdk_json_decode_object failed");
33 			return;
34 		}
35 	}
36 
37 	rc = accel_mlx5_enable(&attr);
38 	if (rc) {
39 		spdk_jsonrpc_send_error_response_fmt(request, rc, "mlx5 scan failed with %d", rc);
40 	} else {
41 		spdk_jsonrpc_send_bool_response(request, true);
42 	}
43 }
44 SPDK_RPC_REGISTER("mlx5_scan_accel_module", rpc_mlx5_scan_accel_module, SPDK_RPC_STARTUP)
45