2 * This file is provided under a dual BSD/GPLv2 license. When using or
3 * redistributing this file, you may do so under either license.
7 * Copyright 2013-2016 Freescale Semiconductor Inc.
8 * Copyright 2016-2017 NXP.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions are met:
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * * Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * * Neither the name of the above-listed copyright holders nor the
18 * names of any contributors may be used to endorse or promote products
19 * derived from this software without specific prior written permission.
23 * ALTERNATIVELY, this software may be distributed under the terms of the
24 * GNU General Public License ("GPL") as published by the Free Software
25 * Foundation, either version 2 of that License or (at your option) any
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
29 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
32 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
33 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
34 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
35 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
36 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
37 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38 * POSSIBILITY OF SUCH DAMAGE.
40 #include <fsl_mc_sys.h>
41 #include <fsl_mc_cmd.h>
43 #include <fsl_dpbp_cmd.h>
46 * dpbp_open() - Open a control session for the specified object.
47 * @mc_io: Pointer to MC portal's I/O object
48 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
49 * @dpbp_id: DPBP unique ID
50 * @token: Returned token; use in subsequent API calls
52 * This function can be used to open a control session for an
53 * already created object; an object may have been declared in
54 * the DPL or by calling the dpbp_create function.
55 * This function returns a unique authentication token,
56 * associated with the specific object ID and the specific MC
57 * portal; this token must be used in all subsequent commands for
58 * this specific object
60 * Return: '0' on Success; Error code otherwise.
62 int dpbp_open(struct fsl_mc_io *mc_io,
67 struct dpbp_cmd_open *cmd_params;
68 struct mc_command cmd = { 0 };
72 cmd.header = mc_encode_cmd_header(DPBP_CMDID_OPEN,
74 cmd_params = (struct dpbp_cmd_open *)cmd.params;
75 cmd_params->dpbp_id = cpu_to_le32(dpbp_id);
77 /* send command to mc*/
78 err = mc_send_command(mc_io, &cmd);
82 /* retrieve response parameters */
83 *token = mc_cmd_hdr_read_token(&cmd);
89 * dpbp_close() - Close the control session of the object
90 * @mc_io: Pointer to MC portal's I/O object
91 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
92 * @token: Token of DPBP object
94 * After this function is called, no further operations are
95 * allowed on the object without opening a new control session.
97 * Return: '0' on Success; Error code otherwise.
99 int dpbp_close(struct fsl_mc_io *mc_io,
103 struct mc_command cmd = { 0 };
105 /* prepare command */
106 cmd.header = mc_encode_cmd_header(DPBP_CMDID_CLOSE, cmd_flags,
109 /* send command to mc*/
110 return mc_send_command(mc_io, &cmd);
114 * dpbp_create() - Create the DPBP object.
115 * @mc_io: Pointer to MC portal's I/O object
116 * @dprc_token: Parent container token; '0' for default container
117 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
118 * @cfg: Configuration structure
119 * @obj_id: Returned object id; use in subsequent API calls
121 * Create the DPBP object, allocate required resources and
122 * perform required initialization.
124 * This function accepts an authentication token of a parent
125 * container that this object should be assigned to and returns
126 * an object id. This object_id will be used in all subsequent calls to
127 * this specific object.
129 * Return: '0' on Success; Error code otherwise.
131 int dpbp_create(struct fsl_mc_io *mc_io,
134 const struct dpbp_cfg *cfg,
137 struct mc_command cmd = { 0 };
140 (void)(cfg); /* unused */
142 /* prepare command */
143 cmd.header = mc_encode_cmd_header(DPBP_CMDID_CREATE,
144 cmd_flags, dprc_token);
146 /* send command to mc*/
147 err = mc_send_command(mc_io, &cmd);
151 /* retrieve response parameters */
152 *obj_id = mc_cmd_read_object_id(&cmd);
158 * dpbp_destroy() - Destroy the DPBP object and release all its resources.
159 * @mc_io: Pointer to MC portal's I/O object
160 * @dprc_token: Parent container token; '0' for default container
161 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
162 * @obj_id: ID of DPBP object
164 * Return: '0' on Success; error code otherwise.
166 int dpbp_destroy(struct fsl_mc_io *mc_io,
171 struct dpbp_cmd_destroy *cmd_params;
172 struct mc_command cmd = { 0 };
174 /* prepare command */
175 cmd.header = mc_encode_cmd_header(DPBP_CMDID_DESTROY,
176 cmd_flags, dprc_token);
178 cmd_params = (struct dpbp_cmd_destroy *)cmd.params;
179 cmd_params->object_id = cpu_to_le32(obj_id);
181 /* send command to mc*/
182 return mc_send_command(mc_io, &cmd);
186 * dpbp_enable() - Enable the DPBP.
187 * @mc_io: Pointer to MC portal's I/O object
188 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
189 * @token: Token of DPBP object
191 * Return: '0' on Success; Error code otherwise.
193 int dpbp_enable(struct fsl_mc_io *mc_io,
197 struct mc_command cmd = { 0 };
199 /* prepare command */
200 cmd.header = mc_encode_cmd_header(DPBP_CMDID_ENABLE, cmd_flags,
203 /* send command to mc*/
204 return mc_send_command(mc_io, &cmd);
208 * dpbp_disable() - Disable the DPBP.
209 * @mc_io: Pointer to MC portal's I/O object
210 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
211 * @token: Token of DPBP object
213 * Return: '0' on Success; Error code otherwise.
215 int dpbp_disable(struct fsl_mc_io *mc_io,
219 struct mc_command cmd = { 0 };
221 /* prepare command */
222 cmd.header = mc_encode_cmd_header(DPBP_CMDID_DISABLE,
225 /* send command to mc*/
226 return mc_send_command(mc_io, &cmd);
230 * dpbp_is_enabled() - Check if the DPBP is enabled.
231 * @mc_io: Pointer to MC portal's I/O object
232 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
233 * @token: Token of DPBP object
234 * @en: Returns '1' if object is enabled; '0' otherwise
236 * Return: '0' on Success; Error code otherwise.
238 int dpbp_is_enabled(struct fsl_mc_io *mc_io,
243 struct dpbp_rsp_is_enabled *rsp_params;
244 struct mc_command cmd = { 0 };
247 /* prepare command */
248 cmd.header = mc_encode_cmd_header(DPBP_CMDID_IS_ENABLED, cmd_flags,
251 /* send command to mc*/
252 err = mc_send_command(mc_io, &cmd);
256 /* retrieve response parameters */
257 rsp_params = (struct dpbp_rsp_is_enabled *)cmd.params;
258 *en = rsp_params->enabled & DPBP_ENABLE;
264 * dpbp_reset() - Reset the DPBP, returns the object to initial state.
265 * @mc_io: Pointer to MC portal's I/O object
266 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
267 * @token: Token of DPBP object
269 * Return: '0' on Success; Error code otherwise.
271 int dpbp_reset(struct fsl_mc_io *mc_io,
275 struct mc_command cmd = { 0 };
277 /* prepare command */
278 cmd.header = mc_encode_cmd_header(DPBP_CMDID_RESET,
281 /* send command to mc*/
282 return mc_send_command(mc_io, &cmd);
284 int dpbp_get_attributes(struct fsl_mc_io *mc_io,
287 struct dpbp_attr *attr)
289 struct dpbp_rsp_get_attributes *rsp_params;
290 struct mc_command cmd = { 0 };
293 /* prepare command */
294 cmd.header = mc_encode_cmd_header(DPBP_CMDID_GET_ATTR,
297 /* send command to mc*/
298 err = mc_send_command(mc_io, &cmd);
302 /* retrieve response parameters */
303 rsp_params = (struct dpbp_rsp_get_attributes *)cmd.params;
304 attr->bpid = le16_to_cpu(rsp_params->bpid);
305 attr->id = le32_to_cpu(rsp_params->id);
311 * dpbp_get_api_version - Get Data Path Buffer Pool API version
312 * @mc_io: Pointer to Mc portal's I/O object
313 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
314 * @major_ver: Major version of Buffer Pool API
315 * @minor_ver: Minor version of Buffer Pool API
317 * Return: '0' on Success; Error code otherwise.
319 int dpbp_get_api_version(struct fsl_mc_io *mc_io,
324 struct dpbp_rsp_get_api_version *rsp_params;
325 struct mc_command cmd = { 0 };
328 /* prepare command */
329 cmd.header = mc_encode_cmd_header(DPBP_CMDID_GET_API_VERSION,
332 /* send command to mc */
333 err = mc_send_command(mc_io, &cmd);
337 /* retrieve response parameters */
338 rsp_params = (struct dpbp_rsp_get_api_version *)cmd.params;
339 *major_ver = le16_to_cpu(rsp_params->major);
340 *minor_ver = le16_to_cpu(rsp_params->minor);
346 * dpbp_get_num_free_bufs() - Get number of free buffers in the buffer pool
347 * @mc_io: Pointer to MC portal's I/O object
348 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
349 * @token: Token of DPBP object
350 * @num_free_bufs: Number of free buffers
352 * Return: '0' on Success; Error code otherwise.
355 int dpbp_get_num_free_bufs(struct fsl_mc_io *mc_io,
358 uint32_t *num_free_bufs)
360 struct dpbp_rsp_get_num_free_bufs *rsp_params;
361 struct mc_command cmd = { 0 };
364 /* prepare command */
365 cmd.header = mc_encode_cmd_header(DPBP_CMDID_GET_FREE_BUFFERS_NUM,
369 /* send command to mc*/
370 err = mc_send_command(mc_io, &cmd);
374 /* retrieve response parameters */
375 rsp_params = (struct dpbp_rsp_get_num_free_bufs *)cmd.params;
376 *num_free_bufs = le32_to_cpu(rsp_params->num_free_bufs);