2 * Copyright (C) 2013-2016 Freescale Semiconductor
5 * SPDX-License-Identifier: GPL-2.0+
8 #include <fsl-mc/fsl_mc_sys.h>
9 #include <fsl-mc/fsl_mc_cmd.h>
10 #include <fsl-mc/fsl_dpni.h>
12 int dpni_prepare_cfg(const struct dpni_cfg
*cfg
,
15 uint64_t *params
= (uint64_t *)cfg_buf
;
17 DPNI_PREP_CFG(params
, cfg
);
22 int dpni_extract_cfg(struct dpni_cfg
*cfg
,
23 const uint8_t *cfg_buf
)
25 uint64_t *params
= (uint64_t *)cfg_buf
;
27 DPNI_EXT_CFG(params
, cfg
);
32 int dpni_open(struct fsl_mc_io
*mc_io
,
37 struct mc_command cmd
= { 0 };
41 cmd
.header
= mc_encode_cmd_header(DPNI_CMDID_OPEN
,
44 DPNI_CMD_OPEN(cmd
, dpni_id
);
46 /* send command to mc*/
47 err
= mc_send_command(mc_io
, &cmd
);
51 /* retrieve response parameters */
52 *token
= MC_CMD_HDR_READ_TOKEN(cmd
.header
);
57 int dpni_close(struct fsl_mc_io
*mc_io
,
61 struct mc_command cmd
= { 0 };
64 cmd
.header
= mc_encode_cmd_header(DPNI_CMDID_CLOSE
,
68 /* send command to mc*/
69 return mc_send_command(mc_io
, &cmd
);
72 int dpni_create(struct fsl_mc_io
*mc_io
,
75 const struct dpni_cfg
*cfg
,
78 struct mc_command cmd
= { 0 };
82 cmd
.header
= mc_encode_cmd_header(DPNI_CMDID_CREATE
,
85 DPNI_CMD_CREATE(cmd
, cfg
);
87 /* send command to mc*/
88 err
= mc_send_command(mc_io
, &cmd
);
92 /* retrieve response parameters */
93 MC_CMD_READ_OBJ_ID(cmd
, *obj_id
);
98 int dpni_destroy(struct fsl_mc_io
*mc_io
,
103 struct mc_command cmd
= { 0 };
105 /* prepare command */
106 cmd
.header
= mc_encode_cmd_header(DPNI_CMDID_DESTROY
,
110 /* set object id to destroy */
111 CMD_DESTROY_SET_OBJ_ID_PARAM0(cmd
, obj_id
);
113 /* send command to mc*/
114 return mc_send_command(mc_io
, &cmd
);
117 int dpni_set_pools(struct fsl_mc_io
*mc_io
,
120 const struct dpni_pools_cfg
*cfg
)
122 struct mc_command cmd
= { 0 };
124 /* prepare command */
125 cmd
.header
= mc_encode_cmd_header(DPNI_CMDID_SET_POOLS
,
128 DPNI_CMD_SET_POOLS(cmd
, cfg
);
130 /* send command to mc*/
131 return mc_send_command(mc_io
, &cmd
);
134 int dpni_enable(struct fsl_mc_io
*mc_io
,
138 struct mc_command cmd
= { 0 };
140 /* prepare command */
141 cmd
.header
= mc_encode_cmd_header(DPNI_CMDID_ENABLE
,
145 /* send command to mc*/
146 return mc_send_command(mc_io
, &cmd
);
149 int dpni_disable(struct fsl_mc_io
*mc_io
,
153 struct mc_command cmd
= { 0 };
155 /* prepare command */
156 cmd
.header
= mc_encode_cmd_header(DPNI_CMDID_DISABLE
,
160 /* send command to mc*/
161 return mc_send_command(mc_io
, &cmd
);
164 int dpni_reset(struct fsl_mc_io
*mc_io
,
168 struct mc_command cmd
= { 0 };
170 /* prepare command */
171 cmd
.header
= mc_encode_cmd_header(DPNI_CMDID_RESET
,
175 /* send command to mc*/
176 return mc_send_command(mc_io
, &cmd
);
179 int dpni_get_attributes(struct fsl_mc_io
*mc_io
,
182 struct dpni_attr
*attr
)
184 struct mc_command cmd
= { 0 };
187 /* prepare command */
188 cmd
.header
= mc_encode_cmd_header(DPNI_CMDID_GET_ATTR
,
191 /* send command to mc*/
192 err
= mc_send_command(mc_io
, &cmd
);
196 /* retrieve response parameters */
197 DPNI_RSP_GET_ATTR(cmd
, attr
);
202 int dpni_set_errors_behavior(struct fsl_mc_io
*mc_io
,
205 struct dpni_error_cfg
*cfg
)
207 struct mc_command cmd
= { 0 };
209 /* prepare command */
210 cmd
.header
= mc_encode_cmd_header(DPNI_CMDID_SET_ERRORS_BEHAVIOR
,
213 DPNI_CMD_SET_ERRORS_BEHAVIOR(cmd
, cfg
);
215 /* send command to mc*/
216 return mc_send_command(mc_io
, &cmd
);
219 int dpni_set_buffer_layout(struct fsl_mc_io
*mc_io
,
222 const struct dpni_buffer_layout
*layout
,
223 enum dpni_queue_type type
)
225 struct mc_command cmd
= { 0 };
227 /* prepare command */
228 cmd
.header
= mc_encode_cmd_header(DPNI_CMDID_SET_BUFFER_LAYOUT
,
231 DPNI_CMD_SET_BUFFER_LAYOUT(cmd
, layout
, type
);
233 /* send command to mc*/
234 return mc_send_command(mc_io
, &cmd
);
237 int dpni_get_qdid(struct fsl_mc_io
*mc_io
,
242 struct mc_command cmd
= { 0 };
245 /* prepare command */
246 cmd
.header
= mc_encode_cmd_header(DPNI_CMDID_GET_QDID
,
250 /* send command to mc*/
251 err
= mc_send_command(mc_io
, &cmd
);
255 /* retrieve response parameters */
256 DPNI_RSP_GET_QDID(cmd
, *qdid
);
261 int dpni_get_tx_data_offset(struct fsl_mc_io
*mc_io
,
264 uint16_t *data_offset
)
266 struct mc_command cmd
= { 0 };
269 /* prepare command */
270 cmd
.header
= mc_encode_cmd_header(DPNI_CMDID_GET_TX_DATA_OFFSET
,
274 /* send command to mc*/
275 err
= mc_send_command(mc_io
, &cmd
);
279 /* retrieve response parameters */
280 DPNI_RSP_GET_TX_DATA_OFFSET(cmd
, *data_offset
);
285 int dpni_set_link_cfg(struct fsl_mc_io
*mc_io
,
288 const struct dpni_link_cfg
*cfg
)
290 struct mc_command cmd
= { 0 };
292 /* prepare command */
293 cmd
.header
= mc_encode_cmd_header(DPNI_CMDID_SET_LINK_CFG
,
296 DPNI_CMD_SET_LINK_CFG(cmd
, cfg
);
298 /* send command to mc*/
299 return mc_send_command(mc_io
, &cmd
);
302 int dpni_get_link_state(struct fsl_mc_io
*mc_io
,
305 struct dpni_link_state
*state
)
307 struct mc_command cmd
= { 0 };
310 /* prepare command */
311 cmd
.header
= mc_encode_cmd_header(DPNI_CMDID_GET_LINK_STATE
,
315 /* send command to mc*/
316 err
= mc_send_command(mc_io
, &cmd
);
320 /* retrieve response parameters */
321 DPNI_RSP_GET_LINK_STATE(cmd
, state
);
327 int dpni_set_primary_mac_addr(struct fsl_mc_io
*mc_io
,
330 const uint8_t mac_addr
[6])
332 struct mc_command cmd
= { 0 };
334 /* prepare command */
335 cmd
.header
= mc_encode_cmd_header(DPNI_CMDID_SET_PRIM_MAC
,
338 DPNI_CMD_SET_PRIMARY_MAC_ADDR(cmd
, mac_addr
);
340 /* send command to mc*/
341 return mc_send_command(mc_io
, &cmd
);
344 int dpni_get_primary_mac_addr(struct fsl_mc_io
*mc_io
,
349 struct mc_command cmd
= { 0 };
352 /* prepare command */
353 cmd
.header
= mc_encode_cmd_header(DPNI_CMDID_GET_PRIM_MAC
,
357 /* send command to mc*/
358 err
= mc_send_command(mc_io
, &cmd
);
362 /* retrieve response parameters */
363 DPNI_RSP_GET_PRIMARY_MAC_ADDR(cmd
, mac_addr
);
368 int dpni_add_mac_addr(struct fsl_mc_io
*mc_io
,
371 const uint8_t mac_addr
[6])
373 struct mc_command cmd
= { 0 };
375 /* prepare command */
376 cmd
.header
= mc_encode_cmd_header(DPNI_CMDID_ADD_MAC_ADDR
,
379 DPNI_CMD_ADD_MAC_ADDR(cmd
, mac_addr
);
381 /* send command to mc*/
382 return mc_send_command(mc_io
, &cmd
);
385 int dpni_remove_mac_addr(struct fsl_mc_io
*mc_io
,
388 const uint8_t mac_addr
[6])
390 struct mc_command cmd
= { 0 };
392 /* prepare command */
393 cmd
.header
= mc_encode_cmd_header(DPNI_CMDID_REMOVE_MAC_ADDR
,
396 DPNI_CMD_REMOVE_MAC_ADDR(cmd
, mac_addr
);
398 /* send command to mc*/
399 return mc_send_command(mc_io
, &cmd
);
402 int dpni_get_api_version(struct fsl_mc_io
*mc_io
,
407 struct mc_command cmd
= { 0 };
410 /* prepare command */
411 cmd
.header
= mc_encode_cmd_header(DPNI_CMDID_GET_API_VERSION
,
414 /* send command to mc */
415 err
= mc_send_command(mc_io
, &cmd
);
419 /* retrieve response parameters */
420 mc_cmd_read_api_version(&cmd
, major_ver
, minor_ver
);
425 int dpni_set_queue(struct fsl_mc_io
*mc_io
,
428 enum dpni_queue_type type
,
431 const struct dpni_queue
*queue
)
433 struct mc_command cmd
= { 0 };
434 /* prepare command */
435 cmd
.header
= mc_encode_cmd_header(DPNI_CMDID_SET_QUEUE
,
438 DPNI_CMD_SET_QUEUE(cmd
, type
, tc
, index
, queue
);
440 /* send command to mc*/
441 return mc_send_command(mc_io
, &cmd
);
444 int dpni_get_queue(struct fsl_mc_io
*mc_io
,
447 enum dpni_queue_type type
,
450 struct dpni_queue
*queue
)
452 struct mc_command cmd
= { 0 };
455 /* prepare command */
456 cmd
.header
= mc_encode_cmd_header(DPNI_CMDID_GET_QUEUE
,
459 DPNI_CMD_GET_QUEUE(cmd
, type
, tc
, index
);
461 /* send command to mc*/
462 err
= mc_send_command(mc_io
, &cmd
);
466 /* retrieve response parameters */
467 DPNI_RSP_GET_QUEUE(cmd
, queue
);
471 int dpni_set_tx_confirmation_mode(struct fsl_mc_io
*mc_io
,
474 enum dpni_confirmation_mode mode
)
476 struct dpni_tx_confirmation_mode
*cmd_params
;
477 struct mc_command cmd
= { 0 };
479 /* prepare command */
480 cmd
.header
= mc_encode_cmd_header(DPNI_CMDID_SET_TX_CONFIRMATION_MODE
,
484 cmd_params
= (struct dpni_tx_confirmation_mode
*)cmd
.params
;
485 cmd_params
->confirmation_mode
= mode
;
487 /* send command to mc*/
488 return mc_send_command(mc_io
, &cmd
);
491 int dpni_get_statistics(struct fsl_mc_io
*mc_io
,
495 struct dpni_statistics
*stat
)
497 struct mc_command cmd
= { 0 };
500 /* prepare command */
501 cmd
.header
= mc_encode_cmd_header(DPNI_CMDID_GET_STATISTICS
,
503 DPNI_CMD_GET_STATISTICS(cmd
, page
);
505 /* send command to mc*/
506 err
= mc_send_command(mc_io
, &cmd
);
510 /* retrieve response parameters */
511 DPNI_RSP_GET_STATISTICS(cmd
, stat
);
516 int dpni_reset_statistics(struct fsl_mc_io
*mc_io
,
520 struct mc_command cmd
= { 0 };
522 /* prepare command */
523 cmd
.header
= mc_encode_cmd_header(DPNI_CMDID_RESET_STATISTICS
,
526 /* send command to mc*/
527 return mc_send_command(mc_io
, &cmd
);