regex/mlx5: add engine status check
[dpdk.git] / drivers / regex / mlx5 / mlx5_regex_devx.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright 2020 Mellanox Technologies, Ltd
3  */
4
5 #include <rte_errno.h>
6 #include <rte_log.h>
7
8 #include <mlx5_glue.h>
9 #include <mlx5_devx_cmds.h>
10 #include <mlx5_prm.h>
11
12 #include "mlx5_regex.h"
13 #include "mlx5_regex_utils.h"
14
15 int
16 mlx5_devx_regex_register_write(struct ibv_context *ctx, int engine_id,
17                                uint32_t addr, uint32_t data)
18 {
19         uint32_t out[MLX5_ST_SZ_DW(set_regexp_register_out)] = {0};
20         uint32_t in[MLX5_ST_SZ_DW(set_regexp_register_in)] = {0};
21         int ret;
22
23         MLX5_SET(set_regexp_register_in, in, opcode,
24                  MLX5_CMD_SET_REGEX_REGISTERS);
25         MLX5_SET(set_regexp_register_in, in, engine_id, engine_id);
26         MLX5_SET(set_regexp_register_in, in, register_address, addr);
27         MLX5_SET(set_regexp_register_in, in, register_data, data);
28
29         ret = mlx5_glue->devx_general_cmd(ctx, in, sizeof(in), out,
30                                           sizeof(out));
31         if (ret) {
32                 DRV_LOG(ERR, "Set regexp register failed %d", ret);
33                 rte_errno = errno;
34                 return -errno;
35         }
36         return 0;
37 }
38
39 int
40 mlx5_devx_regex_register_read(struct ibv_context *ctx, int engine_id,
41                               uint32_t addr, uint32_t *data)
42 {
43         uint32_t out[MLX5_ST_SZ_DW(query_regexp_register_out)] = {0};
44         uint32_t in[MLX5_ST_SZ_DW(query_regexp_register_in)] = {0};
45         int ret;
46
47         MLX5_SET(query_regexp_register_in, in, opcode,
48                  MLX5_CMD_QUERY_REGEX_REGISTERS);
49         MLX5_SET(query_regexp_register_in, in, engine_id, engine_id);
50         MLX5_SET(query_regexp_register_in, in, register_address, addr);
51
52         ret = mlx5_glue->devx_general_cmd(ctx, in, sizeof(in), out,
53                                           sizeof(out));
54         if (ret) {
55                 DRV_LOG(ERR, "Query regexp register failed %d", ret);
56                 rte_errno = errno;
57                 return -errno;
58         }
59         *data = MLX5_GET(query_regexp_register_out, out, register_data);
60         return 0;
61 }