blob: 43a2ff43f8883baec29bfda6c7601b2c29a60de1 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Prabhakar Kushwaha872d48a2015-11-04 12:25:54 +05302/*
3 * Freescale Layerscape MC I/O wrapper
4 *
Yogesh Gaura6f2a6e2018-05-09 10:52:17 +05305 * Copyright 2015-2016 Freescale Semiconductor, Inc.
Yogesh Gaur2557c5a2017-11-15 11:59:31 +05306 * Copyright 2017 NXP
Prabhakar Kushwaha872d48a2015-11-04 12:25:54 +05307 * Author: Prabhakar Kushwaha <prabhakar@freescale.com>
Prabhakar Kushwaha872d48a2015-11-04 12:25:54 +05308 */
9
10#include <fsl-mc/fsl_mc_sys.h>
11#include <fsl-mc/fsl_mc_cmd.h>
12#include <fsl-mc/fsl_dpmac.h>
13
14int dpmac_open(struct fsl_mc_io *mc_io,
15 uint32_t cmd_flags,
16 int dpmac_id,
17 uint16_t *token)
18{
19 struct mc_command cmd = { 0 };
20 int err;
21
22 /* prepare command */
23 cmd.header = mc_encode_cmd_header(DPMAC_CMDID_OPEN,
24 cmd_flags,
25 0);
26 DPMAC_CMD_OPEN(cmd, dpmac_id);
27
28 /* send command to mc*/
29 err = mc_send_command(mc_io, &cmd);
30 if (err)
31 return err;
32
33 /* retrieve response parameters */
34 *token = MC_CMD_HDR_READ_TOKEN(cmd.header);
35
36 return err;
37}
38
39int dpmac_close(struct fsl_mc_io *mc_io,
40 uint32_t cmd_flags,
41 uint16_t token)
42{
43 struct mc_command cmd = { 0 };
44
45 /* prepare command */
46 cmd.header = mc_encode_cmd_header(DPMAC_CMDID_CLOSE, cmd_flags,
47 token);
48
49 /* send command to mc*/
50 return mc_send_command(mc_io, &cmd);
51}
52
53int dpmac_create(struct fsl_mc_io *mc_io,
Yogesh Gaur2557c5a2017-11-15 11:59:31 +053054 uint16_t dprc_token,
Prabhakar Kushwaha872d48a2015-11-04 12:25:54 +053055 uint32_t cmd_flags,
56 const struct dpmac_cfg *cfg,
Yogesh Gaur2557c5a2017-11-15 11:59:31 +053057 uint32_t *obj_id)
Prabhakar Kushwaha872d48a2015-11-04 12:25:54 +053058{
59 struct mc_command cmd = { 0 };
60 int err;
61
62 /* prepare command */
63 cmd.header = mc_encode_cmd_header(DPMAC_CMDID_CREATE,
64 cmd_flags,
Yogesh Gaur2557c5a2017-11-15 11:59:31 +053065 dprc_token);
Prabhakar Kushwaha872d48a2015-11-04 12:25:54 +053066 DPMAC_CMD_CREATE(cmd, cfg);
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 */
Yogesh Gaur2557c5a2017-11-15 11:59:31 +053074 MC_CMD_READ_OBJ_ID(cmd, *obj_id);
Prabhakar Kushwaha872d48a2015-11-04 12:25:54 +053075
76 return 0;
77}
78
79int dpmac_destroy(struct fsl_mc_io *mc_io,
Yogesh Gaur2557c5a2017-11-15 11:59:31 +053080 uint16_t dprc_token,
Prabhakar Kushwaha872d48a2015-11-04 12:25:54 +053081 uint32_t cmd_flags,
Yogesh Gaur2557c5a2017-11-15 11:59:31 +053082 uint32_t obj_id)
Prabhakar Kushwaha872d48a2015-11-04 12:25:54 +053083{
84 struct mc_command cmd = { 0 };
85
86 /* prepare command */
87 cmd.header = mc_encode_cmd_header(DPMAC_CMDID_DESTROY,
88 cmd_flags,
Yogesh Gaur2557c5a2017-11-15 11:59:31 +053089 dprc_token);
90
91 /* set object id to destroy */
92 CMD_DESTROY_SET_OBJ_ID_PARAM0(cmd, obj_id);
Prabhakar Kushwaha872d48a2015-11-04 12:25:54 +053093
94 /* send command to mc*/
95 return mc_send_command(mc_io, &cmd);
96}
97
98int dpmac_get_attributes(struct fsl_mc_io *mc_io,
99 uint32_t cmd_flags,
100 uint16_t token,
101 struct dpmac_attr *attr)
102{
103 struct mc_command cmd = { 0 };
104 int err;
105
106 /* prepare command */
107 cmd.header = mc_encode_cmd_header(DPMAC_CMDID_GET_ATTR,
108 cmd_flags,
109 token);
110
111 /* send command to mc*/
112 err = mc_send_command(mc_io, &cmd);
113 if (err)
114 return err;
115
116 /* retrieve response parameters */
117 DPMAC_RSP_GET_ATTRIBUTES(cmd, attr);
118
119 return 0;
120}
121
122int dpmac_mdio_read(struct fsl_mc_io *mc_io,
123 uint32_t cmd_flags,
124 uint16_t token,
125 struct dpmac_mdio_cfg *cfg)
126{
127 struct mc_command cmd = { 0 };
128 int err;
129
130 /* prepare command */
131 cmd.header = mc_encode_cmd_header(DPMAC_CMDID_MDIO_READ,
132 cmd_flags,
133 token);
134 DPMAC_CMD_MDIO_READ(cmd, cfg);
135
136 /* send command to mc*/
137 err = mc_send_command(mc_io, &cmd);
138 if (err)
139 return err;
140
141 /* retrieve response parameters */
142 DPMAC_RSP_MDIO_READ(cmd, cfg->data);
143
144 return 0;
145}
146
147int dpmac_mdio_write(struct fsl_mc_io *mc_io,
148 uint32_t cmd_flags,
149 uint16_t token,
150 struct dpmac_mdio_cfg *cfg)
151{
152 struct mc_command cmd = { 0 };
153
154 /* prepare command */
155 cmd.header = mc_encode_cmd_header(DPMAC_CMDID_MDIO_WRITE,
156 cmd_flags,
157 token);
158 DPMAC_CMD_MDIO_WRITE(cmd, cfg);
159
160 /* send command to mc*/
161 return mc_send_command(mc_io, &cmd);
162}
163
164int dpmac_get_link_cfg(struct fsl_mc_io *mc_io,
165 uint32_t cmd_flags,
166 uint16_t token,
167 struct dpmac_link_cfg *cfg)
168{
169 struct mc_command cmd = { 0 };
170 int err = 0;
171
172 /* prepare command */
173 cmd.header = mc_encode_cmd_header(DPMAC_CMDID_GET_LINK_CFG,
174 cmd_flags,
175 token);
176
177 /* send command to mc*/
178 err = mc_send_command(mc_io, &cmd);
179 if (err)
180 return err;
181
182 DPMAC_RSP_GET_LINK_CFG(cmd, cfg);
183
184 return 0;
185}
186
187int dpmac_set_link_state(struct fsl_mc_io *mc_io,
188 uint32_t cmd_flags,
189 uint16_t token,
190 struct dpmac_link_state *link_state)
191{
192 struct mc_command cmd = { 0 };
193
194 /* prepare command */
195 cmd.header = mc_encode_cmd_header(DPMAC_CMDID_SET_LINK_STATE,
196 cmd_flags,
197 token);
198 DPMAC_CMD_SET_LINK_STATE(cmd, link_state);
199
200 /* send command to mc*/
201 return mc_send_command(mc_io, &cmd);
202}
203
204int dpmac_get_counter(struct fsl_mc_io *mc_io,
205 uint32_t cmd_flags,
206 uint16_t token,
207 enum dpmac_counter type,
208 uint64_t *counter)
209{
210 struct mc_command cmd = { 0 };
211 int err = 0;
212
213 /* prepare command */
214 cmd.header = mc_encode_cmd_header(DPMAC_CMDID_GET_COUNTER,
215 cmd_flags,
216 token);
217 DPMAC_CMD_GET_COUNTER(cmd, type);
218
219 /* send command to mc*/
220 err = mc_send_command(mc_io, &cmd);
221 if (err)
222 return err;
223
224 DPMAC_RSP_GET_COUNTER(cmd, *counter);
225
226 return 0;
227}
Yogesh Gaur2557c5a2017-11-15 11:59:31 +0530228
229int dpmac_get_api_version(struct fsl_mc_io *mc_io,
230 u32 cmd_flags,
231 u16 *major_ver,
232 u16 *minor_ver)
233{
234 struct mc_command cmd = { 0 };
235 int err;
236
237 /* prepare command */
238 cmd.header = mc_encode_cmd_header(DPMAC_CMDID_GET_API_VERSION,
239 cmd_flags, 0);
240
241 /* send command to mc */
242 err = mc_send_command(mc_io, &cmd);
243 if (err)
244 return err;
245
246 /* retrieve response parameters */
247 mc_cmd_read_api_version(&cmd, major_ver, minor_ver);
248
249 return 0;
250}