Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright 2018-2021 NXP
3 : : */
4 : :
5 : : #include <fsl_mc_sys.h>
6 : : #include <fsl_mc_cmd.h>
7 : : #include <fsl_dpdmai.h>
8 : : #include <fsl_dpdmai_cmd.h>
9 : :
10 : : #include <eal_export.h>
11 : :
12 : : /**
13 : : * dpdmai_open() - Open a control session for the specified object
14 : : * @mc_io: Pointer to MC portal's I/O object
15 : : * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
16 : : * @dpdmai_id: DPDMAI unique ID
17 : : * @token: Returned token; use in subsequent API calls
18 : : *
19 : : * This function can be used to open a control session for an
20 : : * already created object; an object may have been declared in
21 : : * the DPL or by calling the dpdmai_create() function.
22 : : * This function returns a unique authentication token,
23 : : * associated with the specific object ID and the specific MC
24 : : * portal; this token must be used in all subsequent commands for
25 : : * this specific object.
26 : : *
27 : : * Return: '0' on Success; Error code otherwise.
28 : : */
29 : : RTE_EXPORT_INTERNAL_SYMBOL(dpdmai_open)
30 : 0 : int dpdmai_open(struct fsl_mc_io *mc_io,
31 : : uint32_t cmd_flags,
32 : : int dpdmai_id,
33 : : uint16_t *token)
34 : : {
35 : : struct dpdmai_cmd_open *cmd_params;
36 : 0 : struct mc_command cmd = { 0 };
37 : : int err;
38 : :
39 : : /* prepare command */
40 : 0 : cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_OPEN,
41 : : cmd_flags,
42 : : 0);
43 : : cmd_params = (struct dpdmai_cmd_open *)cmd.params;
44 : 0 : cmd_params->dpdmai_id = cpu_to_le32(dpdmai_id);
45 : :
46 : : /* send command to mc*/
47 : 0 : err = mc_send_command(mc_io, &cmd);
48 [ # # ]: 0 : if (err)
49 : : return err;
50 : :
51 : : /* retrieve response parameters */
52 : 0 : *token = mc_cmd_hdr_read_token(&cmd);
53 : :
54 : 0 : return 0;
55 : : }
56 : :
57 : : /**
58 : : * dpdmai_close() - Close the control session of the object
59 : : * @mc_io: Pointer to MC portal's I/O object
60 : : * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
61 : : * @token: Token of DPDMAI object
62 : : *
63 : : * After this function is called, no further operations are
64 : : * allowed on the object without opening a new control session.
65 : : *
66 : : * Return: '0' on Success; Error code otherwise.
67 : : */
68 : : RTE_EXPORT_INTERNAL_SYMBOL(dpdmai_close)
69 : 0 : int dpdmai_close(struct fsl_mc_io *mc_io,
70 : : uint32_t cmd_flags,
71 : : uint16_t token)
72 : : {
73 : 0 : struct mc_command cmd = { 0 };
74 : :
75 : : /* prepare command */
76 : 0 : cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_CLOSE,
77 : : cmd_flags, token);
78 : :
79 : : /* send command to mc*/
80 : 0 : return mc_send_command(mc_io, &cmd);
81 : : }
82 : :
83 : : /**
84 : : * dpdmai_create() - Create the DPDMAI object
85 : : * @mc_io: Pointer to MC portal's I/O object
86 : : * @dprc_token: Parent container token; '0' for default container
87 : : * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
88 : : * @cfg: Configuration structure
89 : : * @obj_id: Returned object id
90 : : *
91 : : * Create the DPDMAI object, allocate required resources and
92 : : * perform required initialization.
93 : : *
94 : : * The object can be created either by declaring it in the
95 : : * DPL file, or by calling this function.
96 : : *
97 : : * The function accepts an authentication token of a parent
98 : : * container that this object should be assigned to. The token
99 : : * can be '0' so the object will be assigned to the default container.
100 : : * The newly created object can be opened with the returned
101 : : * object id and using the container's associated tokens and MC portals.
102 : : *
103 : : * Return: '0' on Success; Error code otherwise.
104 : : */
105 : 0 : int dpdmai_create(struct fsl_mc_io *mc_io,
106 : : uint16_t dprc_token,
107 : : uint32_t cmd_flags,
108 : : const struct dpdmai_cfg *cfg,
109 : : uint32_t *obj_id)
110 : : {
111 : : struct dpdmai_cmd_create *cmd_params;
112 : 0 : struct mc_command cmd = { 0 };
113 : : int err;
114 : :
115 : : /* prepare command */
116 : 0 : cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_CREATE,
117 : : cmd_flags,
118 : : dprc_token);
119 : : cmd_params = (struct dpdmai_cmd_create *)cmd.params;
120 : 0 : cmd_params->num_queues = cfg->num_queues;
121 : 0 : cmd_params->priorities[0] = cfg->priorities[0];
122 : 0 : cmd_params->priorities[1] = cfg->priorities[1];
123 : 0 : cmd_params->options = cpu_to_le32(cfg->adv.options);
124 : :
125 : : /* send command to mc*/
126 : 0 : err = mc_send_command(mc_io, &cmd);
127 [ # # ]: 0 : if (err)
128 : : return err;
129 : :
130 : : /* retrieve response parameters */
131 : 0 : *obj_id = mc_cmd_read_object_id(&cmd);
132 : :
133 : 0 : return 0;
134 : : }
135 : :
136 : : /**
137 : : * dpdmai_destroy() - Destroy the DPDMAI object and release all its resources.
138 : : * @mc_io: Pointer to MC portal's I/O object
139 : : * @dprc_token: Parent container token; '0' for default container
140 : : * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
141 : : * @object_id: The object id; it must be a valid id within the container that
142 : : * created this object;
143 : : *
144 : : * The function accepts the authentication token of the parent container that
145 : : * created the object (not the one that currently owns the object). The object
146 : : * is searched within parent using the provided 'object_id'.
147 : : * All tokens to the object must be closed before calling destroy.
148 : : *
149 : : * Return: '0' on Success; error code otherwise.
150 : : */
151 : 0 : int dpdmai_destroy(struct fsl_mc_io *mc_io,
152 : : uint16_t dprc_token,
153 : : uint32_t cmd_flags,
154 : : uint32_t object_id)
155 : : {
156 : : struct dpdmai_cmd_destroy *cmd_params;
157 : 0 : struct mc_command cmd = { 0 };
158 : :
159 : : /* prepare command */
160 : 0 : cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_DESTROY,
161 : : cmd_flags,
162 : : dprc_token);
163 : : cmd_params = (struct dpdmai_cmd_destroy *)cmd.params;
164 : 0 : cmd_params->dpdmai_id = cpu_to_le32(object_id);
165 : :
166 : : /* send command to mc*/
167 : 0 : return mc_send_command(mc_io, &cmd);
168 : : }
169 : :
170 : : /**
171 : : * dpdmai_enable() - Enable the DPDMAI, allow sending and receiving frames.
172 : : * @mc_io: Pointer to MC portal's I/O object
173 : : * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
174 : : * @token: Token of DPDMAI object
175 : : *
176 : : * Return: '0' on Success; Error code otherwise.
177 : : */
178 : : RTE_EXPORT_INTERNAL_SYMBOL(dpdmai_enable)
179 : 0 : int dpdmai_enable(struct fsl_mc_io *mc_io,
180 : : uint32_t cmd_flags,
181 : : uint16_t token)
182 : : {
183 : 0 : struct mc_command cmd = { 0 };
184 : :
185 : : /* prepare command */
186 : 0 : cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_ENABLE,
187 : : cmd_flags,
188 : : token);
189 : :
190 : : /* send command to mc*/
191 : 0 : return mc_send_command(mc_io, &cmd);
192 : : }
193 : :
194 : : /**
195 : : * dpdmai_disable() - Disable the DPDMAI, stop sending and receiving frames.
196 : : * @mc_io: Pointer to MC portal's I/O object
197 : : * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
198 : : * @token: Token of DPDMAI object
199 : : *
200 : : * Return: '0' on Success; Error code otherwise.
201 : : */
202 : : RTE_EXPORT_INTERNAL_SYMBOL(dpdmai_disable)
203 : 0 : int dpdmai_disable(struct fsl_mc_io *mc_io,
204 : : uint32_t cmd_flags,
205 : : uint16_t token)
206 : : {
207 : 0 : struct mc_command cmd = { 0 };
208 : :
209 : : /* prepare command */
210 : 0 : cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_DISABLE,
211 : : cmd_flags,
212 : : token);
213 : :
214 : : /* send command to mc*/
215 : 0 : return mc_send_command(mc_io, &cmd);
216 : : }
217 : :
218 : : /**
219 : : * dpdmai_is_enabled() - Check if the DPDMAI is enabled.
220 : : * @mc_io: Pointer to MC portal's I/O object
221 : : * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
222 : : * @token: Token of DPDMAI object
223 : : * @en: Returns '1' if object is enabled; '0' otherwise
224 : : *
225 : : * Return: '0' on Success; Error code otherwise.
226 : : */
227 : 0 : int dpdmai_is_enabled(struct fsl_mc_io *mc_io,
228 : : uint32_t cmd_flags,
229 : : uint16_t token,
230 : : int *en)
231 : : {
232 : : struct dpdmai_rsp_is_enabled *rsp_params;
233 : 0 : struct mc_command cmd = { 0 };
234 : : int err;
235 : :
236 : : /* prepare command */
237 : 0 : cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_IS_ENABLED,
238 : : cmd_flags,
239 : : token);
240 : :
241 : : /* send command to mc*/
242 : 0 : err = mc_send_command(mc_io, &cmd);
243 [ # # ]: 0 : if (err)
244 : : return err;
245 : :
246 : : /* retrieve response parameters */
247 : : rsp_params = (struct dpdmai_rsp_is_enabled *)cmd.params;
248 : 0 : *en = dpdmai_get_field(rsp_params->en, ENABLE);
249 : :
250 : 0 : return 0;
251 : : }
252 : :
253 : : /**
254 : : * dpdmai_reset() - Reset the DPDMAI, returns the object to initial state.
255 : : * @mc_io: Pointer to MC portal's I/O object
256 : : * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
257 : : * @token: Token of DPDMAI object
258 : : *
259 : : * Return: '0' on Success; Error code otherwise.
260 : : */
261 : 0 : int dpdmai_reset(struct fsl_mc_io *mc_io,
262 : : uint32_t cmd_flags,
263 : : uint16_t token)
264 : : {
265 : 0 : struct mc_command cmd = { 0 };
266 : :
267 : : /* prepare command */
268 : 0 : cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_RESET,
269 : : cmd_flags,
270 : : token);
271 : :
272 : : /* send command to mc*/
273 : 0 : return mc_send_command(mc_io, &cmd);
274 : : }
275 : :
276 : : /**
277 : : * dpdmai_get_attributes() - Retrieve DPDMAI attributes.
278 : : * @mc_io: Pointer to MC portal's I/O object
279 : : * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
280 : : * @token: Token of DPDMAI object
281 : : * @attr: Returned object's attributes
282 : : *
283 : : * Return: '0' on Success; Error code otherwise.
284 : : */
285 : : RTE_EXPORT_INTERNAL_SYMBOL(dpdmai_get_attributes)
286 : 0 : int dpdmai_get_attributes(struct fsl_mc_io *mc_io,
287 : : uint32_t cmd_flags,
288 : : uint16_t token,
289 : : struct dpdmai_attr *attr)
290 : : {
291 : : struct dpdmai_rsp_get_attr *rsp_params;
292 : 0 : struct mc_command cmd = { 0 };
293 : : int err;
294 : :
295 : : /* prepare command */
296 : 0 : cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_GET_ATTR,
297 : : cmd_flags,
298 : : token);
299 : :
300 : : /* send command to mc*/
301 : 0 : err = mc_send_command(mc_io, &cmd);
302 [ # # ]: 0 : if (err)
303 : : return err;
304 : :
305 : : /* retrieve response parameters */
306 : : rsp_params = (struct dpdmai_rsp_get_attr *)cmd.params;
307 : 0 : attr->id = le32_to_cpu(rsp_params->id);
308 : 0 : attr->num_of_priorities = rsp_params->num_of_priorities;
309 : 0 : attr->num_of_queues = rsp_params->num_of_queues;
310 : 0 : attr->options = le32_to_cpu(rsp_params->options);
311 : :
312 : 0 : return 0;
313 : : }
314 : :
315 : : /**
316 : : * dpdmai_set_rx_queue() - Set Rx queue configuration
317 : : * @mc_io: Pointer to MC portal's I/O object
318 : : * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
319 : : * @token: Token of DPDMAI object
320 : : * @queue_idx: Rx queue index. Accepted values are form 0 to num_queues
321 : : * parameter provided in dpdmai_create
322 : : * @priority: Select the queue relative to number of
323 : : * priorities configured at DPDMAI creation; use
324 : : * DPDMAI_ALL_QUEUES to configure all Rx queues
325 : : * identically.
326 : : * @cfg: Rx queue configuration
327 : : *
328 : : * Return: '0' on Success; Error code otherwise.
329 : : */
330 : : RTE_EXPORT_INTERNAL_SYMBOL(dpdmai_set_rx_queue)
331 : 0 : int dpdmai_set_rx_queue(struct fsl_mc_io *mc_io,
332 : : uint32_t cmd_flags,
333 : : uint16_t token,
334 : : uint8_t queue_idx,
335 : : uint8_t priority,
336 : : const struct dpdmai_rx_queue_cfg *cfg)
337 : : {
338 : : struct dpdmai_cmd_set_rx_queue *cmd_params;
339 : 0 : struct mc_command cmd = { 0 };
340 : :
341 : : /* prepare command */
342 : 0 : cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_SET_RX_QUEUE,
343 : : cmd_flags,
344 : : token);
345 : : cmd_params = (struct dpdmai_cmd_set_rx_queue *)cmd.params;
346 : 0 : cmd_params->dest_id = cpu_to_le32(cfg->dest_cfg.dest_id);
347 : 0 : cmd_params->dest_priority = cfg->dest_cfg.priority;
348 : 0 : cmd_params->priority = priority;
349 : 0 : cmd_params->queue_idx = queue_idx;
350 : 0 : cmd_params->user_ctx = cpu_to_le64(cfg->user_ctx);
351 : 0 : cmd_params->options = cpu_to_le32(cfg->options);
352 : 0 : dpdmai_set_field(cmd_params->dest_type,
353 : : DEST_TYPE,
354 : : cfg->dest_cfg.dest_type);
355 : :
356 : : /* send command to mc*/
357 : 0 : return mc_send_command(mc_io, &cmd);
358 : : }
359 : :
360 : : /**
361 : : * dpdmai_get_rx_queue() - Retrieve Rx queue attributes.
362 : : * @mc_io: Pointer to MC portal's I/O object
363 : : * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
364 : : * @token: Token of DPDMAI object
365 : : * @queue_idx: Rx queue index. Accepted values are form 0 to num_queues
366 : : * parameter provided in dpdmai_create
367 : : * @priority: Select the queue relative to number of
368 : : * priorities configured at DPDMAI creation
369 : : * @attr: Returned Rx queue attributes
370 : : *
371 : : * Return: '0' on Success; Error code otherwise.
372 : : */
373 : : RTE_EXPORT_INTERNAL_SYMBOL(dpdmai_get_rx_queue)
374 : 0 : int dpdmai_get_rx_queue(struct fsl_mc_io *mc_io,
375 : : uint32_t cmd_flags,
376 : : uint16_t token,
377 : : uint8_t queue_idx,
378 : : uint8_t priority,
379 : : struct dpdmai_rx_queue_attr *attr)
380 : : {
381 : : struct dpdmai_cmd_get_queue *cmd_params;
382 : : struct dpdmai_rsp_get_rx_queue *rsp_params;
383 : 0 : struct mc_command cmd = { 0 };
384 : : int err;
385 : :
386 : : /* prepare command */
387 : 0 : cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_GET_RX_QUEUE,
388 : : cmd_flags,
389 : : token);
390 : : cmd_params = (struct dpdmai_cmd_get_queue *)cmd.params;
391 : 0 : cmd_params->priority = priority;
392 : 0 : cmd_params->queue_idx = queue_idx;
393 : :
394 : : /* send command to mc*/
395 : 0 : err = mc_send_command(mc_io, &cmd);
396 [ # # ]: 0 : if (err)
397 : : return err;
398 : :
399 : : /* retrieve response parameters */
400 : : rsp_params = (struct dpdmai_rsp_get_rx_queue *)cmd.params;
401 : 0 : attr->user_ctx = le64_to_cpu(rsp_params->user_ctx);
402 : 0 : attr->fqid = le32_to_cpu(rsp_params->fqid);
403 : 0 : attr->dest_cfg.dest_id = le32_to_cpu(rsp_params->dest_id);
404 : 0 : attr->dest_cfg.priority = le32_to_cpu(rsp_params->dest_priority);
405 : 0 : attr->dest_cfg.dest_type = dpdmai_get_field(rsp_params->dest_type,
406 : : DEST_TYPE);
407 : :
408 : 0 : return 0;
409 : : }
410 : :
411 : : /**
412 : : * dpdmai_get_tx_queue() - Retrieve Tx queue attributes.
413 : : * @mc_io: Pointer to MC portal's I/O object
414 : : * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
415 : : * @token: Token of DPDMAI object
416 : : * @queue_idx: Tx queue index. Accepted values are form 0 to num_queues
417 : : * parameter provided in dpdmai_create
418 : : * @priority: Select the queue relative to number of
419 : : * priorities configured at DPDMAI creation
420 : : * @attr: Returned Tx queue attributes
421 : : *
422 : : * Return: '0' on Success; Error code otherwise.
423 : : */
424 : : RTE_EXPORT_INTERNAL_SYMBOL(dpdmai_get_tx_queue)
425 : 0 : int dpdmai_get_tx_queue(struct fsl_mc_io *mc_io,
426 : : uint32_t cmd_flags,
427 : : uint16_t token,
428 : : uint8_t queue_idx,
429 : : uint8_t priority,
430 : : struct dpdmai_tx_queue_attr *attr)
431 : : {
432 : : struct dpdmai_cmd_get_queue *cmd_params;
433 : : struct dpdmai_rsp_get_tx_queue *rsp_params;
434 : 0 : struct mc_command cmd = { 0 };
435 : : int err;
436 : :
437 : : /* prepare command */
438 : 0 : cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_GET_TX_QUEUE,
439 : : cmd_flags,
440 : : token);
441 : : cmd_params = (struct dpdmai_cmd_get_queue *)cmd.params;
442 : 0 : cmd_params->priority = priority;
443 : 0 : cmd_params->queue_idx = queue_idx;
444 : :
445 : : /* send command to mc*/
446 : 0 : err = mc_send_command(mc_io, &cmd);
447 [ # # ]: 0 : if (err)
448 : : return err;
449 : :
450 : : /* retrieve response parameters */
451 : : rsp_params = (struct dpdmai_rsp_get_tx_queue *)cmd.params;
452 : 0 : attr->fqid = le32_to_cpu(rsp_params->fqid);
453 : :
454 : 0 : return 0;
455 : : }
|