1 /* SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0)
3 * Copyright 2013-2016 Freescale Semiconductor Inc.
4 * Copyright 2016-2017 NXP
7 #include <fsl_mc_sys.h>
8 #include <fsl_mc_cmd.h>
10 #include <fsl_dpio_cmd.h>
13 * dpio_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 * @dpio_id: DPIO unique ID
17 * @token: Returned token; use in subsequent API calls
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 dpio_create() function.
22 * This function returns a unique authentication token,
23 * associated with the specific object ID and any MC portals
24 * assigned to the parent container; this token must be used in
25 * all subsequent commands for this specific object.
27 * Return: '0' on Success; Error code otherwise.
29 int dpio_open(struct fsl_mc_io *mc_io,
34 struct dpio_cmd_open *cmd_params;
35 struct mc_command cmd = { 0 };
39 cmd.header = mc_encode_cmd_header(DPIO_CMDID_OPEN,
42 cmd_params = (struct dpio_cmd_open *)cmd.params;
43 cmd_params->dpio_id = cpu_to_le32(dpio_id);
45 /* send command to mc*/
46 err = mc_send_command(mc_io, &cmd);
50 /* retrieve response parameters */
51 *token = mc_cmd_hdr_read_token(&cmd);
57 * dpio_close() - Close the control session of the object
58 * @mc_io: Pointer to MC portal's I/O object
59 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
60 * @token: Token of DPIO object
62 * Return: '0' on Success; Error code otherwise.
64 int dpio_close(struct fsl_mc_io *mc_io,
68 struct mc_command cmd = { 0 };
71 cmd.header = mc_encode_cmd_header(DPIO_CMDID_CLOSE,
75 /* send command to mc*/
76 return mc_send_command(mc_io, &cmd);
80 * dpio_create() - Create the DPIO 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 DPIO 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 dpio_create(struct fsl_mc_io *mc_io,
104 const struct dpio_cfg *cfg,
107 struct dpio_cmd_create *cmd_params;
108 struct mc_command cmd = { 0 };
111 /* prepare command */
112 cmd.header = mc_encode_cmd_header(DPIO_CMDID_CREATE,
115 cmd_params = (struct dpio_cmd_create *)cmd.params;
116 cmd_params->num_priorities = cfg->num_priorities;
117 dpio_set_field(cmd_params->channel_mode,
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 * dpio_destroy() - Destroy the DPIO 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 dpio_destroy(struct fsl_mc_io *mc_io,
152 struct dpio_cmd_destroy *cmd_params;
153 struct mc_command cmd = { 0 };
155 /* prepare command */
156 cmd.header = mc_encode_cmd_header(DPIO_CMDID_DESTROY,
160 /* set object id to destroy */
161 cmd_params = (struct dpio_cmd_destroy *)cmd.params;
162 cmd_params->dpio_id = cpu_to_le32(object_id);
164 /* send command to mc*/
165 return mc_send_command(mc_io, &cmd);
169 * dpio_enable() - Enable the DPIO, allow I/O portal operations.
170 * @mc_io: Pointer to MC portal's I/O object
171 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
172 * @token: Token of DPIO object
174 * Return: '0' on Success; Error code otherwise
176 int dpio_enable(struct fsl_mc_io *mc_io,
180 struct mc_command cmd = { 0 };
182 /* prepare command */
183 cmd.header = mc_encode_cmd_header(DPIO_CMDID_ENABLE,
187 /* send command to mc*/
188 return mc_send_command(mc_io, &cmd);
192 * dpio_disable() - Disable the DPIO, stop any I/O portal operation.
193 * @mc_io: Pointer to MC portal's I/O object
194 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
195 * @token: Token of DPIO object
197 * Return: '0' on Success; Error code otherwise
199 int dpio_disable(struct fsl_mc_io *mc_io,
203 struct mc_command cmd = { 0 };
205 /* prepare command */
206 cmd.header = mc_encode_cmd_header(DPIO_CMDID_DISABLE,
210 /* send command to mc*/
211 return mc_send_command(mc_io, &cmd);
215 * dpio_is_enabled() - Check if the DPIO is enabled.
216 * @mc_io: Pointer to MC portal's I/O object
217 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
218 * @token: Token of DPIO object
219 * @en: Returns '1' if object is enabled; '0' otherwise
221 * Return: '0' on Success; Error code otherwise.
223 int dpio_is_enabled(struct fsl_mc_io *mc_io,
228 struct dpio_rsp_is_enabled *rsp_params;
229 struct mc_command cmd = { 0 };
232 /* prepare command */
233 cmd.header = mc_encode_cmd_header(DPIO_CMDID_IS_ENABLED, cmd_flags,
236 /* send command to mc*/
237 err = mc_send_command(mc_io, &cmd);
241 /* retrieve response parameters */
242 rsp_params = (struct dpio_rsp_is_enabled *)cmd.params;
243 *en = dpio_get_field(rsp_params->en, ENABLE);
249 * dpio_reset() - Reset the DPIO, returns the object to initial state.
250 * @mc_io: Pointer to MC portal's I/O object
251 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
252 * @token: Token of DPIO object
254 * Return: '0' on Success; Error code otherwise.
256 int dpio_reset(struct fsl_mc_io *mc_io,
260 struct mc_command cmd = { 0 };
262 /* prepare command */
263 cmd.header = mc_encode_cmd_header(DPIO_CMDID_RESET,
267 /* send command to mc*/
268 return mc_send_command(mc_io, &cmd);
272 * dpio_get_attributes() - Retrieve DPIO attributes
273 * @mc_io: Pointer to MC portal's I/O object
274 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
275 * @token: Token of DPIO object
276 * @attr: Returned object's attributes
278 * Return: '0' on Success; Error code otherwise
280 int dpio_get_attributes(struct fsl_mc_io *mc_io,
283 struct dpio_attr *attr)
285 struct dpio_rsp_get_attr *rsp_params;
286 struct mc_command cmd = { 0 };
289 /* prepare command */
290 cmd.header = mc_encode_cmd_header(DPIO_CMDID_GET_ATTR,
294 /* send command to mc*/
295 err = mc_send_command(mc_io, &cmd);
299 /* retrieve response parameters */
300 rsp_params = (struct dpio_rsp_get_attr *)cmd.params;
301 attr->id = le32_to_cpu(rsp_params->id);
302 attr->qbman_portal_id = le16_to_cpu(rsp_params->qbman_portal_id);
303 attr->num_priorities = rsp_params->num_priorities;
304 attr->qbman_portal_ce_offset =
305 le64_to_cpu(rsp_params->qbman_portal_ce_offset);
306 attr->qbman_portal_ci_offset =
307 le64_to_cpu(rsp_params->qbman_portal_ci_offset);
308 attr->qbman_version = le32_to_cpu(rsp_params->qbman_version);
309 attr->clk = le32_to_cpu(rsp_params->clk);
310 attr->channel_mode = dpio_get_field(rsp_params->channel_mode,
317 * dpio_set_stashing_destination() - Set the stashing destination.
318 * @mc_io: Pointer to MC portal's I/O object
319 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
320 * @token: Token of DPIO object
321 * @sdest: Stashing destination value
323 * Return: '0' on Success; Error code otherwise.
325 int dpio_set_stashing_destination(struct fsl_mc_io *mc_io,
330 struct dpio_stashing_dest *cmd_params;
331 struct mc_command cmd = { 0 };
333 /* prepare command */
334 cmd.header = mc_encode_cmd_header(DPIO_CMDID_SET_STASHING_DEST,
337 cmd_params = (struct dpio_stashing_dest *)cmd.params;
338 cmd_params->sdest = sdest;
340 /* send command to mc*/
341 return mc_send_command(mc_io, &cmd);
345 * dpio_get_stashing_destination() - Get the stashing destination..
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 DPIO object
349 * @sdest: Returns the stashing destination value
351 * Return: '0' on Success; Error code otherwise.
353 int dpio_get_stashing_destination(struct fsl_mc_io *mc_io,
358 struct dpio_stashing_dest *rsp_params;
359 struct mc_command cmd = { 0 };
362 /* prepare command */
363 cmd.header = mc_encode_cmd_header(DPIO_CMDID_GET_STASHING_DEST,
367 /* send command to mc*/
368 err = mc_send_command(mc_io, &cmd);
372 /* retrieve response parameters */
373 rsp_params = (struct dpio_stashing_dest *)cmd.params;
374 *sdest = rsp_params->sdest;
380 * dpio_add_static_dequeue_channel() - Add a static dequeue channel.
381 * @mc_io: Pointer to MC portal's I/O object
382 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
383 * @token: Token of DPIO object
384 * @dpcon_id: DPCON object ID
385 * @channel_index: Returned channel index to be used in qbman API
387 * Return: '0' on Success; Error code otherwise.
389 int dpio_add_static_dequeue_channel(struct fsl_mc_io *mc_io,
393 uint8_t *channel_index)
395 struct dpio_rsp_add_static_dequeue_channel *rsp_params;
396 struct dpio_cmd_static_dequeue_channel *cmd_params;
397 struct mc_command cmd = { 0 };
400 /* prepare command */
401 cmd.header = mc_encode_cmd_header(DPIO_CMDID_ADD_STATIC_DEQUEUE_CHANNEL,
404 cmd_params = (struct dpio_cmd_static_dequeue_channel *)cmd.params;
405 cmd_params->dpcon_id = cpu_to_le32(dpcon_id);
407 /* send command to mc*/
408 err = mc_send_command(mc_io, &cmd);
412 /* retrieve response parameters */
413 rsp_params = (struct dpio_rsp_add_static_dequeue_channel *)cmd.params;
414 *channel_index = rsp_params->channel_index;
420 * dpio_remove_static_dequeue_channel() - Remove a static dequeue channel.
421 * @mc_io: Pointer to MC portal's I/O object
422 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
423 * @token: Token of DPIO object
424 * @dpcon_id: DPCON object ID
426 * Return: '0' on Success; Error code otherwise.
428 int dpio_remove_static_dequeue_channel(struct fsl_mc_io *mc_io,
433 struct dpio_cmd_static_dequeue_channel *cmd_params;
434 struct mc_command cmd = { 0 };
436 /* prepare command */
437 cmd.header = mc_encode_cmd_header(
438 DPIO_CMDID_REMOVE_STATIC_DEQUEUE_CHANNEL,
441 cmd_params = (struct dpio_cmd_static_dequeue_channel *)cmd.params;
442 cmd_params->dpcon_id = cpu_to_le32(dpcon_id);
444 /* send command to mc*/
445 return mc_send_command(mc_io, &cmd);
449 * dpio_get_api_version() - Get Data Path I/O API version
450 * @mc_io: Pointer to MC portal's I/O object
451 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
452 * @major_ver: Major version of data path i/o API
453 * @minor_ver: Minor version of data path i/o API
455 * Return: '0' on Success; Error code otherwise.
457 int dpio_get_api_version(struct fsl_mc_io *mc_io,
462 struct dpio_rsp_get_api_version *rsp_params;
463 struct mc_command cmd = { 0 };
466 cmd.header = mc_encode_cmd_header(DPIO_CMDID_GET_API_VERSION,
470 err = mc_send_command(mc_io, &cmd);
474 rsp_params = (struct dpio_rsp_get_api_version *)cmd.params;
475 *major_ver = le16_to_cpu(rsp_params->major);
476 *minor_ver = le16_to_cpu(rsp_params->minor);