net/mlx5: enforce limitation on IPv6 next protocol
[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 }
62
63 int
64 mlx5_devx_regex_database_stop(void *ctx, uint8_t engine)
65 {
66         uint32_t out[MLX5_ST_SZ_DW(set_regexp_params_out)] = {0};
67         uint32_t in[MLX5_ST_SZ_DW(set_regexp_params_in)] = {0};
68         int ret;
69
70         MLX5_SET(set_regexp_params_in, in, opcode, MLX5_CMD_SET_REGEX_PARAMS);
71         MLX5_SET(set_regexp_params_in, in, engine_id, engine);
72         MLX5_SET(set_regexp_params_in, in, regexp_params.stop_engine, 1);
73         MLX5_SET(set_regexp_params_in, in, field_select.stop_engine, 1);
74         ret = mlx5_glue->devx_general_cmd(ctx, in, sizeof(in), out,
75                                           sizeof(out));
76         if (ret) {
77                 DRV_LOG(ERR, "Database stop failed %d", ret);
78                 rte_errno = errno;
79                 return -errno;
80         }
81         return 0;
82 }
83
84 int
85 mlx5_devx_regex_database_resume(void *ctx, uint8_t engine)
86 {
87         uint32_t out[MLX5_ST_SZ_DW(set_regexp_params_out)] = {0};
88         uint32_t in[MLX5_ST_SZ_DW(set_regexp_params_in)] = {0};
89         int ret;
90
91         MLX5_SET(set_regexp_params_in, in, opcode, MLX5_CMD_SET_REGEX_PARAMS);
92         MLX5_SET(set_regexp_params_in, in, engine_id, engine);
93         MLX5_SET(set_regexp_params_in, in, regexp_params.stop_engine, 0);
94         MLX5_SET(set_regexp_params_in, in, field_select.stop_engine, 1);
95         ret = mlx5_glue->devx_general_cmd(ctx, in, sizeof(in), out,
96                                           sizeof(out));
97         if (ret) {
98                 DRV_LOG(ERR, "Database start failed %d", ret);
99                 rte_errno = errno;
100                 return -errno;
101         }
102         return 0;
103 }
104
105 int
106 mlx5_devx_regex_database_program(void *ctx, uint8_t engine, uint32_t umem_id,
107                                  uint64_t umem_offset)
108 {
109         uint32_t out[MLX5_ST_SZ_DW(set_regexp_params_out)] = {0};
110         uint32_t in[MLX5_ST_SZ_DW(set_regexp_params_in)] = {0};
111         int ret;
112
113         MLX5_SET(set_regexp_params_in, in, opcode, MLX5_CMD_SET_REGEX_PARAMS);
114         MLX5_SET(set_regexp_params_in, in, engine_id, engine);
115         MLX5_SET(set_regexp_params_in, in, regexp_params.db_umem_id, umem_id);
116         MLX5_SET64(set_regexp_params_in, in, regexp_params.db_umem_offset,
117                    umem_offset);
118         MLX5_SET(set_regexp_params_in, in, field_select.db_umem_id, 1);
119         ret = mlx5_glue->devx_general_cmd(ctx, in, sizeof(in), out,
120                                           sizeof(out));
121         if (ret) {
122                 DRV_LOG(ERR, "Database program failed %d", ret);
123                 rte_errno = errno;
124                 return -errno;
125         }
126         return 0;
127 }