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);
271 int dpio_get_attributes(struct fsl_mc_io *mc_io,
274 struct dpio_attr *attr)
276 struct dpio_rsp_get_attr *rsp_params;
277 struct mc_command cmd = { 0 };
280 /* prepare command */
281 cmd.header = mc_encode_cmd_header(DPIO_CMDID_GET_ATTR,
285 /* send command to mc*/
286 err = mc_send_command(mc_io, &cmd);
290 /* retrieve response parameters */
291 rsp_params = (struct dpio_rsp_get_attr *)cmd.params;
292 attr->id = le32_to_cpu(rsp_params->id);
293 attr->qbman_portal_id = le16_to_cpu(rsp_params->qbman_portal_id);
294 attr->num_priorities = rsp_params->num_priorities;
295 attr->qbman_portal_ce_offset =
296 le64_to_cpu(rsp_params->qbman_portal_ce_offset);
297 attr->qbman_portal_ci_offset =
298 le64_to_cpu(rsp_params->qbman_portal_ci_offset);
299 attr->qbman_version = le32_to_cpu(rsp_params->qbman_version);
300 attr->clk = le32_to_cpu(rsp_params->clk);
301 attr->channel_mode = dpio_get_field(rsp_params->channel_mode,
308 * dpio_set_stashing_destination() - Set the stashing destination.
309 * @mc_io: Pointer to MC portal's I/O object
310 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
311 * @token: Token of DPIO object
312 * @sdest: Stashing destination value
314 * Return: '0' on Success; Error code otherwise.
316 int dpio_set_stashing_destination(struct fsl_mc_io *mc_io,
321 struct dpio_stashing_dest *cmd_params;
322 struct mc_command cmd = { 0 };
324 /* prepare command */
325 cmd.header = mc_encode_cmd_header(DPIO_CMDID_SET_STASHING_DEST,
328 cmd_params = (struct dpio_stashing_dest *)cmd.params;
329 cmd_params->sdest = sdest;
331 /* send command to mc*/
332 return mc_send_command(mc_io, &cmd);
336 * dpio_get_stashing_destination() - Get the stashing destination..
337 * @mc_io: Pointer to MC portal's I/O object
338 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
339 * @token: Token of DPIO object
340 * @sdest: Returns the stashing destination value
342 * Return: '0' on Success; Error code otherwise.
344 int dpio_get_stashing_destination(struct fsl_mc_io *mc_io,
349 struct dpio_stashing_dest *rsp_params;
350 struct mc_command cmd = { 0 };
353 /* prepare command */
354 cmd.header = mc_encode_cmd_header(DPIO_CMDID_GET_STASHING_DEST,
358 /* send command to mc*/
359 err = mc_send_command(mc_io, &cmd);
363 /* retrieve response parameters */
364 rsp_params = (struct dpio_stashing_dest *)cmd.params;
365 *sdest = rsp_params->sdest;
371 * dpio_add_static_dequeue_channel() - Add a static dequeue channel.
372 * @mc_io: Pointer to MC portal's I/O object
373 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
374 * @token: Token of DPIO object
375 * @dpcon_id: DPCON object ID
376 * @channel_index: Returned channel index to be used in qbman API
378 * Return: '0' on Success; Error code otherwise.
380 int dpio_add_static_dequeue_channel(struct fsl_mc_io *mc_io,
384 uint8_t *channel_index)
386 struct dpio_rsp_add_static_dequeue_channel *rsp_params;
387 struct dpio_cmd_static_dequeue_channel *cmd_params;
388 struct mc_command cmd = { 0 };
391 /* prepare command */
392 cmd.header = mc_encode_cmd_header(DPIO_CMDID_ADD_STATIC_DEQUEUE_CHANNEL,
395 cmd_params = (struct dpio_cmd_static_dequeue_channel *)cmd.params;
396 cmd_params->dpcon_id = cpu_to_le32(dpcon_id);
398 /* send command to mc*/
399 err = mc_send_command(mc_io, &cmd);
403 /* retrieve response parameters */
404 rsp_params = (struct dpio_rsp_add_static_dequeue_channel *)cmd.params;
405 *channel_index = rsp_params->channel_index;
411 * dpio_remove_static_dequeue_channel() - Remove a static dequeue channel.
412 * @mc_io: Pointer to MC portal's I/O object
413 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
414 * @token: Token of DPIO object
415 * @dpcon_id: DPCON object ID
417 * Return: '0' on Success; Error code otherwise.
419 int dpio_remove_static_dequeue_channel(struct fsl_mc_io *mc_io,
424 struct dpio_cmd_static_dequeue_channel *cmd_params;
425 struct mc_command cmd = { 0 };
427 /* prepare command */
428 cmd.header = mc_encode_cmd_header(
429 DPIO_CMDID_REMOVE_STATIC_DEQUEUE_CHANNEL,
432 cmd_params = (struct dpio_cmd_static_dequeue_channel *)cmd.params;
433 cmd_params->dpcon_id = cpu_to_le32(dpcon_id);
435 /* send command to mc*/
436 return mc_send_command(mc_io, &cmd);
440 * dpio_get_api_version() - Get Data Path I/O API version
441 * @mc_io: Pointer to MC portal's I/O object
442 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
443 * @major_ver: Major version of data path i/o API
444 * @minor_ver: Minor version of data path i/o API
446 * Return: '0' on Success; Error code otherwise.
448 int dpio_get_api_version(struct fsl_mc_io *mc_io,
453 struct dpio_rsp_get_api_version *rsp_params;
454 struct mc_command cmd = { 0 };
457 cmd.header = mc_encode_cmd_header(DPIO_CMDID_GET_API_VERSION,
461 err = mc_send_command(mc_io, &cmd);
465 rsp_params = (struct dpio_rsp_get_api_version *)cmd.params;
466 *major_ver = le16_to_cpu(rsp_params->major);
467 *minor_ver = le16_to_cpu(rsp_params->minor);