2 * Copyright (C) 2013-2015 Freescale Semiconductor
4 * SPDX-License-Identifier: GPL-2.0+
7 #include <fsl-mc/fsl_mc_sys.h>
8 #include <fsl-mc/fsl_mc_cmd.h>
9 #include <fsl-mc/fsl_dpni.h>
11 int dpni_open(struct fsl_mc_io *mc_io,
16 struct mc_command cmd = { 0 };
20 cmd.header = mc_encode_cmd_header(DPNI_CMDID_OPEN,
23 DPNI_CMD_OPEN(cmd, dpni_id);
25 /* send command to mc*/
26 err = mc_send_command(mc_io, &cmd);
30 /* retrieve response parameters */
31 *token = MC_CMD_HDR_READ_TOKEN(cmd.header);
36 int dpni_close(struct fsl_mc_io *mc_io,
40 struct mc_command cmd = { 0 };
43 cmd.header = mc_encode_cmd_header(DPNI_CMDID_CLOSE,
47 /* send command to mc*/
48 return mc_send_command(mc_io, &cmd);
51 int dpni_create(struct fsl_mc_io *mc_io,
53 const struct dpni_cfg *cfg,
56 struct mc_command cmd = { 0 };
60 cmd.header = mc_encode_cmd_header(DPNI_CMDID_CREATE,
63 DPNI_CMD_CREATE(cmd, cfg);
65 /* send command to mc*/
66 err = mc_send_command(mc_io, &cmd);
70 /* retrieve response parameters */
71 *token = MC_CMD_HDR_READ_TOKEN(cmd.header);
76 int dpni_destroy(struct fsl_mc_io *mc_io,
80 struct mc_command cmd = { 0 };
83 cmd.header = mc_encode_cmd_header(DPNI_CMDID_DESTROY,
87 /* send command to mc*/
88 return mc_send_command(mc_io, &cmd);
91 int dpni_set_pools(struct fsl_mc_io *mc_io,
94 const struct dpni_pools_cfg *cfg)
96 struct mc_command cmd = { 0 };
99 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_POOLS,
102 DPNI_CMD_SET_POOLS(cmd, cfg);
104 /* send command to mc*/
105 return mc_send_command(mc_io, &cmd);
108 int dpni_enable(struct fsl_mc_io *mc_io,
112 struct mc_command cmd = { 0 };
114 /* prepare command */
115 cmd.header = mc_encode_cmd_header(DPNI_CMDID_ENABLE,
119 /* send command to mc*/
120 return mc_send_command(mc_io, &cmd);
123 int dpni_disable(struct fsl_mc_io *mc_io,
127 struct mc_command cmd = { 0 };
129 /* prepare command */
130 cmd.header = mc_encode_cmd_header(DPNI_CMDID_DISABLE,
134 /* send command to mc*/
135 return mc_send_command(mc_io, &cmd);
138 int dpni_reset(struct fsl_mc_io *mc_io,
142 struct mc_command cmd = { 0 };
144 /* prepare command */
145 cmd.header = mc_encode_cmd_header(DPNI_CMDID_RESET,
149 /* send command to mc*/
150 return mc_send_command(mc_io, &cmd);
153 int dpni_get_attributes(struct fsl_mc_io *mc_io,
156 struct dpni_attr *attr)
158 struct mc_command cmd = { 0 };
161 /* prepare command */
162 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_ATTR,
166 /* send command to mc*/
167 err = mc_send_command(mc_io, &cmd);
171 /* retrieve response parameters */
172 DPNI_RSP_GET_ATTR(cmd, attr);
177 int dpni_get_rx_buffer_layout(struct fsl_mc_io *mc_io,
180 struct dpni_buffer_layout *layout)
182 struct mc_command cmd = { 0 };
185 /* prepare command */
186 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_RX_BUFFER_LAYOUT,
190 /* send command to mc*/
191 err = mc_send_command(mc_io, &cmd);
195 /* retrieve response parameters */
196 DPNI_RSP_GET_RX_BUFFER_LAYOUT(cmd, layout);
201 int dpni_set_rx_buffer_layout(struct fsl_mc_io *mc_io,
204 const struct dpni_buffer_layout *layout)
206 struct mc_command cmd = { 0 };
208 /* prepare command */
209 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_RX_BUFFER_LAYOUT,
212 DPNI_CMD_SET_RX_BUFFER_LAYOUT(cmd, layout);
214 /* send command to mc*/
215 return mc_send_command(mc_io, &cmd);
218 int dpni_get_tx_buffer_layout(struct fsl_mc_io *mc_io,
221 struct dpni_buffer_layout *layout)
223 struct mc_command cmd = { 0 };
226 /* prepare command */
227 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_TX_BUFFER_LAYOUT,
231 /* send command to mc*/
232 err = mc_send_command(mc_io, &cmd);
236 /* retrieve response parameters */
237 DPNI_RSP_GET_TX_BUFFER_LAYOUT(cmd, layout);
242 int dpni_set_tx_buffer_layout(struct fsl_mc_io *mc_io,
245 const struct dpni_buffer_layout *layout)
247 struct mc_command cmd = { 0 };
249 /* prepare command */
250 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_TX_BUFFER_LAYOUT,
253 DPNI_CMD_SET_TX_BUFFER_LAYOUT(cmd, layout);
255 /* send command to mc*/
256 return mc_send_command(mc_io, &cmd);
259 int dpni_get_tx_conf_buffer_layout(struct fsl_mc_io *mc_io,
262 struct dpni_buffer_layout *layout)
264 struct mc_command cmd = { 0 };
267 /* prepare command */
268 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_TX_CONF_BUFFER_LAYOUT,
272 /* send command to mc*/
273 err = mc_send_command(mc_io, &cmd);
277 /* retrieve response parameters */
278 DPNI_RSP_GET_TX_CONF_BUFFER_LAYOUT(cmd, layout);
283 int dpni_set_tx_conf_buffer_layout(struct fsl_mc_io *mc_io,
286 const struct dpni_buffer_layout *layout)
288 struct mc_command cmd = { 0 };
290 /* prepare command */
291 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_TX_CONF_BUFFER_LAYOUT,
294 DPNI_CMD_SET_TX_CONF_BUFFER_LAYOUT(cmd, layout);
296 /* send command to mc*/
297 return mc_send_command(mc_io, &cmd);
300 int dpni_get_qdid(struct fsl_mc_io *mc_io,
305 struct mc_command cmd = { 0 };
308 /* prepare command */
309 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_QDID,
313 /* send command to mc*/
314 err = mc_send_command(mc_io, &cmd);
318 /* retrieve response parameters */
319 DPNI_RSP_GET_QDID(cmd, *qdid);
324 int dpni_get_tx_data_offset(struct fsl_mc_io *mc_io,
327 uint16_t *data_offset)
329 struct mc_command cmd = { 0 };
332 /* prepare command */
333 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_TX_DATA_OFFSET,
337 /* send command to mc*/
338 err = mc_send_command(mc_io, &cmd);
342 /* retrieve response parameters */
343 DPNI_RSP_GET_TX_DATA_OFFSET(cmd, *data_offset);
348 int dpni_get_counter(struct fsl_mc_io *mc_io,
351 enum dpni_counter counter,
354 struct mc_command cmd = { 0 };
357 /* prepare command */
358 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_COUNTER,
361 DPNI_CMD_GET_COUNTER(cmd, counter);
363 /* send command to mc*/
364 err = mc_send_command(mc_io, &cmd);
368 /* retrieve response parameters */
369 DPNI_RSP_GET_COUNTER(cmd, *value);
374 int dpni_set_counter(struct fsl_mc_io *mc_io,
377 enum dpni_counter counter,
380 struct mc_command cmd = { 0 };
382 /* prepare command */
383 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_COUNTER,
386 DPNI_CMD_SET_COUNTER(cmd, counter, value);
388 /* send command to mc*/
389 return mc_send_command(mc_io, &cmd);
392 int dpni_set_link_cfg(struct fsl_mc_io *mc_io,
395 const struct dpni_link_cfg *cfg)
397 struct mc_command cmd = { 0 };
399 /* prepare command */
400 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_LINK_CFG,
403 DPNI_CMD_SET_LINK_CFG(cmd, cfg);
405 /* send command to mc*/
406 return mc_send_command(mc_io, &cmd);
409 int dpni_get_link_state(struct fsl_mc_io *mc_io,
412 struct dpni_link_state *state)
414 struct mc_command cmd = { 0 };
417 /* prepare command */
418 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_LINK_STATE,
422 /* send command to mc*/
423 err = mc_send_command(mc_io, &cmd);
427 /* retrieve response parameters */
428 DPNI_RSP_GET_LINK_STATE(cmd, state);
434 int dpni_set_primary_mac_addr(struct fsl_mc_io *mc_io,
437 const uint8_t mac_addr[6])
439 struct mc_command cmd = { 0 };
441 /* prepare command */
442 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_PRIM_MAC,
445 DPNI_CMD_SET_PRIMARY_MAC_ADDR(cmd, mac_addr);
447 /* send command to mc*/
448 return mc_send_command(mc_io, &cmd);
451 int dpni_get_primary_mac_addr(struct fsl_mc_io *mc_io,
456 struct mc_command cmd = { 0 };
459 /* prepare command */
460 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_PRIM_MAC,
464 /* send command to mc*/
465 err = mc_send_command(mc_io, &cmd);
469 /* retrieve response parameters */
470 DPNI_RSP_GET_PRIMARY_MAC_ADDR(cmd, mac_addr);
475 int dpni_add_mac_addr(struct fsl_mc_io *mc_io,
478 const uint8_t mac_addr[6])
480 struct mc_command cmd = { 0 };
482 /* prepare command */
483 cmd.header = mc_encode_cmd_header(DPNI_CMDID_ADD_MAC_ADDR,
486 DPNI_CMD_ADD_MAC_ADDR(cmd, mac_addr);
488 /* send command to mc*/
489 return mc_send_command(mc_io, &cmd);
492 int dpni_remove_mac_addr(struct fsl_mc_io *mc_io,
495 const uint8_t mac_addr[6])
497 struct mc_command cmd = { 0 };
499 /* prepare command */
500 cmd.header = mc_encode_cmd_header(DPNI_CMDID_REMOVE_MAC_ADDR,
503 DPNI_CMD_REMOVE_MAC_ADDR(cmd, mac_addr);
505 /* send command to mc*/
506 return mc_send_command(mc_io, &cmd);
509 int dpni_set_tx_flow(struct fsl_mc_io *mc_io,
513 const struct dpni_tx_flow_cfg *cfg)
515 struct mc_command cmd = { 0 };
518 /* prepare command */
519 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_TX_FLOW,
522 DPNI_CMD_SET_TX_FLOW(cmd, *flow_id, cfg);
524 /* send command to mc*/
525 err = mc_send_command(mc_io, &cmd);
529 /* retrieve response parameters */
530 DPNI_RSP_SET_TX_FLOW(cmd, *flow_id);
535 int dpni_get_tx_flow(struct fsl_mc_io *mc_io,
539 struct dpni_tx_flow_attr *attr)
541 struct mc_command cmd = { 0 };
544 /* prepare command */
545 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_TX_FLOW,
548 DPNI_CMD_GET_TX_FLOW(cmd, flow_id);
550 /* send command to mc*/
551 err = mc_send_command(mc_io, &cmd);
555 /* retrieve response parameters */
556 DPNI_RSP_GET_TX_FLOW(cmd, attr);
561 int dpni_set_rx_flow(struct fsl_mc_io *mc_io,
566 const struct dpni_queue_cfg *cfg)
568 struct mc_command cmd = { 0 };
570 /* prepare command */
571 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_RX_FLOW,
574 DPNI_CMD_SET_RX_FLOW(cmd, tc_id, flow_id, cfg);
576 /* send command to mc*/
577 return mc_send_command(mc_io, &cmd);
580 int dpni_get_rx_flow(struct fsl_mc_io *mc_io,
585 struct dpni_queue_attr *attr)
587 struct mc_command cmd = { 0 };
589 /* prepare command */
590 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_RX_FLOW,
593 DPNI_CMD_GET_RX_FLOW(cmd, tc_id, flow_id);
595 /* send command to mc*/
596 err = mc_send_command(mc_io, &cmd);
600 /* retrieve response parameters */
601 DPNI_RSP_GET_RX_FLOW(cmd, attr);