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, int dpni_id, uint16_t *token)
13 struct mc_command cmd = { 0 };
17 cmd.header = mc_encode_cmd_header(DPNI_CMDID_OPEN,
19 DPNI_CMD_OPEN(cmd, dpni_id);
21 /* send command to mc*/
22 err = mc_send_command(mc_io, &cmd);
26 /* retrieve response parameters */
27 *token = MC_CMD_HDR_READ_TOKEN(cmd.header);
32 int dpni_close(struct fsl_mc_io *mc_io, uint16_t token)
34 struct mc_command cmd = { 0 };
37 cmd.header = mc_encode_cmd_header(DPNI_CMDID_CLOSE,
38 MC_CMD_PRI_HIGH, token);
40 /* send command to mc*/
41 return mc_send_command(mc_io, &cmd);
44 int dpni_set_pools(struct fsl_mc_io *mc_io,
46 const struct dpni_pools_cfg *cfg)
48 struct mc_command cmd = { 0 };
51 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_POOLS,
54 DPNI_CMD_SET_POOLS(cmd, cfg);
56 /* send command to mc*/
57 return mc_send_command(mc_io, &cmd);
60 int dpni_enable(struct fsl_mc_io *mc_io, uint16_t token)
62 struct mc_command cmd = { 0 };
65 cmd.header = mc_encode_cmd_header(DPNI_CMDID_ENABLE,
66 MC_CMD_PRI_LOW, token);
68 /* send command to mc*/
69 return mc_send_command(mc_io, &cmd);
72 int dpni_disable(struct fsl_mc_io *mc_io, uint16_t token)
74 struct mc_command cmd = { 0 };
77 cmd.header = mc_encode_cmd_header(DPNI_CMDID_DISABLE,
81 /* send command to mc*/
82 return mc_send_command(mc_io, &cmd);
85 int dpni_reset(struct fsl_mc_io *mc_io, uint16_t token)
87 struct mc_command cmd = { 0 };
90 cmd.header = mc_encode_cmd_header(DPNI_CMDID_RESET,
91 MC_CMD_PRI_LOW, token);
93 /* send command to mc*/
94 return mc_send_command(mc_io, &cmd);
97 int dpni_get_attributes(struct fsl_mc_io *mc_io,
99 struct dpni_attr *attr)
101 struct mc_command cmd = { 0 };
104 /* prepare command */
105 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_ATTR,
109 /* send command to mc*/
110 err = mc_send_command(mc_io, &cmd);
114 /* retrieve response parameters */
115 DPNI_RSP_GET_ATTR(cmd, attr);
120 int dpni_get_rx_buffer_layout(struct fsl_mc_io *mc_io,
122 struct dpni_buffer_layout *layout)
124 struct mc_command cmd = { 0 };
127 /* prepare command */
128 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_RX_BUFFER_LAYOUT,
129 MC_CMD_PRI_LOW, token);
131 /* send command to mc*/
132 err = mc_send_command(mc_io, &cmd);
136 /* retrieve response parameters */
137 DPNI_RSP_GET_RX_BUFFER_LAYOUT(cmd, layout);
142 int dpni_set_rx_buffer_layout(struct fsl_mc_io *mc_io,
144 const struct dpni_buffer_layout *layout)
146 struct mc_command cmd = { 0 };
148 /* prepare command */
149 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_RX_BUFFER_LAYOUT,
150 MC_CMD_PRI_LOW, token);
151 DPNI_CMD_SET_RX_BUFFER_LAYOUT(cmd, layout);
153 /* send command to mc*/
154 return mc_send_command(mc_io, &cmd);
157 int dpni_get_tx_buffer_layout(struct fsl_mc_io *mc_io,
159 struct dpni_buffer_layout *layout)
161 struct mc_command cmd = { 0 };
164 /* prepare command */
165 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_TX_BUFFER_LAYOUT,
166 MC_CMD_PRI_LOW, token);
168 /* send command to mc*/
169 err = mc_send_command(mc_io, &cmd);
173 /* retrieve response parameters */
174 DPNI_RSP_GET_TX_BUFFER_LAYOUT(cmd, layout);
179 int dpni_set_tx_buffer_layout(struct fsl_mc_io *mc_io,
181 const struct dpni_buffer_layout *layout)
183 struct mc_command cmd = { 0 };
185 /* prepare command */
186 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_TX_BUFFER_LAYOUT,
187 MC_CMD_PRI_LOW, token);
188 DPNI_CMD_SET_TX_BUFFER_LAYOUT(cmd, layout);
190 /* send command to mc*/
191 return mc_send_command(mc_io, &cmd);
194 int dpni_get_tx_conf_buffer_layout(struct fsl_mc_io *mc_io,
196 struct dpni_buffer_layout *layout)
198 struct mc_command cmd = { 0 };
201 /* prepare command */
202 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_TX_CONF_BUFFER_LAYOUT,
203 MC_CMD_PRI_LOW, token);
205 /* send command to mc*/
206 err = mc_send_command(mc_io, &cmd);
210 /* retrieve response parameters */
211 DPNI_RSP_GET_TX_CONF_BUFFER_LAYOUT(cmd, layout);
216 int dpni_set_tx_conf_buffer_layout(struct fsl_mc_io *mc_io,
218 const struct dpni_buffer_layout *layout)
220 struct mc_command cmd = { 0 };
222 /* prepare command */
223 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_TX_CONF_BUFFER_LAYOUT,
224 MC_CMD_PRI_LOW, token);
225 DPNI_CMD_SET_TX_CONF_BUFFER_LAYOUT(cmd, layout);
227 /* send command to mc*/
228 return mc_send_command(mc_io, &cmd);
231 int dpni_get_qdid(struct fsl_mc_io *mc_io, uint16_t token, uint16_t *qdid)
233 struct mc_command cmd = { 0 };
236 /* prepare command */
237 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_QDID,
241 /* send command to mc*/
242 err = mc_send_command(mc_io, &cmd);
246 /* retrieve response parameters */
247 DPNI_RSP_GET_QDID(cmd, *qdid);
252 int dpni_get_tx_data_offset(struct fsl_mc_io *mc_io,
254 uint16_t *data_offset)
256 struct mc_command cmd = { 0 };
259 /* prepare command */
260 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_TX_DATA_OFFSET,
261 MC_CMD_PRI_LOW, token);
263 /* send command to mc*/
264 err = mc_send_command(mc_io, &cmd);
268 /* retrieve response parameters */
269 DPNI_RSP_GET_TX_DATA_OFFSET(cmd, *data_offset);
274 int dpni_get_counter(struct fsl_mc_io *mc_io,
276 enum dpni_counter counter,
279 struct mc_command cmd = { 0 };
282 /* prepare command */
283 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_COUNTER,
284 MC_CMD_PRI_LOW, token);
285 DPNI_CMD_GET_COUNTER(cmd, counter);
287 /* send command to mc*/
288 err = mc_send_command(mc_io, &cmd);
292 /* retrieve response parameters */
293 DPNI_RSP_GET_COUNTER(cmd, *value);
298 int dpni_set_counter(struct fsl_mc_io *mc_io,
300 enum dpni_counter counter,
303 struct mc_command cmd = { 0 };
305 /* prepare command */
306 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_COUNTER,
307 MC_CMD_PRI_LOW, token);
308 DPNI_CMD_SET_COUNTER(cmd, counter, value);
310 /* send command to mc*/
311 return mc_send_command(mc_io, &cmd);
314 int dpni_set_link_cfg(struct fsl_mc_io *mc_io,
316 const struct dpni_link_cfg *cfg)
318 struct mc_command cmd = { 0 };
320 /* prepare command */
321 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_LINK_CFG,
322 MC_CMD_PRI_LOW, token);
323 DPNI_CMD_SET_LINK_CFG(cmd, cfg);
325 /* send command to mc*/
326 return mc_send_command(mc_io, &cmd);
329 int dpni_get_link_state(struct fsl_mc_io *mc_io,
331 struct dpni_link_state *state)
333 struct mc_command cmd = { 0 };
336 /* prepare command */
337 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_LINK_STATE,
338 MC_CMD_PRI_LOW, token);
340 /* send command to mc*/
341 err = mc_send_command(mc_io, &cmd);
345 /* retrieve response parameters */
346 DPNI_RSP_GET_LINK_STATE(cmd, state);
352 int dpni_set_primary_mac_addr(struct fsl_mc_io *mc_io,
354 const uint8_t mac_addr[6])
356 struct mc_command cmd = { 0 };
358 /* prepare command */
359 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_PRIM_MAC,
360 MC_CMD_PRI_LOW, token);
361 DPNI_CMD_SET_PRIMARY_MAC_ADDR(cmd, mac_addr);
363 /* send command to mc*/
364 return mc_send_command(mc_io, &cmd);
367 int dpni_get_primary_mac_addr(struct fsl_mc_io *mc_io,
371 struct mc_command cmd = { 0 };
374 /* prepare command */
375 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_PRIM_MAC,
376 MC_CMD_PRI_LOW, token);
378 /* send command to mc*/
379 err = mc_send_command(mc_io, &cmd);
383 /* retrieve response parameters */
384 DPNI_RSP_GET_PRIMARY_MAC_ADDR(cmd, mac_addr);
389 int dpni_add_mac_addr(struct fsl_mc_io *mc_io,
391 const uint8_t mac_addr[6])
393 struct mc_command cmd = { 0 };
395 /* prepare command */
396 cmd.header = mc_encode_cmd_header(DPNI_CMDID_ADD_MAC_ADDR,
397 MC_CMD_PRI_LOW, token);
398 DPNI_CMD_ADD_MAC_ADDR(cmd, mac_addr);
400 /* send command to mc*/
401 return mc_send_command(mc_io, &cmd);
404 int dpni_remove_mac_addr(struct fsl_mc_io *mc_io,
406 const uint8_t mac_addr[6])
408 struct mc_command cmd = { 0 };
410 /* prepare command */
411 cmd.header = mc_encode_cmd_header(DPNI_CMDID_REMOVE_MAC_ADDR,
412 MC_CMD_PRI_LOW, token);
413 DPNI_CMD_REMOVE_MAC_ADDR(cmd, mac_addr);
415 /* send command to mc*/
416 return mc_send_command(mc_io, &cmd);
419 int dpni_set_tx_flow(struct fsl_mc_io *mc_io,
422 const struct dpni_tx_flow_cfg *cfg)
424 struct mc_command cmd = { 0 };
427 /* prepare command */
428 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_TX_FLOW,
429 MC_CMD_PRI_LOW, token);
430 DPNI_CMD_SET_TX_FLOW(cmd, *flow_id, cfg);
432 /* send command to mc*/
433 err = mc_send_command(mc_io, &cmd);
437 /* retrieve response parameters */
438 DPNI_RSP_SET_TX_FLOW(cmd, *flow_id);
443 int dpni_get_tx_flow(struct fsl_mc_io *mc_io,
446 struct dpni_tx_flow_attr *attr)
448 struct mc_command cmd = { 0 };
451 /* prepare command */
452 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_TX_FLOW,
453 MC_CMD_PRI_LOW, token);
454 DPNI_CMD_GET_TX_FLOW(cmd, flow_id);
456 /* send command to mc*/
457 err = mc_send_command(mc_io, &cmd);
461 /* retrieve response parameters */
462 DPNI_RSP_GET_TX_FLOW(cmd, attr);
467 int dpni_set_rx_flow(struct fsl_mc_io *mc_io,
471 const struct dpni_queue_cfg *cfg)
473 struct mc_command cmd = { 0 };
475 /* prepare command */
476 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_RX_FLOW,
477 MC_CMD_PRI_LOW, token);
478 DPNI_CMD_SET_RX_FLOW(cmd, tc_id, flow_id, cfg);
480 /* send command to mc*/
481 return mc_send_command(mc_io, &cmd);
484 int dpni_get_rx_flow(struct fsl_mc_io *mc_io,
488 struct dpni_queue_attr *attr)
490 struct mc_command cmd = { 0 };
492 /* prepare command */
493 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_RX_FLOW,
494 MC_CMD_PRI_LOW, token);
495 DPNI_CMD_GET_RX_FLOW(cmd, tc_id, flow_id);
497 /* send command to mc*/
498 err = mc_send_command(mc_io, &cmd);
502 /* retrieve response parameters */
503 DPNI_RSP_GET_RX_FLOW(cmd, attr);