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