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
79 * struct dpsw_cfg - DPSW configuration
80 * @num_ifs: Number of external and internal interfaces
81 * @adv: Advanced parameters; default is all zeros;
82 * use this structure to change default settings
83 * @adv.options: Enable/Disable DPSW features (bitmap)
84 * @adv.max_vlans: Maximum Number of VLAN's; 0 - indicates default 16
85 * @adv.max_meters_per_if: Number of meters per interface
86 * @adv.max_fdbs: Maximum Number of FDB's; 0 - indicates default 16
87 * @adv.max_fdb_entries: Number of FDB entries for default FDB table;
88 * 0 - indicates default 1024 entries.
89 * @adv.fdb_aging_time: Default FDB aging time for default FDB table;
90 * 0 - indicates default 300 seconds
91 * @adv.max_fdb_mc_groups: Number of multicast groups in each FDB table;
92 * 0 - indicates default 32
93 * @adv.component_type: Indicates the component type of this bridge
100 u8 max_meters_per_if;
104 u16 max_fdb_mc_groups;
105 enum dpsw_component_type component_type;
109 int dpsw_enable(struct fsl_mc_io *mc_io,
113 int dpsw_disable(struct fsl_mc_io *mc_io,
117 int dpsw_reset(struct fsl_mc_io *mc_io,
122 * DPSW IRQ Index and Events
125 #define DPSW_IRQ_INDEX_IF 0x0000
126 #define DPSW_IRQ_INDEX_L2SW 0x0001
129 * IRQ event - Indicates that the link state changed
131 #define DPSW_IRQ_EVENT_LINK_CHANGED 0x0001
134 * struct dpsw_irq_cfg - IRQ configuration
135 * @addr: Address that must be written to signal a message-based interrupt
136 * @val: Value to write into irq_addr address
137 * @irq_num: A user defined number associated with this IRQ
139 struct dpsw_irq_cfg {
145 int dpsw_set_irq_enable(struct fsl_mc_io *mc_io,
151 int dpsw_set_irq_mask(struct fsl_mc_io *mc_io,
157 int dpsw_get_irq_status(struct fsl_mc_io *mc_io,
163 int dpsw_clear_irq_status(struct fsl_mc_io *mc_io,
170 * struct dpsw_attr - Structure representing DPSW attributes
171 * @id: DPSW object ID
172 * @options: Enable/Disable DPSW features
173 * @max_vlans: Maximum Number of VLANs
174 * @max_meters_per_if: Number of meters per interface
175 * @max_fdbs: Maximum Number of FDBs
176 * @max_fdb_entries: Number of FDB entries for default FDB table;
177 * 0 - indicates default 1024 entries.
178 * @fdb_aging_time: Default FDB aging time for default FDB table;
179 * 0 - indicates default 300 seconds
180 * @max_fdb_mc_groups: Number of multicast groups in each FDB table;
181 * 0 - indicates default 32
182 * @mem_size: DPSW frame storage memory size
183 * @num_ifs: Number of interfaces
184 * @num_vlans: Current number of VLANs
185 * @num_fdbs: Current number of FDBs
186 * @component_type: Component type of this bridge
192 u8 max_meters_per_if;
196 u16 max_fdb_mc_groups;
201 enum dpsw_component_type component_type;
204 int dpsw_get_attributes(struct fsl_mc_io *mc_io,
207 struct dpsw_attr *attr);
210 * enum dpsw_action - Action selection for special/control frames
211 * @DPSW_ACTION_DROP: Drop frame
212 * @DPSW_ACTION_REDIRECT: Redirect frame to control port
215 DPSW_ACTION_DROP = 0,
216 DPSW_ACTION_REDIRECT = 1
220 * Enable auto-negotiation
222 #define DPSW_LINK_OPT_AUTONEG 0x0000000000000001ULL
224 * Enable half-duplex mode
226 #define DPSW_LINK_OPT_HALF_DUPLEX 0x0000000000000002ULL
228 * Enable pause frames
230 #define DPSW_LINK_OPT_PAUSE 0x0000000000000004ULL
232 * Enable a-symmetric pause frames
234 #define DPSW_LINK_OPT_ASYM_PAUSE 0x0000000000000008ULL
237 * struct dpsw_link_cfg - Structure representing DPSW link configuration
239 * @options: Mask of available options; use 'DPSW_LINK_OPT_<X>' values
241 struct dpsw_link_cfg {
246 int dpsw_if_set_link_cfg(struct fsl_mc_io *mc_io,
250 struct dpsw_link_cfg *cfg);
252 * struct dpsw_link_state - Structure representing DPSW link state
254 * @options: Mask of available options; use 'DPSW_LINK_OPT_<X>' values
255 * @up: 0 - covers two cases: down and disconnected, 1 - up
257 struct dpsw_link_state {
263 int dpsw_if_get_link_state(struct fsl_mc_io *mc_io,
267 struct dpsw_link_state *state);
269 int dpsw_if_set_flooding(struct fsl_mc_io *mc_io,
275 int dpsw_if_set_broadcast(struct fsl_mc_io *mc_io,
282 * struct dpsw_tci_cfg - Tag Control Information (TCI) configuration
283 * @pcp: Priority Code Point (PCP): a 3-bit field which refers
284 * to the IEEE 802.1p priority
285 * @dei: Drop Eligible Indicator (DEI): a 1-bit field. May be used
286 * separately or in conjunction with PCP to indicate frames
287 * eligible to be dropped in the presence of congestion
288 * @vlan_id: VLAN Identifier (VID): a 12-bit field specifying the VLAN
289 * to which the frame belongs. The hexadecimal values
290 * of 0x000 and 0xFFF are reserved;
291 * all other values may be used as VLAN identifiers,
292 * allowing up to 4,094 VLANs
294 struct dpsw_tci_cfg {
300 int dpsw_if_set_tci(struct fsl_mc_io *mc_io,
304 const struct dpsw_tci_cfg *cfg);
306 int dpsw_if_get_tci(struct fsl_mc_io *mc_io,
310 struct dpsw_tci_cfg *cfg);
313 * enum dpsw_stp_state - Spanning Tree Protocol (STP) states
314 * @DPSW_STP_STATE_BLOCKING: Blocking state
315 * @DPSW_STP_STATE_LISTENING: Listening state
316 * @DPSW_STP_STATE_LEARNING: Learning state
317 * @DPSW_STP_STATE_FORWARDING: Forwarding state
320 enum dpsw_stp_state {
321 DPSW_STP_STATE_DISABLED = 0,
322 DPSW_STP_STATE_LISTENING = 1,
323 DPSW_STP_STATE_LEARNING = 2,
324 DPSW_STP_STATE_FORWARDING = 3,
325 DPSW_STP_STATE_BLOCKING = 0
329 * struct dpsw_stp_cfg - Spanning Tree Protocol (STP) Configuration
330 * @vlan_id: VLAN ID STP state
333 struct dpsw_stp_cfg {
335 enum dpsw_stp_state state;
338 int dpsw_if_set_stp(struct fsl_mc_io *mc_io,
342 const struct dpsw_stp_cfg *cfg);
345 * enum dpsw_accepted_frames - Types of frames to accept
346 * @DPSW_ADMIT_ALL: The device accepts VLAN tagged, untagged and
347 * priority tagged frames
348 * @DPSW_ADMIT_ONLY_VLAN_TAGGED: The device discards untagged frames or
349 * Priority-Tagged frames received on this interface.
352 enum dpsw_accepted_frames {
354 DPSW_ADMIT_ONLY_VLAN_TAGGED = 3
358 * enum dpsw_counter - Counters types
359 * @DPSW_CNT_ING_FRAME: Counts ingress frames
360 * @DPSW_CNT_ING_BYTE: Counts ingress bytes
361 * @DPSW_CNT_ING_FLTR_FRAME: Counts filtered ingress frames
362 * @DPSW_CNT_ING_FRAME_DISCARD: Counts discarded ingress frame
363 * @DPSW_CNT_ING_MCAST_FRAME: Counts ingress multicast frames
364 * @DPSW_CNT_ING_MCAST_BYTE: Counts ingress multicast bytes
365 * @DPSW_CNT_ING_BCAST_FRAME: Counts ingress broadcast frames
366 * @DPSW_CNT_ING_BCAST_BYTES: Counts ingress broadcast bytes
367 * @DPSW_CNT_EGR_FRAME: Counts egress frames
368 * @DPSW_CNT_EGR_BYTE: Counts eEgress bytes
369 * @DPSW_CNT_EGR_FRAME_DISCARD: Counts discarded egress frames
370 * @DPSW_CNT_EGR_STP_FRAME_DISCARD: Counts egress STP discarded frames
373 DPSW_CNT_ING_FRAME = 0x0,
374 DPSW_CNT_ING_BYTE = 0x1,
375 DPSW_CNT_ING_FLTR_FRAME = 0x2,
376 DPSW_CNT_ING_FRAME_DISCARD = 0x3,
377 DPSW_CNT_ING_MCAST_FRAME = 0x4,
378 DPSW_CNT_ING_MCAST_BYTE = 0x5,
379 DPSW_CNT_ING_BCAST_FRAME = 0x6,
380 DPSW_CNT_ING_BCAST_BYTES = 0x7,
381 DPSW_CNT_EGR_FRAME = 0x8,
382 DPSW_CNT_EGR_BYTE = 0x9,
383 DPSW_CNT_EGR_FRAME_DISCARD = 0xa,
384 DPSW_CNT_EGR_STP_FRAME_DISCARD = 0xb
387 int dpsw_if_get_counter(struct fsl_mc_io *mc_io,
391 enum dpsw_counter type,
394 int dpsw_if_enable(struct fsl_mc_io *mc_io,
399 int dpsw_if_disable(struct fsl_mc_io *mc_io,
404 int dpsw_if_set_max_frame_length(struct fsl_mc_io *mc_io,
411 * struct dpsw_vlan_cfg - VLAN Configuration
412 * @fdb_id: Forwarding Data Base
414 struct dpsw_vlan_cfg {
418 int dpsw_vlan_add(struct fsl_mc_io *mc_io,
422 const struct dpsw_vlan_cfg *cfg);
425 * struct dpsw_vlan_if_cfg - Set of VLAN Interfaces
426 * @num_ifs: The number of interfaces that are assigned to the egress
428 * @if_id: The set of interfaces that are
429 * assigned to the egress list for this VLAN
431 struct dpsw_vlan_if_cfg {
433 u16 if_id[DPSW_MAX_IF];
436 int dpsw_vlan_add_if(struct fsl_mc_io *mc_io,
440 const struct dpsw_vlan_if_cfg *cfg);
442 int dpsw_vlan_add_if_untagged(struct fsl_mc_io *mc_io,
446 const struct dpsw_vlan_if_cfg *cfg);
448 int dpsw_vlan_remove_if(struct fsl_mc_io *mc_io,
452 const struct dpsw_vlan_if_cfg *cfg);
454 int dpsw_vlan_remove_if_untagged(struct fsl_mc_io *mc_io,
458 const struct dpsw_vlan_if_cfg *cfg);
460 int dpsw_vlan_remove(struct fsl_mc_io *mc_io,
466 * enum dpsw_fdb_entry_type - FDB Entry type - Static/Dynamic
467 * @DPSW_FDB_ENTRY_STATIC: Static entry
468 * @DPSW_FDB_ENTRY_DINAMIC: Dynamic entry
470 enum dpsw_fdb_entry_type {
471 DPSW_FDB_ENTRY_STATIC = 0,
472 DPSW_FDB_ENTRY_DINAMIC = 1
476 * struct dpsw_fdb_unicast_cfg - Unicast entry configuration
477 * @type: Select static or dynamic entry
478 * @mac_addr: MAC address
479 * @if_egress: Egress interface ID
481 struct dpsw_fdb_unicast_cfg {
482 enum dpsw_fdb_entry_type type;
487 int dpsw_fdb_add_unicast(struct fsl_mc_io *mc_io,
491 const struct dpsw_fdb_unicast_cfg *cfg);
493 int dpsw_fdb_remove_unicast(struct fsl_mc_io *mc_io,
497 const struct dpsw_fdb_unicast_cfg *cfg);
500 * struct dpsw_fdb_multicast_cfg - Multi-cast entry configuration
501 * @type: Select static or dynamic entry
502 * @mac_addr: MAC address
503 * @num_ifs: Number of external and internal interfaces
504 * @if_id: Egress interface IDs
506 struct dpsw_fdb_multicast_cfg {
507 enum dpsw_fdb_entry_type type;
510 u16 if_id[DPSW_MAX_IF];
513 int dpsw_fdb_add_multicast(struct fsl_mc_io *mc_io,
517 const struct dpsw_fdb_multicast_cfg *cfg);
519 int dpsw_fdb_remove_multicast(struct fsl_mc_io *mc_io,
523 const struct dpsw_fdb_multicast_cfg *cfg);
526 * enum dpsw_fdb_learning_mode - Auto-learning modes
527 * @DPSW_FDB_LEARNING_MODE_DIS: Disable Auto-learning
528 * @DPSW_FDB_LEARNING_MODE_HW: Enable HW auto-Learning
529 * @DPSW_FDB_LEARNING_MODE_NON_SECURE: Enable None secure learning by CPU
530 * @DPSW_FDB_LEARNING_MODE_SECURE: Enable secure learning by CPU
532 * NONE - SECURE LEARNING
533 * SMAC found DMAC found CTLU Action
534 * v v Forward frame to
535 * 1. DMAC destination
536 * - v Forward frame to
537 * 1. DMAC destination
538 * 2. Control interface
539 * v - Forward frame to
540 * 1. Flooding list of interfaces
541 * - - Forward frame to
542 * 1. Flooding list of interfaces
543 * 2. Control interface
545 * SMAC found DMAC found CTLU Action
546 * v v Forward frame to
547 * 1. DMAC destination
548 * - v Forward frame to
549 * 1. Control interface
550 * v - Forward frame to
551 * 1. Flooding list of interfaces
552 * - - Forward frame to
553 * 1. Control interface
555 enum dpsw_fdb_learning_mode {
556 DPSW_FDB_LEARNING_MODE_DIS = 0,
557 DPSW_FDB_LEARNING_MODE_HW = 1,
558 DPSW_FDB_LEARNING_MODE_NON_SECURE = 2,
559 DPSW_FDB_LEARNING_MODE_SECURE = 3
562 int dpsw_fdb_set_learning_mode(struct fsl_mc_io *mc_io,
566 enum dpsw_fdb_learning_mode mode);
569 * struct dpsw_fdb_attr - FDB Attributes
570 * @max_fdb_entries: Number of FDB entries
571 * @fdb_aging_time: Aging time in seconds
572 * @learning_mode: Learning mode
573 * @num_fdb_mc_groups: Current number of multicast groups
574 * @max_fdb_mc_groups: Maximum number of multicast groups
576 struct dpsw_fdb_attr {
579 enum dpsw_fdb_learning_mode learning_mode;
580 u16 num_fdb_mc_groups;
581 u16 max_fdb_mc_groups;
584 int dpsw_get_api_version(struct fsl_mc_io *mc_io,
589 #endif /* __FSL_DPSW_H */