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