1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2013-2016 Freescale Semiconductor
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_prepare_cfg(const struct dpni_cfg *cfg,
14 uint64_t *params = (uint64_t *)cfg_buf;
16 DPNI_PREP_CFG(params, cfg);
21 int dpni_extract_cfg(struct dpni_cfg *cfg,
22 const uint8_t *cfg_buf)
24 uint64_t *params = (uint64_t *)cfg_buf;
26 DPNI_EXT_CFG(params, cfg);
31 int dpni_open(struct fsl_mc_io *mc_io,
36 struct mc_command cmd = { 0 };
40 cmd.header = mc_encode_cmd_header(DPNI_CMDID_OPEN,
43 DPNI_CMD_OPEN(cmd, dpni_id);
45 /* send command to mc*/
46 err = mc_send_command(mc_io, &cmd);
50 /* retrieve response parameters */
51 *token = MC_CMD_HDR_READ_TOKEN(cmd.header);
56 int dpni_close(struct fsl_mc_io *mc_io,
60 struct mc_command cmd = { 0 };
63 cmd.header = mc_encode_cmd_header(DPNI_CMDID_CLOSE,
67 /* send command to mc*/
68 return mc_send_command(mc_io, &cmd);
71 int dpni_create(struct fsl_mc_io *mc_io,
74 const struct dpni_cfg *cfg,
77 struct mc_command cmd = { 0 };
81 cmd.header = mc_encode_cmd_header(DPNI_CMDID_CREATE,
84 DPNI_CMD_CREATE(cmd, cfg);
86 /* send command to mc*/
87 err = mc_send_command(mc_io, &cmd);
91 /* retrieve response parameters */
92 MC_CMD_READ_OBJ_ID(cmd, *obj_id);
97 int dpni_destroy(struct fsl_mc_io *mc_io,
102 struct mc_command cmd = { 0 };
104 /* prepare command */
105 cmd.header = mc_encode_cmd_header(DPNI_CMDID_DESTROY,
109 /* set object id to destroy */
110 CMD_DESTROY_SET_OBJ_ID_PARAM0(cmd, obj_id);
112 /* send command to mc*/
113 return mc_send_command(mc_io, &cmd);
116 int dpni_set_pools(struct fsl_mc_io *mc_io,
119 const struct dpni_pools_cfg *cfg)
121 struct mc_command cmd = { 0 };
123 /* prepare command */
124 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_POOLS,
127 DPNI_CMD_SET_POOLS(cmd, cfg);
129 /* send command to mc*/
130 return mc_send_command(mc_io, &cmd);
133 int dpni_enable(struct fsl_mc_io *mc_io,
137 struct mc_command cmd = { 0 };
139 /* prepare command */
140 cmd.header = mc_encode_cmd_header(DPNI_CMDID_ENABLE,
144 /* send command to mc*/
145 return mc_send_command(mc_io, &cmd);
148 int dpni_disable(struct fsl_mc_io *mc_io,
152 struct mc_command cmd = { 0 };
154 /* prepare command */
155 cmd.header = mc_encode_cmd_header(DPNI_CMDID_DISABLE,
159 /* send command to mc*/
160 return mc_send_command(mc_io, &cmd);
163 int dpni_reset(struct fsl_mc_io *mc_io,
167 struct mc_command cmd = { 0 };
169 /* prepare command */
170 cmd.header = mc_encode_cmd_header(DPNI_CMDID_RESET,
174 /* send command to mc*/
175 return mc_send_command(mc_io, &cmd);
178 int dpni_get_attributes(struct fsl_mc_io *mc_io,
181 struct dpni_attr *attr)
183 struct mc_command cmd = { 0 };
186 /* prepare command */
187 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_ATTR,
190 /* send command to mc*/
191 err = mc_send_command(mc_io, &cmd);
195 /* retrieve response parameters */
196 DPNI_RSP_GET_ATTR(cmd, attr);
201 int dpni_set_errors_behavior(struct fsl_mc_io *mc_io,
204 struct dpni_error_cfg *cfg)
206 struct mc_command cmd = { 0 };
208 /* prepare command */
209 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_ERRORS_BEHAVIOR,
212 DPNI_CMD_SET_ERRORS_BEHAVIOR(cmd, cfg);
214 /* send command to mc*/
215 return mc_send_command(mc_io, &cmd);
218 int dpni_set_buffer_layout(struct fsl_mc_io *mc_io,
221 const struct dpni_buffer_layout *layout,
222 enum dpni_queue_type type)
224 struct mc_command cmd = { 0 };
226 /* prepare command */
227 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_BUFFER_LAYOUT,
230 DPNI_CMD_SET_BUFFER_LAYOUT(cmd, layout, type);
232 /* send command to mc*/
233 return mc_send_command(mc_io, &cmd);
236 int dpni_get_qdid(struct fsl_mc_io *mc_io,
241 struct mc_command cmd = { 0 };
244 /* prepare command */
245 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_QDID,
249 /* send command to mc*/
250 err = mc_send_command(mc_io, &cmd);
254 /* retrieve response parameters */
255 DPNI_RSP_GET_QDID(cmd, *qdid);
260 int dpni_get_tx_data_offset(struct fsl_mc_io *mc_io,
263 uint16_t *data_offset)
265 struct mc_command cmd = { 0 };
268 /* prepare command */
269 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_TX_DATA_OFFSET,
273 /* send command to mc*/
274 err = mc_send_command(mc_io, &cmd);
278 /* retrieve response parameters */
279 DPNI_RSP_GET_TX_DATA_OFFSET(cmd, *data_offset);
284 int dpni_set_link_cfg(struct fsl_mc_io *mc_io,
287 const struct dpni_link_cfg *cfg)
289 struct mc_command cmd = { 0 };
291 /* prepare command */
292 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_LINK_CFG,
295 DPNI_CMD_SET_LINK_CFG(cmd, cfg);
297 /* send command to mc*/
298 return mc_send_command(mc_io, &cmd);
301 int dpni_get_link_state(struct fsl_mc_io *mc_io,
304 struct dpni_link_state *state)
306 struct mc_command cmd = { 0 };
309 /* prepare command */
310 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_LINK_STATE,
314 /* send command to mc*/
315 err = mc_send_command(mc_io, &cmd);
319 /* retrieve response parameters */
320 DPNI_RSP_GET_LINK_STATE(cmd, state);
326 int dpni_set_primary_mac_addr(struct fsl_mc_io *mc_io,
329 const uint8_t mac_addr[6])
331 struct mc_command cmd = { 0 };
333 /* prepare command */
334 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_PRIM_MAC,
337 DPNI_CMD_SET_PRIMARY_MAC_ADDR(cmd, mac_addr);
339 /* send command to mc*/
340 return mc_send_command(mc_io, &cmd);
343 int dpni_get_primary_mac_addr(struct fsl_mc_io *mc_io,
348 struct mc_command cmd = { 0 };
351 /* prepare command */
352 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_PRIM_MAC,
356 /* send command to mc*/
357 err = mc_send_command(mc_io, &cmd);
361 /* retrieve response parameters */
362 DPNI_RSP_GET_PRIMARY_MAC_ADDR(cmd, mac_addr);
367 int dpni_add_mac_addr(struct fsl_mc_io *mc_io,
370 const uint8_t mac_addr[6])
372 struct mc_command cmd = { 0 };
374 /* prepare command */
375 cmd.header = mc_encode_cmd_header(DPNI_CMDID_ADD_MAC_ADDR,
378 DPNI_CMD_ADD_MAC_ADDR(cmd, mac_addr);
380 /* send command to mc*/
381 return mc_send_command(mc_io, &cmd);
384 int dpni_remove_mac_addr(struct fsl_mc_io *mc_io,
387 const uint8_t mac_addr[6])
389 struct mc_command cmd = { 0 };
391 /* prepare command */
392 cmd.header = mc_encode_cmd_header(DPNI_CMDID_REMOVE_MAC_ADDR,
395 DPNI_CMD_REMOVE_MAC_ADDR(cmd, mac_addr);
397 /* send command to mc*/
398 return mc_send_command(mc_io, &cmd);
401 int dpni_get_api_version(struct fsl_mc_io *mc_io,
406 struct mc_command cmd = { 0 };
409 /* prepare command */
410 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_API_VERSION,
413 /* send command to mc */
414 err = mc_send_command(mc_io, &cmd);
418 /* retrieve response parameters */
419 mc_cmd_read_api_version(&cmd, major_ver, minor_ver);
424 int dpni_set_queue(struct fsl_mc_io *mc_io,
427 enum dpni_queue_type type,
430 const struct dpni_queue *queue)
432 struct mc_command cmd = { 0 };
433 /* prepare command */
434 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_QUEUE,
437 DPNI_CMD_SET_QUEUE(cmd, type, tc, index, queue);
439 /* send command to mc*/
440 return mc_send_command(mc_io, &cmd);
443 int dpni_get_queue(struct fsl_mc_io *mc_io,
446 enum dpni_queue_type type,
449 struct dpni_queue *queue)
451 struct mc_command cmd = { 0 };
454 /* prepare command */
455 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_QUEUE,
458 DPNI_CMD_GET_QUEUE(cmd, type, tc, index);
460 /* send command to mc*/
461 err = mc_send_command(mc_io, &cmd);
465 /* retrieve response parameters */
466 DPNI_RSP_GET_QUEUE(cmd, queue);
470 int dpni_set_tx_confirmation_mode(struct fsl_mc_io *mc_io,
473 enum dpni_confirmation_mode mode)
475 struct dpni_tx_confirmation_mode *cmd_params;
476 struct mc_command cmd = { 0 };
478 /* prepare command */
479 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_TX_CONFIRMATION_MODE,
483 cmd_params = (struct dpni_tx_confirmation_mode *)cmd.params;
484 cmd_params->confirmation_mode = mode;
486 /* send command to mc*/
487 return mc_send_command(mc_io, &cmd);
490 int dpni_get_statistics(struct fsl_mc_io *mc_io,
494 struct dpni_statistics *stat)
496 struct mc_command cmd = { 0 };
499 /* prepare command */
500 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_STATISTICS,
502 DPNI_CMD_GET_STATISTICS(cmd, page);
504 /* send command to mc*/
505 err = mc_send_command(mc_io, &cmd);
509 /* retrieve response parameters */
510 DPNI_RSP_GET_STATISTICS(cmd, stat);
515 int dpni_reset_statistics(struct fsl_mc_io *mc_io,
519 struct mc_command cmd = { 0 };
521 /* prepare command */
522 cmd.header = mc_encode_cmd_header(DPNI_CMDID_RESET_STATISTICS,
525 /* send command to mc*/
526 return mc_send_command(mc_io, &cmd);