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