Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright (c) 2022 Marvell.
3 : : */
4 : :
5 : : #include <errno.h>
6 : :
7 : : #include <rte_common.h>
8 : : #include <rte_malloc.h>
9 : : #include <rte_mldev.h>
10 : :
11 : : #include "test_device_ops.h"
12 : :
13 : : static bool
14 : 0 : test_device_cap_check(struct ml_options *opt)
15 : : {
16 : 0 : if (!ml_test_cap_check(opt))
17 : 0 : return false;
18 : :
19 : : return true;
20 : : }
21 : :
22 : : static int
23 : 0 : test_device_opt_check(struct ml_options *opt)
24 : : {
25 : : int ret;
26 : :
27 : : /* check common opts */
28 : 0 : ret = ml_test_opt_check(opt);
29 : 0 : if (ret != 0)
30 : 0 : return ret;
31 : :
32 : : return 0;
33 : : }
34 : :
35 : : static void
36 : 0 : test_device_opt_dump(struct ml_options *opt)
37 : : {
38 : : /* dump common opts */
39 : 0 : ml_test_opt_dump(opt);
40 : 0 : }
41 : :
42 : : static int
43 : 0 : test_device_setup(struct ml_test *test, struct ml_options *opt)
44 : : {
45 : : struct test_device *t;
46 : : void *test_device;
47 : : int ret = 0;
48 : :
49 : : /* allocate for test structure */
50 : 0 : test_device = rte_zmalloc_socket(test->name, sizeof(struct test_device),
51 : : RTE_CACHE_LINE_SIZE, opt->socket_id);
52 : 0 : if (test_device == NULL) {
53 : 0 : ml_err("failed to allocate memory for test_model");
54 : : ret = -ENOMEM;
55 : 0 : goto error;
56 : : }
57 : 0 : test->test_priv = test_device;
58 : : t = ml_test_priv(test);
59 : :
60 : 0 : t->cmn.result = ML_TEST_FAILED;
61 : 0 : t->cmn.opt = opt;
62 : :
63 : : /* get device info */
64 : 0 : ret = rte_ml_dev_info_get(opt->dev_id, &t->cmn.dev_info);
65 : 0 : if (ret < 0) {
66 : 0 : ml_err("failed to get device info");
67 : 0 : goto error;
68 : : }
69 : :
70 : : return 0;
71 : :
72 : 0 : error:
73 : 0 : rte_free(test_device);
74 : :
75 : 0 : return ret;
76 : : }
77 : :
78 : : static void
79 : 0 : test_device_destroy(struct ml_test *test, struct ml_options *opt)
80 : : {
81 : : struct test_device *t;
82 : :
83 : : RTE_SET_USED(opt);
84 : :
85 : : t = ml_test_priv(test);
86 : 0 : rte_free(t);
87 : 0 : }
88 : :
89 : : static int
90 : 0 : test_device_reconfigure(struct ml_test *test, struct ml_options *opt)
91 : : {
92 : : struct rte_ml_dev_config dev_config;
93 : : struct rte_ml_dev_qp_conf qp_conf;
94 : : struct test_device *t;
95 : : uint16_t qp_id = 0;
96 : : int ret = 0;
97 : :
98 : : t = ml_test_priv(test);
99 : :
100 : : /* configure with default options */
101 : 0 : ret = ml_test_device_configure(test, opt);
102 : 0 : if (ret != 0)
103 : : return ret;
104 : :
105 : : /* setup queue pairs with nb_user options */
106 : 0 : for (qp_id = 0; qp_id < opt->queue_pairs; qp_id++) {
107 : 0 : qp_conf.nb_desc = opt->queue_size;
108 : 0 : qp_conf.cb = NULL;
109 : :
110 : 0 : ret = rte_ml_dev_queue_pair_setup(opt->dev_id, qp_id, &qp_conf, opt->socket_id);
111 : 0 : if (ret != 0) {
112 : 0 : ml_err("Failed to setup ML device queue-pair, dev_id = %d, qp_id = %u\n",
113 : : opt->dev_id, qp_id);
114 : 0 : goto error;
115 : : }
116 : : }
117 : :
118 : : /* start device */
119 : 0 : ret = ml_test_device_start(test, opt);
120 : 0 : if (ret != 0)
121 : 0 : goto error;
122 : :
123 : : /* stop device */
124 : 0 : ret = ml_test_device_stop(test, opt);
125 : 0 : if (ret != 0) {
126 : 0 : ml_err("Failed to stop device");
127 : 0 : goto error;
128 : : }
129 : :
130 : : /* reconfigure device based on dev_info */
131 : 0 : dev_config.socket_id = opt->socket_id;
132 : 0 : dev_config.nb_models = t->cmn.dev_info.max_models;
133 : 0 : dev_config.nb_queue_pairs = t->cmn.dev_info.max_queue_pairs;
134 : 0 : ret = rte_ml_dev_configure(opt->dev_id, &dev_config);
135 : 0 : if (ret != 0) {
136 : 0 : ml_err("Failed to reconfigure ML device, dev_id = %d\n", opt->dev_id);
137 : 0 : return ret;
138 : : }
139 : :
140 : : /* setup queue pairs */
141 : 0 : for (qp_id = 0; qp_id < t->cmn.dev_info.max_queue_pairs; qp_id++) {
142 : 0 : qp_conf.nb_desc = t->cmn.dev_info.max_desc;
143 : 0 : qp_conf.cb = NULL;
144 : :
145 : 0 : ret = rte_ml_dev_queue_pair_setup(opt->dev_id, qp_id, &qp_conf, opt->socket_id);
146 : 0 : if (ret != 0) {
147 : 0 : ml_err("Failed to setup ML device queue-pair, dev_id = %d, qp_id = %u\n",
148 : : opt->dev_id, qp_id);
149 : 0 : goto error;
150 : : }
151 : : }
152 : :
153 : : /* start device */
154 : 0 : ret = ml_test_device_start(test, opt);
155 : 0 : if (ret != 0)
156 : 0 : goto error;
157 : :
158 : : /* stop device */
159 : 0 : ret = ml_test_device_stop(test, opt);
160 : 0 : if (ret != 0)
161 : 0 : goto error;
162 : :
163 : : /* close device */
164 : 0 : ret = ml_test_device_close(test, opt);
165 : 0 : if (ret != 0)
166 : 0 : return ret;
167 : :
168 : : return 0;
169 : :
170 : 0 : error:
171 : 0 : ml_test_device_close(test, opt);
172 : :
173 : 0 : return ret;
174 : : }
175 : :
176 : : static int
177 : 0 : test_device_driver(struct ml_test *test, struct ml_options *opt)
178 : : {
179 : : struct test_device *t;
180 : : int ret = 0;
181 : :
182 : : t = ml_test_priv(test);
183 : :
184 : : /* sub-test: device reconfigure */
185 : 0 : ret = test_device_reconfigure(test, opt);
186 : 0 : if (ret != 0) {
187 : : printf("\n");
188 : : printf("Model Device Reconfigure Test: " CLRED "%s" CLNRM "\n", "Failed");
189 : 0 : goto error;
190 : : } else {
191 : : printf("\n");
192 : : printf("Model Device Reconfigure Test: " CLYEL "%s" CLNRM "\n", "Passed");
193 : : }
194 : :
195 : : printf("\n");
196 : :
197 : 0 : t->cmn.result = ML_TEST_SUCCESS;
198 : :
199 : 0 : return 0;
200 : :
201 : : error:
202 : 0 : t->cmn.result = ML_TEST_FAILED;
203 : 0 : return -1;
204 : : }
205 : :
206 : : static int
207 : 0 : test_device_result(struct ml_test *test, struct ml_options *opt)
208 : : {
209 : : struct test_device *t;
210 : :
211 : : RTE_SET_USED(opt);
212 : :
213 : : t = ml_test_priv(test);
214 : :
215 : 0 : return t->cmn.result;
216 : : }
217 : :
218 : : static const struct ml_test_ops device_ops = {
219 : : .cap_check = test_device_cap_check,
220 : : .opt_check = test_device_opt_check,
221 : : .opt_dump = test_device_opt_dump,
222 : : .test_setup = test_device_setup,
223 : : .test_destroy = test_device_destroy,
224 : : .test_driver = test_device_driver,
225 : : .test_result = test_device_result,
226 : : };
227 : :
228 : 0 : ML_TEST_REGISTER(device_ops);
|