1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright (C) 2022 Intel Corporation. 3 * All rights reserved. 4 */ 5 6 #include "accel_dpdk_compressdev.h" 7 #include "spdk/rpc.h" 8 #include "spdk/util.h" 9 #include "spdk/string.h" 10 #include "spdk/log.h" 11 12 struct rpc_compressdev_scan_accel_module { 13 uint32_t pmd; 14 }; 15 16 static const struct spdk_json_object_decoder rpc_compressdev_scan_accel_module_decoder[] = { 17 {"pmd", offsetof(struct rpc_compressdev_scan_accel_module, pmd), spdk_json_decode_uint32}, 18 }; 19 20 static void 21 rpc_compressdev_scan_accel_module(struct spdk_jsonrpc_request *request, 22 const struct spdk_json_val *params) 23 { 24 struct rpc_compressdev_scan_accel_module req; 25 int rc = 0; 26 27 if (spdk_json_decode_object(params, rpc_compressdev_scan_accel_module_decoder, 28 SPDK_COUNTOF(rpc_compressdev_scan_accel_module_decoder), 29 &req)) { 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 if (req.pmd >= COMPRESS_PMD_MAX) { 37 spdk_jsonrpc_send_error_response_fmt(request, -EINVAL, 38 "PMD value %d should be less than %d", req.pmd, COMPRESS_PMD_MAX); 39 return; 40 } 41 42 rc = accel_compressdev_enable_probe(&req.pmd); 43 if (rc) { 44 spdk_jsonrpc_send_error_response(request, rc, spdk_strerror(-rc)); 45 return; 46 } 47 48 accel_dpdk_compressdev_enable(); 49 spdk_jsonrpc_send_bool_response(request, true); 50 } 51 SPDK_RPC_REGISTER("compressdev_scan_accel_module", rpc_compressdev_scan_accel_module, 52 SPDK_RPC_STARTUP) 53