1 /* SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0)
3 * Copyright 2013-2016 Freescale Semiconductor Inc.
4 * Copyright 2018-2021 NXP
7 #include <fsl_mc_sys.h>
8 #include <fsl_mc_cmd.h>
9 #include <fsl_dpdmux.h>
10 #include <fsl_dpdmux_cmd.h>
12 /** @addtogroup dpdmux
17 * dpdmux_open() - Open a control session for the specified object
18 * @mc_io: Pointer to MC portal's I/O object
19 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
20 * @dpdmux_id: DPDMUX unique ID
21 * @token: Returned token; use in subsequent API calls
23 * This function can be used to open a control session for an
24 * already created object; an object may have been declared in
25 * the DPL or by calling the dpdmux_create() function.
26 * This function returns a unique authentication token,
27 * associated with the specific object ID and the specific MC
28 * portal; this token must be used in all subsequent commands for
29 * this specific object.
31 * Return: '0' on Success; Error code otherwise.
33 int dpdmux_open(struct fsl_mc_io *mc_io,
38 struct mc_command cmd = { 0 };
39 struct dpdmux_cmd_open *cmd_params;
43 cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_OPEN,
46 cmd_params = (struct dpdmux_cmd_open *)cmd.params;
47 cmd_params->dpdmux_id = cpu_to_le32(dpdmux_id);
49 /* send command to mc*/
50 err = mc_send_command(mc_io, &cmd);
54 /* retrieve response parameters */
55 *token = mc_cmd_hdr_read_token(&cmd);
61 * dpdmux_close() - Close the control session of the object
62 * @mc_io: Pointer to MC portal's I/O object
63 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
64 * @token: Token of DPDMUX object
66 * After this function is called, no further operations are
67 * allowed on the object without opening a new control session.
69 * Return: '0' on Success; Error code otherwise.
71 int dpdmux_close(struct fsl_mc_io *mc_io,
75 struct mc_command cmd = { 0 };
78 cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_CLOSE,
82 /* send command to mc*/
83 return mc_send_command(mc_io, &cmd);
87 * dpdmux_create() - Create the DPDMUX object
88 * @mc_io: Pointer to MC portal's I/O object
89 * @dprc_token: Parent container token; '0' for default container
90 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
91 * @cfg: Configuration structure
92 * @obj_id: returned object id
94 * Create the DPDMUX object, allocate required resources and
95 * perform required initialization.
97 * The object can be created either by declaring it in the
98 * DPL file, or by calling this function.
100 * The function accepts an authentication token of a parent
101 * container that this object should be assigned to. The token
102 * can be '0' so the object will be assigned to the default container.
103 * The newly created object can be opened with the returned
104 * object id and using the container's associated tokens and MC portals.
106 * Return: '0' on Success; Error code otherwise.
108 int dpdmux_create(struct fsl_mc_io *mc_io,
111 const struct dpdmux_cfg *cfg,
114 struct mc_command cmd = { 0 };
115 struct dpdmux_cmd_create *cmd_params;
118 /* prepare command */
119 cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_CREATE,
122 cmd_params = (struct dpdmux_cmd_create *)cmd.params;
123 cmd_params->method = cfg->method;
124 cmd_params->manip = cfg->manip;
125 cmd_params->num_ifs = cpu_to_le16(cfg->num_ifs);
126 cmd_params->default_if = cpu_to_le16(cfg->default_if);
127 cmd_params->adv_max_dmat_entries =
128 cpu_to_le16(cfg->adv.max_dmat_entries);
129 cmd_params->adv_max_mc_groups = cpu_to_le16(cfg->adv.max_mc_groups);
130 cmd_params->adv_max_vlan_ids = cpu_to_le16(cfg->adv.max_vlan_ids);
131 cmd_params->mem_size = cpu_to_le16(cfg->adv.mem_size);
132 cmd_params->options = cpu_to_le64(cfg->adv.options);
134 /* send command to mc*/
135 err = mc_send_command(mc_io, &cmd);
139 /* retrieve response parameters */
140 *obj_id = mc_cmd_read_object_id(&cmd);
146 * dpdmux_destroy() - Destroy the DPDMUX object and release all its resources.
147 * @mc_io: Pointer to MC portal's I/O object
148 * @dprc_token: Parent container token; '0' for default container
149 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
150 * @object_id: The object id; it must be a valid id within the container that
151 * created this object;
153 * The function accepts the authentication token of the parent container that
154 * created the object (not the one that currently owns the object). The object
155 * is searched within parent using the provided 'object_id'.
156 * All tokens to the object must be closed before calling destroy.
158 * Return: '0' on Success; error code otherwise.
160 int dpdmux_destroy(struct fsl_mc_io *mc_io,
165 struct mc_command cmd = { 0 };
166 struct dpdmux_cmd_destroy *cmd_params;
168 /* prepare command */
169 cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_DESTROY,
172 cmd_params = (struct dpdmux_cmd_destroy *)cmd.params;
173 cmd_params->dpdmux_id = cpu_to_le32(object_id);
175 /* send command to mc*/
176 return mc_send_command(mc_io, &cmd);
180 * dpdmux_enable() - Enable DPDMUX functionality
181 * @mc_io: Pointer to MC portal's I/O object
182 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
183 * @token: Token of DPDMUX object
185 * Return: '0' on Success; Error code otherwise.
187 int dpdmux_enable(struct fsl_mc_io *mc_io,
191 struct mc_command cmd = { 0 };
193 /* prepare command */
194 cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_ENABLE,
198 /* send command to mc*/
199 return mc_send_command(mc_io, &cmd);
203 * dpdmux_disable() - Disable DPDMUX functionality
204 * @mc_io: Pointer to MC portal's I/O object
205 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
206 * @token: Token of DPDMUX object
208 * Return: '0' on Success; Error code otherwise.
210 int dpdmux_disable(struct fsl_mc_io *mc_io,
214 struct mc_command cmd = { 0 };
216 /* prepare command */
217 cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_DISABLE,
221 /* send command to mc*/
222 return mc_send_command(mc_io, &cmd);
226 * dpdmux_is_enabled() - Check if the DPDMUX is enabled.
227 * @mc_io: Pointer to MC portal's I/O object
228 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
229 * @token: Token of DPDMUX object
230 * @en: Returns '1' if object is enabled; '0' otherwise
232 * Return: '0' on Success; Error code otherwise.
234 int dpdmux_is_enabled(struct fsl_mc_io *mc_io,
239 struct mc_command cmd = { 0 };
240 struct dpdmux_rsp_is_enabled *rsp_params;
243 /* prepare command */
244 cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_IS_ENABLED,
248 /* send command to mc*/
249 err = mc_send_command(mc_io, &cmd);
253 /* retrieve response parameters */
254 rsp_params = (struct dpdmux_rsp_is_enabled *)cmd.params;
255 *en = dpdmux_get_field(rsp_params->en, ENABLE);
261 * dpdmux_reset() - Reset the DPDMUX, returns the object to initial state.
262 * @mc_io: Pointer to MC portal's I/O object
263 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
264 * @token: Token of DPDMUX object
266 * Return: '0' on Success; Error code otherwise.
268 int dpdmux_reset(struct fsl_mc_io *mc_io,
272 struct mc_command cmd = { 0 };
274 /* prepare command */
275 cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_RESET,
279 /* send command to mc*/
280 return mc_send_command(mc_io, &cmd);
284 * dpdmux_set_resetable() - Set overall resetable DPDMUX parameters.
285 * @mc_io: Pointer to MC portal's I/O object
286 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
287 * @token: Token of DPDMUX object
288 * @skip_reset_flags: By default all are 0.
289 * By setting 1 will deactivate the reset.
291 * DPDMUX_SKIP_DEFAULT_INTERFACE 0x01
292 * DPDMUX_SKIP_UNICAST_RULES 0x02
293 * DPDMUX_SKIP_MULTICAST_RULES 0x04
295 * For example, by default, through DPDMUX_RESET the default
296 * interface will be restored with the one from create.
297 * By setting DPDMUX_SKIP_DEFAULT_INTERFACE flag,
298 * through DPDMUX_RESET the default interface will not be modified.
300 * Return: '0' on Success; Error code otherwise.
302 int dpdmux_set_resetable(struct fsl_mc_io *mc_io,
305 uint8_t skip_reset_flags)
307 struct mc_command cmd = { 0 };
308 struct dpdmux_cmd_set_skip_reset_flags *cmd_params;
310 /* prepare command */
311 cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_SET_RESETABLE,
314 cmd_params = (struct dpdmux_cmd_set_skip_reset_flags *)cmd.params;
315 dpdmux_set_field(cmd_params->skip_reset_flags,
319 /* send command to mc*/
320 return mc_send_command(mc_io, &cmd);
324 * dpdmux_get_resetable() - Get overall resetable parameters.
325 * @mc_io: Pointer to MC portal's I/O object
326 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
327 * @token: Token of DPDMUX object
328 * @skip_reset_flags: Get the reset flags.
331 * DPDMUX_SKIP_DEFAULT_INTERFACE 0x01
332 * DPDMUX_SKIP_UNICAST_RULES 0x02
333 * DPDMUX_SKIP_MULTICAST_RULES 0x04
335 * Return: '0' on Success; Error code otherwise.
337 int dpdmux_get_resetable(struct fsl_mc_io *mc_io,
340 uint8_t *skip_reset_flags)
342 struct mc_command cmd = { 0 };
343 struct dpdmux_rsp_get_skip_reset_flags *rsp_params;
346 /* prepare command */
347 cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_GET_RESETABLE,
351 /* send command to mc*/
352 err = mc_send_command(mc_io, &cmd);
356 /* retrieve response parameters */
357 rsp_params = (struct dpdmux_rsp_get_skip_reset_flags *)cmd.params;
358 *skip_reset_flags = dpdmux_get_field(rsp_params->skip_reset_flags,
365 * dpdmux_get_attributes() - Retrieve DPDMUX attributes
366 * @mc_io: Pointer to MC portal's I/O object
367 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
368 * @token: Token of DPDMUX object
369 * @attr: Returned object's attributes
371 * Return: '0' on Success; Error code otherwise.
373 int dpdmux_get_attributes(struct fsl_mc_io *mc_io,
376 struct dpdmux_attr *attr)
378 struct mc_command cmd = { 0 };
379 struct dpdmux_rsp_get_attr *rsp_params;
382 /* prepare command */
383 cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_GET_ATTR,
387 /* send command to mc*/
388 err = mc_send_command(mc_io, &cmd);
392 /* retrieve response parameters */
393 rsp_params = (struct dpdmux_rsp_get_attr *)cmd.params;
394 attr->id = le32_to_cpu(rsp_params->id);
395 attr->options = le64_to_cpu(rsp_params->options);
396 attr->method = rsp_params->method;
397 attr->manip = rsp_params->manip;
398 attr->num_ifs = le16_to_cpu(rsp_params->num_ifs);
399 attr->mem_size = le16_to_cpu(rsp_params->mem_size);
400 attr->default_if = le16_to_cpu(rsp_params->default_if);
406 * dpdmux_if_enable() - Enable Interface
407 * @mc_io: Pointer to MC portal's I/O object
408 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
409 * @token: Token of DPDMUX object
410 * @if_id: Interface Identifier
412 * Return: Completion status. '0' on Success; Error code otherwise.
414 int dpdmux_if_enable(struct fsl_mc_io *mc_io,
419 struct dpdmux_cmd_if *cmd_params;
420 struct mc_command cmd = { 0 };
422 /* prepare command */
423 cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_IF_ENABLE,
426 cmd_params = (struct dpdmux_cmd_if *)cmd.params;
427 cmd_params->if_id = cpu_to_le16(if_id);
429 /* send command to mc*/
430 return mc_send_command(mc_io, &cmd);
434 * dpdmux_if_disable() - Disable Interface
435 * @mc_io: Pointer to MC portal's I/O object
436 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
437 * @token: Token of DPDMUX object
438 * @if_id: Interface Identifier
440 * Return: Completion status. '0' on Success; Error code otherwise.
442 int dpdmux_if_disable(struct fsl_mc_io *mc_io,
447 struct dpdmux_cmd_if *cmd_params;
448 struct mc_command cmd = { 0 };
450 /* prepare command */
451 cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_IF_DISABLE,
454 cmd_params = (struct dpdmux_cmd_if *)cmd.params;
455 cmd_params->if_id = cpu_to_le16(if_id);
457 /* send command to mc*/
458 return mc_send_command(mc_io, &cmd);
462 * dpdmux_set_max_frame_length() - Set the maximum frame length in DPDMUX
463 * @mc_io: Pointer to MC portal's I/O object
464 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
465 * @token: Token of DPDMUX object
466 * @max_frame_length: The required maximum frame length
468 * Update the maximum frame length on all DMUX interfaces.
469 * In case of VEPA, the maximum frame length on all dmux interfaces
470 * will be updated with the minimum value of the mfls of the connected
471 * dpnis and the actual value of dmux mfl.
473 * Return: '0' on Success; Error code otherwise.
475 int dpdmux_set_max_frame_length(struct fsl_mc_io *mc_io,
478 uint16_t max_frame_length)
480 struct mc_command cmd = { 0 };
481 struct dpdmux_cmd_set_max_frame_length *cmd_params;
483 /* prepare command */
484 cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_SET_MAX_FRAME_LENGTH,
487 cmd_params = (struct dpdmux_cmd_set_max_frame_length *)cmd.params;
488 cmd_params->max_frame_length = cpu_to_le16(max_frame_length);
490 /* send command to mc*/
491 return mc_send_command(mc_io, &cmd);
495 * dpdmux_ul_reset_counters() - Function resets the uplink counter
496 * @mc_io: Pointer to MC portal's I/O object
497 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
498 * @token: Token of DPDMUX object
500 * Return: '0' on Success; Error code otherwise.
502 int dpdmux_ul_reset_counters(struct fsl_mc_io *mc_io,
506 struct mc_command cmd = { 0 };
508 /* prepare command */
509 cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_UL_RESET_COUNTERS,
513 /* send command to mc*/
514 return mc_send_command(mc_io, &cmd);
518 * dpdmux_if_set_accepted_frames() - Set the accepted frame types
519 * @mc_io: Pointer to MC portal's I/O object
520 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
521 * @token: Token of DPDMUX object
522 * @if_id: Interface ID (0 for uplink, or 1-num_ifs);
523 * @cfg: Frame types configuration
525 * if 'DPDMUX_ADMIT_ONLY_VLAN_TAGGED' is set - untagged frames or
526 * priority-tagged frames are discarded.
527 * if 'DPDMUX_ADMIT_ONLY_UNTAGGED' is set - untagged frames or
528 * priority-tagged frames are accepted.
529 * if 'DPDMUX_ADMIT_ALL' is set (default mode) - all VLAN tagged,
530 * untagged and priority-tagged frame are accepted;
532 * Return: '0' on Success; Error code otherwise.
534 int dpdmux_if_set_accepted_frames(struct fsl_mc_io *mc_io,
538 const struct dpdmux_accepted_frames *cfg)
540 struct mc_command cmd = { 0 };
541 struct dpdmux_cmd_if_set_accepted_frames *cmd_params;
543 /* prepare command */
544 cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_IF_SET_ACCEPTED_FRAMES,
547 cmd_params = (struct dpdmux_cmd_if_set_accepted_frames *)cmd.params;
548 cmd_params->if_id = cpu_to_le16(if_id);
549 dpdmux_set_field(cmd_params->frames_options,
550 ACCEPTED_FRAMES_TYPE,
552 dpdmux_set_field(cmd_params->frames_options,
553 UNACCEPTED_FRAMES_ACTION,
556 /* send command to mc*/
557 return mc_send_command(mc_io, &cmd);
561 * dpdmux_if_get_attributes() - Obtain DPDMUX interface attributes
562 * @mc_io: Pointer to MC portal's I/O object
563 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
564 * @token: Token of DPDMUX object
565 * @if_id: Interface ID (0 for uplink, or 1-num_ifs);
566 * @attr: Interface attributes
568 * Return: '0' on Success; Error code otherwise.
570 int dpdmux_if_get_attributes(struct fsl_mc_io *mc_io,
574 struct dpdmux_if_attr *attr)
576 struct mc_command cmd = { 0 };
577 struct dpdmux_cmd_if *cmd_params;
578 struct dpdmux_rsp_if_get_attr *rsp_params;
581 /* prepare command */
582 cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_IF_GET_ATTR,
585 cmd_params = (struct dpdmux_cmd_if *)cmd.params;
586 cmd_params->if_id = cpu_to_le16(if_id);
588 /* send command to mc*/
589 err = mc_send_command(mc_io, &cmd);
593 /* retrieve response parameters */
594 rsp_params = (struct dpdmux_rsp_if_get_attr *)cmd.params;
595 attr->rate = le32_to_cpu(rsp_params->rate);
596 attr->enabled = dpdmux_get_field(rsp_params->enabled, ENABLE);
597 attr->is_default = dpdmux_get_field(rsp_params->enabled, IS_DEFAULT);
598 attr->accept_frame_type = dpdmux_get_field(
599 rsp_params->accepted_frames_type,
600 ACCEPTED_FRAMES_TYPE);
606 * dpdmux_if_remove_l2_rule() - Remove L2 rule from DPDMUX table
607 * @mc_io: Pointer to MC portal's I/O object
608 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
609 * @token: Token of DPDMUX object
610 * @if_id: Destination interface ID
613 * Function removes a L2 rule from DPDMUX table
614 * or adds an interface to an existing multicast address
616 * Return: '0' on Success; Error code otherwise.
618 int dpdmux_if_remove_l2_rule(struct fsl_mc_io *mc_io,
622 const struct dpdmux_l2_rule *rule)
624 struct mc_command cmd = { 0 };
625 struct dpdmux_cmd_if_l2_rule *cmd_params;
627 /* prepare command */
628 cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_IF_REMOVE_L2_RULE,
631 cmd_params = (struct dpdmux_cmd_if_l2_rule *)cmd.params;
632 cmd_params->if_id = cpu_to_le16(if_id);
633 cmd_params->vlan_id = cpu_to_le16(rule->vlan_id);
634 cmd_params->mac_addr5 = rule->mac_addr[5];
635 cmd_params->mac_addr4 = rule->mac_addr[4];
636 cmd_params->mac_addr3 = rule->mac_addr[3];
637 cmd_params->mac_addr2 = rule->mac_addr[2];
638 cmd_params->mac_addr1 = rule->mac_addr[1];
639 cmd_params->mac_addr0 = rule->mac_addr[0];
641 /* send command to mc*/
642 return mc_send_command(mc_io, &cmd);
646 * dpdmux_if_add_l2_rule() - Add L2 rule into DPDMUX table
647 * @mc_io: Pointer to MC portal's I/O object
648 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
649 * @token: Token of DPDMUX object
650 * @if_id: Destination interface ID
653 * Function adds a L2 rule into DPDMUX table
654 * or adds an interface to an existing multicast address
656 * Return: '0' on Success; Error code otherwise.
658 int dpdmux_if_add_l2_rule(struct fsl_mc_io *mc_io,
662 const struct dpdmux_l2_rule *rule)
664 struct mc_command cmd = { 0 };
665 struct dpdmux_cmd_if_l2_rule *cmd_params;
667 /* prepare command */
668 cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_IF_ADD_L2_RULE,
671 cmd_params = (struct dpdmux_cmd_if_l2_rule *)cmd.params;
672 cmd_params->if_id = cpu_to_le16(if_id);
673 cmd_params->vlan_id = cpu_to_le16(rule->vlan_id);
674 cmd_params->mac_addr5 = rule->mac_addr[5];
675 cmd_params->mac_addr4 = rule->mac_addr[4];
676 cmd_params->mac_addr3 = rule->mac_addr[3];
677 cmd_params->mac_addr2 = rule->mac_addr[2];
678 cmd_params->mac_addr1 = rule->mac_addr[1];
679 cmd_params->mac_addr0 = rule->mac_addr[0];
681 /* send command to mc*/
682 return mc_send_command(mc_io, &cmd);
686 * dpdmux_if_get_counter() - Functions obtains specific counter of an interface
687 * @mc_io: Pointer to MC portal's I/O object
688 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
689 * @token: Token of DPDMUX object
690 * @if_id: Interface Id
691 * @counter_type: counter type
692 * @counter: Returned specific counter information
694 * Return: '0' on Success; Error code otherwise.
696 int dpdmux_if_get_counter(struct fsl_mc_io *mc_io,
700 enum dpdmux_counter_type counter_type,
703 struct mc_command cmd = { 0 };
704 struct dpdmux_cmd_if_get_counter *cmd_params;
705 struct dpdmux_rsp_if_get_counter *rsp_params;
708 /* prepare command */
709 cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_IF_GET_COUNTER,
712 cmd_params = (struct dpdmux_cmd_if_get_counter *)cmd.params;
713 cmd_params->if_id = cpu_to_le16(if_id);
714 cmd_params->counter_type = counter_type;
716 /* send command to mc*/
717 err = mc_send_command(mc_io, &cmd);
721 /* retrieve response parameters */
722 rsp_params = (struct dpdmux_rsp_if_get_counter *)cmd.params;
723 *counter = le64_to_cpu(rsp_params->counter);
729 * dpdmux_if_set_link_cfg() - set the link configuration.
730 * @mc_io: Pointer to MC portal's I/O object
731 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
732 * @token: Token of DPSW object
733 * @if_id: interface id
734 * @cfg: Link configuration
736 * Return: '0' on Success; Error code otherwise.
738 int dpdmux_if_set_link_cfg(struct fsl_mc_io *mc_io,
742 struct dpdmux_link_cfg *cfg)
744 struct mc_command cmd = { 0 };
745 struct dpdmux_cmd_if_set_link_cfg *cmd_params;
747 /* prepare command */
748 cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_IF_SET_LINK_CFG,
751 cmd_params = (struct dpdmux_cmd_if_set_link_cfg *)cmd.params;
752 cmd_params->if_id = cpu_to_le16(if_id);
753 cmd_params->rate = cpu_to_le32(cfg->rate);
754 cmd_params->options = cpu_to_le64(cfg->options);
755 cmd_params->advertising = cpu_to_le64(cfg->advertising);
757 /* send command to mc*/
758 return mc_send_command(mc_io, &cmd);
762 * dpdmux_if_get_link_state - Return the link state
763 * @mc_io: Pointer to MC portal's I/O object
764 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
765 * @token: Token of DPSW object
766 * @if_id: interface id
769 * @returns '0' on Success; Error code otherwise.
771 int dpdmux_if_get_link_state(struct fsl_mc_io *mc_io,
775 struct dpdmux_link_state *state)
777 struct mc_command cmd = { 0 };
778 struct dpdmux_cmd_if_get_link_state *cmd_params;
779 struct dpdmux_rsp_if_get_link_state *rsp_params;
782 /* prepare command */
783 cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_IF_GET_LINK_STATE,
786 cmd_params = (struct dpdmux_cmd_if_get_link_state *)cmd.params;
787 cmd_params->if_id = cpu_to_le16(if_id);
789 /* send command to mc*/
790 err = mc_send_command(mc_io, &cmd);
794 /* retrieve response parameters */
795 rsp_params = (struct dpdmux_rsp_if_get_link_state *)cmd.params;
796 state->rate = le32_to_cpu(rsp_params->rate);
797 state->options = le64_to_cpu(rsp_params->options);
798 state->up = dpdmux_get_field(rsp_params->up, UP);
799 state->state_valid = dpdmux_get_field(rsp_params->up, STATE_VALID);
800 state->supported = le64_to_cpu(rsp_params->supported);
801 state->advertising = le64_to_cpu(rsp_params->advertising);
807 * dpdmux_if_set_default - Set default interface
808 * @mc_io: Pointer to MC portal's I/O object
809 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
810 * @token: Token of DPSW object
811 * @if_id: interface id
813 * @returns '0' on Success; Error code otherwise.
815 int dpdmux_if_set_default(struct fsl_mc_io *mc_io,
820 struct dpdmux_cmd_if *cmd_params;
821 struct mc_command cmd = { 0 };
823 /* prepare command */
824 cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_IF_SET_DEFAULT,
827 cmd_params = (struct dpdmux_cmd_if *)cmd.params;
828 cmd_params->if_id = cpu_to_le16(if_id);
830 /* send command to mc*/
831 return mc_send_command(mc_io, &cmd);
835 * dpdmux_if_get_default - Get default interface
836 * @mc_io: Pointer to MC portal's I/O object
837 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
838 * @token: Token of DPSW object
839 * @if_id: interface id
841 * @returns '0' on Success; Error code otherwise.
843 int dpdmux_if_get_default(struct fsl_mc_io *mc_io,
848 struct dpdmux_cmd_if *rsp_params;
849 struct mc_command cmd = { 0 };
852 /* prepare command */
853 cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_IF_GET_DEFAULT,
857 /* send command to mc*/
858 err = mc_send_command(mc_io, &cmd);
862 /* retrieve response parameters */
863 rsp_params = (struct dpdmux_cmd_if *)cmd.params;
864 *if_id = le16_to_cpu(rsp_params->if_id);
870 * dpdmux_set_custom_key - Set a custom classification key.
872 * This API is only available for DPDMUX instance created with
873 * DPDMUX_METHOD_CUSTOM. This API must be called before populating the
874 * classification table using dpdmux_add_custom_cls_entry.
876 * Calls to dpdmux_set_custom_key remove all existing classification entries
877 * that may have been added previously using dpdmux_add_custom_cls_entry.
879 * @mc_io: Pointer to MC portal's I/O object
880 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
881 * @token: Token of DPSW object
882 * @if_id: Interface id
883 * @key_cfg_iova: DMA address of a configuration structure set up using
884 * dpkg_prepare_key_cfg. Maximum key size is 24 bytes
886 * @returns '0' on Success; Error code otherwise.
888 int dpdmux_set_custom_key(struct fsl_mc_io *mc_io,
891 uint64_t key_cfg_iova)
893 struct dpdmux_set_custom_key *cmd_params;
894 struct mc_command cmd = { 0 };
896 /* prepare command */
897 cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_SET_CUSTOM_KEY,
900 cmd_params = (struct dpdmux_set_custom_key *)cmd.params;
901 cmd_params->key_cfg_iova = cpu_to_le64(key_cfg_iova);
903 /* send command to mc*/
904 return mc_send_command(mc_io, &cmd);
908 * dpdmux_add_custom_cls_entry - Adds a custom classification entry.
910 * This API is only available for DPDMUX instances created with
911 * DPDMUX_METHOD_CUSTOM. Before calling this function a classification key
912 * composition rule must be set up using dpdmux_set_custom_key.
914 * @mc_io: Pointer to MC portal's I/O object
915 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
916 * @token: Token of DPSW object
917 * @rule: Classification rule to insert. Rules cannot be duplicated, if a
918 * matching rule already exists, the action will be replaced.
919 * @action: Action to perform for matching traffic.
921 * @returns '0' on Success; Error code otherwise.
923 int dpdmux_add_custom_cls_entry(struct fsl_mc_io *mc_io,
926 struct dpdmux_rule_cfg *rule,
927 struct dpdmux_cls_action *action)
929 struct dpdmux_cmd_add_custom_cls_entry *cmd_params;
930 struct mc_command cmd = { 0 };
932 /* prepare command */
933 cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_ADD_CUSTOM_CLS_ENTRY,
937 cmd_params = (struct dpdmux_cmd_add_custom_cls_entry *)cmd.params;
938 cmd_params->key_size = rule->key_size;
939 cmd_params->entry_index = rule->entry_index;
940 cmd_params->dest_if = cpu_to_le16(action->dest_if);
941 cmd_params->key_iova = cpu_to_le64(rule->key_iova);
942 cmd_params->mask_iova = cpu_to_le64(rule->mask_iova);
944 /* send command to mc*/
945 return mc_send_command(mc_io, &cmd);
949 * dpdmux_remove_custom_cls_entry - Removes a custom classification entry.
951 * This API is only available for DPDMUX instances created with
952 * DPDMUX_METHOD_CUSTOM. The API can be used to remove classification
953 * entries previously inserted using dpdmux_add_custom_cls_entry.
955 * @mc_io: Pointer to MC portal's I/O object
956 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
957 * @token: Token of DPSW object
958 * @rule: Classification rule to remove
960 * @returns '0' on Success; Error code otherwise.
962 int dpdmux_remove_custom_cls_entry(struct fsl_mc_io *mc_io,
965 struct dpdmux_rule_cfg *rule)
967 struct dpdmux_cmd_remove_custom_cls_entry *cmd_params;
968 struct mc_command cmd = { 0 };
970 /* prepare command */
971 cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_REMOVE_CUSTOM_CLS_ENTRY,
974 cmd_params = (struct dpdmux_cmd_remove_custom_cls_entry *)cmd.params;
975 cmd_params->key_size = rule->key_size;
976 cmd_params->key_iova = cpu_to_le64(rule->key_iova);
977 cmd_params->mask_iova = cpu_to_le64(rule->mask_iova);
979 /* send command to mc*/
980 return mc_send_command(mc_io, &cmd);
984 * dpdmux_get_api_version() - Get Data Path Demux API version
985 * @mc_io: Pointer to MC portal's I/O object
986 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
987 * @major_ver: Major version of data path demux API
988 * @minor_ver: Minor version of data path demux API
990 * Return: '0' on Success; Error code otherwise.
992 int dpdmux_get_api_version(struct fsl_mc_io *mc_io,
997 struct mc_command cmd = { 0 };
998 struct dpdmux_rsp_get_api_version *rsp_params;
1001 cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_GET_API_VERSION,
1005 err = mc_send_command(mc_io, &cmd);
1009 rsp_params = (struct dpdmux_rsp_get_api_version *)cmd.params;
1010 *major_ver = le16_to_cpu(rsp_params->major);
1011 *minor_ver = le16_to_cpu(rsp_params->minor);
1017 * dpdmux_if_set_errors_behavior() - Set errors behavior
1018 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1019 * @token: Token of DPSW object
1020 * @if_id: Interface Identifier
1021 * @cfg: Errors configuration
1023 * Provides a set of frame errors that will be rejected or accepted by the
1024 * dpdmux interface. The frame with this errors will no longer be dropped by
1025 * the dpdmux interface. When frame has parsing error the distribution to
1026 * expected interface may fail. If the frame must be distributed using the
1027 * information from a header that was not parsed due errors the frame may
1028 * be discarded or end up on a default interface because needed data was not
1030 * This function may be called numerous times with different error masks
1032 * Return: '0' on Success; Error code otherwise.
1034 int dpdmux_if_set_errors_behavior(struct fsl_mc_io *mc_io, uint32_t cmd_flags,
1035 uint16_t token, uint16_t if_id, struct dpdmux_error_cfg *cfg)
1037 struct mc_command cmd = { 0 };
1038 struct dpdmux_cmd_set_errors_behavior *cmd_params;
1040 /* prepare command */
1041 cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_SET_ERRORS_BEHAVIOR,
1044 cmd_params = (struct dpdmux_cmd_set_errors_behavior *)cmd.params;
1045 cmd_params->errors = cpu_to_le32(cfg->errors);
1046 dpdmux_set_field(cmd_params->flags, ERROR_ACTION, cfg->error_action);
1047 cmd_params->if_id = cpu_to_le16(if_id);
1049 /* send command to mc*/
1050 return mc_send_command(mc_io, &cmd);