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_dpbp_cmd.h>
13 * dpbp_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 * @dpbp_id: DPBP 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 dpbp_create function.
22 * This function returns a unique authentication token,
23 * associated with the specific object ID and the specific MC
24 * portal; this token must be used in all subsequent commands for
25 * this specific object
27 * Return: '0' on Success; Error code otherwise.
29 int dpbp_open(struct fsl_mc_io *mc_io,
34 struct dpbp_cmd_open *cmd_params;
35 struct mc_command cmd = { 0 };
39 cmd.header = mc_encode_cmd_header(DPBP_CMDID_OPEN,
41 cmd_params = (struct dpbp_cmd_open *)cmd.params;
42 cmd_params->dpbp_id = cpu_to_le32(dpbp_id);
44 /* send command to mc*/
45 err = mc_send_command(mc_io, &cmd);
49 /* retrieve response parameters */
50 *token = mc_cmd_hdr_read_token(&cmd);
56 * dpbp_close() - Close the control session of the object
57 * @mc_io: Pointer to MC portal's I/O object
58 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
59 * @token: Token of DPBP object
61 * After this function is called, no further operations are
62 * allowed on the object without opening a new control session.
64 * Return: '0' on Success; Error code otherwise.
66 int dpbp_close(struct fsl_mc_io *mc_io,
70 struct mc_command cmd = { 0 };
73 cmd.header = mc_encode_cmd_header(DPBP_CMDID_CLOSE, cmd_flags,
76 /* send command to mc*/
77 return mc_send_command(mc_io, &cmd);
81 * dpbp_create() - Create the DPBP object.
82 * @mc_io: Pointer to MC portal's I/O object
83 * @dprc_token: Parent container token; '0' for default container
84 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
85 * @cfg: Configuration structure
86 * @obj_id: Returned object id; use in subsequent API calls
88 * Create the DPBP object, allocate required resources and
89 * perform required initialization.
91 * This function accepts an authentication token of a parent
92 * container that this object should be assigned to and returns
93 * an object id. This object_id will be used in all subsequent calls to
94 * this specific object.
96 * Return: '0' on Success; Error code otherwise.
98 int dpbp_create(struct fsl_mc_io *mc_io,
101 const struct dpbp_cfg *cfg,
104 struct mc_command cmd = { 0 };
107 (void)(cfg); /* unused */
109 /* prepare command */
110 cmd.header = mc_encode_cmd_header(DPBP_CMDID_CREATE,
111 cmd_flags, dprc_token);
113 /* send command to mc*/
114 err = mc_send_command(mc_io, &cmd);
118 /* retrieve response parameters */
119 *obj_id = mc_cmd_read_object_id(&cmd);
125 * dpbp_destroy() - Destroy the DPBP object and release all its resources.
126 * @mc_io: Pointer to MC portal's I/O object
127 * @dprc_token: Parent container token; '0' for default container
128 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
129 * @obj_id: ID of DPBP object
131 * Return: '0' on Success; error code otherwise.
133 int dpbp_destroy(struct fsl_mc_io *mc_io,
138 struct dpbp_cmd_destroy *cmd_params;
139 struct mc_command cmd = { 0 };
141 /* prepare command */
142 cmd.header = mc_encode_cmd_header(DPBP_CMDID_DESTROY,
143 cmd_flags, dprc_token);
145 cmd_params = (struct dpbp_cmd_destroy *)cmd.params;
146 cmd_params->object_id = cpu_to_le32(obj_id);
148 /* send command to mc*/
149 return mc_send_command(mc_io, &cmd);
153 * dpbp_enable() - Enable the DPBP.
154 * @mc_io: Pointer to MC portal's I/O object
155 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
156 * @token: Token of DPBP object
158 * Return: '0' on Success; Error code otherwise.
160 int dpbp_enable(struct fsl_mc_io *mc_io,
164 struct mc_command cmd = { 0 };
166 /* prepare command */
167 cmd.header = mc_encode_cmd_header(DPBP_CMDID_ENABLE, cmd_flags,
170 /* send command to mc*/
171 return mc_send_command(mc_io, &cmd);
175 * dpbp_disable() - Disable the DPBP.
176 * @mc_io: Pointer to MC portal's I/O object
177 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
178 * @token: Token of DPBP object
180 * Return: '0' on Success; Error code otherwise.
182 int dpbp_disable(struct fsl_mc_io *mc_io,
186 struct mc_command cmd = { 0 };
188 /* prepare command */
189 cmd.header = mc_encode_cmd_header(DPBP_CMDID_DISABLE,
192 /* send command to mc*/
193 return mc_send_command(mc_io, &cmd);
197 * dpbp_is_enabled() - Check if the DPBP is enabled.
198 * @mc_io: Pointer to MC portal's I/O object
199 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
200 * @token: Token of DPBP object
201 * @en: Returns '1' if object is enabled; '0' otherwise
203 * Return: '0' on Success; Error code otherwise.
205 int dpbp_is_enabled(struct fsl_mc_io *mc_io,
210 struct dpbp_rsp_is_enabled *rsp_params;
211 struct mc_command cmd = { 0 };
214 /* prepare command */
215 cmd.header = mc_encode_cmd_header(DPBP_CMDID_IS_ENABLED, cmd_flags,
218 /* send command to mc*/
219 err = mc_send_command(mc_io, &cmd);
223 /* retrieve response parameters */
224 rsp_params = (struct dpbp_rsp_is_enabled *)cmd.params;
225 *en = rsp_params->enabled & DPBP_ENABLE;
231 * dpbp_reset() - Reset the DPBP, returns the object to initial state.
232 * @mc_io: Pointer to MC portal's I/O object
233 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
234 * @token: Token of DPBP object
236 * Return: '0' on Success; Error code otherwise.
238 int dpbp_reset(struct fsl_mc_io *mc_io,
242 struct mc_command cmd = { 0 };
244 /* prepare command */
245 cmd.header = mc_encode_cmd_header(DPBP_CMDID_RESET,
248 /* send command to mc*/
249 return mc_send_command(mc_io, &cmd);
251 int dpbp_get_attributes(struct fsl_mc_io *mc_io,
254 struct dpbp_attr *attr)
256 struct dpbp_rsp_get_attributes *rsp_params;
257 struct mc_command cmd = { 0 };
260 /* prepare command */
261 cmd.header = mc_encode_cmd_header(DPBP_CMDID_GET_ATTR,
264 /* send command to mc*/
265 err = mc_send_command(mc_io, &cmd);
269 /* retrieve response parameters */
270 rsp_params = (struct dpbp_rsp_get_attributes *)cmd.params;
271 attr->bpid = le16_to_cpu(rsp_params->bpid);
272 attr->id = le32_to_cpu(rsp_params->id);
278 * dpbp_get_api_version - Get Data Path Buffer Pool API version
279 * @mc_io: Pointer to Mc portal's I/O object
280 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
281 * @major_ver: Major version of Buffer Pool API
282 * @minor_ver: Minor version of Buffer Pool API
284 * Return: '0' on Success; Error code otherwise.
286 int dpbp_get_api_version(struct fsl_mc_io *mc_io,
291 struct dpbp_rsp_get_api_version *rsp_params;
292 struct mc_command cmd = { 0 };
295 /* prepare command */
296 cmd.header = mc_encode_cmd_header(DPBP_CMDID_GET_API_VERSION,
299 /* send command to mc */
300 err = mc_send_command(mc_io, &cmd);
304 /* retrieve response parameters */
305 rsp_params = (struct dpbp_rsp_get_api_version *)cmd.params;
306 *major_ver = le16_to_cpu(rsp_params->major);
307 *minor_ver = le16_to_cpu(rsp_params->minor);
313 * dpbp_get_num_free_bufs() - Get number of free buffers in the buffer pool
314 * @mc_io: Pointer to MC portal's I/O object
315 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
316 * @token: Token of DPBP object
317 * @num_free_bufs: Number of free buffers
319 * Return: '0' on Success; Error code otherwise.
322 int dpbp_get_num_free_bufs(struct fsl_mc_io *mc_io,
325 uint32_t *num_free_bufs)
327 struct dpbp_rsp_get_num_free_bufs *rsp_params;
328 struct mc_command cmd = { 0 };
331 /* prepare command */
332 cmd.header = mc_encode_cmd_header(DPBP_CMDID_GET_FREE_BUFFERS_NUM,
336 /* send command to mc*/
337 err = mc_send_command(mc_io, &cmd);
341 /* retrieve response parameters */
342 rsp_params = (struct dpbp_rsp_get_num_free_bufs *)cmd.params;
343 *num_free_bufs = le32_to_cpu(rsp_params->num_free_bufs);