xref: /openbmc/u-boot/drivers/net/fsl-mc/dpni.c (revision 7c0e5d86)
1 /*
2  * Copyright (C) 2013-2015 Freescale Semiconductor
3  *
4  * SPDX-License-Identifier:	GPL-2.0+
5  */
6 
7 #include <fsl-mc/fsl_mc_sys.h>
8 #include <fsl-mc/fsl_mc_cmd.h>
9 #include <fsl-mc/fsl_dpni.h>
10 
11 int dpni_open(struct fsl_mc_io *mc_io,
12 	      uint32_t cmd_flags,
13 	      int dpni_id,
14 	      uint16_t *token)
15 {
16 	struct mc_command cmd = { 0 };
17 	int err;
18 
19 	/* prepare command */
20 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_OPEN,
21 					  cmd_flags,
22 					  0);
23 	DPNI_CMD_OPEN(cmd, dpni_id);
24 
25 	/* send command to mc*/
26 	err = mc_send_command(mc_io, &cmd);
27 	if (err)
28 		return err;
29 
30 	/* retrieve response parameters */
31 	*token = MC_CMD_HDR_READ_TOKEN(cmd.header);
32 
33 	return 0;
34 }
35 
36 int dpni_close(struct fsl_mc_io *mc_io,
37 	       uint32_t cmd_flags,
38 	       uint16_t token)
39 {
40 	struct mc_command cmd = { 0 };
41 
42 	/* prepare command */
43 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_CLOSE,
44 					  cmd_flags,
45 					  token);
46 
47 	/* send command to mc*/
48 	return mc_send_command(mc_io, &cmd);
49 }
50 
51 int dpni_set_pools(struct fsl_mc_io *mc_io,
52 		   uint32_t cmd_flags,
53 		   uint16_t token,
54 		   const struct dpni_pools_cfg *cfg)
55 {
56 	struct mc_command cmd = { 0 };
57 
58 	/* prepare command */
59 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_POOLS,
60 					  cmd_flags,
61 					  token);
62 	DPNI_CMD_SET_POOLS(cmd, cfg);
63 
64 	/* send command to mc*/
65 	return mc_send_command(mc_io, &cmd);
66 }
67 
68 int dpni_enable(struct fsl_mc_io *mc_io,
69 		uint32_t cmd_flags,
70 		uint16_t token)
71 {
72 	struct mc_command cmd = { 0 };
73 
74 	/* prepare command */
75 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_ENABLE,
76 					  cmd_flags,
77 					  token);
78 
79 	/* send command to mc*/
80 	return mc_send_command(mc_io, &cmd);
81 }
82 
83 int dpni_disable(struct fsl_mc_io *mc_io,
84 		 uint32_t cmd_flags,
85 		 uint16_t token)
86 {
87 	struct mc_command cmd = { 0 };
88 
89 	/* prepare command */
90 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_DISABLE,
91 					  cmd_flags,
92 					  token);
93 
94 	/* send command to mc*/
95 	return mc_send_command(mc_io, &cmd);
96 }
97 
98 int dpni_reset(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(DPNI_CMDID_RESET,
106 					  cmd_flags,
107 					  token);
108 
109 	/* send command to mc*/
110 	return mc_send_command(mc_io, &cmd);
111 }
112 
113 int dpni_get_attributes(struct fsl_mc_io *mc_io,
114 			uint32_t cmd_flags,
115 			uint16_t token,
116 			struct dpni_attr *attr)
117 {
118 	struct mc_command cmd = { 0 };
119 	int err;
120 
121 	/* prepare command */
122 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_ATTR,
123 					  cmd_flags,
124 					  token);
125 
126 	/* send command to mc*/
127 	err = mc_send_command(mc_io, &cmd);
128 	if (err)
129 		return err;
130 
131 	/* retrieve response parameters */
132 	DPNI_RSP_GET_ATTR(cmd, attr);
133 
134 	return 0;
135 }
136 
137 int dpni_get_rx_buffer_layout(struct fsl_mc_io *mc_io,
138 			      uint32_t cmd_flags,
139 			      uint16_t token,
140 			      struct dpni_buffer_layout *layout)
141 {
142 	struct mc_command cmd = { 0 };
143 	int err;
144 
145 	/* prepare command */
146 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_RX_BUFFER_LAYOUT,
147 					  cmd_flags,
148 					  token);
149 
150 	/* send command to mc*/
151 	err = mc_send_command(mc_io, &cmd);
152 	if (err)
153 		return err;
154 
155 	/* retrieve response parameters */
156 	DPNI_RSP_GET_RX_BUFFER_LAYOUT(cmd, layout);
157 
158 	return 0;
159 }
160 
161 int dpni_set_rx_buffer_layout(struct fsl_mc_io *mc_io,
162 			      uint32_t cmd_flags,
163 			      uint16_t token,
164 			      const struct dpni_buffer_layout *layout)
165 {
166 	struct mc_command cmd = { 0 };
167 
168 	/* prepare command */
169 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_RX_BUFFER_LAYOUT,
170 					  cmd_flags,
171 					  token);
172 	DPNI_CMD_SET_RX_BUFFER_LAYOUT(cmd, layout);
173 
174 	/* send command to mc*/
175 	return mc_send_command(mc_io, &cmd);
176 }
177 
178 int dpni_get_tx_buffer_layout(struct fsl_mc_io *mc_io,
179 			      uint32_t cmd_flags,
180 			      uint16_t token,
181 			      struct dpni_buffer_layout *layout)
182 {
183 	struct mc_command cmd = { 0 };
184 	int err;
185 
186 	/* prepare command */
187 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_TX_BUFFER_LAYOUT,
188 					  cmd_flags,
189 					  token);
190 
191 	/* send command to mc*/
192 	err = mc_send_command(mc_io, &cmd);
193 	if (err)
194 		return err;
195 
196 	/* retrieve response parameters */
197 	DPNI_RSP_GET_TX_BUFFER_LAYOUT(cmd, layout);
198 
199 	return 0;
200 }
201 
202 int dpni_set_tx_buffer_layout(struct fsl_mc_io *mc_io,
203 			      uint32_t cmd_flags,
204 			      uint16_t token,
205 			      const struct dpni_buffer_layout *layout)
206 {
207 	struct mc_command cmd = { 0 };
208 
209 	/* prepare command */
210 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_TX_BUFFER_LAYOUT,
211 					  cmd_flags,
212 					  token);
213 	DPNI_CMD_SET_TX_BUFFER_LAYOUT(cmd, layout);
214 
215 	/* send command to mc*/
216 	return mc_send_command(mc_io, &cmd);
217 }
218 
219 int dpni_get_tx_conf_buffer_layout(struct fsl_mc_io *mc_io,
220 				   uint32_t cmd_flags,
221 				   uint16_t token,
222 				   struct dpni_buffer_layout *layout)
223 {
224 	struct mc_command cmd = { 0 };
225 	int err;
226 
227 	/* prepare command */
228 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_TX_CONF_BUFFER_LAYOUT,
229 					  cmd_flags,
230 					  token);
231 
232 	/* send command to mc*/
233 	err = mc_send_command(mc_io, &cmd);
234 	if (err)
235 		return err;
236 
237 	/* retrieve response parameters */
238 	DPNI_RSP_GET_TX_CONF_BUFFER_LAYOUT(cmd, layout);
239 
240 	return 0;
241 }
242 
243 int dpni_set_tx_conf_buffer_layout(struct fsl_mc_io *mc_io,
244 				   uint32_t cmd_flags,
245 				   uint16_t token,
246 				   const struct dpni_buffer_layout *layout)
247 {
248 	struct mc_command cmd = { 0 };
249 
250 	/* prepare command */
251 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_TX_CONF_BUFFER_LAYOUT,
252 					  cmd_flags,
253 					  token);
254 	DPNI_CMD_SET_TX_CONF_BUFFER_LAYOUT(cmd, layout);
255 
256 	/* send command to mc*/
257 	return mc_send_command(mc_io, &cmd);
258 }
259 
260 int dpni_get_qdid(struct fsl_mc_io *mc_io,
261 		  uint32_t cmd_flags,
262 		  uint16_t token,
263 		  uint16_t *qdid)
264 {
265 	struct mc_command cmd = { 0 };
266 	int err;
267 
268 	/* prepare command */
269 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_QDID,
270 					  cmd_flags,
271 					  token);
272 
273 	/* send command to mc*/
274 	err = mc_send_command(mc_io, &cmd);
275 	if (err)
276 		return err;
277 
278 	/* retrieve response parameters */
279 	DPNI_RSP_GET_QDID(cmd, *qdid);
280 
281 	return 0;
282 }
283 
284 int dpni_get_tx_data_offset(struct fsl_mc_io *mc_io,
285 			    uint32_t cmd_flags,
286 			    uint16_t token,
287 			    uint16_t *data_offset)
288 {
289 	struct mc_command cmd = { 0 };
290 	int err;
291 
292 	/* prepare command */
293 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_TX_DATA_OFFSET,
294 					  cmd_flags,
295 					  token);
296 
297 	/* send command to mc*/
298 	err = mc_send_command(mc_io, &cmd);
299 	if (err)
300 		return err;
301 
302 	/* retrieve response parameters */
303 	DPNI_RSP_GET_TX_DATA_OFFSET(cmd, *data_offset);
304 
305 	return 0;
306 }
307 
308 int dpni_get_counter(struct fsl_mc_io *mc_io,
309 		     uint32_t cmd_flags,
310 		     uint16_t token,
311 		     enum dpni_counter counter,
312 		     uint64_t *value)
313 {
314 	struct mc_command cmd = { 0 };
315 	int err;
316 
317 	/* prepare command */
318 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_COUNTER,
319 					  cmd_flags,
320 					  token);
321 	DPNI_CMD_GET_COUNTER(cmd, counter);
322 
323 	/* send command to mc*/
324 	err = mc_send_command(mc_io, &cmd);
325 	if (err)
326 		return err;
327 
328 	/* retrieve response parameters */
329 	DPNI_RSP_GET_COUNTER(cmd, *value);
330 
331 	return 0;
332 }
333 
334 int dpni_set_counter(struct fsl_mc_io *mc_io,
335 		     uint32_t cmd_flags,
336 		     uint16_t token,
337 		     enum dpni_counter counter,
338 		     uint64_t value)
339 {
340 	struct mc_command cmd = { 0 };
341 
342 	/* prepare command */
343 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_COUNTER,
344 					  cmd_flags,
345 					  token);
346 	DPNI_CMD_SET_COUNTER(cmd, counter, value);
347 
348 	/* send command to mc*/
349 	return mc_send_command(mc_io, &cmd);
350 }
351 
352 int dpni_set_link_cfg(struct fsl_mc_io *mc_io,
353 		      uint32_t cmd_flags,
354 		      uint16_t token,
355 		      const struct dpni_link_cfg *cfg)
356 {
357 	struct mc_command cmd = { 0 };
358 
359 	/* prepare command */
360 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_LINK_CFG,
361 					  cmd_flags,
362 					  token);
363 	DPNI_CMD_SET_LINK_CFG(cmd, cfg);
364 
365 	/* send command to mc*/
366 	return mc_send_command(mc_io, &cmd);
367 }
368 
369 int dpni_get_link_state(struct fsl_mc_io *mc_io,
370 			uint32_t cmd_flags,
371 			uint16_t token,
372 			struct dpni_link_state *state)
373 {
374 	struct mc_command cmd = { 0 };
375 	int err;
376 
377 	/* prepare command */
378 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_LINK_STATE,
379 					  cmd_flags,
380 					  token);
381 
382 	/* send command to mc*/
383 	err = mc_send_command(mc_io, &cmd);
384 	if (err)
385 		return err;
386 
387 	/* retrieve response parameters */
388 	DPNI_RSP_GET_LINK_STATE(cmd, state);
389 
390 	return 0;
391 }
392 
393 
394 int dpni_set_primary_mac_addr(struct fsl_mc_io *mc_io,
395 			      uint32_t cmd_flags,
396 			      uint16_t token,
397 			      const uint8_t mac_addr[6])
398 {
399 	struct mc_command cmd = { 0 };
400 
401 	/* prepare command */
402 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_PRIM_MAC,
403 					  cmd_flags,
404 					  token);
405 	DPNI_CMD_SET_PRIMARY_MAC_ADDR(cmd, mac_addr);
406 
407 	/* send command to mc*/
408 	return mc_send_command(mc_io, &cmd);
409 }
410 
411 int dpni_get_primary_mac_addr(struct fsl_mc_io *mc_io,
412 			      uint32_t cmd_flags,
413 			      uint16_t token,
414 			      uint8_t mac_addr[6])
415 {
416 	struct mc_command cmd = { 0 };
417 	int err;
418 
419 	/* prepare command */
420 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_PRIM_MAC,
421 					  cmd_flags,
422 					  token);
423 
424 	/* send command to mc*/
425 	err = mc_send_command(mc_io, &cmd);
426 	if (err)
427 		return err;
428 
429 	/* retrieve response parameters */
430 	DPNI_RSP_GET_PRIMARY_MAC_ADDR(cmd, mac_addr);
431 
432 	return 0;
433 }
434 
435 int dpni_add_mac_addr(struct fsl_mc_io *mc_io,
436 		      uint32_t cmd_flags,
437 		      uint16_t token,
438 		      const uint8_t mac_addr[6])
439 {
440 	struct mc_command cmd = { 0 };
441 
442 	/* prepare command */
443 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_ADD_MAC_ADDR,
444 					  cmd_flags,
445 					  token);
446 	DPNI_CMD_ADD_MAC_ADDR(cmd, mac_addr);
447 
448 	/* send command to mc*/
449 	return mc_send_command(mc_io, &cmd);
450 }
451 
452 int dpni_remove_mac_addr(struct fsl_mc_io *mc_io,
453 			 uint32_t cmd_flags,
454 			 uint16_t token,
455 			 const uint8_t mac_addr[6])
456 {
457 	struct mc_command cmd = { 0 };
458 
459 	/* prepare command */
460 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_REMOVE_MAC_ADDR,
461 					  cmd_flags,
462 					  token);
463 	DPNI_CMD_REMOVE_MAC_ADDR(cmd, mac_addr);
464 
465 	/* send command to mc*/
466 	return mc_send_command(mc_io, &cmd);
467 }
468 
469 int dpni_set_tx_flow(struct fsl_mc_io *mc_io,
470 		     uint32_t cmd_flags,
471 		     uint16_t token,
472 		     uint16_t *flow_id,
473 		     const struct dpni_tx_flow_cfg *cfg)
474 {
475 	struct mc_command cmd = { 0 };
476 	int err;
477 
478 	/* prepare command */
479 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_TX_FLOW,
480 					  cmd_flags,
481 					  token);
482 	DPNI_CMD_SET_TX_FLOW(cmd, *flow_id, cfg);
483 
484 	/* send command to mc*/
485 	err = mc_send_command(mc_io, &cmd);
486 	if (err)
487 		return err;
488 
489 	/* retrieve response parameters */
490 	DPNI_RSP_SET_TX_FLOW(cmd, *flow_id);
491 
492 	return 0;
493 }
494 
495 int dpni_get_tx_flow(struct fsl_mc_io *mc_io,
496 		     uint32_t cmd_flags,
497 		     uint16_t token,
498 		     uint16_t flow_id,
499 		     struct dpni_tx_flow_attr *attr)
500 {
501 	struct mc_command cmd = { 0 };
502 	int err;
503 
504 	/* prepare command */
505 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_TX_FLOW,
506 					  cmd_flags,
507 					  token);
508 	DPNI_CMD_GET_TX_FLOW(cmd, flow_id);
509 
510 	/* send command to mc*/
511 	err = mc_send_command(mc_io, &cmd);
512 	if (err)
513 		return err;
514 
515 	/* retrieve response parameters */
516 	DPNI_RSP_GET_TX_FLOW(cmd, attr);
517 
518 	return 0;
519 }
520 
521 int dpni_set_rx_flow(struct fsl_mc_io *mc_io,
522 		     uint32_t cmd_flags,
523 		     uint16_t token,
524 		     uint8_t tc_id,
525 		     uint16_t flow_id,
526 		     const struct dpni_queue_cfg *cfg)
527 {
528 	struct mc_command cmd = { 0 };
529 
530 	/* prepare command */
531 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_RX_FLOW,
532 					  cmd_flags,
533 					  token);
534 	DPNI_CMD_SET_RX_FLOW(cmd, tc_id, flow_id, cfg);
535 
536 	/* send command to mc*/
537 	return mc_send_command(mc_io, &cmd);
538 }
539 
540 int dpni_get_rx_flow(struct fsl_mc_io *mc_io,
541 		     uint32_t cmd_flags,
542 		     uint16_t token,
543 		     uint8_t tc_id,
544 		     uint16_t flow_id,
545 		     struct dpni_queue_attr *attr)
546 {
547 	struct mc_command cmd = { 0 };
548 	int err;
549 	/* prepare command */
550 	cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_RX_FLOW,
551 					  cmd_flags,
552 					  token);
553 	DPNI_CMD_GET_RX_FLOW(cmd, tc_id, flow_id);
554 
555 	/* send command to mc*/
556 	err = mc_send_command(mc_io, &cmd);
557 	if (err)
558 		return err;
559 
560 	/* retrieve response parameters */
561 	DPNI_RSP_GET_RX_FLOW(cmd, attr);
562 
563 	return 0;
564 }
565