1 /* SPDX-License-Identifier: BSD-3-Clause
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];
120 /* send command to mc*/
121 err = mc_send_command(mc_io, &cmd);
125 /* retrieve response parameters */
126 *obj_id = mc_cmd_read_object_id(&cmd);
132 * dpdmai_destroy() - Destroy the DPDMAI object and release all its resources.
133 * @mc_io: Pointer to MC portal's I/O object
134 * @dprc_token: Parent container token; '0' for default container
135 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
136 * @object_id: The object id; it must be a valid id within the container that
137 * created this object;
139 * The function accepts the authentication token of the parent container that
140 * created the object (not the one that currently owns the object). The object
141 * is searched within parent using the provided 'object_id'.
142 * All tokens to the object must be closed before calling destroy.
144 * Return: '0' on Success; error code otherwise.
146 int dpdmai_destroy(struct fsl_mc_io *mc_io,
151 struct dpdmai_cmd_destroy *cmd_params;
152 struct mc_command cmd = { 0 };
154 /* prepare command */
155 cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_DESTROY,
158 cmd_params = (struct dpdmai_cmd_destroy *)cmd.params;
159 cmd_params->dpdmai_id = cpu_to_le32(object_id);
161 /* send command to mc*/
162 return mc_send_command(mc_io, &cmd);
166 * dpdmai_enable() - Enable the DPDMAI, allow sending and receiving frames.
167 * @mc_io: Pointer to MC portal's I/O object
168 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
169 * @token: Token of DPDMAI object
171 * Return: '0' on Success; Error code otherwise.
173 int dpdmai_enable(struct fsl_mc_io *mc_io,
177 struct mc_command cmd = { 0 };
179 /* prepare command */
180 cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_ENABLE,
184 /* send command to mc*/
185 return mc_send_command(mc_io, &cmd);
189 * dpdmai_disable() - Disable the DPDMAI, stop sending and receiving frames.
190 * @mc_io: Pointer to MC portal's I/O object
191 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
192 * @token: Token of DPDMAI object
194 * Return: '0' on Success; Error code otherwise.
196 int dpdmai_disable(struct fsl_mc_io *mc_io,
200 struct mc_command cmd = { 0 };
202 /* prepare command */
203 cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_DISABLE,
207 /* send command to mc*/
208 return mc_send_command(mc_io, &cmd);
212 * dpdmai_is_enabled() - Check if the DPDMAI is enabled.
213 * @mc_io: Pointer to MC portal's I/O object
214 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
215 * @token: Token of DPDMAI object
216 * @en: Returns '1' if object is enabled; '0' otherwise
218 * Return: '0' on Success; Error code otherwise.
220 int dpdmai_is_enabled(struct fsl_mc_io *mc_io,
225 struct dpdmai_rsp_is_enabled *rsp_params;
226 struct mc_command cmd = { 0 };
229 /* prepare command */
230 cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_IS_ENABLED,
234 /* send command to mc*/
235 err = mc_send_command(mc_io, &cmd);
239 /* retrieve response parameters */
240 rsp_params = (struct dpdmai_rsp_is_enabled *)cmd.params;
241 *en = dpdmai_get_field(rsp_params->en, ENABLE);
247 * dpdmai_reset() - Reset the DPDMAI, returns the object to initial state.
248 * @mc_io: Pointer to MC portal's I/O object
249 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
250 * @token: Token of DPDMAI object
252 * Return: '0' on Success; Error code otherwise.
254 int dpdmai_reset(struct fsl_mc_io *mc_io,
258 struct mc_command cmd = { 0 };
260 /* prepare command */
261 cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_RESET,
265 /* send command to mc*/
266 return mc_send_command(mc_io, &cmd);
270 * dpdmai_get_attributes() - Retrieve DPDMAI attributes.
271 * @mc_io: Pointer to MC portal's I/O object
272 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
273 * @token: Token of DPDMAI object
274 * @attr: Returned object's attributes
276 * Return: '0' on Success; Error code otherwise.
278 int dpdmai_get_attributes(struct fsl_mc_io *mc_io,
281 struct dpdmai_attr *attr)
283 struct dpdmai_rsp_get_attr *rsp_params;
284 struct mc_command cmd = { 0 };
287 /* prepare command */
288 cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_GET_ATTR,
292 /* send command to mc*/
293 err = mc_send_command(mc_io, &cmd);
297 /* retrieve response parameters */
298 rsp_params = (struct dpdmai_rsp_get_attr *)cmd.params;
299 attr->id = le32_to_cpu(rsp_params->id);
300 attr->num_of_priorities = rsp_params->num_of_priorities;
301 attr->num_of_queues = rsp_params->num_of_queues;
307 * dpdmai_set_rx_queue() - Set Rx queue configuration
308 * @mc_io: Pointer to MC portal's I/O object
309 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
310 * @token: Token of DPDMAI object
311 * @queue_idx: Rx queue index. Accepted values are form 0 to num_queues
312 * parameter provided in dpdmai_create
313 * @priority: Select the queue relative to number of
314 * priorities configured at DPDMAI creation; use
315 * DPDMAI_ALL_QUEUES to configure all Rx queues
317 * @cfg: Rx queue configuration
319 * Return: '0' on Success; Error code otherwise.
321 int dpdmai_set_rx_queue(struct fsl_mc_io *mc_io,
326 const struct dpdmai_rx_queue_cfg *cfg)
328 struct dpdmai_cmd_set_rx_queue *cmd_params;
329 struct mc_command cmd = { 0 };
331 /* prepare command */
332 cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_SET_RX_QUEUE,
335 cmd_params = (struct dpdmai_cmd_set_rx_queue *)cmd.params;
336 cmd_params->dest_id = cpu_to_le32(cfg->dest_cfg.dest_id);
337 cmd_params->dest_priority = cfg->dest_cfg.priority;
338 cmd_params->priority = priority;
339 cmd_params->queue_idx = queue_idx;
340 cmd_params->user_ctx = cpu_to_le64(cfg->user_ctx);
341 cmd_params->options = cpu_to_le32(cfg->options);
342 dpdmai_set_field(cmd_params->dest_type,
344 cfg->dest_cfg.dest_type);
346 /* send command to mc*/
347 return mc_send_command(mc_io, &cmd);
351 * dpdmai_get_rx_queue() - Retrieve Rx queue attributes.
352 * @mc_io: Pointer to MC portal's I/O object
353 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
354 * @token: Token of DPDMAI object
355 * @queue_idx: Rx queue index. Accepted values are form 0 to num_queues
356 * parameter provided in dpdmai_create
357 * @priority: Select the queue relative to number of
358 * priorities configured at DPDMAI creation
359 * @attr: Returned Rx queue attributes
361 * Return: '0' on Success; Error code otherwise.
363 int dpdmai_get_rx_queue(struct fsl_mc_io *mc_io,
368 struct dpdmai_rx_queue_attr *attr)
370 struct dpdmai_cmd_get_queue *cmd_params;
371 struct dpdmai_rsp_get_rx_queue *rsp_params;
372 struct mc_command cmd = { 0 };
375 /* prepare command */
376 cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_GET_RX_QUEUE,
379 cmd_params = (struct dpdmai_cmd_get_queue *)cmd.params;
380 cmd_params->priority = priority;
381 cmd_params->queue_idx = queue_idx;
383 /* send command to mc*/
384 err = mc_send_command(mc_io, &cmd);
388 /* retrieve response parameters */
389 rsp_params = (struct dpdmai_rsp_get_rx_queue *)cmd.params;
390 attr->user_ctx = le64_to_cpu(rsp_params->user_ctx);
391 attr->fqid = le32_to_cpu(rsp_params->fqid);
392 attr->dest_cfg.dest_id = le32_to_cpu(rsp_params->dest_id);
393 attr->dest_cfg.priority = le32_to_cpu(rsp_params->dest_priority);
394 attr->dest_cfg.dest_type = dpdmai_get_field(rsp_params->dest_type,
401 * dpdmai_get_tx_queue() - Retrieve Tx queue attributes.
402 * @mc_io: Pointer to MC portal's I/O object
403 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
404 * @token: Token of DPDMAI object
405 * @queue_idx: Tx queue index. Accepted values are form 0 to num_queues
406 * parameter provided in dpdmai_create
407 * @priority: Select the queue relative to number of
408 * priorities configured at DPDMAI creation
409 * @attr: Returned Tx queue attributes
411 * Return: '0' on Success; Error code otherwise.
413 int dpdmai_get_tx_queue(struct fsl_mc_io *mc_io,
418 struct dpdmai_tx_queue_attr *attr)
420 struct dpdmai_cmd_get_queue *cmd_params;
421 struct dpdmai_rsp_get_tx_queue *rsp_params;
422 struct mc_command cmd = { 0 };
425 /* prepare command */
426 cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_GET_TX_QUEUE,
429 cmd_params = (struct dpdmai_cmd_get_queue *)cmd.params;
430 cmd_params->priority = priority;
431 cmd_params->queue_idx = queue_idx;
433 /* send command to mc*/
434 err = mc_send_command(mc_io, &cmd);
438 /* retrieve response parameters */
439 rsp_params = (struct dpdmai_rsp_get_tx_queue *)cmd.params;
440 attr->fqid = le32_to_cpu(rsp_params->fqid);