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->priorities[0] = cfg->priorities[0];
117 cmd_params->priorities[1] = cfg->priorities[1];
119 /* send command to mc*/
120 err = mc_send_command(mc_io, &cmd);
124 /* retrieve response parameters */
125 *obj_id = mc_cmd_read_object_id(&cmd);
131 * dpdmai_destroy() - Destroy the DPDMAI object and release all its resources.
132 * @mc_io: Pointer to MC portal's I/O object
133 * @dprc_token: Parent container token; '0' for default container
134 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
135 * @object_id: The object id; it must be a valid id within the container that
136 * created this object;
138 * The function accepts the authentication token of the parent container that
139 * created the object (not the one that currently owns the object). The object
140 * is searched within parent using the provided 'object_id'.
141 * All tokens to the object must be closed before calling destroy.
143 * Return: '0' on Success; error code otherwise.
145 int dpdmai_destroy(struct fsl_mc_io *mc_io,
150 struct dpdmai_cmd_destroy *cmd_params;
151 struct mc_command cmd = { 0 };
153 /* prepare command */
154 cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_DESTROY,
157 cmd_params = (struct dpdmai_cmd_destroy *)cmd.params;
158 cmd_params->dpdmai_id = cpu_to_le32(object_id);
160 /* send command to mc*/
161 return mc_send_command(mc_io, &cmd);
165 * dpdmai_enable() - Enable the DPDMAI, allow sending and receiving frames.
166 * @mc_io: Pointer to MC portal's I/O object
167 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
168 * @token: Token of DPDMAI object
170 * Return: '0' on Success; Error code otherwise.
172 int dpdmai_enable(struct fsl_mc_io *mc_io,
176 struct mc_command cmd = { 0 };
178 /* prepare command */
179 cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_ENABLE,
183 /* send command to mc*/
184 return mc_send_command(mc_io, &cmd);
188 * dpdmai_disable() - Disable the DPDMAI, stop sending and receiving frames.
189 * @mc_io: Pointer to MC portal's I/O object
190 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
191 * @token: Token of DPDMAI object
193 * Return: '0' on Success; Error code otherwise.
195 int dpdmai_disable(struct fsl_mc_io *mc_io,
199 struct mc_command cmd = { 0 };
201 /* prepare command */
202 cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_DISABLE,
206 /* send command to mc*/
207 return mc_send_command(mc_io, &cmd);
211 * dpdmai_is_enabled() - Check if the DPDMAI is enabled.
212 * @mc_io: Pointer to MC portal's I/O object
213 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
214 * @token: Token of DPDMAI object
215 * @en: Returns '1' if object is enabled; '0' otherwise
217 * Return: '0' on Success; Error code otherwise.
219 int dpdmai_is_enabled(struct fsl_mc_io *mc_io,
224 struct dpdmai_rsp_is_enabled *rsp_params;
225 struct mc_command cmd = { 0 };
228 /* prepare command */
229 cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_IS_ENABLED,
233 /* send command to mc*/
234 err = mc_send_command(mc_io, &cmd);
238 /* retrieve response parameters */
239 rsp_params = (struct dpdmai_rsp_is_enabled *)cmd.params;
240 *en = dpdmai_get_field(rsp_params->en, ENABLE);
246 * dpdmai_reset() - Reset the DPDMAI, returns the object to initial state.
247 * @mc_io: Pointer to MC portal's I/O object
248 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
249 * @token: Token of DPDMAI object
251 * Return: '0' on Success; Error code otherwise.
253 int dpdmai_reset(struct fsl_mc_io *mc_io,
257 struct mc_command cmd = { 0 };
259 /* prepare command */
260 cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_RESET,
264 /* send command to mc*/
265 return mc_send_command(mc_io, &cmd);
269 * dpdmai_get_attributes() - Retrieve DPDMAI attributes.
270 * @mc_io: Pointer to MC portal's I/O object
271 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
272 * @token: Token of DPDMAI object
273 * @attr: Returned object's attributes
275 * Return: '0' on Success; Error code otherwise.
277 int dpdmai_get_attributes(struct fsl_mc_io *mc_io,
280 struct dpdmai_attr *attr)
282 struct dpdmai_rsp_get_attr *rsp_params;
283 struct mc_command cmd = { 0 };
286 /* prepare command */
287 cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_GET_ATTR,
291 /* send command to mc*/
292 err = mc_send_command(mc_io, &cmd);
296 /* retrieve response parameters */
297 rsp_params = (struct dpdmai_rsp_get_attr *)cmd.params;
298 attr->id = le32_to_cpu(rsp_params->id);
299 attr->num_of_priorities = rsp_params->num_of_priorities;
305 * dpdmai_set_rx_queue() - Set Rx queue configuration
306 * @mc_io: Pointer to MC portal's I/O object
307 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
308 * @token: Token of DPDMAI object
309 * @priority: Select the queue relative to number of
310 * priorities configured at DPDMAI creation; use
311 * DPDMAI_ALL_QUEUES to configure all Rx queues
313 * @cfg: Rx queue configuration
315 * Return: '0' on Success; Error code otherwise.
317 int dpdmai_set_rx_queue(struct fsl_mc_io *mc_io,
321 const struct dpdmai_rx_queue_cfg *cfg)
323 struct dpdmai_cmd_set_rx_queue *cmd_params;
324 struct mc_command cmd = { 0 };
326 /* prepare command */
327 cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_SET_RX_QUEUE,
330 cmd_params = (struct dpdmai_cmd_set_rx_queue *)cmd.params;
331 cmd_params->dest_id = cpu_to_le32(cfg->dest_cfg.dest_id);
332 cmd_params->dest_priority = cfg->dest_cfg.priority;
333 cmd_params->priority = priority;
334 cmd_params->user_ctx = cpu_to_le64(cfg->user_ctx);
335 cmd_params->options = cpu_to_le32(cfg->options);
336 dpdmai_set_field(cmd_params->dest_type,
338 cfg->dest_cfg.dest_type);
340 /* send command to mc*/
341 return mc_send_command(mc_io, &cmd);
345 * dpdmai_get_rx_queue() - Retrieve Rx queue attributes.
346 * @mc_io: Pointer to MC portal's I/O object
347 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
348 * @token: Token of DPDMAI object
349 * @priority: Select the queue relative to number of
350 * priorities configured at DPDMAI creation
351 * @attr: Returned Rx queue attributes
353 * Return: '0' on Success; Error code otherwise.
355 int dpdmai_get_rx_queue(struct fsl_mc_io *mc_io,
359 struct dpdmai_rx_queue_attr *attr)
361 struct dpdmai_cmd_get_queue *cmd_params;
362 struct dpdmai_rsp_get_rx_queue *rsp_params;
363 struct mc_command cmd = { 0 };
366 /* prepare command */
367 cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_GET_RX_QUEUE,
370 cmd_params = (struct dpdmai_cmd_get_queue *)cmd.params;
371 cmd_params->priority = priority;
373 /* send command to mc*/
374 err = mc_send_command(mc_io, &cmd);
378 /* retrieve response parameters */
379 rsp_params = (struct dpdmai_rsp_get_rx_queue *)cmd.params;
380 attr->user_ctx = le64_to_cpu(rsp_params->user_ctx);
381 attr->fqid = le32_to_cpu(rsp_params->fqid);
382 attr->dest_cfg.dest_id = le32_to_cpu(rsp_params->dest_id);
383 attr->dest_cfg.priority = le32_to_cpu(rsp_params->dest_priority);
384 attr->dest_cfg.dest_type = dpdmai_get_field(rsp_params->dest_type,
391 * dpdmai_get_tx_queue() - Retrieve Tx queue attributes.
392 * @mc_io: Pointer to MC portal's I/O object
393 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
394 * @token: Token of DPDMAI object
395 * @priority: Select the queue relative to number of
396 * priorities configured at DPDMAI creation
397 * @attr: Returned Tx queue attributes
399 * Return: '0' on Success; Error code otherwise.
401 int dpdmai_get_tx_queue(struct fsl_mc_io *mc_io,
405 struct dpdmai_tx_queue_attr *attr)
407 struct dpdmai_cmd_get_queue *cmd_params;
408 struct dpdmai_rsp_get_tx_queue *rsp_params;
409 struct mc_command cmd = { 0 };
412 /* prepare command */
413 cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_GET_TX_QUEUE,
416 cmd_params = (struct dpdmai_cmd_get_queue *)cmd.params;
417 cmd_params->priority = priority;
419 /* send command to mc*/
420 err = mc_send_command(mc_io, &cmd);
424 /* retrieve response parameters */
425 rsp_params = (struct dpdmai_rsp_get_tx_queue *)cmd.params;
426 attr->fqid = le32_to_cpu(rsp_params->fqid);