1 /* SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0)
3 * Copyright 2013-2016 Freescale Semiconductor Inc.
4 * Copyright 2018-2021 NXP
14 /** @addtogroup dpdmux Data Path Demux API
15 * Contains API for handling DPDMUX topology and functionality
19 int dpdmux_open(struct fsl_mc_io *mc_io,
24 int dpdmux_close(struct fsl_mc_io *mc_io,
29 * DPDMUX general options
33 * Enable bridging between internal interfaces
35 #define DPDMUX_OPT_BRIDGE_EN 0x0000000000000002ULL
38 * Mask support for classification
40 #define DPDMUX_OPT_CLS_MASK_SUPPORT 0x0000000000000020ULL
43 * Automatic max frame length - maximum frame length for dpdmux interface will
44 * be changed automatically by connected dpni objects.
46 #define DPDMUX_OPT_AUTO_MAX_FRAME_LEN 0x0000000000000040ULL
48 #define DPDMUX_IRQ_INDEX_IF 0x0000
49 #define DPDMUX_IRQ_INDEX 0x0001
52 * IRQ event - Indicates that the link state changed
54 #define DPDMUX_IRQ_EVENT_LINK_CHANGED 0x0001
57 * enum dpdmux_manip - DPDMUX manipulation operations
58 * @DPDMUX_MANIP_NONE: No manipulation on frames
59 * @DPDMUX_MANIP_ADD_REMOVE_S_VLAN: Add S-VLAN on egress, remove it on ingress
62 DPDMUX_MANIP_NONE = 0x0,
63 DPDMUX_MANIP_ADD_REMOVE_S_VLAN = 0x1
67 * enum dpdmux_method - DPDMUX method options
68 * @DPDMUX_METHOD_NONE: no DPDMUX method
69 * @DPDMUX_METHOD_C_VLAN_MAC: DPDMUX based on C-VLAN and MAC address
70 * @DPDMUX_METHOD_MAC: DPDMUX based on MAC address
71 * @DPDMUX_METHOD_C_VLAN: DPDMUX based on C-VLAN
72 * @DPDMUX_METHOD_S_VLAN: DPDMUX based on S-VLAN
75 DPDMUX_METHOD_NONE = 0x0,
76 DPDMUX_METHOD_C_VLAN_MAC = 0x1,
77 DPDMUX_METHOD_MAC = 0x2,
78 DPDMUX_METHOD_C_VLAN = 0x3,
79 DPDMUX_METHOD_S_VLAN = 0x4,
80 DPDMUX_METHOD_CUSTOM = 0x5,
84 * struct dpdmux_cfg - DPDMUX configuration parameters
85 * @method: Defines the operation method for the DPDMUX address table
86 * @manip: Required manipulation operation
87 * @num_ifs: Number of interfaces (excluding the uplink interface)
88 * @default_if: Default interface number (different from uplink,
89 maximum value num_ifs)
90 * @adv: Advanced parameters; default is all zeros;
91 * use this structure to change default settings
92 * @adv.options: DPDMUX options - combination of 'DPDMUX_OPT_<X>' flags.
93 * @adv.max_dmat_entries: Maximum entries in DPDMUX address table
94 * 0 - indicates default: 64 entries per interface.
95 * @adv.max_mc_groups: Number of multicast groups in DPDMUX table
96 * 0 - indicates default: 32 multicast groups.
97 * @adv.max_vlan_ids: Maximum vlan ids allowed in the system -
98 * relevant only case of working in mac+vlan method.
99 * 0 - indicates default 16 vlan ids.
100 * @adv.mem_size: Size of the memory used for internal buffers expressed as
101 * number of 256byte buffers.
104 enum dpdmux_method method;
105 enum dpdmux_manip manip;
110 uint16_t max_dmat_entries;
111 uint16_t max_mc_groups;
112 uint16_t max_vlan_ids;
117 int dpdmux_create(struct fsl_mc_io *mc_io,
120 const struct dpdmux_cfg *cfg,
123 int dpdmux_destroy(struct fsl_mc_io *mc_io,
128 int dpdmux_enable(struct fsl_mc_io *mc_io,
132 int dpdmux_disable(struct fsl_mc_io *mc_io,
136 int dpdmux_is_enabled(struct fsl_mc_io *mc_io,
141 int dpdmux_reset(struct fsl_mc_io *mc_io,
146 *Setting 1 DPDMUX_RESET will not reset default interface
148 #define DPDMUX_SKIP_DEFAULT_INTERFACE 0x01
150 *Setting 1 DPDMUX_RESET will not reset unicast rules
152 #define DPDMUX_SKIP_UNICAST_RULES 0x02
154 *Setting 1 DPDMUX_RESET will not reset multicast rules
156 #define DPDMUX_SKIP_MULTICAST_RULES 0x04
158 int dpdmux_set_resetable(struct fsl_mc_io *mc_io,
161 uint8_t skip_reset_flags);
163 int dpdmux_get_resetable(struct fsl_mc_io *mc_io,
166 uint8_t *skip_reset_flags);
169 * struct dpdmux_attr - Structure representing DPDMUX attributes
170 * @id: DPDMUX object ID
171 * @options: Configuration options (bitmap)
172 * @method: DPDMUX address table method
173 * @manip: DPDMUX manipulation type
174 * @num_ifs: Number of interfaces (excluding the uplink interface)
175 * @mem_size: DPDMUX frame storage memory size
176 * @default_if: Default interface number (different from uplink,
177 maximum value num_ifs)
182 enum dpdmux_method method;
183 enum dpdmux_manip manip;
187 uint16_t max_dmat_entries;
188 uint16_t max_mc_groups;
189 uint16_t max_vlan_ids;
192 int dpdmux_get_attributes(struct fsl_mc_io *mc_io,
195 struct dpdmux_attr *attr);
197 int dpdmux_set_max_frame_length(struct fsl_mc_io *mc_io,
200 uint16_t max_frame_length);
202 int dpdmux_get_max_frame_length(struct fsl_mc_io *mc_io,
206 uint16_t *max_frame_length);
209 * enum dpdmux_counter_type - Counter types
210 * @DPDMUX_CNT_ING_FRAME: Counts ingress frames
211 * @DPDMUX_CNT_ING_BYTE: Counts ingress bytes
212 * @DPDMUX_CNT_ING_FLTR_FRAME: Counts filtered ingress frames
213 * @DPDMUX_CNT_ING_FRAME_DISCARD: Counts discarded ingress frames
214 * @DPDMUX_CNT_ING_MCAST_FRAME: Counts ingress multicast frames
215 * @DPDMUX_CNT_ING_MCAST_BYTE: Counts ingress multicast bytes
216 * @DPDMUX_CNT_ING_BCAST_FRAME: Counts ingress broadcast frames
217 * @DPDMUX_CNT_ING_BCAST_BYTES: Counts ingress broadcast bytes
218 * @DPDMUX_CNT_EGR_FRAME: Counts egress frames
219 * @DPDMUX_CNT_EGR_BYTE: Counts egress bytes
220 * @DPDMUX_CNT_EGR_FRAME_DISCARD: Counts discarded egress frames
221 * @DPDMUX_CNT_ING_NO_BUFFER_DISCARD: Counts ingress no buffer discard frames
223 enum dpdmux_counter_type {
224 DPDMUX_CNT_ING_FRAME = 0x0,
225 DPDMUX_CNT_ING_BYTE = 0x1,
226 DPDMUX_CNT_ING_FLTR_FRAME = 0x2,
227 DPDMUX_CNT_ING_FRAME_DISCARD = 0x3,
228 DPDMUX_CNT_ING_MCAST_FRAME = 0x4,
229 DPDMUX_CNT_ING_MCAST_BYTE = 0x5,
230 DPDMUX_CNT_ING_BCAST_FRAME = 0x6,
231 DPDMUX_CNT_ING_BCAST_BYTES = 0x7,
232 DPDMUX_CNT_EGR_FRAME = 0x8,
233 DPDMUX_CNT_EGR_BYTE = 0x9,
234 DPDMUX_CNT_EGR_FRAME_DISCARD = 0xa,
235 DPDMUX_CNT_ING_NO_BUFFER_DISCARD = 0xb,
239 * enum dpdmux_accepted_frames_type - DPDMUX frame types
240 * @DPDMUX_ADMIT_ALL: The device accepts VLAN tagged, untagged and
241 * priority-tagged frames
242 * @DPDMUX_ADMIT_ONLY_VLAN_TAGGED: The device discards untagged frames or
243 * priority-tagged frames that are received on this
245 * @DPDMUX_ADMIT_ONLY_UNTAGGED: Untagged frames or priority-tagged frames
246 * received on this interface are accepted
248 enum dpdmux_accepted_frames_type {
249 DPDMUX_ADMIT_ALL = 0,
250 DPDMUX_ADMIT_ONLY_VLAN_TAGGED = 1,
251 DPDMUX_ADMIT_ONLY_UNTAGGED = 2
255 * enum dpdmux_action - DPDMUX action for un-accepted frames
256 * @DPDMUX_ACTION_DROP: Drop un-accepted frames
257 * @DPDMUX_ACTION_REDIRECT_TO_CTRL: Redirect un-accepted frames to the
261 DPDMUX_ACTION_DROP = 0,
262 DPDMUX_ACTION_REDIRECT_TO_CTRL = 1
266 * struct dpdmux_accepted_frames - Frame types configuration
267 * @type: Defines ingress accepted frames
268 * @unaccept_act: Defines action on frames not accepted
270 struct dpdmux_accepted_frames {
271 enum dpdmux_accepted_frames_type type;
272 enum dpdmux_action unaccept_act;
275 int dpdmux_if_set_accepted_frames(struct fsl_mc_io *mc_io,
279 const struct dpdmux_accepted_frames *cfg);
282 * struct dpdmux_if_attr - Structure representing frame types configuration
283 * @rate: Configured interface rate (in bits per second)
284 * @enabled: Indicates if interface is enabled
285 * @accept_frame_type: Indicates type of accepted frames for the interface
287 struct dpdmux_if_attr {
291 enum dpdmux_accepted_frames_type accept_frame_type;
294 int dpdmux_if_get_attributes(struct fsl_mc_io *mc_io,
298 struct dpdmux_if_attr *attr);
300 int dpdmux_if_enable(struct fsl_mc_io *mc_io,
305 int dpdmux_if_disable(struct fsl_mc_io *mc_io,
311 * struct dpdmux_l2_rule - Structure representing L2 rule
312 * @mac_addr: MAC address
315 struct dpdmux_l2_rule {
320 int dpdmux_if_remove_l2_rule(struct fsl_mc_io *mc_io,
324 const struct dpdmux_l2_rule *rule);
326 int dpdmux_if_add_l2_rule(struct fsl_mc_io *mc_io,
330 const struct dpdmux_l2_rule *rule);
332 int dpdmux_if_get_counter(struct fsl_mc_io *mc_io,
336 enum dpdmux_counter_type counter_type,
339 int dpdmux_ul_reset_counters(struct fsl_mc_io *mc_io,
344 * Enable auto-negotiation
346 #define DPDMUX_LINK_OPT_AUTONEG 0x0000000000000001ULL
348 * Enable half-duplex mode
350 #define DPDMUX_LINK_OPT_HALF_DUPLEX 0x0000000000000002ULL
352 * Enable pause frames
354 #define DPDMUX_LINK_OPT_PAUSE 0x0000000000000004ULL
356 * Enable a-symmetric pause frames
358 #define DPDMUX_LINK_OPT_ASYM_PAUSE 0x0000000000000008ULL
361 * struct dpdmux_link_cfg - Structure representing DPDMUX link configuration
363 * @options: Mask of available options; use 'DPDMUX_LINK_OPT_<X>' values
365 struct dpdmux_link_cfg {
368 uint64_t advertising;
371 int dpdmux_if_set_link_cfg(struct fsl_mc_io *mc_io,
375 struct dpdmux_link_cfg *cfg);
377 * struct dpdmux_link_state - Structure representing DPDMUX link state
379 * @options: Mask of available options; use 'DPDMUX_LINK_OPT_<X>' values
380 * @up: 0 - down, 1 - up
381 * @state_valid: Ignore/Update the state of the link
382 * @supported: Speeds capability of the phy (bitmap)
383 * @advertising: Speeds that are advertised for autoneg (bitmap)
385 struct dpdmux_link_state {
391 uint64_t advertising;
394 int dpdmux_if_get_link_state(struct fsl_mc_io *mc_io,
398 struct dpdmux_link_state *state);
400 int dpdmux_if_set_default(struct fsl_mc_io *mc_io,
405 int dpdmux_if_get_default(struct fsl_mc_io *mc_io,
410 int dpdmux_set_custom_key(struct fsl_mc_io *mc_io,
413 uint64_t key_cfg_iova);
416 * struct dpdmux_rule_cfg - Custom classification rule.
418 * @key_iova: DMA address of buffer storing the look-up value
419 * @mask_iova: DMA address of the mask used for TCAM classification. This
420 * parameter is used only if dpdmux was created using option
421 * DPDMUX_OPT_CLS_MASK_SUPPORT.
422 * @key_size: size, in bytes, of the look-up value. This must match the size
423 * of the look-up key defined using dpdmux_set_custom_key, otherwise the
424 * entry will never be hit
425 * @entry_index: rule index into the table. This parameter is used only when
426 * dpdmux object was created using option DPDMUX_OPT_CLS_MASK_SUPPORT. In
427 * this case the rule is masking and the current frame may be a hit for
428 * multiple rules. This parameter determines the order in which the rules
429 * will be checked (smaller entry_index first).
431 struct dpdmux_rule_cfg {
435 uint16_t entry_index;
439 * struct dpdmux_cls_action - Action to execute for frames matching the
440 * classification entry
442 * @dest_if: Interface to forward the frames to. Port numbering is similar to
443 * the one used to connect interfaces:
444 * - 0 is the uplink port,
445 * - all others are downlink ports.
447 struct dpdmux_cls_action {
451 int dpdmux_add_custom_cls_entry(struct fsl_mc_io *mc_io,
454 struct dpdmux_rule_cfg *rule,
455 struct dpdmux_cls_action *action);
457 int dpdmux_remove_custom_cls_entry(struct fsl_mc_io *mc_io,
460 struct dpdmux_rule_cfg *rule);
462 int dpdmux_get_api_version(struct fsl_mc_io *mc_io,
465 uint16_t *minor_ver);
468 * Discard bit. This bit must be used together with other bits in
469 * DPDMUX_ERROR_ACTION_CONTINUE to disable discarding of frames containing
472 #define DPDMUX_ERROR_DISC 0x80000000
476 #define DPDMUX_ERROR_MS 0x40000000
480 #define DPDMUX_ERROR_PTP 0x08000000
482 * This is a multicast frame
484 #define DPDMUX_ERROR_MC 0x04000000
486 * This is a broadcast frame
488 #define DPDMUX_ERROR_BC 0x02000000
490 * Invalid Key composition or key size error
492 #define DPDMUX_ERROR_KSE 0x00040000
494 * Extract out of frame header
496 #define DPDMUX_ERROR_EOFHE 0x00020000
498 * Maximum number of chained lookups is reached
500 #define DPDMUX_ERROR_MNLE 0x00010000
504 #define DPDMUX_ERROR_TIDE 0x00008000
506 * Policer initialization entry error
508 #define DPDMUX_ERROR_PIEE 0x00004000
512 #define DPDMUX_ERROR_FLE 0x00002000
514 * Frame physical error
516 #define DPDMUX_ERROR_FPE 0x00001000
518 * Cycle limit is exceeded and frame parsing is forced to terminate early
520 #define DPDMUX_ERROR_PTE 0x00000080
522 * Invalid softparse instruction is encountered
524 #define DPDMUX_ERROR_ISP 0x00000040
526 * Parsing header error
528 #define DPDMUX_ERROR_PHE 0x00000020
530 * Block limit is exceeded. Maximum data that can be read and parsed is 256
532 * Parser will set this bit if it needs more that this limit to parse.
534 #define DPDMUX_ERROR_BLE 0x00000010
536 * L3 checksum validation
538 #define DPDMUX__ERROR_L3CV 0x00000008
542 #define DPDMUX__ERROR_L3CE 0x00000004
544 * L4 checksum validation
546 #define DPDMUX__ERROR_L4CV 0x00000002
550 #define DPDMUX__ERROR_L4CE 0x00000001
552 enum dpdmux_error_action {
553 DPDMUX_ERROR_ACTION_DISCARD = 0,
554 DPDMUX_ERROR_ACTION_CONTINUE = 1
558 * Configure how dpdmux interface behaves on errors
559 * @errors - or'ed combination of DPDMUX_ERROR_*
560 * @action - set to DPDMUX_ERROR_ACTION_DISCARD or DPDMUX_ERROR_ACTION_CONTINUE
562 struct dpdmux_error_cfg {
564 enum dpdmux_error_action error_action;
567 int dpdmux_if_set_errors_behavior(struct fsl_mc_io *mc_io, uint32_t cmd_flags,
568 uint16_t token, uint16_t if_id, struct dpdmux_error_cfg *cfg);
570 #endif /* __FSL_DPDMUX_H */