1 /* SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0)
3 * Copyright 2013-2016 Freescale Semiconductor Inc.
4 * Copyright 2018-2019 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
->adv_max_dmat_entries
=
127 cpu_to_le16(cfg
->adv
.max_dmat_entries
);
128 cmd_params
->adv_max_mc_groups
= cpu_to_le16(cfg
->adv
.max_mc_groups
);
129 cmd_params
->adv_max_vlan_ids
= cpu_to_le16(cfg
->adv
.max_vlan_ids
);
130 cmd_params
->options
= cpu_to_le64(cfg
->adv
.options
);
132 /* send command to mc*/
133 err
= mc_send_command(mc_io
, &cmd
);
137 /* retrieve response parameters */
138 *obj_id
= mc_cmd_read_object_id(&cmd
);
144 * dpdmux_destroy() - Destroy the DPDMUX object and release all its resources.
145 * @mc_io: Pointer to MC portal's I/O object
146 * @dprc_token: Parent container token; '0' for default container
147 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
148 * @object_id: The object id; it must be a valid id within the container that
149 * created this object;
151 * The function accepts the authentication token of the parent container that
152 * created the object (not the one that currently owns the object). The object
153 * is searched within parent using the provided 'object_id'.
154 * All tokens to the object must be closed before calling destroy.
156 * Return: '0' on Success; error code otherwise.
158 int dpdmux_destroy(struct fsl_mc_io
*mc_io
,
163 struct mc_command cmd
= { 0 };
164 struct dpdmux_cmd_destroy
*cmd_params
;
166 /* prepare command */
167 cmd
.header
= mc_encode_cmd_header(DPDMUX_CMDID_DESTROY
,
170 cmd_params
= (struct dpdmux_cmd_destroy
*)cmd
.params
;
171 cmd_params
->dpdmux_id
= cpu_to_le32(object_id
);
173 /* send command to mc*/
174 return mc_send_command(mc_io
, &cmd
);
178 * dpdmux_enable() - Enable DPDMUX functionality
179 * @mc_io: Pointer to MC portal's I/O object
180 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
181 * @token: Token of DPDMUX object
183 * Return: '0' on Success; Error code otherwise.
185 int dpdmux_enable(struct fsl_mc_io
*mc_io
,
189 struct mc_command cmd
= { 0 };
191 /* prepare command */
192 cmd
.header
= mc_encode_cmd_header(DPDMUX_CMDID_ENABLE
,
196 /* send command to mc*/
197 return mc_send_command(mc_io
, &cmd
);
201 * dpdmux_disable() - Disable DPDMUX functionality
202 * @mc_io: Pointer to MC portal's I/O object
203 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
204 * @token: Token of DPDMUX object
206 * Return: '0' on Success; Error code otherwise.
208 int dpdmux_disable(struct fsl_mc_io
*mc_io
,
212 struct mc_command cmd
= { 0 };
214 /* prepare command */
215 cmd
.header
= mc_encode_cmd_header(DPDMUX_CMDID_DISABLE
,
219 /* send command to mc*/
220 return mc_send_command(mc_io
, &cmd
);
224 * dpdmux_is_enabled() - Check if the DPDMUX is enabled.
225 * @mc_io: Pointer to MC portal's I/O object
226 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
227 * @token: Token of DPDMUX object
228 * @en: Returns '1' if object is enabled; '0' otherwise
230 * Return: '0' on Success; Error code otherwise.
232 int dpdmux_is_enabled(struct fsl_mc_io
*mc_io
,
237 struct mc_command cmd
= { 0 };
238 struct dpdmux_rsp_is_enabled
*rsp_params
;
241 /* prepare command */
242 cmd
.header
= mc_encode_cmd_header(DPDMUX_CMDID_IS_ENABLED
,
246 /* send command to mc*/
247 err
= mc_send_command(mc_io
, &cmd
);
251 /* retrieve response parameters */
252 rsp_params
= (struct dpdmux_rsp_is_enabled
*)cmd
.params
;
253 *en
= dpdmux_get_field(rsp_params
->en
, ENABLE
);
259 * dpdmux_reset() - Reset the DPDMUX, returns the object to initial state.
260 * @mc_io: Pointer to MC portal's I/O object
261 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
262 * @token: Token of DPDMUX object
264 * Return: '0' on Success; Error code otherwise.
266 int dpdmux_reset(struct fsl_mc_io
*mc_io
,
270 struct mc_command cmd
= { 0 };
272 /* prepare command */
273 cmd
.header
= mc_encode_cmd_header(DPDMUX_CMDID_RESET
,
277 /* send command to mc*/
278 return mc_send_command(mc_io
, &cmd
);
282 * dpdmux_get_attributes() - Retrieve DPDMUX attributes
283 * @mc_io: Pointer to MC portal's I/O object
284 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
285 * @token: Token of DPDMUX object
286 * @attr: Returned object's attributes
288 * Return: '0' on Success; Error code otherwise.
290 int dpdmux_get_attributes(struct fsl_mc_io
*mc_io
,
293 struct dpdmux_attr
*attr
)
295 struct mc_command cmd
= { 0 };
296 struct dpdmux_rsp_get_attr
*rsp_params
;
299 /* prepare command */
300 cmd
.header
= mc_encode_cmd_header(DPDMUX_CMDID_GET_ATTR
,
304 /* send command to mc*/
305 err
= mc_send_command(mc_io
, &cmd
);
309 /* retrieve response parameters */
310 rsp_params
= (struct dpdmux_rsp_get_attr
*)cmd
.params
;
311 attr
->id
= le32_to_cpu(rsp_params
->id
);
312 attr
->options
= le64_to_cpu(rsp_params
->options
);
313 attr
->method
= rsp_params
->method
;
314 attr
->manip
= rsp_params
->manip
;
315 attr
->num_ifs
= le16_to_cpu(rsp_params
->num_ifs
);
316 attr
->mem_size
= le16_to_cpu(rsp_params
->mem_size
);
322 * dpdmux_if_enable() - Enable Interface
323 * @mc_io: Pointer to MC portal's I/O object
324 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
325 * @token: Token of DPDMUX object
326 * @if_id: Interface Identifier
328 * Return: Completion status. '0' on Success; Error code otherwise.
330 int dpdmux_if_enable(struct fsl_mc_io
*mc_io
,
335 struct dpdmux_cmd_if
*cmd_params
;
336 struct mc_command cmd
= { 0 };
338 /* prepare command */
339 cmd
.header
= mc_encode_cmd_header(DPDMUX_CMDID_IF_ENABLE
,
342 cmd_params
= (struct dpdmux_cmd_if
*)cmd
.params
;
343 cmd_params
->if_id
= cpu_to_le16(if_id
);
345 /* send command to mc*/
346 return mc_send_command(mc_io
, &cmd
);
350 * dpdmux_if_disable() - Disable Interface
351 * @mc_io: Pointer to MC portal's I/O object
352 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
353 * @token: Token of DPDMUX object
354 * @if_id: Interface Identifier
356 * Return: Completion status. '0' on Success; Error code otherwise.
358 int dpdmux_if_disable(struct fsl_mc_io
*mc_io
,
363 struct dpdmux_cmd_if
*cmd_params
;
364 struct mc_command cmd
= { 0 };
366 /* prepare command */
367 cmd
.header
= mc_encode_cmd_header(DPDMUX_CMDID_IF_DISABLE
,
370 cmd_params
= (struct dpdmux_cmd_if
*)cmd
.params
;
371 cmd_params
->if_id
= cpu_to_le16(if_id
);
373 /* send command to mc*/
374 return mc_send_command(mc_io
, &cmd
);
378 * dpdmux_set_max_frame_length() - Set the maximum frame length in DPDMUX
379 * @mc_io: Pointer to MC portal's I/O object
380 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
381 * @token: Token of DPDMUX object
382 * @max_frame_length: The required maximum frame length
384 * Update the maximum frame length on all DMUX interfaces.
385 * In case of VEPA, the maximum frame length on all dmux interfaces
386 * will be updated with the minimum value of the mfls of the connected
387 * dpnis and the actual value of dmux mfl.
389 * Return: '0' on Success; Error code otherwise.
391 int dpdmux_set_max_frame_length(struct fsl_mc_io
*mc_io
,
394 uint16_t max_frame_length
)
396 struct mc_command cmd
= { 0 };
397 struct dpdmux_cmd_set_max_frame_length
*cmd_params
;
399 /* prepare command */
400 cmd
.header
= mc_encode_cmd_header(DPDMUX_CMDID_SET_MAX_FRAME_LENGTH
,
403 cmd_params
= (struct dpdmux_cmd_set_max_frame_length
*)cmd
.params
;
404 cmd_params
->max_frame_length
= cpu_to_le16(max_frame_length
);
406 /* send command to mc*/
407 return mc_send_command(mc_io
, &cmd
);
411 * dpdmux_ul_reset_counters() - Function resets the uplink counter
412 * @mc_io: Pointer to MC portal's I/O object
413 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
414 * @token: Token of DPDMUX object
416 * Return: '0' on Success; Error code otherwise.
418 int dpdmux_ul_reset_counters(struct fsl_mc_io
*mc_io
,
422 struct mc_command cmd
= { 0 };
424 /* prepare command */
425 cmd
.header
= mc_encode_cmd_header(DPDMUX_CMDID_UL_RESET_COUNTERS
,
429 /* send command to mc*/
430 return mc_send_command(mc_io
, &cmd
);
434 * dpdmux_if_set_accepted_frames() - Set the accepted frame types
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 ID (0 for uplink, or 1-num_ifs);
439 * @cfg: Frame types configuration
441 * if 'DPDMUX_ADMIT_ONLY_VLAN_TAGGED' is set - untagged frames or
442 * priority-tagged frames are discarded.
443 * if 'DPDMUX_ADMIT_ONLY_UNTAGGED' is set - untagged frames or
444 * priority-tagged frames are accepted.
445 * if 'DPDMUX_ADMIT_ALL' is set (default mode) - all VLAN tagged,
446 * untagged and priority-tagged frame are accepted;
448 * Return: '0' on Success; Error code otherwise.
450 int dpdmux_if_set_accepted_frames(struct fsl_mc_io
*mc_io
,
454 const struct dpdmux_accepted_frames
*cfg
)
456 struct mc_command cmd
= { 0 };
457 struct dpdmux_cmd_if_set_accepted_frames
*cmd_params
;
459 /* prepare command */
460 cmd
.header
= mc_encode_cmd_header(DPDMUX_CMDID_IF_SET_ACCEPTED_FRAMES
,
463 cmd_params
= (struct dpdmux_cmd_if_set_accepted_frames
*)cmd
.params
;
464 cmd_params
->if_id
= cpu_to_le16(if_id
);
465 dpdmux_set_field(cmd_params
->frames_options
,
466 ACCEPTED_FRAMES_TYPE
,
468 dpdmux_set_field(cmd_params
->frames_options
,
469 UNACCEPTED_FRAMES_ACTION
,
472 /* send command to mc*/
473 return mc_send_command(mc_io
, &cmd
);
477 * dpdmux_if_get_attributes() - Obtain DPDMUX interface attributes
478 * @mc_io: Pointer to MC portal's I/O object
479 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
480 * @token: Token of DPDMUX object
481 * @if_id: Interface ID (0 for uplink, or 1-num_ifs);
482 * @attr: Interface attributes
484 * Return: '0' on Success; Error code otherwise.
486 int dpdmux_if_get_attributes(struct fsl_mc_io
*mc_io
,
490 struct dpdmux_if_attr
*attr
)
492 struct mc_command cmd
= { 0 };
493 struct dpdmux_cmd_if
*cmd_params
;
494 struct dpdmux_rsp_if_get_attr
*rsp_params
;
497 /* prepare command */
498 cmd
.header
= mc_encode_cmd_header(DPDMUX_CMDID_IF_GET_ATTR
,
501 cmd_params
= (struct dpdmux_cmd_if
*)cmd
.params
;
502 cmd_params
->if_id
= cpu_to_le16(if_id
);
504 /* send command to mc*/
505 err
= mc_send_command(mc_io
, &cmd
);
509 /* retrieve response parameters */
510 rsp_params
= (struct dpdmux_rsp_if_get_attr
*)cmd
.params
;
511 attr
->rate
= le32_to_cpu(rsp_params
->rate
);
512 attr
->enabled
= dpdmux_get_field(rsp_params
->enabled
, ENABLE
);
513 attr
->is_default
= dpdmux_get_field(rsp_params
->enabled
, IS_DEFAULT
);
514 attr
->accept_frame_type
= dpdmux_get_field(
515 rsp_params
->accepted_frames_type
,
516 ACCEPTED_FRAMES_TYPE
);
522 * dpdmux_if_remove_l2_rule() - Remove L2 rule from DPDMUX table
523 * @mc_io: Pointer to MC portal's I/O object
524 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
525 * @token: Token of DPDMUX object
526 * @if_id: Destination interface ID
529 * Function removes a L2 rule from DPDMUX table
530 * or adds an interface to an existing multicast address
532 * Return: '0' on Success; Error code otherwise.
534 int dpdmux_if_remove_l2_rule(struct fsl_mc_io
*mc_io
,
538 const struct dpdmux_l2_rule
*rule
)
540 struct mc_command cmd
= { 0 };
541 struct dpdmux_cmd_if_l2_rule
*cmd_params
;
543 /* prepare command */
544 cmd
.header
= mc_encode_cmd_header(DPDMUX_CMDID_IF_REMOVE_L2_RULE
,
547 cmd_params
= (struct dpdmux_cmd_if_l2_rule
*)cmd
.params
;
548 cmd_params
->if_id
= cpu_to_le16(if_id
);
549 cmd_params
->vlan_id
= cpu_to_le16(rule
->vlan_id
);
550 cmd_params
->mac_addr5
= rule
->mac_addr
[5];
551 cmd_params
->mac_addr4
= rule
->mac_addr
[4];
552 cmd_params
->mac_addr3
= rule
->mac_addr
[3];
553 cmd_params
->mac_addr2
= rule
->mac_addr
[2];
554 cmd_params
->mac_addr1
= rule
->mac_addr
[1];
555 cmd_params
->mac_addr0
= rule
->mac_addr
[0];
557 /* send command to mc*/
558 return mc_send_command(mc_io
, &cmd
);
562 * dpdmux_if_add_l2_rule() - Add L2 rule into DPDMUX table
563 * @mc_io: Pointer to MC portal's I/O object
564 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
565 * @token: Token of DPDMUX object
566 * @if_id: Destination interface ID
569 * Function adds a L2 rule into DPDMUX table
570 * or adds an interface to an existing multicast address
572 * Return: '0' on Success; Error code otherwise.
574 int dpdmux_if_add_l2_rule(struct fsl_mc_io
*mc_io
,
578 const struct dpdmux_l2_rule
*rule
)
580 struct mc_command cmd
= { 0 };
581 struct dpdmux_cmd_if_l2_rule
*cmd_params
;
583 /* prepare command */
584 cmd
.header
= mc_encode_cmd_header(DPDMUX_CMDID_IF_ADD_L2_RULE
,
587 cmd_params
= (struct dpdmux_cmd_if_l2_rule
*)cmd
.params
;
588 cmd_params
->if_id
= cpu_to_le16(if_id
);
589 cmd_params
->vlan_id
= cpu_to_le16(rule
->vlan_id
);
590 cmd_params
->mac_addr5
= rule
->mac_addr
[5];
591 cmd_params
->mac_addr4
= rule
->mac_addr
[4];
592 cmd_params
->mac_addr3
= rule
->mac_addr
[3];
593 cmd_params
->mac_addr2
= rule
->mac_addr
[2];
594 cmd_params
->mac_addr1
= rule
->mac_addr
[1];
595 cmd_params
->mac_addr0
= rule
->mac_addr
[0];
597 /* send command to mc*/
598 return mc_send_command(mc_io
, &cmd
);
602 * dpdmux_if_get_counter() - Functions obtains specific counter of an interface
603 * @mc_io: Pointer to MC portal's I/O object
604 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
605 * @token: Token of DPDMUX object
606 * @if_id: Interface Id
607 * @counter_type: counter type
608 * @counter: Returned specific counter information
610 * Return: '0' on Success; Error code otherwise.
612 int dpdmux_if_get_counter(struct fsl_mc_io
*mc_io
,
616 enum dpdmux_counter_type counter_type
,
619 struct mc_command cmd
= { 0 };
620 struct dpdmux_cmd_if_get_counter
*cmd_params
;
621 struct dpdmux_rsp_if_get_counter
*rsp_params
;
624 /* prepare command */
625 cmd
.header
= mc_encode_cmd_header(DPDMUX_CMDID_IF_GET_COUNTER
,
628 cmd_params
= (struct dpdmux_cmd_if_get_counter
*)cmd
.params
;
629 cmd_params
->if_id
= cpu_to_le16(if_id
);
630 cmd_params
->counter_type
= counter_type
;
632 /* send command to mc*/
633 err
= mc_send_command(mc_io
, &cmd
);
637 /* retrieve response parameters */
638 rsp_params
= (struct dpdmux_rsp_if_get_counter
*)cmd
.params
;
639 *counter
= le64_to_cpu(rsp_params
->counter
);
645 * dpdmux_if_set_link_cfg() - set the link configuration.
646 * @mc_io: Pointer to MC portal's I/O object
647 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
648 * @token: Token of DPSW object
649 * @if_id: interface id
650 * @cfg: Link configuration
652 * Return: '0' on Success; Error code otherwise.
654 int dpdmux_if_set_link_cfg(struct fsl_mc_io
*mc_io
,
658 struct dpdmux_link_cfg
*cfg
)
660 struct mc_command cmd
= { 0 };
661 struct dpdmux_cmd_if_set_link_cfg
*cmd_params
;
663 /* prepare command */
664 cmd
.header
= mc_encode_cmd_header(DPDMUX_CMDID_IF_SET_LINK_CFG
,
667 cmd_params
= (struct dpdmux_cmd_if_set_link_cfg
*)cmd
.params
;
668 cmd_params
->if_id
= cpu_to_le16(if_id
);
669 cmd_params
->rate
= cpu_to_le32(cfg
->rate
);
670 cmd_params
->options
= cpu_to_le64(cfg
->options
);
671 cmd_params
->advertising
= cpu_to_le64(cfg
->advertising
);
673 /* send command to mc*/
674 return mc_send_command(mc_io
, &cmd
);
678 * dpdmux_if_get_link_state - Return the link state
679 * @mc_io: Pointer to MC portal's I/O object
680 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
681 * @token: Token of DPSW object
682 * @if_id: interface id
685 * @returns '0' on Success; Error code otherwise.
687 int dpdmux_if_get_link_state(struct fsl_mc_io
*mc_io
,
691 struct dpdmux_link_state
*state
)
693 struct mc_command cmd
= { 0 };
694 struct dpdmux_cmd_if_get_link_state
*cmd_params
;
695 struct dpdmux_rsp_if_get_link_state
*rsp_params
;
698 /* prepare command */
699 cmd
.header
= mc_encode_cmd_header(DPDMUX_CMDID_IF_GET_LINK_STATE
,
702 cmd_params
= (struct dpdmux_cmd_if_get_link_state
*)cmd
.params
;
703 cmd_params
->if_id
= cpu_to_le16(if_id
);
705 /* send command to mc*/
706 err
= mc_send_command(mc_io
, &cmd
);
710 /* retrieve response parameters */
711 rsp_params
= (struct dpdmux_rsp_if_get_link_state
*)cmd
.params
;
712 state
->rate
= le32_to_cpu(rsp_params
->rate
);
713 state
->options
= le64_to_cpu(rsp_params
->options
);
714 state
->up
= dpdmux_get_field(rsp_params
->up
, UP
);
715 state
->state_valid
= dpdmux_get_field(rsp_params
->up
, STATE_VALID
);
716 state
->supported
= le64_to_cpu(rsp_params
->supported
);
717 state
->advertising
= le64_to_cpu(rsp_params
->advertising
);
723 * dpdmux_if_set_default - Set default interface
724 * @mc_io: Pointer to MC portal's I/O object
725 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
726 * @token: Token of DPSW object
727 * @if_id: interface id
729 * @returns '0' on Success; Error code otherwise.
731 int dpdmux_if_set_default(struct fsl_mc_io
*mc_io
,
736 struct dpdmux_cmd_if
*cmd_params
;
737 struct mc_command cmd
= { 0 };
739 /* prepare command */
740 cmd
.header
= mc_encode_cmd_header(DPDMUX_CMDID_IF_SET_DEFAULT
,
743 cmd_params
= (struct dpdmux_cmd_if
*)cmd
.params
;
744 cmd_params
->if_id
= cpu_to_le16(if_id
);
746 /* send command to mc*/
747 return mc_send_command(mc_io
, &cmd
);
751 * dpdmux_if_get_default - Get default interface
752 * @mc_io: Pointer to MC portal's I/O object
753 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
754 * @token: Token of DPSW object
755 * @if_id: interface id
757 * @returns '0' on Success; Error code otherwise.
759 int dpdmux_if_get_default(struct fsl_mc_io
*mc_io
,
764 struct dpdmux_cmd_if
*rsp_params
;
765 struct mc_command cmd
= { 0 };
768 /* prepare command */
769 cmd
.header
= mc_encode_cmd_header(DPDMUX_CMDID_IF_GET_DEFAULT
,
773 /* send command to mc*/
774 err
= mc_send_command(mc_io
, &cmd
);
778 /* retrieve response parameters */
779 rsp_params
= (struct dpdmux_cmd_if
*)cmd
.params
;
780 *if_id
= le16_to_cpu(rsp_params
->if_id
);
786 * dpdmux_set_custom_key - Set a custom classification key.
788 * This API is only available for DPDMUX instance created with
789 * DPDMUX_METHOD_CUSTOM. This API must be called before populating the
790 * classification table using dpdmux_add_custom_cls_entry.
792 * Calls to dpdmux_set_custom_key remove all existing classification entries
793 * that may have been added previously using dpdmux_add_custom_cls_entry.
795 * @mc_io: Pointer to MC portal's I/O object
796 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
797 * @token: Token of DPSW object
798 * @if_id: Interface id
799 * @key_cfg_iova: DMA address of a configuration structure set up using
800 * dpkg_prepare_key_cfg. Maximum key size is 24 bytes
802 * @returns '0' on Success; Error code otherwise.
804 int dpdmux_set_custom_key(struct fsl_mc_io
*mc_io
,
807 uint64_t key_cfg_iova
)
809 struct dpdmux_set_custom_key
*cmd_params
;
810 struct mc_command cmd
= { 0 };
812 /* prepare command */
813 cmd
.header
= mc_encode_cmd_header(DPDMUX_CMDID_SET_CUSTOM_KEY
,
816 cmd_params
= (struct dpdmux_set_custom_key
*)cmd
.params
;
817 cmd_params
->key_cfg_iova
= cpu_to_le64(key_cfg_iova
);
819 /* send command to mc*/
820 return mc_send_command(mc_io
, &cmd
);
824 * dpdmux_add_custom_cls_entry - Adds a custom classification entry.
826 * This API is only available for DPDMUX instances created with
827 * DPDMUX_METHOD_CUSTOM. Before calling this function a classification key
828 * composition rule must be set up using dpdmux_set_custom_key.
830 * @mc_io: Pointer to MC portal's I/O object
831 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
832 * @token: Token of DPSW object
833 * @rule: Classification rule to insert. Rules cannot be duplicated, if a
834 * matching rule already exists, the action will be replaced.
835 * @action: Action to perform for matching traffic.
837 * @returns '0' on Success; Error code otherwise.
839 int dpdmux_add_custom_cls_entry(struct fsl_mc_io
*mc_io
,
842 struct dpdmux_rule_cfg
*rule
,
843 struct dpdmux_cls_action
*action
)
845 struct dpdmux_cmd_add_custom_cls_entry
*cmd_params
;
846 struct mc_command cmd
= { 0 };
848 /* prepare command */
849 cmd
.header
= mc_encode_cmd_header(DPDMUX_CMDID_ADD_CUSTOM_CLS_ENTRY
,
853 cmd_params
= (struct dpdmux_cmd_add_custom_cls_entry
*)cmd
.params
;
854 cmd_params
->key_size
= rule
->key_size
;
855 cmd_params
->dest_if
= cpu_to_le16(action
->dest_if
);
856 cmd_params
->key_iova
= cpu_to_le64(rule
->key_iova
);
857 cmd_params
->mask_iova
= cpu_to_le64(rule
->mask_iova
);
859 /* send command to mc*/
860 return mc_send_command(mc_io
, &cmd
);
864 * dpdmux_remove_custom_cls_entry - Removes a custom classification entry.
866 * This API is only available for DPDMUX instances created with
867 * DPDMUX_METHOD_CUSTOM. The API can be used to remove classification
868 * entries previously inserted using dpdmux_add_custom_cls_entry.
870 * @mc_io: Pointer to MC portal's I/O object
871 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
872 * @token: Token of DPSW object
873 * @rule: Classification rule to remove
875 * @returns '0' on Success; Error code otherwise.
877 int dpdmux_remove_custom_cls_entry(struct fsl_mc_io
*mc_io
,
880 struct dpdmux_rule_cfg
*rule
)
882 struct dpdmux_cmd_remove_custom_cls_entry
*cmd_params
;
883 struct mc_command cmd
= { 0 };
885 /* prepare command */
886 cmd
.header
= mc_encode_cmd_header(DPDMUX_CMDID_REMOVE_CUSTOM_CLS_ENTRY
,
889 cmd_params
= (struct dpdmux_cmd_remove_custom_cls_entry
*)cmd
.params
;
890 cmd_params
->key_size
= rule
->key_size
;
891 cmd_params
->key_iova
= cpu_to_le64(rule
->key_iova
);
892 cmd_params
->mask_iova
= cpu_to_le64(rule
->mask_iova
);
894 /* send command to mc*/
895 return mc_send_command(mc_io
, &cmd
);
899 * dpdmux_get_api_version() - Get Data Path Demux API version
900 * @mc_io: Pointer to MC portal's I/O object
901 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
902 * @major_ver: Major version of data path demux API
903 * @minor_ver: Minor version of data path demux API
905 * Return: '0' on Success; Error code otherwise.
907 int dpdmux_get_api_version(struct fsl_mc_io
*mc_io
,
912 struct mc_command cmd
= { 0 };
913 struct dpdmux_rsp_get_api_version
*rsp_params
;
916 cmd
.header
= mc_encode_cmd_header(DPDMUX_CMDID_GET_API_VERSION
,
920 err
= mc_send_command(mc_io
, &cmd
);
924 rsp_params
= (struct dpdmux_rsp_get_api_version
*)cmd
.params
;
925 *major_ver
= le16_to_cpu(rsp_params
->major
);
926 *minor_ver
= le16_to_cpu(rsp_params
->minor
);