2 * Freescale Layerscape MC I/O wrapper
4 * Copyright (C) 2015-2016 Freescale Semiconductor, Inc.
6 * Author: Prabhakar Kushwaha <prabhakar@freescale.com>
8 * SPDX-License-Identifier: GPL-2.0+
11 #include <fsl-mc/fsl_mc_sys.h>
12 #include <fsl-mc/fsl_mc_cmd.h>
13 #include <fsl-mc/fsl_dpmac.h>
15 int dpmac_open(struct fsl_mc_io
*mc_io
,
20 struct mc_command cmd
= { 0 };
24 cmd
.header
= mc_encode_cmd_header(DPMAC_CMDID_OPEN
,
27 DPMAC_CMD_OPEN(cmd
, dpmac_id
);
29 /* send command to mc*/
30 err
= mc_send_command(mc_io
, &cmd
);
34 /* retrieve response parameters */
35 *token
= MC_CMD_HDR_READ_TOKEN(cmd
.header
);
40 int dpmac_close(struct fsl_mc_io
*mc_io
,
44 struct mc_command cmd
= { 0 };
47 cmd
.header
= mc_encode_cmd_header(DPMAC_CMDID_CLOSE
, cmd_flags
,
50 /* send command to mc*/
51 return mc_send_command(mc_io
, &cmd
);
54 int dpmac_create(struct fsl_mc_io
*mc_io
,
57 const struct dpmac_cfg
*cfg
,
60 struct mc_command cmd
= { 0 };
64 cmd
.header
= mc_encode_cmd_header(DPMAC_CMDID_CREATE
,
67 DPMAC_CMD_CREATE(cmd
, cfg
);
69 /* send command to mc*/
70 err
= mc_send_command(mc_io
, &cmd
);
74 /* retrieve response parameters */
75 MC_CMD_READ_OBJ_ID(cmd
, *obj_id
);
80 int dpmac_destroy(struct fsl_mc_io
*mc_io
,
85 struct mc_command cmd
= { 0 };
88 cmd
.header
= mc_encode_cmd_header(DPMAC_CMDID_DESTROY
,
92 /* set object id to destroy */
93 CMD_DESTROY_SET_OBJ_ID_PARAM0(cmd
, obj_id
);
95 /* send command to mc*/
96 return mc_send_command(mc_io
, &cmd
);
99 int dpmac_get_attributes(struct fsl_mc_io
*mc_io
,
102 struct dpmac_attr
*attr
)
104 struct mc_command cmd
= { 0 };
107 /* prepare command */
108 cmd
.header
= mc_encode_cmd_header(DPMAC_CMDID_GET_ATTR
,
112 /* send command to mc*/
113 err
= mc_send_command(mc_io
, &cmd
);
117 /* retrieve response parameters */
118 DPMAC_RSP_GET_ATTRIBUTES(cmd
, attr
);
123 int dpmac_mdio_read(struct fsl_mc_io
*mc_io
,
126 struct dpmac_mdio_cfg
*cfg
)
128 struct mc_command cmd
= { 0 };
131 /* prepare command */
132 cmd
.header
= mc_encode_cmd_header(DPMAC_CMDID_MDIO_READ
,
135 DPMAC_CMD_MDIO_READ(cmd
, cfg
);
137 /* send command to mc*/
138 err
= mc_send_command(mc_io
, &cmd
);
142 /* retrieve response parameters */
143 DPMAC_RSP_MDIO_READ(cmd
, cfg
->data
);
148 int dpmac_mdio_write(struct fsl_mc_io
*mc_io
,
151 struct dpmac_mdio_cfg
*cfg
)
153 struct mc_command cmd
= { 0 };
155 /* prepare command */
156 cmd
.header
= mc_encode_cmd_header(DPMAC_CMDID_MDIO_WRITE
,
159 DPMAC_CMD_MDIO_WRITE(cmd
, cfg
);
161 /* send command to mc*/
162 return mc_send_command(mc_io
, &cmd
);
165 int dpmac_get_link_cfg(struct fsl_mc_io
*mc_io
,
168 struct dpmac_link_cfg
*cfg
)
170 struct mc_command cmd
= { 0 };
173 /* prepare command */
174 cmd
.header
= mc_encode_cmd_header(DPMAC_CMDID_GET_LINK_CFG
,
178 /* send command to mc*/
179 err
= mc_send_command(mc_io
, &cmd
);
183 DPMAC_RSP_GET_LINK_CFG(cmd
, cfg
);
188 int dpmac_set_link_state(struct fsl_mc_io
*mc_io
,
191 struct dpmac_link_state
*link_state
)
193 struct mc_command cmd
= { 0 };
195 /* prepare command */
196 cmd
.header
= mc_encode_cmd_header(DPMAC_CMDID_SET_LINK_STATE
,
199 DPMAC_CMD_SET_LINK_STATE(cmd
, link_state
);
201 /* send command to mc*/
202 return mc_send_command(mc_io
, &cmd
);
205 int dpmac_get_counter(struct fsl_mc_io
*mc_io
,
208 enum dpmac_counter type
,
211 struct mc_command cmd
= { 0 };
214 /* prepare command */
215 cmd
.header
= mc_encode_cmd_header(DPMAC_CMDID_GET_COUNTER
,
218 DPMAC_CMD_GET_COUNTER(cmd
, type
);
220 /* send command to mc*/
221 err
= mc_send_command(mc_io
, &cmd
);
225 DPMAC_RSP_GET_COUNTER(cmd
, *counter
);
230 int dpmac_get_api_version(struct fsl_mc_io
*mc_io
,
235 struct mc_command cmd
= { 0 };
238 /* prepare command */
239 cmd
.header
= mc_encode_cmd_header(DPMAC_CMDID_GET_API_VERSION
,
242 /* send command to mc */
243 err
= mc_send_command(mc_io
, &cmd
);
247 /* retrieve response parameters */
248 mc_cmd_read_api_version(&cmd
, major_ver
, minor_ver
);