1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2018-2021 NXP
5 #include <fsl_mc_sys.h>
6 #include <fsl_mc_cmd.h>
7 #include <fsl_dpdmai.h>
8 #include <fsl_dpdmai_cmd.h>
11 * dpdmai_open() - Open a control session for the specified object
12 * @mc_io: Pointer to MC portal's I/O object
13 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
14 * @dpdmai_id: DPDMAI unique ID
15 * @token: Returned token; use in subsequent API calls
17 * This function can be used to open a control session for an
18 * already created object; an object may have been declared in
19 * the DPL or by calling the dpdmai_create() function.
20 * This function returns a unique authentication token,
21 * associated with the specific object ID and the specific MC
22 * portal; this token must be used in all subsequent commands for
23 * this specific object.
25 * Return: '0' on Success; Error code otherwise.
27 int dpdmai_open(struct fsl_mc_io *mc_io,
32 struct dpdmai_cmd_open *cmd_params;
33 struct mc_command cmd = { 0 };
37 cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_OPEN,
40 cmd_params = (struct dpdmai_cmd_open *)cmd.params;
41 cmd_params->dpdmai_id = cpu_to_le32(dpdmai_id);
43 /* send command to mc*/
44 err = mc_send_command(mc_io, &cmd);
48 /* retrieve response parameters */
49 *token = mc_cmd_hdr_read_token(&cmd);
55 * dpdmai_close() - Close the control session of the object
56 * @mc_io: Pointer to MC portal's I/O object
57 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
58 * @token: Token of DPDMAI object
60 * After this function is called, no further operations are
61 * allowed on the object without opening a new control session.
63 * Return: '0' on Success; Error code otherwise.
65 int dpdmai_close(struct fsl_mc_io *mc_io,
69 struct mc_command cmd = { 0 };
72 cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_CLOSE,
75 /* send command to mc*/
76 return mc_send_command(mc_io, &cmd);
80 * dpdmai_create() - Create the DPDMAI object
81 * @mc_io: Pointer to MC portal's I/O object
82 * @dprc_token: Parent container token; '0' for default container
83 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
84 * @cfg: Configuration structure
85 * @obj_id: Returned object id
87 * Create the DPDMAI object, allocate required resources and
88 * perform required initialization.
90 * The object can be created either by declaring it in the
91 * DPL file, or by calling this function.
93 * The function accepts an authentication token of a parent
94 * container that this object should be assigned to. The token
95 * can be '0' so the object will be assigned to the default container.
96 * The newly created object can be opened with the returned
97 * object id and using the container's associated tokens and MC portals.
99 * Return: '0' on Success; Error code otherwise.
101 int dpdmai_create(struct fsl_mc_io *mc_io,
104 const struct dpdmai_cfg *cfg,
107 struct dpdmai_cmd_create *cmd_params;
108 struct mc_command cmd = { 0 };
111 /* prepare command */
112 cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_CREATE,
115 cmd_params = (struct dpdmai_cmd_create *)cmd.params;
116 cmd_params->num_queues = cfg->num_queues;
117 cmd_params->priorities[0] = cfg->priorities[0];
118 cmd_params->priorities[1] = cfg->priorities[1];
119 cmd_params->options = cpu_to_le32(cfg->adv.options);
121 /* send command to mc*/
122 err = mc_send_command(mc_io, &cmd);
126 /* retrieve response parameters */
127 *obj_id = mc_cmd_read_object_id(&cmd);
133 * dpdmai_destroy() - Destroy the DPDMAI object and release all its resources.
134 * @mc_io: Pointer to MC portal's I/O object
135 * @dprc_token: Parent container token; '0' for default container
136 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
137 * @object_id: The object id; it must be a valid id within the container that
138 * created this object;
140 * The function accepts the authentication token of the parent container that
141 * created the object (not the one that currently owns the object). The object
142 * is searched within parent using the provided 'object_id'.
143 * All tokens to the object must be closed before calling destroy.
145 * Return: '0' on Success; error code otherwise.
147 int dpdmai_destroy(struct fsl_mc_io *mc_io,
152 struct dpdmai_cmd_destroy *cmd_params;
153 struct mc_command cmd = { 0 };
155 /* prepare command */
156 cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_DESTROY,
159 cmd_params = (struct dpdmai_cmd_destroy *)cmd.params;
160 cmd_params->dpdmai_id = cpu_to_le32(object_id);
162 /* send command to mc*/
163 return mc_send_command(mc_io, &cmd);
167 * dpdmai_enable() - Enable the DPDMAI, allow sending and receiving frames.
168 * @mc_io: Pointer to MC portal's I/O object
169 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
170 * @token: Token of DPDMAI object
172 * Return: '0' on Success; Error code otherwise.
174 int dpdmai_enable(struct fsl_mc_io *mc_io,
178 struct mc_command cmd = { 0 };
180 /* prepare command */
181 cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_ENABLE,
185 /* send command to mc*/
186 return mc_send_command(mc_io, &cmd);
190 * dpdmai_disable() - Disable the DPDMAI, stop sending and receiving frames.
191 * @mc_io: Pointer to MC portal's I/O object
192 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
193 * @token: Token of DPDMAI object
195 * Return: '0' on Success; Error code otherwise.
197 int dpdmai_disable(struct fsl_mc_io *mc_io,
201 struct mc_command cmd = { 0 };
203 /* prepare command */
204 cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_DISABLE,
208 /* send command to mc*/
209 return mc_send_command(mc_io, &cmd);
213 * dpdmai_is_enabled() - Check if the DPDMAI is enabled.
214 * @mc_io: Pointer to MC portal's I/O object
215 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
216 * @token: Token of DPDMAI object
217 * @en: Returns '1' if object is enabled; '0' otherwise
219 * Return: '0' on Success; Error code otherwise.
221 int dpdmai_is_enabled(struct fsl_mc_io *mc_io,
226 struct dpdmai_rsp_is_enabled *rsp_params;
227 struct mc_command cmd = { 0 };
230 /* prepare command */
231 cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_IS_ENABLED,
235 /* send command to mc*/
236 err = mc_send_command(mc_io, &cmd);
240 /* retrieve response parameters */
241 rsp_params = (struct dpdmai_rsp_is_enabled *)cmd.params;
242 *en = dpdmai_get_field(rsp_params->en, ENABLE);
248 * dpdmai_reset() - Reset the DPDMAI, returns the object to initial state.
249 * @mc_io: Pointer to MC portal's I/O object
250 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
251 * @token: Token of DPDMAI object
253 * Return: '0' on Success; Error code otherwise.
255 int dpdmai_reset(struct fsl_mc_io *mc_io,
259 struct mc_command cmd = { 0 };
261 /* prepare command */
262 cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_RESET,
266 /* send command to mc*/
267 return mc_send_command(mc_io, &cmd);
271 * dpdmai_get_attributes() - Retrieve DPDMAI attributes.
272 * @mc_io: Pointer to MC portal's I/O object
273 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
274 * @token: Token of DPDMAI object
275 * @attr: Returned object's attributes
277 * Return: '0' on Success; Error code otherwise.
279 int dpdmai_get_attributes(struct fsl_mc_io *mc_io,
282 struct dpdmai_attr *attr)
284 struct dpdmai_rsp_get_attr *rsp_params;
285 struct mc_command cmd = { 0 };
288 /* prepare command */
289 cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_GET_ATTR,
293 /* send command to mc*/
294 err = mc_send_command(mc_io, &cmd);
298 /* retrieve response parameters */
299 rsp_params = (struct dpdmai_rsp_get_attr *)cmd.params;
300 attr->id = le32_to_cpu(rsp_params->id);
301 attr->num_of_priorities = rsp_params->num_of_priorities;
302 attr->num_of_queues = rsp_params->num_of_queues;
303 attr->options = le32_to_cpu(rsp_params->options);
309 * dpdmai_set_rx_queue() - Set Rx queue configuration
310 * @mc_io: Pointer to MC portal's I/O object
311 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
312 * @token: Token of DPDMAI object
313 * @queue_idx: Rx queue index. Accepted values are form 0 to num_queues
314 * parameter provided in dpdmai_create
315 * @priority: Select the queue relative to number of
316 * priorities configured at DPDMAI creation; use
317 * DPDMAI_ALL_QUEUES to configure all Rx queues
319 * @cfg: Rx queue configuration
321 * Return: '0' on Success; Error code otherwise.
323 int dpdmai_set_rx_queue(struct fsl_mc_io *mc_io,
328 const struct dpdmai_rx_queue_cfg *cfg)
330 struct dpdmai_cmd_set_rx_queue *cmd_params;
331 struct mc_command cmd = { 0 };
333 /* prepare command */
334 cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_SET_RX_QUEUE,
337 cmd_params = (struct dpdmai_cmd_set_rx_queue *)cmd.params;
338 cmd_params->dest_id = cpu_to_le32(cfg->dest_cfg.dest_id);
339 cmd_params->dest_priority = cfg->dest_cfg.priority;
340 cmd_params->priority = priority;
341 cmd_params->queue_idx = queue_idx;
342 cmd_params->user_ctx = cpu_to_le64(cfg->user_ctx);
343 cmd_params->options = cpu_to_le32(cfg->options);
344 dpdmai_set_field(cmd_params->dest_type,
346 cfg->dest_cfg.dest_type);
348 /* send command to mc*/
349 return mc_send_command(mc_io, &cmd);
353 * dpdmai_get_rx_queue() - Retrieve Rx queue attributes.
354 * @mc_io: Pointer to MC portal's I/O object
355 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
356 * @token: Token of DPDMAI object
357 * @queue_idx: Rx queue index. Accepted values are form 0 to num_queues
358 * parameter provided in dpdmai_create
359 * @priority: Select the queue relative to number of
360 * priorities configured at DPDMAI creation
361 * @attr: Returned Rx queue attributes
363 * Return: '0' on Success; Error code otherwise.
365 int dpdmai_get_rx_queue(struct fsl_mc_io *mc_io,
370 struct dpdmai_rx_queue_attr *attr)
372 struct dpdmai_cmd_get_queue *cmd_params;
373 struct dpdmai_rsp_get_rx_queue *rsp_params;
374 struct mc_command cmd = { 0 };
377 /* prepare command */
378 cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_GET_RX_QUEUE,
381 cmd_params = (struct dpdmai_cmd_get_queue *)cmd.params;
382 cmd_params->priority = priority;
383 cmd_params->queue_idx = queue_idx;
385 /* send command to mc*/
386 err = mc_send_command(mc_io, &cmd);
390 /* retrieve response parameters */
391 rsp_params = (struct dpdmai_rsp_get_rx_queue *)cmd.params;
392 attr->user_ctx = le64_to_cpu(rsp_params->user_ctx);
393 attr->fqid = le32_to_cpu(rsp_params->fqid);
394 attr->dest_cfg.dest_id = le32_to_cpu(rsp_params->dest_id);
395 attr->dest_cfg.priority = le32_to_cpu(rsp_params->dest_priority);
396 attr->dest_cfg.dest_type = dpdmai_get_field(rsp_params->dest_type,
403 * dpdmai_get_tx_queue() - Retrieve Tx queue attributes.
404 * @mc_io: Pointer to MC portal's I/O object
405 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
406 * @token: Token of DPDMAI object
407 * @queue_idx: Tx queue index. Accepted values are form 0 to num_queues
408 * parameter provided in dpdmai_create
409 * @priority: Select the queue relative to number of
410 * priorities configured at DPDMAI creation
411 * @attr: Returned Tx queue attributes
413 * Return: '0' on Success; Error code otherwise.
415 int dpdmai_get_tx_queue(struct fsl_mc_io *mc_io,
420 struct dpdmai_tx_queue_attr *attr)
422 struct dpdmai_cmd_get_queue *cmd_params;
423 struct dpdmai_rsp_get_tx_queue *rsp_params;
424 struct mc_command cmd = { 0 };
427 /* prepare command */
428 cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_GET_TX_QUEUE,
431 cmd_params = (struct dpdmai_cmd_get_queue *)cmd.params;
432 cmd_params->priority = priority;
433 cmd_params->queue_idx = queue_idx;
435 /* send command to mc*/
436 err = mc_send_command(mc_io, &cmd);
440 /* retrieve response parameters */
441 rsp_params = (struct dpdmai_rsp_get_tx_queue *)cmd.params;
442 attr->fqid = le32_to_cpu(rsp_params->fqid);