xref: /openbmc/u-boot/drivers/net/fsl-mc/dpmac.c (revision d9b23e26)
1 /*
2  * Freescale Layerscape MC I/O wrapper
3  *
4  * Copyright (C) 2015 Freescale Semiconductor, Inc.
5  * Author: Prabhakar Kushwaha <prabhakar@freescale.com>
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_dpmac.h>
13 
14 int 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 
39 int 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 
53 int dpmac_create(struct fsl_mc_io *mc_io,
54 		 uint32_t cmd_flags,
55 		 const struct dpmac_cfg *cfg,
56 		 uint16_t *token)
57 {
58 	struct mc_command cmd = { 0 };
59 	int err;
60 
61 	/* prepare command */
62 	cmd.header = mc_encode_cmd_header(DPMAC_CMDID_CREATE,
63 					  cmd_flags,
64 					  0);
65 	DPMAC_CMD_CREATE(cmd, cfg);
66 
67 	/* send command to mc*/
68 	err = mc_send_command(mc_io, &cmd);
69 	if (err)
70 		return err;
71 
72 	/* retrieve response parameters */
73 	*token = MC_CMD_HDR_READ_TOKEN(cmd.header);
74 
75 	return 0;
76 }
77 
78 int dpmac_destroy(struct fsl_mc_io *mc_io,
79 		  uint32_t cmd_flags,
80 		  uint16_t token)
81 {
82 	struct mc_command cmd = { 0 };
83 
84 	/* prepare command */
85 	cmd.header = mc_encode_cmd_header(DPMAC_CMDID_DESTROY,
86 					  cmd_flags,
87 					  token);
88 
89 	/* send command to mc*/
90 	return mc_send_command(mc_io, &cmd);
91 }
92 
93 int dpmac_get_attributes(struct fsl_mc_io *mc_io,
94 			 uint32_t cmd_flags,
95 			 uint16_t token,
96 			 struct dpmac_attr *attr)
97 {
98 	struct mc_command cmd = { 0 };
99 	int err;
100 
101 	/* prepare command */
102 	cmd.header = mc_encode_cmd_header(DPMAC_CMDID_GET_ATTR,
103 					  cmd_flags,
104 					  token);
105 
106 	/* send command to mc*/
107 	err = mc_send_command(mc_io, &cmd);
108 	if (err)
109 		return err;
110 
111 	/* retrieve response parameters */
112 	DPMAC_RSP_GET_ATTRIBUTES(cmd, attr);
113 
114 	return 0;
115 }
116 
117 int dpmac_mdio_read(struct fsl_mc_io *mc_io,
118 		    uint32_t cmd_flags,
119 		    uint16_t token,
120 		    struct dpmac_mdio_cfg *cfg)
121 {
122 	struct mc_command cmd = { 0 };
123 	int err;
124 
125 	/* prepare command */
126 	cmd.header = mc_encode_cmd_header(DPMAC_CMDID_MDIO_READ,
127 					  cmd_flags,
128 					  token);
129 	DPMAC_CMD_MDIO_READ(cmd, cfg);
130 
131 	/* send command to mc*/
132 	err = mc_send_command(mc_io, &cmd);
133 	if (err)
134 		return err;
135 
136 	/* retrieve response parameters */
137 	DPMAC_RSP_MDIO_READ(cmd, cfg->data);
138 
139 	return 0;
140 }
141 
142 int dpmac_mdio_write(struct fsl_mc_io *mc_io,
143 		     uint32_t cmd_flags,
144 		     uint16_t token,
145 		     struct dpmac_mdio_cfg *cfg)
146 {
147 	struct mc_command cmd = { 0 };
148 
149 	/* prepare command */
150 	cmd.header = mc_encode_cmd_header(DPMAC_CMDID_MDIO_WRITE,
151 					  cmd_flags,
152 					  token);
153 	DPMAC_CMD_MDIO_WRITE(cmd, cfg);
154 
155 	/* send command to mc*/
156 	return mc_send_command(mc_io, &cmd);
157 }
158 
159 int dpmac_get_link_cfg(struct fsl_mc_io *mc_io,
160 		       uint32_t cmd_flags,
161 		       uint16_t token,
162 		       struct dpmac_link_cfg *cfg)
163 {
164 	struct mc_command cmd = { 0 };
165 	int err = 0;
166 
167 	/* prepare command */
168 	cmd.header = mc_encode_cmd_header(DPMAC_CMDID_GET_LINK_CFG,
169 					  cmd_flags,
170 					  token);
171 
172 	/* send command to mc*/
173 	err = mc_send_command(mc_io, &cmd);
174 	if (err)
175 		return err;
176 
177 	DPMAC_RSP_GET_LINK_CFG(cmd, cfg);
178 
179 	return 0;
180 }
181 
182 int dpmac_set_link_state(struct fsl_mc_io *mc_io,
183 			 uint32_t cmd_flags,
184 			 uint16_t token,
185 			 struct dpmac_link_state *link_state)
186 {
187 	struct mc_command cmd = { 0 };
188 
189 	/* prepare command */
190 	cmd.header = mc_encode_cmd_header(DPMAC_CMDID_SET_LINK_STATE,
191 					  cmd_flags,
192 					  token);
193 	DPMAC_CMD_SET_LINK_STATE(cmd, link_state);
194 
195 	/* send command to mc*/
196 	return mc_send_command(mc_io, &cmd);
197 }
198 
199 int dpmac_get_counter(struct fsl_mc_io *mc_io,
200 		      uint32_t cmd_flags,
201 		      uint16_t token,
202 		      enum dpmac_counter type,
203 		      uint64_t *counter)
204 {
205 	struct mc_command cmd = { 0 };
206 	int err = 0;
207 
208 	/* prepare command */
209 	cmd.header = mc_encode_cmd_header(DPMAC_CMDID_GET_COUNTER,
210 					  cmd_flags,
211 					  token);
212 	DPMAC_CMD_GET_COUNTER(cmd, type);
213 
214 	/* send command to mc*/
215 	err = mc_send_command(mc_io, &cmd);
216 	if (err)
217 		return err;
218 
219 	DPMAC_RSP_GET_COUNTER(cmd, *counter);
220 
221 	return 0;
222 }
223