1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Copyright 2014-2016 Freescale Semiconductor Inc.
4 * Copyright 2017-2018 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
78 int dpsw_enable(struct fsl_mc_io *mc_io,
82 int dpsw_disable(struct fsl_mc_io *mc_io,
86 int dpsw_reset(struct fsl_mc_io *mc_io,
91 * DPSW IRQ Index and Events
94 #define DPSW_IRQ_INDEX_IF 0x0000
95 #define DPSW_IRQ_INDEX_L2SW 0x0001
98 * IRQ event - Indicates that the link state changed
100 #define DPSW_IRQ_EVENT_LINK_CHANGED 0x0001
103 * struct dpsw_irq_cfg - IRQ configuration
104 * @addr: Address that must be written to signal a message-based interrupt
105 * @val: Value to write into irq_addr address
106 * @irq_num: A user defined number associated with this IRQ
108 struct dpsw_irq_cfg {
114 int dpsw_set_irq_enable(struct fsl_mc_io *mc_io,
120 int dpsw_set_irq_mask(struct fsl_mc_io *mc_io,
126 int dpsw_get_irq_status(struct fsl_mc_io *mc_io,
132 int dpsw_clear_irq_status(struct fsl_mc_io *mc_io,
139 * struct dpsw_attr - Structure representing DPSW attributes
140 * @id: DPSW object ID
141 * @options: Enable/Disable DPSW features
142 * @max_vlans: Maximum Number of VLANs
143 * @max_meters_per_if: Number of meters per interface
144 * @max_fdbs: Maximum Number of FDBs
145 * @max_fdb_entries: Number of FDB entries for default FDB table;
146 * 0 - indicates default 1024 entries.
147 * @fdb_aging_time: Default FDB aging time for default FDB table;
148 * 0 - indicates default 300 seconds
149 * @max_fdb_mc_groups: Number of multicast groups in each FDB table;
150 * 0 - indicates default 32
151 * @mem_size: DPSW frame storage memory size
152 * @num_ifs: Number of interfaces
153 * @num_vlans: Current number of VLANs
154 * @num_fdbs: Current number of FDBs
155 * @component_type: Component type of this bridge
161 u8 max_meters_per_if;
165 u16 max_fdb_mc_groups;
170 enum dpsw_component_type component_type;
173 int dpsw_get_attributes(struct fsl_mc_io *mc_io,
176 struct dpsw_attr *attr);
179 * enum dpsw_action - Action selection for special/control frames
180 * @DPSW_ACTION_DROP: Drop frame
181 * @DPSW_ACTION_REDIRECT: Redirect frame to control port
184 DPSW_ACTION_DROP = 0,
185 DPSW_ACTION_REDIRECT = 1
189 * Enable auto-negotiation
191 #define DPSW_LINK_OPT_AUTONEG 0x0000000000000001ULL
193 * Enable half-duplex mode
195 #define DPSW_LINK_OPT_HALF_DUPLEX 0x0000000000000002ULL
197 * Enable pause frames
199 #define DPSW_LINK_OPT_PAUSE 0x0000000000000004ULL
201 * Enable a-symmetric pause frames
203 #define DPSW_LINK_OPT_ASYM_PAUSE 0x0000000000000008ULL
206 * struct dpsw_link_cfg - Structure representing DPSW link configuration
208 * @options: Mask of available options; use 'DPSW_LINK_OPT_<X>' values
210 struct dpsw_link_cfg {
215 int dpsw_if_set_link_cfg(struct fsl_mc_io *mc_io,
219 struct dpsw_link_cfg *cfg);
221 * struct dpsw_link_state - Structure representing DPSW link state
223 * @options: Mask of available options; use 'DPSW_LINK_OPT_<X>' values
224 * @up: 0 - covers two cases: down and disconnected, 1 - up
226 struct dpsw_link_state {
232 int dpsw_if_get_link_state(struct fsl_mc_io *mc_io,
236 struct dpsw_link_state *state);
239 * struct dpsw_tci_cfg - Tag Control Information (TCI) configuration
240 * @pcp: Priority Code Point (PCP): a 3-bit field which refers
241 * to the IEEE 802.1p priority
242 * @dei: Drop Eligible Indicator (DEI): a 1-bit field. May be used
243 * separately or in conjunction with PCP to indicate frames
244 * eligible to be dropped in the presence of congestion
245 * @vlan_id: VLAN Identifier (VID): a 12-bit field specifying the VLAN
246 * to which the frame belongs. The hexadecimal values
247 * of 0x000 and 0xFFF are reserved;
248 * all other values may be used as VLAN identifiers,
249 * allowing up to 4,094 VLANs
251 struct dpsw_tci_cfg {
257 int dpsw_if_set_tci(struct fsl_mc_io *mc_io,
261 const struct dpsw_tci_cfg *cfg);
263 int dpsw_if_get_tci(struct fsl_mc_io *mc_io,
267 struct dpsw_tci_cfg *cfg);
270 * enum dpsw_stp_state - Spanning Tree Protocol (STP) states
271 * @DPSW_STP_STATE_BLOCKING: Blocking state
272 * @DPSW_STP_STATE_LISTENING: Listening state
273 * @DPSW_STP_STATE_LEARNING: Learning state
274 * @DPSW_STP_STATE_FORWARDING: Forwarding state
277 enum dpsw_stp_state {
278 DPSW_STP_STATE_DISABLED = 0,
279 DPSW_STP_STATE_LISTENING = 1,
280 DPSW_STP_STATE_LEARNING = 2,
281 DPSW_STP_STATE_FORWARDING = 3,
282 DPSW_STP_STATE_BLOCKING = 0
286 * struct dpsw_stp_cfg - Spanning Tree Protocol (STP) Configuration
287 * @vlan_id: VLAN ID STP state
290 struct dpsw_stp_cfg {
292 enum dpsw_stp_state state;
295 int dpsw_if_set_stp(struct fsl_mc_io *mc_io,
299 const struct dpsw_stp_cfg *cfg);
302 * enum dpsw_accepted_frames - Types of frames to accept
303 * @DPSW_ADMIT_ALL: The device accepts VLAN tagged, untagged and
304 * priority tagged frames
305 * @DPSW_ADMIT_ONLY_VLAN_TAGGED: The device discards untagged frames or
306 * Priority-Tagged frames received on this interface.
309 enum dpsw_accepted_frames {
311 DPSW_ADMIT_ONLY_VLAN_TAGGED = 3
315 * enum dpsw_counter - Counters types
316 * @DPSW_CNT_ING_FRAME: Counts ingress frames
317 * @DPSW_CNT_ING_BYTE: Counts ingress bytes
318 * @DPSW_CNT_ING_FLTR_FRAME: Counts filtered ingress frames
319 * @DPSW_CNT_ING_FRAME_DISCARD: Counts discarded ingress frame
320 * @DPSW_CNT_ING_MCAST_FRAME: Counts ingress multicast frames
321 * @DPSW_CNT_ING_MCAST_BYTE: Counts ingress multicast bytes
322 * @DPSW_CNT_ING_BCAST_FRAME: Counts ingress broadcast frames
323 * @DPSW_CNT_ING_BCAST_BYTES: Counts ingress broadcast bytes
324 * @DPSW_CNT_EGR_FRAME: Counts egress frames
325 * @DPSW_CNT_EGR_BYTE: Counts egress bytes
326 * @DPSW_CNT_EGR_FRAME_DISCARD: Counts discarded egress frames
327 * @DPSW_CNT_EGR_STP_FRAME_DISCARD: Counts egress STP discarded frames
328 * @DPSW_CNT_ING_NO_BUFF_DISCARD: Counts ingress no buffer discarded frames
331 DPSW_CNT_ING_FRAME = 0x0,
332 DPSW_CNT_ING_BYTE = 0x1,
333 DPSW_CNT_ING_FLTR_FRAME = 0x2,
334 DPSW_CNT_ING_FRAME_DISCARD = 0x3,
335 DPSW_CNT_ING_MCAST_FRAME = 0x4,
336 DPSW_CNT_ING_MCAST_BYTE = 0x5,
337 DPSW_CNT_ING_BCAST_FRAME = 0x6,
338 DPSW_CNT_ING_BCAST_BYTES = 0x7,
339 DPSW_CNT_EGR_FRAME = 0x8,
340 DPSW_CNT_EGR_BYTE = 0x9,
341 DPSW_CNT_EGR_FRAME_DISCARD = 0xa,
342 DPSW_CNT_EGR_STP_FRAME_DISCARD = 0xb,
343 DPSW_CNT_ING_NO_BUFF_DISCARD = 0xc,
346 int dpsw_if_get_counter(struct fsl_mc_io *mc_io,
350 enum dpsw_counter type,
353 int dpsw_if_enable(struct fsl_mc_io *mc_io,
358 int dpsw_if_disable(struct fsl_mc_io *mc_io,
363 int dpsw_if_set_max_frame_length(struct fsl_mc_io *mc_io,
370 * struct dpsw_vlan_cfg - VLAN Configuration
371 * @fdb_id: Forwarding Data Base
373 struct dpsw_vlan_cfg {
377 int dpsw_vlan_add(struct fsl_mc_io *mc_io,
381 const struct dpsw_vlan_cfg *cfg);
384 * struct dpsw_vlan_if_cfg - Set of VLAN Interfaces
385 * @num_ifs: The number of interfaces that are assigned to the egress
387 * @if_id: The set of interfaces that are
388 * assigned to the egress list for this VLAN
390 struct dpsw_vlan_if_cfg {
392 u16 if_id[DPSW_MAX_IF];
395 int dpsw_vlan_add_if(struct fsl_mc_io *mc_io,
399 const struct dpsw_vlan_if_cfg *cfg);
401 int dpsw_vlan_add_if_untagged(struct fsl_mc_io *mc_io,
405 const struct dpsw_vlan_if_cfg *cfg);
407 int dpsw_vlan_remove_if(struct fsl_mc_io *mc_io,
411 const struct dpsw_vlan_if_cfg *cfg);
413 int dpsw_vlan_remove_if_untagged(struct fsl_mc_io *mc_io,
417 const struct dpsw_vlan_if_cfg *cfg);
419 int dpsw_vlan_remove(struct fsl_mc_io *mc_io,
425 * enum dpsw_fdb_entry_type - FDB Entry type - Static/Dynamic
426 * @DPSW_FDB_ENTRY_STATIC: Static entry
427 * @DPSW_FDB_ENTRY_DINAMIC: Dynamic entry
429 enum dpsw_fdb_entry_type {
430 DPSW_FDB_ENTRY_STATIC = 0,
431 DPSW_FDB_ENTRY_DINAMIC = 1
435 * struct dpsw_fdb_unicast_cfg - Unicast entry configuration
436 * @type: Select static or dynamic entry
437 * @mac_addr: MAC address
438 * @if_egress: Egress interface ID
440 struct dpsw_fdb_unicast_cfg {
441 enum dpsw_fdb_entry_type type;
446 int dpsw_fdb_add_unicast(struct fsl_mc_io *mc_io,
450 const struct dpsw_fdb_unicast_cfg *cfg);
452 int dpsw_fdb_remove_unicast(struct fsl_mc_io *mc_io,
456 const struct dpsw_fdb_unicast_cfg *cfg);
458 #define DPSW_FDB_ENTRY_TYPE_DYNAMIC BIT(0)
459 #define DPSW_FDB_ENTRY_TYPE_UNICAST BIT(1)
462 * struct fdb_dump_entry - fdb snapshot entry
463 * @mac_addr: MAC address
464 * @type: bit0 - DINAMIC(1)/STATIC(0), bit1 - UNICAST(1)/MULTICAST(0)
465 * @if_info: unicast - egress interface, multicast - number of egress interfaces
466 * @if_mask: multicast - egress interface mask
468 struct fdb_dump_entry {
475 int dpsw_fdb_dump(struct fsl_mc_io *mc_io,
484 * struct dpsw_fdb_multicast_cfg - Multi-cast entry configuration
485 * @type: Select static or dynamic entry
486 * @mac_addr: MAC address
487 * @num_ifs: Number of external and internal interfaces
488 * @if_id: Egress interface IDs
490 struct dpsw_fdb_multicast_cfg {
491 enum dpsw_fdb_entry_type type;
494 u16 if_id[DPSW_MAX_IF];
497 int dpsw_fdb_add_multicast(struct fsl_mc_io *mc_io,
501 const struct dpsw_fdb_multicast_cfg *cfg);
503 int dpsw_fdb_remove_multicast(struct fsl_mc_io *mc_io,
507 const struct dpsw_fdb_multicast_cfg *cfg);
510 * enum dpsw_fdb_learning_mode - Auto-learning modes
511 * @DPSW_FDB_LEARNING_MODE_DIS: Disable Auto-learning
512 * @DPSW_FDB_LEARNING_MODE_HW: Enable HW auto-Learning
513 * @DPSW_FDB_LEARNING_MODE_NON_SECURE: Enable None secure learning by CPU
514 * @DPSW_FDB_LEARNING_MODE_SECURE: Enable secure learning by CPU
516 * NONE - SECURE LEARNING
517 * SMAC found DMAC found CTLU Action
518 * v v Forward frame to
519 * 1. DMAC destination
520 * - v Forward frame to
521 * 1. DMAC destination
522 * 2. Control interface
523 * v - Forward frame to
524 * 1. Flooding list of interfaces
525 * - - Forward frame to
526 * 1. Flooding list of interfaces
527 * 2. Control interface
529 * SMAC found DMAC found CTLU Action
530 * v v Forward frame to
531 * 1. DMAC destination
532 * - v Forward frame to
533 * 1. Control interface
534 * v - Forward frame to
535 * 1. Flooding list of interfaces
536 * - - Forward frame to
537 * 1. Control interface
539 enum dpsw_fdb_learning_mode {
540 DPSW_FDB_LEARNING_MODE_DIS = 0,
541 DPSW_FDB_LEARNING_MODE_HW = 1,
542 DPSW_FDB_LEARNING_MODE_NON_SECURE = 2,
543 DPSW_FDB_LEARNING_MODE_SECURE = 3
547 * struct dpsw_fdb_attr - FDB Attributes
548 * @max_fdb_entries: Number of FDB entries
549 * @fdb_aging_time: Aging time in seconds
550 * @learning_mode: Learning mode
551 * @num_fdb_mc_groups: Current number of multicast groups
552 * @max_fdb_mc_groups: Maximum number of multicast groups
554 struct dpsw_fdb_attr {
557 enum dpsw_fdb_learning_mode learning_mode;
558 u16 num_fdb_mc_groups;
559 u16 max_fdb_mc_groups;
562 int dpsw_get_api_version(struct fsl_mc_io *mc_io,
567 int dpsw_if_get_port_mac_addr(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
568 u16 if_id, u8 mac_addr[6]);
570 int dpsw_if_get_primary_mac_addr(struct fsl_mc_io *mc_io, u32 cmd_flags,
571 u16 token, u16 if_id, u8 mac_addr[6]);
573 int dpsw_if_set_primary_mac_addr(struct fsl_mc_io *mc_io, u32 cmd_flags,
574 u16 token, u16 if_id, u8 mac_addr[6]);
576 #endif /* __FSL_DPSW_H */