blob: 5e17ccf73d386da1e2cc44539efca95ad15597ba [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -07002/*
3 * Freescale Layerscape MC I/O wrapper
4 *
Yogesh Gaur1a0c4ae2018-05-09 10:52:17 +05305 * Copyright 2013-2016 Freescale Semiconductor, Inc.
Ioana Ciornei2f232fa2023-05-31 19:04:30 +03006 * Copyright 2017-2023 NXP
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -07007 */
8#include <fsl-mc/fsl_mc_sys.h>
9#include <fsl-mc/fsl_mc_cmd.h>
10#include <fsl-mc/fsl_dpbp.h>
11
Ioana Ciornei2f232fa2023-05-31 19:04:30 +030012/**
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
18 *
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
26 *
27 * Return: '0' on Success; Error code otherwise.
28 */
29int dpbp_open(struct fsl_mc_io *mc_io, u32 cmd_flags, int dpbp_id, u16 *token)
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -070030{
Ioana Ciornei2f232fa2023-05-31 19:04:30 +030031 struct dpbp_cmd_open *cmd_params;
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -070032 struct mc_command cmd = { 0 };
33 int err;
34
35 /* prepare command */
36 cmd.header = mc_encode_cmd_header(DPBP_CMDID_OPEN,
Ioana Ciornei2f232fa2023-05-31 19:04:30 +030037 cmd_flags, 0);
38 cmd_params = (struct dpbp_cmd_open *)cmd.params;
39 cmd_params->dpbp_id = cpu_to_le32(dpbp_id);
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -070040
41 /* send command to mc*/
42 err = mc_send_command(mc_io, &cmd);
43 if (err)
44 return err;
45
46 /* retrieve response parameters */
Ioana Ciornei2f232fa2023-05-31 19:04:30 +030047 *token = mc_cmd_hdr_read_token(&cmd);
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -070048
49 return err;
50}
51
Ioana Ciornei2f232fa2023-05-31 19:04:30 +030052/**
53 * dpbp_close() - Close the control session of the object
54 * @mc_io: Pointer to MC portal's I/O object
55 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
56 * @token: Token of DPBP object
57 *
58 * After this function is called, no further operations are
59 * allowed on the object without opening a new control session.
60 *
61 * Return: '0' on Success; Error code otherwise.
62 */
63int dpbp_close(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token)
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -070064{
65 struct mc_command cmd = { 0 };
66
67 /* prepare command */
Prabhakar Kushwaha9564df62015-07-07 15:40:06 +053068 cmd.header = mc_encode_cmd_header(DPBP_CMDID_CLOSE, cmd_flags,
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -070069 token);
70
71 /* send command to mc*/
72 return mc_send_command(mc_io, &cmd);
73}
74
Ioana Ciornei2f232fa2023-05-31 19:04:30 +030075/**
76 * dpbp_create() - Create the DPBP object.
77 * @mc_io: Pointer to MC portal's I/O object
78 * @dprc_token: Parent container token; '0' for default container
79 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
80 * @cfg: Configuration structure
81 * @obj_id: Returned object id; use in subsequent API calls
82 *
83 * Create the DPBP object, allocate required resources and
84 * perform required initialization.
85 *
86 * This function accepts an authentication token of a parent
87 * container that this object should be assigned to and returns
88 * an object id. This object_id will be used in all subsequent calls to
89 * this specific object.
90 *
91 * Return: '0' on Success; Error code otherwise.
92 */
93int dpbp_create(struct fsl_mc_io *mc_io, u16 dprc_token, u32 cmd_flags,
94 const struct dpbp_cfg *cfg, u32 *obj_id)
Prabhakar Kushwahacf0c8cf2015-11-04 12:25:53 +053095{
96 struct mc_command cmd = { 0 };
97 int err;
98
99 (void)(cfg); /* unused */
100
101 /* prepare command */
102 cmd.header = mc_encode_cmd_header(DPBP_CMDID_CREATE,
Ioana Ciornei2f232fa2023-05-31 19:04:30 +0300103 cmd_flags, dprc_token);
Prabhakar Kushwahacf0c8cf2015-11-04 12:25:53 +0530104
105 /* send command to mc*/
106 err = mc_send_command(mc_io, &cmd);
107 if (err)
108 return err;
109
110 /* retrieve response parameters */
Ioana Ciornei2f232fa2023-05-31 19:04:30 +0300111 *obj_id = mc_cmd_read_object_id(&cmd);
Prabhakar Kushwahacf0c8cf2015-11-04 12:25:53 +0530112
113 return 0;
114}
115
Ioana Ciornei2f232fa2023-05-31 19:04:30 +0300116/**
117 * dpbp_destroy() - Destroy the DPBP object and release all its resources.
118 * @mc_io: Pointer to MC portal's I/O object
119 * @dprc_token: Parent container token; '0' for default container
120 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
121 * @obj_id: ID of DPBP object
122 *
123 * Return: '0' on Success; error code otherwise.
124 */
125int dpbp_destroy(struct fsl_mc_io *mc_io, u16 dprc_token, u32 cmd_flags,
126 u32 obj_id)
Prabhakar Kushwahacf0c8cf2015-11-04 12:25:53 +0530127{
Ioana Ciornei2f232fa2023-05-31 19:04:30 +0300128 struct dpbp_cmd_destroy *cmd_params;
Prabhakar Kushwahacf0c8cf2015-11-04 12:25:53 +0530129 struct mc_command cmd = { 0 };
130
131 /* prepare command */
132 cmd.header = mc_encode_cmd_header(DPBP_CMDID_DESTROY,
Ioana Ciornei2f232fa2023-05-31 19:04:30 +0300133 cmd_flags, dprc_token);
Yogesh Gaur318c32f2017-11-15 11:59:31 +0530134
Ioana Ciornei2f232fa2023-05-31 19:04:30 +0300135 cmd_params = (struct dpbp_cmd_destroy *)cmd.params;
136 cmd_params->object_id = cpu_to_le32(obj_id);
Prabhakar Kushwahacf0c8cf2015-11-04 12:25:53 +0530137
138 /* send command to mc*/
139 return mc_send_command(mc_io, &cmd);
140}
141
Ioana Ciornei2f232fa2023-05-31 19:04:30 +0300142/**
143 * dpbp_enable() - Enable the DPBP.
144 * @mc_io: Pointer to MC portal's I/O object
145 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
146 * @token: Token of DPBP object
147 *
148 * Return: '0' on Success; Error code otherwise.
149 */
150int dpbp_enable(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token)
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700151{
152 struct mc_command cmd = { 0 };
153
154 /* prepare command */
Prabhakar Kushwaha9564df62015-07-07 15:40:06 +0530155 cmd.header = mc_encode_cmd_header(DPBP_CMDID_ENABLE, cmd_flags,
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700156 token);
157
158 /* send command to mc*/
159 return mc_send_command(mc_io, &cmd);
160}
161
Ioana Ciornei2f232fa2023-05-31 19:04:30 +0300162/**
163 * dpbp_disable() - Disable the DPBP.
164 * @mc_io: Pointer to MC portal's I/O object
165 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
166 * @token: Token of DPBP object
167 *
168 * Return: '0' on Success; Error code otherwise.
169 */
170int dpbp_disable(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token)
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700171{
172 struct mc_command cmd = { 0 };
173
174 /* prepare command */
175 cmd.header = mc_encode_cmd_header(DPBP_CMDID_DISABLE,
Ioana Ciornei2f232fa2023-05-31 19:04:30 +0300176 cmd_flags, token);
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700177
178 /* send command to mc*/
179 return mc_send_command(mc_io, &cmd);
180}
181
Ioana Ciornei2f232fa2023-05-31 19:04:30 +0300182/**
183 * dpbp_reset() - Reset the DPBP, returns the object to initial state.
184 * @mc_io: Pointer to MC portal's I/O object
185 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
186 * @token: Token of DPBP object
187 *
188 * Return: '0' on Success; Error code otherwise.
189 */
190int dpbp_reset(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token)
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700191{
192 struct mc_command cmd = { 0 };
193
194 /* prepare command */
195 cmd.header = mc_encode_cmd_header(DPBP_CMDID_RESET,
Ioana Ciornei2f232fa2023-05-31 19:04:30 +0300196 cmd_flags, token);
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700197
198 /* send command to mc*/
199 return mc_send_command(mc_io, &cmd);
200}
201
Ioana Ciornei2f232fa2023-05-31 19:04:30 +0300202/**
203 * dpbp_get_attributes - Retrieve DPBP attributes.
204 *
205 * @mc_io: Pointer to MC portal's I/O object
206 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
207 * @token: Token of DPBP object
208 * @attr: Returned object's attributes
209 *
210 * Return: '0' on Success; Error code otherwise.
211 */
212int dpbp_get_attributes(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700213 struct dpbp_attr *attr)
214{
Ioana Ciornei2f232fa2023-05-31 19:04:30 +0300215 struct dpbp_rsp_get_attributes *rsp_params;
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700216 struct mc_command cmd = { 0 };
217 int err;
218
219 /* prepare command */
220 cmd.header = mc_encode_cmd_header(DPBP_CMDID_GET_ATTR,
Ioana Ciornei2f232fa2023-05-31 19:04:30 +0300221 cmd_flags, token);
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700222
223 /* send command to mc*/
224 err = mc_send_command(mc_io, &cmd);
225 if (err)
226 return err;
227
228 /* retrieve response parameters */
Ioana Ciornei2f232fa2023-05-31 19:04:30 +0300229 rsp_params = (struct dpbp_rsp_get_attributes *)cmd.params;
230 attr->bpid = le16_to_cpu(rsp_params->bpid);
231 attr->id = le32_to_cpu(rsp_params->id);
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700232
233 return 0;
234}
Yogesh Gaur318c32f2017-11-15 11:59:31 +0530235
Ioana Ciornei2f232fa2023-05-31 19:04:30 +0300236/**
237 * dpbp_get_api_version - Get Data Path Buffer Pool API version
238 * @mc_io: Pointer to Mc portal's I/O object
239 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
240 * @major_ver: Major version of Buffer Pool API
241 * @minor_ver: Minor version of Buffer Pool API
242 *
243 * Return: '0' on Success; Error code otherwise.
244 */
245int dpbp_get_api_version(struct fsl_mc_io *mc_io, u32 cmd_flags,
246 u16 *major_ver, u16 *minor_ver)
Yogesh Gaur318c32f2017-11-15 11:59:31 +0530247{
248 struct mc_command cmd = { 0 };
249 int err;
250
251 /* prepare command */
252 cmd.header = mc_encode_cmd_header(DPBP_CMDID_GET_API_VERSION,
253 cmd_flags, 0);
254
255 /* send command to mc */
256 err = mc_send_command(mc_io, &cmd);
257 if (err)
258 return err;
259
260 /* retrieve response parameters */
261 mc_cmd_read_api_version(&cmd, major_ver, minor_ver);
262
263 return 0;
264}