xref: /openbmc/u-boot/drivers/net/fsl-mc/dprc.c (revision 894c3ad2)
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Freescale Layerscape MC I/O wrapper
4  *
5  * Copyright 2013-2016 Freescale Semiconductor, Inc.
6  * Copyright 2017 NXP
7  */
8 
9 #include <fsl-mc/fsl_mc_sys.h>
10 #include <fsl-mc/fsl_mc_cmd.h>
11 #include <fsl-mc/fsl_dprc.h>
12 
13 int dprc_get_container_id(struct fsl_mc_io *mc_io,
14 			  uint32_t cmd_flags,
15 			  int *container_id)
16 {
17 	struct mc_command cmd = { 0 };
18 	int err;
19 
20 	/* prepare command */
21 	cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_CONT_ID,
22 					  cmd_flags,
23 					  0);
24 
25 	/* send command to mc*/
26 	err = mc_send_command(mc_io, &cmd);
27 	if (err)
28 		return err;
29 
30 	/* retrieve response parameters */
31 	DPRC_RSP_GET_CONTAINER_ID(cmd, *container_id);
32 
33 	return 0;
34 }
35 
36 int dprc_open(struct fsl_mc_io *mc_io,
37 	      uint32_t cmd_flags,
38 	      int container_id,
39 	      uint16_t *token)
40 {
41 	struct mc_command cmd = { 0 };
42 	int err;
43 
44 	/* prepare command */
45 	cmd.header = mc_encode_cmd_header(DPRC_CMDID_OPEN, cmd_flags,
46 					  0);
47 	DPRC_CMD_OPEN(cmd, container_id);
48 
49 	/* send command to mc*/
50 	err = mc_send_command(mc_io, &cmd);
51 	if (err)
52 		return err;
53 
54 	/* retrieve response parameters */
55 	*token = MC_CMD_HDR_READ_TOKEN(cmd.header);
56 
57 	return 0;
58 }
59 
60 int dprc_close(struct fsl_mc_io *mc_io,
61 	       uint32_t cmd_flags,
62 	       uint16_t token)
63 {
64 	struct mc_command cmd = { 0 };
65 
66 	/* prepare command */
67 	cmd.header = mc_encode_cmd_header(DPRC_CMDID_CLOSE, cmd_flags,
68 					  token);
69 
70 	/* send command to mc*/
71 	return mc_send_command(mc_io, &cmd);
72 }
73 
74 int dprc_create_container(struct fsl_mc_io *mc_io,
75 			  uint32_t cmd_flags,
76 			  uint16_t token,
77 			  struct dprc_cfg *cfg,
78 			  int *child_container_id,
79 			  uint64_t *child_portal_paddr)
80 {
81 	struct mc_command cmd = { 0 };
82 	int err;
83 
84 	/* prepare command */
85 	DPRC_CMD_CREATE_CONTAINER(cmd, cfg);
86 
87 	cmd.header = mc_encode_cmd_header(DPRC_CMDID_CREATE_CONT,
88 					  cmd_flags,
89 					  token);
90 
91 	/* send command to mc*/
92 	err = mc_send_command(mc_io, &cmd);
93 	if (err)
94 		return err;
95 
96 	/* retrieve response parameters */
97 	DPRC_RSP_CREATE_CONTAINER(cmd, *child_container_id,
98 				  *child_portal_paddr);
99 
100 	return 0;
101 }
102 
103 int dprc_destroy_container(struct fsl_mc_io *mc_io,
104 			   uint32_t cmd_flags,
105 			   uint16_t token,
106 			   int child_container_id)
107 {
108 	struct mc_command cmd = { 0 };
109 
110 	/* prepare command */
111 	cmd.header = mc_encode_cmd_header(DPRC_CMDID_DESTROY_CONT,
112 					  cmd_flags,
113 					  token);
114 	DPRC_CMD_DESTROY_CONTAINER(cmd, child_container_id);
115 
116 	/* send command to mc*/
117 	return mc_send_command(mc_io, &cmd);
118 }
119 
120 int dprc_reset_container(struct fsl_mc_io *mc_io,
121 			 uint32_t cmd_flags,
122 			 uint16_t token,
123 			 int child_container_id)
124 {
125 	struct mc_command cmd = { 0 };
126 
127 	/* prepare command */
128 	cmd.header = mc_encode_cmd_header(DPRC_CMDID_RESET_CONT,
129 					  cmd_flags,
130 					  token);
131 	DPRC_CMD_RESET_CONTAINER(cmd, child_container_id);
132 
133 	/* send command to mc*/
134 	return mc_send_command(mc_io, &cmd);
135 }
136 
137 int dprc_get_attributes(struct fsl_mc_io *mc_io,
138 			uint32_t cmd_flags,
139 			uint16_t token,
140 			struct dprc_attributes *attr)
141 {
142 	struct mc_command cmd = { 0 };
143 	int err;
144 
145 	/* prepare command */
146 	cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_ATTR,
147 					  cmd_flags,
148 					  token);
149 
150 	/* send command to mc*/
151 	err = mc_send_command(mc_io, &cmd);
152 	if (err)
153 		return err;
154 
155 	/* retrieve response parameters */
156 	DPRC_RSP_GET_ATTRIBUTES(cmd, attr);
157 
158 	return 0;
159 }
160 
161 int dprc_get_obj_count(struct fsl_mc_io *mc_io,
162 		       uint32_t cmd_flags,
163 		       uint16_t token,
164 		       int *obj_count)
165 {
166 	struct mc_command cmd = { 0 };
167 	int err;
168 
169 	/* prepare command */
170 	cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_OBJ_COUNT,
171 					  cmd_flags,
172 					  token);
173 
174 	/* send command to mc*/
175 	err = mc_send_command(mc_io, &cmd);
176 	if (err)
177 		return err;
178 
179 	/* retrieve response parameters */
180 	DPRC_RSP_GET_OBJ_COUNT(cmd, *obj_count);
181 
182 	return 0;
183 }
184 
185 int dprc_get_obj(struct fsl_mc_io *mc_io,
186 		 uint32_t cmd_flags,
187 		 uint16_t token,
188 		 int obj_index,
189 		 struct dprc_obj_desc *obj_desc)
190 {
191 	struct mc_command cmd = { 0 };
192 	int err;
193 
194 	/* prepare command */
195 	cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_OBJ,
196 					  cmd_flags,
197 					  token);
198 	DPRC_CMD_GET_OBJ(cmd, obj_index);
199 
200 	/* send command to mc*/
201 	err = mc_send_command(mc_io, &cmd);
202 	if (err)
203 		return err;
204 
205 	/* retrieve response parameters */
206 	DPRC_RSP_GET_OBJ(cmd, obj_desc);
207 
208 	return 0;
209 }
210 
211 int dprc_get_res_count(struct fsl_mc_io *mc_io,
212 		       uint32_t cmd_flags,
213 		       uint16_t token,
214 		       char *type,
215 		       int *res_count)
216 {
217 	struct mc_command cmd = { 0 };
218 	int err;
219 
220 	*res_count = 0;
221 
222 	/* prepare command */
223 	cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_RES_COUNT,
224 					  cmd_flags,
225 					  token);
226 	DPRC_CMD_GET_RES_COUNT(cmd, type);
227 
228 	/* send command to mc*/
229 	err = mc_send_command(mc_io, &cmd);
230 	if (err)
231 		return err;
232 
233 	/* retrieve response parameters */
234 	DPRC_RSP_GET_RES_COUNT(cmd, *res_count);
235 
236 	return 0;
237 }
238 
239 int dprc_get_res_ids(struct fsl_mc_io *mc_io,
240 		     uint32_t cmd_flags,
241 		     uint16_t token,
242 		     char *type,
243 		     struct dprc_res_ids_range_desc *range_desc)
244 {
245 	struct mc_command cmd = { 0 };
246 	int err;
247 
248 	/* prepare command */
249 	cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_RES_IDS,
250 					  cmd_flags,
251 					  token);
252 	DPRC_CMD_GET_RES_IDS(cmd, range_desc, type);
253 
254 	/* send command to mc*/
255 	err = mc_send_command(mc_io, &cmd);
256 	if (err)
257 		return err;
258 
259 	/* retrieve response parameters */
260 	DPRC_RSP_GET_RES_IDS(cmd, range_desc);
261 
262 	return 0;
263 }
264 
265 int dprc_get_obj_region(struct fsl_mc_io *mc_io,
266 			uint32_t cmd_flags,
267 			uint16_t token,
268 			char *obj_type,
269 			int obj_id,
270 			uint8_t region_index,
271 			struct dprc_region_desc *region_desc)
272 {
273 	struct mc_command cmd = { 0 };
274 	int err;
275 
276 	/* prepare command */
277 	cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_OBJ_REG,
278 					  cmd_flags,
279 					  token);
280 	DPRC_CMD_GET_OBJ_REGION(cmd, obj_type, obj_id, region_index);
281 
282 	/* send command to mc*/
283 	err = mc_send_command(mc_io, &cmd);
284 	if (err)
285 		return err;
286 
287 	/* retrieve response parameters */
288 	DPRC_RSP_GET_OBJ_REGION(cmd, region_desc);
289 
290 	return 0;
291 }
292 
293 int dprc_connect(struct fsl_mc_io *mc_io,
294 		 uint32_t cmd_flags,
295 		 uint16_t token,
296 		 const struct dprc_endpoint *endpoint1,
297 		 const struct dprc_endpoint *endpoint2,
298 		 const struct dprc_connection_cfg *cfg)
299 {
300 	struct mc_command cmd = { 0 };
301 
302 	/* prepare command */
303 	cmd.header = mc_encode_cmd_header(DPRC_CMDID_CONNECT,
304 					  cmd_flags,
305 					  token);
306 	DPRC_CMD_CONNECT(cmd, endpoint1, endpoint2, cfg);
307 
308 	/* send command to mc*/
309 	return mc_send_command(mc_io, &cmd);
310 }
311 
312 int dprc_disconnect(struct fsl_mc_io *mc_io,
313 		    uint32_t cmd_flags,
314 		    uint16_t token,
315 		    const struct dprc_endpoint *endpoint)
316 {
317 	struct mc_command cmd = { 0 };
318 
319 	/* prepare command */
320 	cmd.header = mc_encode_cmd_header(DPRC_CMDID_DISCONNECT,
321 					  cmd_flags,
322 					  token);
323 	DPRC_CMD_DISCONNECT(cmd, endpoint);
324 
325 	/* send command to mc*/
326 	return mc_send_command(mc_io, &cmd);
327 }
328 
329 int dprc_get_connection(struct fsl_mc_io *mc_io,
330 			uint32_t cmd_flags,
331 			uint16_t token,
332 			const struct dprc_endpoint *endpoint1,
333 			struct dprc_endpoint *endpoint2,
334 			int *state)
335 {
336 	struct mc_command cmd = { 0 };
337 	int err;
338 
339 	/* prepare command */
340 	cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_CONNECTION,
341 					  cmd_flags,
342 					  token);
343 	DPRC_CMD_GET_CONNECTION(cmd, endpoint1);
344 
345 	/* send command to mc*/
346 	err = mc_send_command(mc_io, &cmd);
347 	if (err)
348 		return err;
349 
350 	/* retrieve response parameters */
351 	DPRC_RSP_GET_CONNECTION(cmd, endpoint2, *state);
352 
353 	return 0;
354 }
355 
356 int dprc_get_api_version(struct fsl_mc_io *mc_io,
357 			 u32 cmd_flags,
358 			 u16 *major_ver,
359 			 u16 *minor_ver)
360 {
361 	struct mc_command cmd = { 0 };
362 	int err;
363 
364 	/* prepare command */
365 	cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_API_VERSION,
366 					  cmd_flags, 0);
367 
368 	/* send command to mc */
369 	err = mc_send_command(mc_io, &cmd);
370 	if (err)
371 		return err;
372 
373 	/* retrieve response parameters */
374 	mc_cmd_read_api_version(&cmd, major_ver, minor_ver);
375 
376 	return 0;
377 }
378