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_set_pools(struct fsl_mc_io *mc_io,
54 const struct dpni_pools_cfg *cfg)
56 struct mc_command cmd = { 0 };
59 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_POOLS,
62 DPNI_CMD_SET_POOLS(cmd, cfg);
64 /* send command to mc*/
65 return mc_send_command(mc_io, &cmd);
68 int dpni_enable(struct fsl_mc_io *mc_io,
72 struct mc_command cmd = { 0 };
75 cmd.header = mc_encode_cmd_header(DPNI_CMDID_ENABLE,
79 /* send command to mc*/
80 return mc_send_command(mc_io, &cmd);
83 int dpni_disable(struct fsl_mc_io *mc_io,
87 struct mc_command cmd = { 0 };
90 cmd.header = mc_encode_cmd_header(DPNI_CMDID_DISABLE,
94 /* send command to mc*/
95 return mc_send_command(mc_io, &cmd);
98 int dpni_reset(struct fsl_mc_io *mc_io,
102 struct mc_command cmd = { 0 };
104 /* prepare command */
105 cmd.header = mc_encode_cmd_header(DPNI_CMDID_RESET,
109 /* send command to mc*/
110 return mc_send_command(mc_io, &cmd);
113 int dpni_get_attributes(struct fsl_mc_io *mc_io,
116 struct dpni_attr *attr)
118 struct mc_command cmd = { 0 };
121 /* prepare command */
122 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_ATTR,
126 /* send command to mc*/
127 err = mc_send_command(mc_io, &cmd);
131 /* retrieve response parameters */
132 DPNI_RSP_GET_ATTR(cmd, attr);
137 int dpni_get_rx_buffer_layout(struct fsl_mc_io *mc_io,
140 struct dpni_buffer_layout *layout)
142 struct mc_command cmd = { 0 };
145 /* prepare command */
146 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_RX_BUFFER_LAYOUT,
150 /* send command to mc*/
151 err = mc_send_command(mc_io, &cmd);
155 /* retrieve response parameters */
156 DPNI_RSP_GET_RX_BUFFER_LAYOUT(cmd, layout);
161 int dpni_set_rx_buffer_layout(struct fsl_mc_io *mc_io,
164 const struct dpni_buffer_layout *layout)
166 struct mc_command cmd = { 0 };
168 /* prepare command */
169 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_RX_BUFFER_LAYOUT,
172 DPNI_CMD_SET_RX_BUFFER_LAYOUT(cmd, layout);
174 /* send command to mc*/
175 return mc_send_command(mc_io, &cmd);
178 int dpni_get_tx_buffer_layout(struct fsl_mc_io *mc_io,
181 struct dpni_buffer_layout *layout)
183 struct mc_command cmd = { 0 };
186 /* prepare command */
187 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_TX_BUFFER_LAYOUT,
191 /* send command to mc*/
192 err = mc_send_command(mc_io, &cmd);
196 /* retrieve response parameters */
197 DPNI_RSP_GET_TX_BUFFER_LAYOUT(cmd, layout);
202 int dpni_set_tx_buffer_layout(struct fsl_mc_io *mc_io,
205 const struct dpni_buffer_layout *layout)
207 struct mc_command cmd = { 0 };
209 /* prepare command */
210 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_TX_BUFFER_LAYOUT,
213 DPNI_CMD_SET_TX_BUFFER_LAYOUT(cmd, layout);
215 /* send command to mc*/
216 return mc_send_command(mc_io, &cmd);
219 int dpni_get_tx_conf_buffer_layout(struct fsl_mc_io *mc_io,
222 struct dpni_buffer_layout *layout)
224 struct mc_command cmd = { 0 };
227 /* prepare command */
228 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_TX_CONF_BUFFER_LAYOUT,
232 /* send command to mc*/
233 err = mc_send_command(mc_io, &cmd);
237 /* retrieve response parameters */
238 DPNI_RSP_GET_TX_CONF_BUFFER_LAYOUT(cmd, layout);
243 int dpni_set_tx_conf_buffer_layout(struct fsl_mc_io *mc_io,
246 const struct dpni_buffer_layout *layout)
248 struct mc_command cmd = { 0 };
250 /* prepare command */
251 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_TX_CONF_BUFFER_LAYOUT,
254 DPNI_CMD_SET_TX_CONF_BUFFER_LAYOUT(cmd, layout);
256 /* send command to mc*/
257 return mc_send_command(mc_io, &cmd);
260 int dpni_get_qdid(struct fsl_mc_io *mc_io,
265 struct mc_command cmd = { 0 };
268 /* prepare command */
269 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_QDID,
273 /* send command to mc*/
274 err = mc_send_command(mc_io, &cmd);
278 /* retrieve response parameters */
279 DPNI_RSP_GET_QDID(cmd, *qdid);
284 int dpni_get_tx_data_offset(struct fsl_mc_io *mc_io,
287 uint16_t *data_offset)
289 struct mc_command cmd = { 0 };
292 /* prepare command */
293 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_TX_DATA_OFFSET,
297 /* send command to mc*/
298 err = mc_send_command(mc_io, &cmd);
302 /* retrieve response parameters */
303 DPNI_RSP_GET_TX_DATA_OFFSET(cmd, *data_offset);
308 int dpni_get_counter(struct fsl_mc_io *mc_io,
311 enum dpni_counter counter,
314 struct mc_command cmd = { 0 };
317 /* prepare command */
318 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_COUNTER,
321 DPNI_CMD_GET_COUNTER(cmd, counter);
323 /* send command to mc*/
324 err = mc_send_command(mc_io, &cmd);
328 /* retrieve response parameters */
329 DPNI_RSP_GET_COUNTER(cmd, *value);
334 int dpni_set_counter(struct fsl_mc_io *mc_io,
337 enum dpni_counter counter,
340 struct mc_command cmd = { 0 };
342 /* prepare command */
343 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_COUNTER,
346 DPNI_CMD_SET_COUNTER(cmd, counter, value);
348 /* send command to mc*/
349 return mc_send_command(mc_io, &cmd);
352 int dpni_set_link_cfg(struct fsl_mc_io *mc_io,
355 const struct dpni_link_cfg *cfg)
357 struct mc_command cmd = { 0 };
359 /* prepare command */
360 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_LINK_CFG,
363 DPNI_CMD_SET_LINK_CFG(cmd, cfg);
365 /* send command to mc*/
366 return mc_send_command(mc_io, &cmd);
369 int dpni_get_link_state(struct fsl_mc_io *mc_io,
372 struct dpni_link_state *state)
374 struct mc_command cmd = { 0 };
377 /* prepare command */
378 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_LINK_STATE,
382 /* send command to mc*/
383 err = mc_send_command(mc_io, &cmd);
387 /* retrieve response parameters */
388 DPNI_RSP_GET_LINK_STATE(cmd, state);
394 int dpni_set_primary_mac_addr(struct fsl_mc_io *mc_io,
397 const uint8_t mac_addr[6])
399 struct mc_command cmd = { 0 };
401 /* prepare command */
402 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_PRIM_MAC,
405 DPNI_CMD_SET_PRIMARY_MAC_ADDR(cmd, mac_addr);
407 /* send command to mc*/
408 return mc_send_command(mc_io, &cmd);
411 int dpni_get_primary_mac_addr(struct fsl_mc_io *mc_io,
416 struct mc_command cmd = { 0 };
419 /* prepare command */
420 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_PRIM_MAC,
424 /* send command to mc*/
425 err = mc_send_command(mc_io, &cmd);
429 /* retrieve response parameters */
430 DPNI_RSP_GET_PRIMARY_MAC_ADDR(cmd, mac_addr);
435 int dpni_add_mac_addr(struct fsl_mc_io *mc_io,
438 const uint8_t mac_addr[6])
440 struct mc_command cmd = { 0 };
442 /* prepare command */
443 cmd.header = mc_encode_cmd_header(DPNI_CMDID_ADD_MAC_ADDR,
446 DPNI_CMD_ADD_MAC_ADDR(cmd, mac_addr);
448 /* send command to mc*/
449 return mc_send_command(mc_io, &cmd);
452 int dpni_remove_mac_addr(struct fsl_mc_io *mc_io,
455 const uint8_t mac_addr[6])
457 struct mc_command cmd = { 0 };
459 /* prepare command */
460 cmd.header = mc_encode_cmd_header(DPNI_CMDID_REMOVE_MAC_ADDR,
463 DPNI_CMD_REMOVE_MAC_ADDR(cmd, mac_addr);
465 /* send command to mc*/
466 return mc_send_command(mc_io, &cmd);
469 int dpni_set_tx_flow(struct fsl_mc_io *mc_io,
473 const struct dpni_tx_flow_cfg *cfg)
475 struct mc_command cmd = { 0 };
478 /* prepare command */
479 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_TX_FLOW,
482 DPNI_CMD_SET_TX_FLOW(cmd, *flow_id, cfg);
484 /* send command to mc*/
485 err = mc_send_command(mc_io, &cmd);
489 /* retrieve response parameters */
490 DPNI_RSP_SET_TX_FLOW(cmd, *flow_id);
495 int dpni_get_tx_flow(struct fsl_mc_io *mc_io,
499 struct dpni_tx_flow_attr *attr)
501 struct mc_command cmd = { 0 };
504 /* prepare command */
505 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_TX_FLOW,
508 DPNI_CMD_GET_TX_FLOW(cmd, flow_id);
510 /* send command to mc*/
511 err = mc_send_command(mc_io, &cmd);
515 /* retrieve response parameters */
516 DPNI_RSP_GET_TX_FLOW(cmd, attr);
521 int dpni_set_rx_flow(struct fsl_mc_io *mc_io,
526 const struct dpni_queue_cfg *cfg)
528 struct mc_command cmd = { 0 };
530 /* prepare command */
531 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_RX_FLOW,
534 DPNI_CMD_SET_RX_FLOW(cmd, tc_id, flow_id, cfg);
536 /* send command to mc*/
537 return mc_send_command(mc_io, &cmd);
540 int dpni_get_rx_flow(struct fsl_mc_io *mc_io,
545 struct dpni_queue_attr *attr)
547 struct mc_command cmd = { 0 };
549 /* prepare command */
550 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_RX_FLOW,
553 DPNI_CMD_GET_RX_FLOW(cmd, tc_id, flow_id);
555 /* send command to mc*/
556 err = mc_send_command(mc_io, &cmd);
560 /* retrieve response parameters */
561 DPNI_RSP_GET_RX_FLOW(cmd, attr);