xref: /openbmc/u-boot/drivers/net/fsl-mc/dpbp.c (revision 48263504)
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 #include <fsl-mc/fsl_mc_sys.h>
10 #include <fsl-mc/fsl_mc_cmd.h>
11 #include <fsl-mc/fsl_dpbp.h>
12 
13 int dpbp_open(struct fsl_mc_io *mc_io,
14 	      uint32_t cmd_flags,
15 	      int dpbp_id,
16 	      uint16_t *token)
17 {
18 	struct mc_command cmd = { 0 };
19 	int err;
20 
21 	/* prepare command */
22 	cmd.header = mc_encode_cmd_header(DPBP_CMDID_OPEN,
23 					  cmd_flags,
24 					  0);
25 	DPBP_CMD_OPEN(cmd, dpbp_id);
26 
27 	/* send command to mc*/
28 	err = mc_send_command(mc_io, &cmd);
29 	if (err)
30 		return err;
31 
32 	/* retrieve response parameters */
33 	*token = MC_CMD_HDR_READ_TOKEN(cmd.header);
34 
35 	return err;
36 }
37 
38 int dpbp_close(struct fsl_mc_io *mc_io,
39 	       uint32_t cmd_flags,
40 	       uint16_t token)
41 {
42 	struct mc_command cmd = { 0 };
43 
44 	/* prepare command */
45 	cmd.header = mc_encode_cmd_header(DPBP_CMDID_CLOSE, cmd_flags,
46 					  token);
47 
48 	/* send command to mc*/
49 	return mc_send_command(mc_io, &cmd);
50 }
51 
52 int dpbp_create(struct fsl_mc_io *mc_io,
53 		uint16_t dprc_token,
54 		uint32_t cmd_flags,
55 		const struct dpbp_cfg *cfg,
56 		uint32_t *obj_id)
57 {
58 	struct mc_command cmd = { 0 };
59 	int err;
60 
61 	(void)(cfg); /* unused */
62 
63 	/* prepare command */
64 	cmd.header = mc_encode_cmd_header(DPBP_CMDID_CREATE,
65 					  cmd_flags,
66 					  dprc_token);
67 
68 	/* send command to mc*/
69 	err = mc_send_command(mc_io, &cmd);
70 	if (err)
71 		return err;
72 
73 	/* retrieve response parameters */
74 	MC_CMD_READ_OBJ_ID(cmd, *obj_id);
75 
76 	return 0;
77 }
78 
79 int dpbp_destroy(struct fsl_mc_io *mc_io,
80 		 uint16_t dprc_token,
81 		 uint32_t cmd_flags,
82 		 uint32_t obj_id)
83 {
84 	struct mc_command cmd = { 0 };
85 
86 	/* prepare command */
87 	cmd.header = mc_encode_cmd_header(DPBP_CMDID_DESTROY,
88 					  cmd_flags,
89 					  dprc_token);
90 
91 	/* set object id to destroy */
92 	CMD_DESTROY_SET_OBJ_ID_PARAM0(cmd, obj_id);
93 
94 	/* send command to mc*/
95 	return mc_send_command(mc_io, &cmd);
96 }
97 
98 int dpbp_enable(struct fsl_mc_io *mc_io,
99 		uint32_t cmd_flags,
100 		uint16_t token)
101 {
102 	struct mc_command cmd = { 0 };
103 
104 	/* prepare command */
105 	cmd.header = mc_encode_cmd_header(DPBP_CMDID_ENABLE, cmd_flags,
106 					  token);
107 
108 	/* send command to mc*/
109 	return mc_send_command(mc_io, &cmd);
110 }
111 
112 int dpbp_disable(struct fsl_mc_io *mc_io,
113 		 uint32_t cmd_flags,
114 		 uint16_t token)
115 {
116 	struct mc_command cmd = { 0 };
117 
118 	/* prepare command */
119 	cmd.header = mc_encode_cmd_header(DPBP_CMDID_DISABLE,
120 					  cmd_flags,
121 					  token);
122 
123 	/* send command to mc*/
124 	return mc_send_command(mc_io, &cmd);
125 }
126 
127 int dpbp_reset(struct fsl_mc_io *mc_io,
128 	       uint32_t cmd_flags,
129 	       uint16_t token)
130 {
131 	struct mc_command cmd = { 0 };
132 
133 	/* prepare command */
134 	cmd.header = mc_encode_cmd_header(DPBP_CMDID_RESET,
135 					  cmd_flags,
136 					  token);
137 
138 	/* send command to mc*/
139 	return mc_send_command(mc_io, &cmd);
140 }
141 
142 int dpbp_get_attributes(struct fsl_mc_io *mc_io,
143 			uint32_t cmd_flags,
144 			uint16_t token,
145 			struct dpbp_attr *attr)
146 {
147 	struct mc_command cmd = { 0 };
148 	int err;
149 
150 	/* prepare command */
151 	cmd.header = mc_encode_cmd_header(DPBP_CMDID_GET_ATTR,
152 					  cmd_flags,
153 					  token);
154 
155 	/* send command to mc*/
156 	err = mc_send_command(mc_io, &cmd);
157 	if (err)
158 		return err;
159 
160 	/* retrieve response parameters */
161 	DPBP_RSP_GET_ATTRIBUTES(cmd, attr);
162 
163 	return 0;
164 }
165 
166 int dpbp_get_api_version(struct fsl_mc_io *mc_io,
167 			 u32 cmd_flags,
168 			 u16 *major_ver,
169 			 u16 *minor_ver)
170 {
171 	struct mc_command cmd = { 0 };
172 	int err;
173 
174 	/* prepare command */
175 	cmd.header = mc_encode_cmd_header(DPBP_CMDID_GET_API_VERSION,
176 					  cmd_flags, 0);
177 
178 	/* send command to mc */
179 	err = mc_send_command(mc_io, &cmd);
180 	if (err)
181 		return err;
182 
183 	/* retrieve response parameters */
184 	mc_cmd_read_api_version(&cmd, major_ver, minor_ver);
185 
186 	return 0;
187 }
188