1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Copyright 2014-2016 Freescale Semiconductor Inc.
4 * Copyright 2017-2021 NXP
11 /* Data Path L2-Switch API
12 * Contains API for handling DPSW topology and functionality
18 * DPSW general definitions
22 * Maximum number of traffic class priorities
24 #define DPSW_MAX_PRIORITIES 8
26 * Maximum number of interfaces
28 #define DPSW_MAX_IF 64
30 int dpsw_open(struct fsl_mc_io *mc_io,
35 int dpsw_close(struct fsl_mc_io *mc_io,
46 #define DPSW_OPT_FLOODING_DIS 0x0000000000000001ULL
50 #define DPSW_OPT_MULTICAST_DIS 0x0000000000000004ULL
52 * Support control interface
54 #define DPSW_OPT_CTRL_IF_DIS 0x0000000000000010ULL
56 * Disable flooding metering
58 #define DPSW_OPT_FLOODING_METERING_DIS 0x0000000000000020ULL
62 #define DPSW_OPT_METERING_EN 0x0000000000000040ULL
65 * enum dpsw_component_type - component type of a bridge
66 * @DPSW_COMPONENT_TYPE_C_VLAN: A C-VLAN component of an
67 * enterprise VLAN bridge or of a Provider Bridge used
68 * to process C-tagged frames
69 * @DPSW_COMPONENT_TYPE_S_VLAN: An S-VLAN component of a
73 enum dpsw_component_type {
74 DPSW_COMPONENT_TYPE_C_VLAN = 0,
75 DPSW_COMPONENT_TYPE_S_VLAN
79 * enum dpsw_flooding_cfg - flooding configuration requested
80 * @DPSW_FLOODING_PER_VLAN: Flooding replicators are allocated per VLAN and
81 * interfaces present in each of them can be configured using
82 * dpsw_vlan_add_if_flooding()/dpsw_vlan_remove_if_flooding().
83 * This is the default configuration.
85 * @DPSW_FLOODING_PER_FDB: Flooding replicators are allocated per FDB and
86 * interfaces present in each of them can be configured using
87 * dpsw_set_egress_flood().
89 enum dpsw_flooding_cfg {
90 DPSW_FLOODING_PER_VLAN = 0,
91 DPSW_FLOODING_PER_FDB,
95 * enum dpsw_broadcast_cfg - broadcast configuration requested
96 * @DPSW_BROADCAST_PER_OBJECT: There is only one broadcast replicator per DPSW
97 * object. This is the default configuration.
98 * @DPSW_BROADCAST_PER_FDB: Broadcast replicators are allocated per FDB and
99 * interfaces present in each of them can be configured using
100 * dpsw_set_egress_flood().
102 enum dpsw_broadcast_cfg {
103 DPSW_BROADCAST_PER_OBJECT = 0,
104 DPSW_BROADCAST_PER_FDB,
107 int dpsw_enable(struct fsl_mc_io *mc_io,
111 int dpsw_disable(struct fsl_mc_io *mc_io,
115 int dpsw_reset(struct fsl_mc_io *mc_io,
120 * DPSW IRQ Index and Events
123 #define DPSW_IRQ_INDEX_IF 0x0000
124 #define DPSW_IRQ_INDEX_L2SW 0x0001
127 * IRQ event - Indicates that the link state changed
129 #define DPSW_IRQ_EVENT_LINK_CHANGED 0x0001
132 * struct dpsw_irq_cfg - IRQ configuration
133 * @addr: Address that must be written to signal a message-based interrupt
134 * @val: Value to write into irq_addr address
135 * @irq_num: A user defined number associated with this IRQ
137 struct dpsw_irq_cfg {
143 int dpsw_set_irq_enable(struct fsl_mc_io *mc_io,
149 int dpsw_set_irq_mask(struct fsl_mc_io *mc_io,
155 int dpsw_get_irq_status(struct fsl_mc_io *mc_io,
161 int dpsw_clear_irq_status(struct fsl_mc_io *mc_io,
168 * struct dpsw_attr - Structure representing DPSW attributes
169 * @id: DPSW object ID
170 * @options: Enable/Disable DPSW features
171 * @max_vlans: Maximum Number of VLANs
172 * @max_meters_per_if: Number of meters per interface
173 * @max_fdbs: Maximum Number of FDBs
174 * @max_fdb_entries: Number of FDB entries for default FDB table;
175 * 0 - indicates default 1024 entries.
176 * @fdb_aging_time: Default FDB aging time for default FDB table;
177 * 0 - indicates default 300 seconds
178 * @max_fdb_mc_groups: Number of multicast groups in each FDB table;
179 * 0 - indicates default 32
180 * @mem_size: DPSW frame storage memory size
181 * @num_ifs: Number of interfaces
182 * @num_vlans: Current number of VLANs
183 * @num_fdbs: Current number of FDBs
184 * @component_type: Component type of this bridge
185 * @flooding_cfg: Flooding configuration (PER_VLAN - default, PER_FDB)
186 * @broadcast_cfg: Broadcast configuration (PER_OBJECT - default, PER_FDB)
192 u8 max_meters_per_if;
196 u16 max_fdb_mc_groups;
201 enum dpsw_component_type component_type;
202 enum dpsw_flooding_cfg flooding_cfg;
203 enum dpsw_broadcast_cfg broadcast_cfg;
206 int dpsw_get_attributes(struct fsl_mc_io *mc_io,
209 struct dpsw_attr *attr);
212 * struct dpsw_ctrl_if_attr - Control interface attributes
213 * @rx_fqid: Receive FQID
214 * @rx_err_fqid: Receive error FQID
215 * @tx_err_conf_fqid: Transmit error and confirmation FQID
217 struct dpsw_ctrl_if_attr {
220 u32 tx_err_conf_fqid;
223 int dpsw_ctrl_if_get_attributes(struct fsl_mc_io *mc_io, u32 cmd_flags,
224 u16 token, struct dpsw_ctrl_if_attr *attr);
226 enum dpsw_queue_type {
228 DPSW_QUEUE_TX_ERR_CONF,
233 * Maximum number of DPBP
235 #define DPSW_MAX_DPBP 8
238 * struct dpsw_ctrl_if_pools_cfg - Control interface buffer pools configuration
239 * @num_dpbp: Number of DPBPs
240 * @pools: Array of buffer pools parameters; The number of valid entries
241 * must match 'num_dpbp' value
242 * @pools.dpbp_id: DPBP object ID
243 * @pools.buffer_size: Buffer size
244 * @pools.backup_pool: Backup pool
246 struct dpsw_ctrl_if_pools_cfg {
252 } pools[DPSW_MAX_DPBP];
255 int dpsw_ctrl_if_set_pools(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
256 const struct dpsw_ctrl_if_pools_cfg *cfg);
258 #define DPSW_CTRL_IF_QUEUE_OPT_USER_CTX 0x00000001
259 #define DPSW_CTRL_IF_QUEUE_OPT_DEST 0x00000002
261 enum dpsw_ctrl_if_dest {
262 DPSW_CTRL_IF_DEST_NONE = 0,
263 DPSW_CTRL_IF_DEST_DPIO = 1,
266 struct dpsw_ctrl_if_dest_cfg {
267 enum dpsw_ctrl_if_dest dest_type;
272 struct dpsw_ctrl_if_queue_cfg {
275 struct dpsw_ctrl_if_dest_cfg dest_cfg;
278 int dpsw_ctrl_if_set_queue(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
279 enum dpsw_queue_type qtype,
280 const struct dpsw_ctrl_if_queue_cfg *cfg);
282 int dpsw_ctrl_if_enable(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token);
284 int dpsw_ctrl_if_disable(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token);
287 * enum dpsw_action - Action selection for special/control frames
288 * @DPSW_ACTION_DROP: Drop frame
289 * @DPSW_ACTION_REDIRECT: Redirect frame to control port
292 DPSW_ACTION_DROP = 0,
293 DPSW_ACTION_REDIRECT = 1
297 * Enable auto-negotiation
299 #define DPSW_LINK_OPT_AUTONEG 0x0000000000000001ULL
301 * Enable half-duplex mode
303 #define DPSW_LINK_OPT_HALF_DUPLEX 0x0000000000000002ULL
305 * Enable pause frames
307 #define DPSW_LINK_OPT_PAUSE 0x0000000000000004ULL
309 * Enable a-symmetric pause frames
311 #define DPSW_LINK_OPT_ASYM_PAUSE 0x0000000000000008ULL
314 * struct dpsw_link_cfg - Structure representing DPSW link configuration
316 * @options: Mask of available options; use 'DPSW_LINK_OPT_<X>' values
318 struct dpsw_link_cfg {
323 int dpsw_if_set_link_cfg(struct fsl_mc_io *mc_io,
327 struct dpsw_link_cfg *cfg);
329 * struct dpsw_link_state - Structure representing DPSW link state
331 * @options: Mask of available options; use 'DPSW_LINK_OPT_<X>' values
332 * @up: 0 - covers two cases: down and disconnected, 1 - up
334 struct dpsw_link_state {
340 int dpsw_if_get_link_state(struct fsl_mc_io *mc_io,
344 struct dpsw_link_state *state);
347 * struct dpsw_tci_cfg - Tag Control Information (TCI) configuration
348 * @pcp: Priority Code Point (PCP): a 3-bit field which refers
349 * to the IEEE 802.1p priority
350 * @dei: Drop Eligible Indicator (DEI): a 1-bit field. May be used
351 * separately or in conjunction with PCP to indicate frames
352 * eligible to be dropped in the presence of congestion
353 * @vlan_id: VLAN Identifier (VID): a 12-bit field specifying the VLAN
354 * to which the frame belongs. The hexadecimal values
355 * of 0x000 and 0xFFF are reserved;
356 * all other values may be used as VLAN identifiers,
357 * allowing up to 4,094 VLANs
359 struct dpsw_tci_cfg {
365 int dpsw_if_set_tci(struct fsl_mc_io *mc_io,
369 const struct dpsw_tci_cfg *cfg);
371 int dpsw_if_get_tci(struct fsl_mc_io *mc_io,
375 struct dpsw_tci_cfg *cfg);
378 * enum dpsw_stp_state - Spanning Tree Protocol (STP) states
379 * @DPSW_STP_STATE_BLOCKING: Blocking state
380 * @DPSW_STP_STATE_LISTENING: Listening state
381 * @DPSW_STP_STATE_LEARNING: Learning state
382 * @DPSW_STP_STATE_FORWARDING: Forwarding state
385 enum dpsw_stp_state {
386 DPSW_STP_STATE_DISABLED = 0,
387 DPSW_STP_STATE_LISTENING = 1,
388 DPSW_STP_STATE_LEARNING = 2,
389 DPSW_STP_STATE_FORWARDING = 3,
390 DPSW_STP_STATE_BLOCKING = 0
394 * struct dpsw_stp_cfg - Spanning Tree Protocol (STP) Configuration
395 * @vlan_id: VLAN ID STP state
398 struct dpsw_stp_cfg {
400 enum dpsw_stp_state state;
403 int dpsw_if_set_stp(struct fsl_mc_io *mc_io,
407 const struct dpsw_stp_cfg *cfg);
410 * enum dpsw_accepted_frames - Types of frames to accept
411 * @DPSW_ADMIT_ALL: The device accepts VLAN tagged, untagged and
412 * priority tagged frames
413 * @DPSW_ADMIT_ONLY_VLAN_TAGGED: The device discards untagged frames or
414 * Priority-Tagged frames received on this interface.
417 enum dpsw_accepted_frames {
419 DPSW_ADMIT_ONLY_VLAN_TAGGED = 3
423 * enum dpsw_counter - Counters types
424 * @DPSW_CNT_ING_FRAME: Counts ingress frames
425 * @DPSW_CNT_ING_BYTE: Counts ingress bytes
426 * @DPSW_CNT_ING_FLTR_FRAME: Counts filtered ingress frames
427 * @DPSW_CNT_ING_FRAME_DISCARD: Counts discarded ingress frame
428 * @DPSW_CNT_ING_MCAST_FRAME: Counts ingress multicast frames
429 * @DPSW_CNT_ING_MCAST_BYTE: Counts ingress multicast bytes
430 * @DPSW_CNT_ING_BCAST_FRAME: Counts ingress broadcast frames
431 * @DPSW_CNT_ING_BCAST_BYTES: Counts ingress broadcast bytes
432 * @DPSW_CNT_EGR_FRAME: Counts egress frames
433 * @DPSW_CNT_EGR_BYTE: Counts egress bytes
434 * @DPSW_CNT_EGR_FRAME_DISCARD: Counts discarded egress frames
435 * @DPSW_CNT_EGR_STP_FRAME_DISCARD: Counts egress STP discarded frames
436 * @DPSW_CNT_ING_NO_BUFF_DISCARD: Counts ingress no buffer discarded frames
439 DPSW_CNT_ING_FRAME = 0x0,
440 DPSW_CNT_ING_BYTE = 0x1,
441 DPSW_CNT_ING_FLTR_FRAME = 0x2,
442 DPSW_CNT_ING_FRAME_DISCARD = 0x3,
443 DPSW_CNT_ING_MCAST_FRAME = 0x4,
444 DPSW_CNT_ING_MCAST_BYTE = 0x5,
445 DPSW_CNT_ING_BCAST_FRAME = 0x6,
446 DPSW_CNT_ING_BCAST_BYTES = 0x7,
447 DPSW_CNT_EGR_FRAME = 0x8,
448 DPSW_CNT_EGR_BYTE = 0x9,
449 DPSW_CNT_EGR_FRAME_DISCARD = 0xa,
450 DPSW_CNT_EGR_STP_FRAME_DISCARD = 0xb,
451 DPSW_CNT_ING_NO_BUFF_DISCARD = 0xc,
454 int dpsw_if_get_counter(struct fsl_mc_io *mc_io,
458 enum dpsw_counter type,
461 int dpsw_if_enable(struct fsl_mc_io *mc_io,
466 int dpsw_if_disable(struct fsl_mc_io *mc_io,
472 * struct dpsw_if_attr - Structure representing DPSW interface attributes
473 * @num_tcs: Number of traffic classes
474 * @rate: Transmit rate in bits per second
475 * @options: Interface configuration options (bitmap)
476 * @enabled: Indicates if interface is enabled
477 * @accept_all_vlan: The device discards/accepts incoming frames
478 * for VLANs that do not include this interface
479 * @admit_untagged: When set to 'DPSW_ADMIT_ONLY_VLAN_TAGGED', the device
480 * discards untagged frames or priority-tagged frames received on
482 * When set to 'DPSW_ADMIT_ALL', untagged frames or priority-
483 * tagged frames received on this interface are accepted
484 * @qdid: control frames transmit qdid
486 struct dpsw_if_attr {
492 enum dpsw_accepted_frames admit_untagged;
496 int dpsw_if_get_attributes(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
497 u16 if_id, struct dpsw_if_attr *attr);
499 int dpsw_if_set_max_frame_length(struct fsl_mc_io *mc_io,
506 * struct dpsw_vlan_cfg - VLAN Configuration
507 * @fdb_id: Forwarding Data Base
509 struct dpsw_vlan_cfg {
513 int dpsw_vlan_add(struct fsl_mc_io *mc_io,
517 const struct dpsw_vlan_cfg *cfg);
519 #define DPSW_VLAN_ADD_IF_OPT_FDB_ID 0x0001
522 * struct dpsw_vlan_if_cfg - Set of VLAN Interfaces
523 * @num_ifs: The number of interfaces that are assigned to the egress
525 * @if_id: The set of interfaces that are
526 * assigned to the egress list for this VLAN
528 struct dpsw_vlan_if_cfg {
531 u16 if_id[DPSW_MAX_IF];
535 int dpsw_vlan_add_if(struct fsl_mc_io *mc_io,
539 const struct dpsw_vlan_if_cfg *cfg);
541 int dpsw_vlan_add_if_untagged(struct fsl_mc_io *mc_io,
545 const struct dpsw_vlan_if_cfg *cfg);
547 int dpsw_vlan_remove_if(struct fsl_mc_io *mc_io,
551 const struct dpsw_vlan_if_cfg *cfg);
553 int dpsw_vlan_remove_if_untagged(struct fsl_mc_io *mc_io,
557 const struct dpsw_vlan_if_cfg *cfg);
559 int dpsw_vlan_remove(struct fsl_mc_io *mc_io,
565 * enum dpsw_fdb_entry_type - FDB Entry type - Static/Dynamic
566 * @DPSW_FDB_ENTRY_STATIC: Static entry
567 * @DPSW_FDB_ENTRY_DINAMIC: Dynamic entry
569 enum dpsw_fdb_entry_type {
570 DPSW_FDB_ENTRY_STATIC = 0,
571 DPSW_FDB_ENTRY_DINAMIC = 1
575 * struct dpsw_fdb_unicast_cfg - Unicast entry configuration
576 * @type: Select static or dynamic entry
577 * @mac_addr: MAC address
578 * @if_egress: Egress interface ID
580 struct dpsw_fdb_unicast_cfg {
581 enum dpsw_fdb_entry_type type;
586 int dpsw_fdb_add_unicast(struct fsl_mc_io *mc_io,
590 const struct dpsw_fdb_unicast_cfg *cfg);
592 int dpsw_fdb_remove_unicast(struct fsl_mc_io *mc_io,
596 const struct dpsw_fdb_unicast_cfg *cfg);
598 #define DPSW_FDB_ENTRY_TYPE_DYNAMIC BIT(0)
599 #define DPSW_FDB_ENTRY_TYPE_UNICAST BIT(1)
602 * struct fdb_dump_entry - fdb snapshot entry
603 * @mac_addr: MAC address
604 * @type: bit0 - DINAMIC(1)/STATIC(0), bit1 - UNICAST(1)/MULTICAST(0)
605 * @if_info: unicast - egress interface, multicast - number of egress interfaces
606 * @if_mask: multicast - egress interface mask
608 struct fdb_dump_entry {
615 int dpsw_fdb_dump(struct fsl_mc_io *mc_io,
624 * struct dpsw_fdb_multicast_cfg - Multi-cast entry configuration
625 * @type: Select static or dynamic entry
626 * @mac_addr: MAC address
627 * @num_ifs: Number of external and internal interfaces
628 * @if_id: Egress interface IDs
630 struct dpsw_fdb_multicast_cfg {
631 enum dpsw_fdb_entry_type type;
634 u16 if_id[DPSW_MAX_IF];
637 int dpsw_fdb_add_multicast(struct fsl_mc_io *mc_io,
641 const struct dpsw_fdb_multicast_cfg *cfg);
643 int dpsw_fdb_remove_multicast(struct fsl_mc_io *mc_io,
647 const struct dpsw_fdb_multicast_cfg *cfg);
650 * enum dpsw_fdb_learning_mode - Auto-learning modes
651 * @DPSW_FDB_LEARNING_MODE_DIS: Disable Auto-learning
652 * @DPSW_FDB_LEARNING_MODE_HW: Enable HW auto-Learning
653 * @DPSW_FDB_LEARNING_MODE_NON_SECURE: Enable None secure learning by CPU
654 * @DPSW_FDB_LEARNING_MODE_SECURE: Enable secure learning by CPU
656 * NONE - SECURE LEARNING
657 * SMAC found DMAC found CTLU Action
658 * v v Forward frame to
659 * 1. DMAC destination
660 * - v Forward frame to
661 * 1. DMAC destination
662 * 2. Control interface
663 * v - Forward frame to
664 * 1. Flooding list of interfaces
665 * - - Forward frame to
666 * 1. Flooding list of interfaces
667 * 2. Control interface
669 * SMAC found DMAC found CTLU Action
670 * v v Forward frame to
671 * 1. DMAC destination
672 * - v Forward frame to
673 * 1. Control interface
674 * v - Forward frame to
675 * 1. Flooding list of interfaces
676 * - - Forward frame to
677 * 1. Control interface
679 enum dpsw_fdb_learning_mode {
680 DPSW_FDB_LEARNING_MODE_DIS = 0,
681 DPSW_FDB_LEARNING_MODE_HW = 1,
682 DPSW_FDB_LEARNING_MODE_NON_SECURE = 2,
683 DPSW_FDB_LEARNING_MODE_SECURE = 3
687 * struct dpsw_fdb_attr - FDB Attributes
688 * @max_fdb_entries: Number of FDB entries
689 * @fdb_ageing_time: Ageing time in seconds
690 * @learning_mode: Learning mode
691 * @num_fdb_mc_groups: Current number of multicast groups
692 * @max_fdb_mc_groups: Maximum number of multicast groups
694 struct dpsw_fdb_attr {
697 enum dpsw_fdb_learning_mode learning_mode;
698 u16 num_fdb_mc_groups;
699 u16 max_fdb_mc_groups;
702 int dpsw_get_api_version(struct fsl_mc_io *mc_io,
707 int dpsw_if_get_port_mac_addr(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
708 u16 if_id, u8 mac_addr[6]);
710 int dpsw_if_get_primary_mac_addr(struct fsl_mc_io *mc_io, u32 cmd_flags,
711 u16 token, u16 if_id, u8 mac_addr[6]);
713 int dpsw_if_set_primary_mac_addr(struct fsl_mc_io *mc_io, u32 cmd_flags,
714 u16 token, u16 if_id, u8 mac_addr[6]);
717 * struct dpsw_fdb_cfg - FDB Configuration
718 * @num_fdb_entries: Number of FDB entries
719 * @fdb_ageing_time: Ageing time in seconds
721 struct dpsw_fdb_cfg {
726 int dpsw_fdb_add(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token, u16 *fdb_id,
727 const struct dpsw_fdb_cfg *cfg);
729 int dpsw_fdb_remove(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token, u16 fdb_id);
732 * enum dpsw_flood_type - Define the flood type of a DPSW object
733 * @DPSW_BROADCAST: Broadcast flooding
734 * @DPSW_FLOODING: Unknown flooding
736 enum dpsw_flood_type {
741 struct dpsw_egress_flood_cfg {
743 enum dpsw_flood_type flood_type;
745 u16 if_id[DPSW_MAX_IF];
748 int dpsw_set_egress_flood(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
749 const struct dpsw_egress_flood_cfg *cfg);
751 #endif /* __FSL_DPSW_H */