xref: /linux/drivers/net/ethernet/freescale/dpaa2/dpsw.h (revision 91ec2035134982b98fab0609a9fd8480e8217dc1)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Copyright 2014-2016 Freescale Semiconductor Inc.
4  * Copyright 2017-2021 NXP
5  *
6  */
7 
8 #ifndef __FSL_DPSW_H
9 #define __FSL_DPSW_H
10 
11 /* Data Path L2-Switch API
12  * Contains API for handling DPSW topology and functionality
13  */
14 
15 struct fsl_mc_io;
16 
17 /* DPSW general definitions */
18 
19 #define DPSW_MAX_PRIORITIES	8
20 
21 #define DPSW_MAX_IF		64
22 
23 #define DPSW_MAX_LAG_IFS	8
24 
25 int dpsw_open(struct fsl_mc_io *mc_io, u32 cmd_flags, int dpsw_id, u16 *token);
26 
27 int dpsw_close(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token);
28 
29 /* DPSW options */
30 
31 /**
32  * DPSW_OPT_FLOODING_DIS - Flooding was disabled at device create
33  */
34 #define DPSW_OPT_FLOODING_DIS		0x0000000000000001ULL
35 /**
36  * DPSW_OPT_MULTICAST_DIS - Multicast was disabled at device create
37  */
38 #define DPSW_OPT_MULTICAST_DIS		0x0000000000000004ULL
39 /**
40  * DPSW_OPT_CTRL_IF_DIS - Control interface support is disabled
41  */
42 #define DPSW_OPT_CTRL_IF_DIS		0x0000000000000010ULL
43 
44 /**
45  * enum dpsw_component_type - component type of a bridge
46  * @DPSW_COMPONENT_TYPE_C_VLAN: A C-VLAN component of an
47  *   enterprise VLAN bridge or of a Provider Bridge used
48  *   to process C-tagged frames
49  * @DPSW_COMPONENT_TYPE_S_VLAN: An S-VLAN component of a
50  *   Provider Bridge
51  *
52  */
53 enum dpsw_component_type {
54 	DPSW_COMPONENT_TYPE_C_VLAN = 0,
55 	DPSW_COMPONENT_TYPE_S_VLAN
56 };
57 
58 /**
59  *  enum dpsw_flooding_cfg - flooding configuration requested
60  * @DPSW_FLOODING_PER_VLAN: Flooding replicators are allocated per VLAN and
61  * interfaces present in each of them can be configured using
62  * dpsw_vlan_add_if_flooding()/dpsw_vlan_remove_if_flooding().
63  * This is the default configuration.
64  *
65  * @DPSW_FLOODING_PER_FDB: Flooding replicators are allocated per FDB and
66  * interfaces present in each of them can be configured using
67  * dpsw_set_egress_flood().
68  */
69 enum dpsw_flooding_cfg {
70 	DPSW_FLOODING_PER_VLAN = 0,
71 	DPSW_FLOODING_PER_FDB,
72 };
73 
74 /**
75  * enum dpsw_broadcast_cfg - broadcast configuration requested
76  * @DPSW_BROADCAST_PER_OBJECT: There is only one broadcast replicator per DPSW
77  * object. This is the default configuration.
78  * @DPSW_BROADCAST_PER_FDB: Broadcast replicators are allocated per FDB and
79  * interfaces present in each of them can be configured using
80  * dpsw_set_egress_flood().
81  */
82 enum dpsw_broadcast_cfg {
83 	DPSW_BROADCAST_PER_OBJECT = 0,
84 	DPSW_BROADCAST_PER_FDB,
85 };
86 
87 int dpsw_enable(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token);
88 
89 int dpsw_disable(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token);
90 
91 int dpsw_reset(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token);
92 
93 /* DPSW IRQ Index and Events */
94 
95 #define DPSW_IRQ_INDEX_IF		0x0000
96 #define DPSW_IRQ_INDEX_L2SW		0x0001
97 
98 /**
99  * DPSW_IRQ_EVENT_LINK_CHANGED - Indicates that the link state changed
100  */
101 #define DPSW_IRQ_EVENT_LINK_CHANGED	0x0001
102 
103 /**
104  * DPSW_IRQ_EVENT_ENDPOINT_CHANGED - Indicates a change in endpoint
105  */
106 #define DPSW_IRQ_EVENT_ENDPOINT_CHANGED	0x0002
107 
108 /**
109  * struct dpsw_irq_cfg - IRQ configuration
110  * @addr:	Address that must be written to signal a message-based interrupt
111  * @val:	Value to write into irq_addr address
112  * @irq_num: A user defined number associated with this IRQ
113  */
114 struct dpsw_irq_cfg {
115 	u64 addr;
116 	u32 val;
117 	int irq_num;
118 };
119 
120 int dpsw_set_irq_enable(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
121 			u8 irq_index, u8 en);
122 
123 int dpsw_set_irq_mask(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
124 		      u8 irq_index, u32 mask);
125 
126 int dpsw_get_irq_status(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
127 			u8 irq_index, u32 *status);
128 
129 int dpsw_clear_irq_status(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
130 			  u8 irq_index, u32 status);
131 
132 /**
133  * struct dpsw_attr - Structure representing DPSW attributes
134  * @id: DPSW object ID
135  * @options: Enable/Disable DPSW features
136  * @max_vlans: Maximum Number of VLANs
137  * @max_meters_per_if:  Number of meters per interface
138  * @max_fdbs: Maximum Number of FDBs
139  * @max_fdb_entries: Number of FDB entries for default FDB table;
140  *			0 - indicates default 1024 entries.
141  * @fdb_aging_time: Default FDB aging time for default FDB table;
142  *			0 - indicates default 300 seconds
143  * @max_fdb_mc_groups: Number of multicast groups in each FDB table;
144  *			0 - indicates default 32
145  * @mem_size: DPSW frame storage memory size
146  * @num_ifs: Number of interfaces
147  * @num_vlans: Current number of VLANs
148  * @num_fdbs: Current number of FDBs
149  * @component_type: Component type of this bridge
150  * @flooding_cfg: Flooding configuration (PER_VLAN - default, PER_FDB)
151  * @broadcast_cfg: Broadcast configuration (PER_OBJECT - default, PER_FDB)
152  */
153 struct dpsw_attr {
154 	int id;
155 	u64 options;
156 	u16 max_vlans;
157 	u8 max_meters_per_if;
158 	u8 max_fdbs;
159 	u16 max_fdb_entries;
160 	u16 fdb_aging_time;
161 	u16 max_fdb_mc_groups;
162 	u16 num_ifs;
163 	u16 mem_size;
164 	u16 num_vlans;
165 	u8 num_fdbs;
166 	enum dpsw_component_type component_type;
167 	enum dpsw_flooding_cfg flooding_cfg;
168 	enum dpsw_broadcast_cfg broadcast_cfg;
169 };
170 
171 int dpsw_get_attributes(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
172 			struct dpsw_attr *attr);
173 
174 /**
175  * struct dpsw_ctrl_if_attr - Control interface attributes
176  * @rx_fqid:		Receive FQID
177  * @rx_err_fqid:	Receive error FQID
178  * @tx_err_conf_fqid:	Transmit error and confirmation FQID
179  */
180 struct dpsw_ctrl_if_attr {
181 	u32 rx_fqid;
182 	u32 rx_err_fqid;
183 	u32 tx_err_conf_fqid;
184 };
185 
186 int dpsw_ctrl_if_get_attributes(struct fsl_mc_io *mc_io, u32 cmd_flags,
187 				u16 token, struct dpsw_ctrl_if_attr *attr);
188 
189 enum dpsw_queue_type {
190 	DPSW_QUEUE_RX,
191 	DPSW_QUEUE_TX_ERR_CONF,
192 	DPSW_QUEUE_RX_ERR,
193 };
194 
195 #define DPSW_MAX_DPBP     8
196 
197 /**
198  * struct dpsw_ctrl_if_pools_cfg - Control interface buffer pools configuration
199  * @num_dpbp: Number of DPBPs
200  * @pools: Array of buffer pools parameters; The number of valid entries
201  *	must match 'num_dpbp' value
202  * @pools.dpbp_id: DPBP object ID
203  * @pools.buffer_size: Buffer size
204  * @pools.backup_pool: Backup pool
205  */
206 struct dpsw_ctrl_if_pools_cfg {
207 	u8 num_dpbp;
208 	struct {
209 		int dpbp_id;
210 		u16 buffer_size;
211 		int backup_pool;
212 	} pools[DPSW_MAX_DPBP];
213 };
214 
215 int dpsw_ctrl_if_set_pools(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
216 			   const struct dpsw_ctrl_if_pools_cfg *cfg);
217 
218 #define DPSW_CTRL_IF_QUEUE_OPT_USER_CTX		0x00000001
219 #define DPSW_CTRL_IF_QUEUE_OPT_DEST		0x00000002
220 
221 enum dpsw_ctrl_if_dest {
222 	DPSW_CTRL_IF_DEST_NONE = 0,
223 	DPSW_CTRL_IF_DEST_DPIO = 1,
224 };
225 
226 struct dpsw_ctrl_if_dest_cfg {
227 	enum dpsw_ctrl_if_dest dest_type;
228 	int dest_id;
229 	u8 priority;
230 };
231 
232 struct dpsw_ctrl_if_queue_cfg {
233 	u32 options;
234 	u64 user_ctx;
235 	struct dpsw_ctrl_if_dest_cfg dest_cfg;
236 };
237 
238 int dpsw_ctrl_if_set_queue(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
239 			   enum dpsw_queue_type qtype,
240 			   const struct dpsw_ctrl_if_queue_cfg *cfg);
241 
242 int dpsw_ctrl_if_enable(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token);
243 
244 int dpsw_ctrl_if_disable(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token);
245 
246 /**
247  * enum dpsw_action - Action selection for special/control frames
248  * @DPSW_ACTION_DROP: Drop frame
249  * @DPSW_ACTION_REDIRECT: Redirect frame to control port
250  */
251 enum dpsw_action {
252 	DPSW_ACTION_DROP = 0,
253 	DPSW_ACTION_REDIRECT = 1
254 };
255 
256 #define DPSW_LINK_OPT_AUTONEG		0x0000000000000001ULL
257 #define DPSW_LINK_OPT_HALF_DUPLEX	0x0000000000000002ULL
258 #define DPSW_LINK_OPT_PAUSE		0x0000000000000004ULL
259 #define DPSW_LINK_OPT_ASYM_PAUSE	0x0000000000000008ULL
260 
261 /**
262  * struct dpsw_link_cfg - Structure representing DPSW link configuration
263  * @rate: Rate
264  * @options: Mask of available options; use 'DPSW_LINK_OPT_<X>' values
265  */
266 struct dpsw_link_cfg {
267 	u32 rate;
268 	u64 options;
269 };
270 
271 int dpsw_if_set_link_cfg(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token, u16 if_id,
272 			 struct dpsw_link_cfg *cfg);
273 
274 /**
275  * struct dpsw_link_state - Structure representing DPSW link state
276  * @rate: Rate
277  * @options: Mask of available options; use 'DPSW_LINK_OPT_<X>' values
278  * @up: 0 - covers two cases: down and disconnected, 1 - up
279  */
280 struct dpsw_link_state {
281 	u32 rate;
282 	u64 options;
283 	u8 up;
284 };
285 
286 int dpsw_if_get_link_state(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
287 			   u16 if_id, struct dpsw_link_state *state);
288 
289 /**
290  * struct dpsw_tci_cfg - Tag Control Information (TCI) configuration
291  * @pcp: Priority Code Point (PCP): a 3-bit field which refers
292  *		 to the IEEE 802.1p priority
293  * @dei: Drop Eligible Indicator (DEI): a 1-bit field. May be used
294  *		 separately or in conjunction with PCP to indicate frames
295  *		 eligible to be dropped in the presence of congestion
296  * @vlan_id: VLAN Identifier (VID): a 12-bit field specifying the VLAN
297  *			to which the frame belongs. The hexadecimal values
298  *			of 0x000 and 0xFFF are reserved;
299  *			all other values may be used as VLAN identifiers,
300  *			allowing up to 4,094 VLANs
301  */
302 struct dpsw_tci_cfg {
303 	u8 pcp;
304 	u8 dei;
305 	u16 vlan_id;
306 };
307 
308 int dpsw_if_set_tci(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token, u16 if_id,
309 		    const struct dpsw_tci_cfg *cfg);
310 
311 int dpsw_if_get_tci(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token, u16 if_id,
312 		    struct dpsw_tci_cfg *cfg);
313 
314 /**
315  * enum dpsw_stp_state - Spanning Tree Protocol (STP) states
316  * @DPSW_STP_STATE_DISABLED: Disabled state
317  * @DPSW_STP_STATE_LISTENING: Listening state
318  * @DPSW_STP_STATE_LEARNING: Learning state
319  * @DPSW_STP_STATE_FORWARDING: Forwarding state
320  * @DPSW_STP_STATE_BLOCKING: Blocking state
321  *
322  */
323 enum dpsw_stp_state {
324 	DPSW_STP_STATE_DISABLED = 0,
325 	DPSW_STP_STATE_LISTENING = 1,
326 	DPSW_STP_STATE_LEARNING = 2,
327 	DPSW_STP_STATE_FORWARDING = 3,
328 	DPSW_STP_STATE_BLOCKING = 0
329 };
330 
331 /**
332  * struct dpsw_stp_cfg - Spanning Tree Protocol (STP) Configuration
333  * @vlan_id: VLAN ID STP state
334  * @state: STP state
335  */
336 struct dpsw_stp_cfg {
337 	u16 vlan_id;
338 	enum dpsw_stp_state state;
339 };
340 
341 int dpsw_if_set_stp(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token, u16 if_id,
342 		    const struct dpsw_stp_cfg *cfg);
343 
344 /**
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.
350  *
351  */
352 enum dpsw_accepted_frames {
353 	DPSW_ADMIT_ALL = 1,
354 	DPSW_ADMIT_ONLY_VLAN_TAGGED = 3
355 };
356 
357 /**
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 egress bytes
369  * @DPSW_CNT_EGR_FRAME_DISCARD: Counts discarded egress frames
370  * @DPSW_CNT_EGR_STP_FRAME_DISCARD: Counts egress STP discarded frames
371  * @DPSW_CNT_ING_NO_BUFF_DISCARD: Counts ingress no buffer discarded frames
372  */
373 enum dpsw_counter {
374 	DPSW_CNT_ING_FRAME = 0x0,
375 	DPSW_CNT_ING_BYTE = 0x1,
376 	DPSW_CNT_ING_FLTR_FRAME = 0x2,
377 	DPSW_CNT_ING_FRAME_DISCARD = 0x3,
378 	DPSW_CNT_ING_MCAST_FRAME = 0x4,
379 	DPSW_CNT_ING_MCAST_BYTE = 0x5,
380 	DPSW_CNT_ING_BCAST_FRAME = 0x6,
381 	DPSW_CNT_ING_BCAST_BYTES = 0x7,
382 	DPSW_CNT_EGR_FRAME = 0x8,
383 	DPSW_CNT_EGR_BYTE = 0x9,
384 	DPSW_CNT_EGR_FRAME_DISCARD = 0xa,
385 	DPSW_CNT_EGR_STP_FRAME_DISCARD = 0xb,
386 	DPSW_CNT_ING_NO_BUFF_DISCARD = 0xc,
387 };
388 
389 int dpsw_if_get_counter(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
390 			u16 if_id, enum dpsw_counter type, u64 *counter);
391 
392 int dpsw_if_enable(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token, u16 if_id);
393 
394 int dpsw_if_disable(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token, u16 if_id);
395 
396 /**
397  * struct dpsw_if_attr - Structure representing DPSW interface attributes
398  * @num_tcs: Number of traffic classes
399  * @rate: Transmit rate in bits per second
400  * @options: Interface configuration options (bitmap)
401  * @enabled: Indicates if interface is enabled
402  * @accept_all_vlan: The device discards/accepts incoming frames
403  *		for VLANs that do not include this interface
404  * @admit_untagged: When set to 'DPSW_ADMIT_ONLY_VLAN_TAGGED', the device
405  *		discards untagged frames or priority-tagged frames received on
406  *		this interface;
407  *		When set to 'DPSW_ADMIT_ALL', untagged frames or priority-
408  *		tagged frames received on this interface are accepted
409  * @qdid: control frames transmit qdid
410  */
411 struct dpsw_if_attr {
412 	u8 num_tcs;
413 	u32 rate;
414 	u32 options;
415 	int enabled;
416 	int accept_all_vlan;
417 	enum dpsw_accepted_frames admit_untagged;
418 	u16 qdid;
419 };
420 
421 int dpsw_if_get_attributes(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
422 			   u16 if_id, struct dpsw_if_attr *attr);
423 
424 int dpsw_if_set_max_frame_length(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
425 				 u16 if_id, u16 frame_length);
426 
427 /**
428  * struct dpsw_vlan_cfg - VLAN Configuration
429  * @fdb_id: Forwarding Data Base
430  */
431 struct dpsw_vlan_cfg {
432 	u16 fdb_id;
433 };
434 
435 int dpsw_vlan_add(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
436 		  u16 vlan_id, const struct dpsw_vlan_cfg *cfg);
437 
438 #define DPSW_VLAN_ADD_IF_OPT_FDB_ID            0x0001
439 
440 /**
441  * struct dpsw_vlan_if_cfg - Set of VLAN Interfaces
442  * @num_ifs: The number of interfaces that are assigned to the egress
443  *		list for this VLAN
444  * @if_id: The set of interfaces that are
445  *		assigned to the egress list for this VLAN
446  * @options: Options map for this command (DPSW_VLAN_ADD_IF_OPT_FDB_ID)
447  * @fdb_id: FDB id to be used by this VLAN on these specific interfaces
448  *		(taken into account only if the DPSW_VLAN_ADD_IF_OPT_FDB_ID is
449  *		specified in the options field)
450  */
451 struct dpsw_vlan_if_cfg {
452 	u16 num_ifs;
453 	u16 options;
454 	u16 if_id[DPSW_MAX_IF];
455 	u16 fdb_id;
456 };
457 
458 int dpsw_vlan_add_if(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
459 		     u16 vlan_id, const struct dpsw_vlan_if_cfg *cfg);
460 
461 int dpsw_vlan_add_if_untagged(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
462 			      u16 vlan_id, const struct dpsw_vlan_if_cfg *cfg);
463 
464 int dpsw_vlan_remove_if(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
465 			u16 vlan_id, const struct dpsw_vlan_if_cfg *cfg);
466 
467 int dpsw_vlan_remove_if_untagged(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
468 				 u16 vlan_id, const struct dpsw_vlan_if_cfg *cfg);
469 
470 int dpsw_vlan_remove(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
471 		     u16 vlan_id);
472 
473 /**
474  * enum dpsw_fdb_entry_type - FDB Entry type - Static/Dynamic
475  * @DPSW_FDB_ENTRY_STATIC: Static entry
476  * @DPSW_FDB_ENTRY_DINAMIC: Dynamic entry
477  */
478 enum dpsw_fdb_entry_type {
479 	DPSW_FDB_ENTRY_STATIC = 0,
480 	DPSW_FDB_ENTRY_DINAMIC = 1
481 };
482 
483 /**
484  * struct dpsw_fdb_unicast_cfg - Unicast entry configuration
485  * @type: Select static or dynamic entry
486  * @mac_addr: MAC address
487  * @if_egress: Egress interface ID
488  */
489 struct dpsw_fdb_unicast_cfg {
490 	enum dpsw_fdb_entry_type type;
491 	u8 mac_addr[6];
492 	u16 if_egress;
493 };
494 
495 int dpsw_fdb_add_unicast(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
496 			 u16 fdb_id, const struct dpsw_fdb_unicast_cfg *cfg);
497 
498 int dpsw_fdb_remove_unicast(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
499 			    u16 fdb_id, const struct dpsw_fdb_unicast_cfg *cfg);
500 
501 #define DPSW_FDB_ENTRY_TYPE_DYNAMIC  BIT(0)
502 #define DPSW_FDB_ENTRY_TYPE_UNICAST  BIT(1)
503 
504 /**
505  * struct fdb_dump_entry - fdb snapshot entry
506  * @mac_addr: MAC address
507  * @type: bit0 - DINAMIC(1)/STATIC(0), bit1 - UNICAST(1)/MULTICAST(0)
508  * @if_info: unicast - egress interface, multicast - number of egress interfaces
509  * @if_mask: multicast - egress interface mask
510  */
511 struct fdb_dump_entry {
512 	u8 mac_addr[6];
513 	u8 type;
514 	u8 if_info;
515 	u8 if_mask[8];
516 };
517 
518 int dpsw_fdb_dump(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token, u16 fdb_id,
519 		  u64 iova_addr, u32 iova_size, u16 *num_entries);
520 
521 /**
522  * struct dpsw_fdb_multicast_cfg - Multi-cast entry configuration
523  * @type: Select static or dynamic entry
524  * @mac_addr: MAC address
525  * @num_ifs: Number of external and internal interfaces
526  * @if_id: Egress interface IDs
527  */
528 struct dpsw_fdb_multicast_cfg {
529 	enum dpsw_fdb_entry_type type;
530 	u8 mac_addr[6];
531 	u16 num_ifs;
532 	u16 if_id[DPSW_MAX_IF];
533 };
534 
535 int dpsw_fdb_add_multicast(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
536 			   u16 fdb_id, const struct dpsw_fdb_multicast_cfg *cfg);
537 
538 int dpsw_fdb_remove_multicast(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
539 			      u16 fdb_id, const struct dpsw_fdb_multicast_cfg *cfg);
540 
541 /**
542  * enum dpsw_learning_mode - Auto-learning modes
543  * @DPSW_LEARNING_MODE_DIS: Disable Auto-learning
544  * @DPSW_LEARNING_MODE_HW: Enable HW auto-Learning
545  * @DPSW_LEARNING_MODE_NON_SECURE: Enable None secure learning by CPU
546  * @DPSW_LEARNING_MODE_SECURE: Enable secure learning by CPU
547  *
548  *	NONE - SECURE LEARNING
549  *	SMAC found	DMAC found	CTLU Action
550  *	v		v	Forward frame to
551  *						1.  DMAC destination
552  *	-		v	Forward frame to
553  *						1.  DMAC destination
554  *						2.  Control interface
555  *	v		-	Forward frame to
556  *						1.  Flooding list of interfaces
557  *	-		-	Forward frame to
558  *						1.  Flooding list of interfaces
559  *						2.  Control interface
560  *	SECURE LEARING
561  *	SMAC found	DMAC found	CTLU Action
562  *	v		v		Forward frame to
563  *						1.  DMAC destination
564  *	-		v		Forward frame to
565  *						1.  Control interface
566  *	v		-		Forward frame to
567  *						1.  Flooding list of interfaces
568  *	-		-		Forward frame to
569  *						1.  Control interface
570  */
571 enum dpsw_learning_mode {
572 	DPSW_LEARNING_MODE_DIS = 0,
573 	DPSW_LEARNING_MODE_HW = 1,
574 	DPSW_LEARNING_MODE_NON_SECURE = 2,
575 	DPSW_LEARNING_MODE_SECURE = 3
576 };
577 
578 /**
579  * struct dpsw_fdb_attr - FDB Attributes
580  * @max_fdb_entries: Number of FDB entries
581  * @fdb_ageing_time: Ageing time in seconds
582  * @learning_mode: Learning mode
583  * @num_fdb_mc_groups: Current number of multicast groups
584  * @max_fdb_mc_groups: Maximum number of multicast groups
585  */
586 struct dpsw_fdb_attr {
587 	u16 max_fdb_entries;
588 	u16 fdb_ageing_time;
589 	enum dpsw_learning_mode learning_mode;
590 	u16 num_fdb_mc_groups;
591 	u16 max_fdb_mc_groups;
592 };
593 
594 int dpsw_get_api_version(struct fsl_mc_io *mc_io, u32 cmd_flags,
595 			 u16 *major_ver, u16 *minor_ver);
596 
597 int dpsw_if_get_port_mac_addr(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
598 			      u16 if_id, u8 mac_addr[6]);
599 
600 /**
601  * struct dpsw_fdb_cfg  - FDB Configuration
602  * @num_fdb_entries: Number of FDB entries
603  * @fdb_ageing_time: Ageing time in seconds
604  */
605 struct dpsw_fdb_cfg {
606 	u16 num_fdb_entries;
607 	u16 fdb_ageing_time;
608 };
609 
610 int dpsw_fdb_add(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token, u16 *fdb_id,
611 		 const struct dpsw_fdb_cfg *cfg);
612 
613 int dpsw_fdb_remove(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token, u16 fdb_id);
614 
615 /**
616  * enum dpsw_flood_type - Define the flood type of a DPSW object
617  * @DPSW_BROADCAST: Broadcast flooding
618  * @DPSW_FLOODING: Unknown flooding
619  */
620 enum dpsw_flood_type {
621 	DPSW_BROADCAST = 0,
622 	DPSW_FLOODING,
623 };
624 
625 struct dpsw_egress_flood_cfg {
626 	u16 fdb_id;
627 	enum dpsw_flood_type flood_type;
628 	u16 num_ifs;
629 	u16 if_id[DPSW_MAX_IF];
630 };
631 
632 int dpsw_set_egress_flood(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
633 			  const struct dpsw_egress_flood_cfg *cfg);
634 
635 int dpsw_if_set_learning_mode(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
636 			      u16 if_id, enum dpsw_learning_mode mode);
637 
638 /**
639  * struct dpsw_acl_cfg - ACL Configuration
640  * @max_entries: Number of ACL rules
641  */
642 struct dpsw_acl_cfg {
643 	u16 max_entries;
644 };
645 
646 int dpsw_acl_add(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token, u16 *acl_id,
647 		 const struct dpsw_acl_cfg *cfg);
648 
649 int dpsw_acl_remove(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
650 		    u16 acl_id);
651 
652 /**
653  * struct dpsw_acl_if_cfg - List of interfaces to associate with an ACL table
654  * @num_ifs: Number of interfaces
655  * @if_id: List of interfaces
656  */
657 struct dpsw_acl_if_cfg {
658 	u16 num_ifs;
659 	u16 if_id[DPSW_MAX_IF];
660 };
661 
662 int dpsw_acl_add_if(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
663 		    u16 acl_id, const struct dpsw_acl_if_cfg *cfg);
664 
665 int dpsw_acl_remove_if(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
666 		       u16 acl_id, const struct dpsw_acl_if_cfg *cfg);
667 
668 /**
669  * struct dpsw_acl_fields - ACL fields.
670  * @l2_dest_mac: Destination MAC address: BPDU, Multicast, Broadcast, Unicast,
671  *			slow protocols, MVRP, STP
672  * @l2_source_mac: Source MAC address
673  * @l2_tpid: Layer 2 (Ethernet) protocol type, used to identify the following
674  *		protocols: MPLS, PTP, PFC, ARP, Jumbo frames, LLDP, IEEE802.1ae,
675  *		Q-in-Q, IPv4, IPv6, PPPoE
676  * @l2_pcp_dei: indicate which protocol is encapsulated in the payload
677  * @l2_vlan_id: layer 2 VLAN ID
678  * @l2_ether_type: layer 2 Ethernet type
679  * @l3_dscp: Layer 3 differentiated services code point
680  * @l3_protocol: Tells the Network layer at the destination host, to which
681  *		Protocol this packet belongs to. The following protocol are
682  *		supported: ICMP, IGMP, IPv4 (encapsulation), TCP, IPv6
683  *		(encapsulation), GRE, PTP
684  * @l3_source_ip: Source IPv4 IP
685  * @l3_dest_ip: Destination IPv4 IP
686  * @l4_source_port: Source TCP/UDP Port
687  * @l4_dest_port: Destination TCP/UDP Port
688  */
689 struct dpsw_acl_fields {
690 	u8 l2_dest_mac[6];
691 	u8 l2_source_mac[6];
692 	u16 l2_tpid;
693 	u8 l2_pcp_dei;
694 	u16 l2_vlan_id;
695 	u16 l2_ether_type;
696 	u8 l3_dscp;
697 	u8 l3_protocol;
698 	u32 l3_source_ip;
699 	u32 l3_dest_ip;
700 	u16 l4_source_port;
701 	u16 l4_dest_port;
702 };
703 
704 /**
705  * struct dpsw_acl_key - ACL key
706  * @match: Match fields
707  * @mask: Mask: b'1 - valid, b'0 don't care
708  */
709 struct dpsw_acl_key {
710 	struct dpsw_acl_fields match;
711 	struct dpsw_acl_fields mask;
712 };
713 
714 /**
715  * enum dpsw_acl_action - action to be run on the ACL rule match
716  * @DPSW_ACL_ACTION_DROP: Drop frame
717  * @DPSW_ACL_ACTION_REDIRECT: Redirect to certain port
718  * @DPSW_ACL_ACTION_ACCEPT: Accept frame
719  * @DPSW_ACL_ACTION_REDIRECT_TO_CTRL_IF: Redirect to control interface
720  */
721 enum dpsw_acl_action {
722 	DPSW_ACL_ACTION_DROP,
723 	DPSW_ACL_ACTION_REDIRECT,
724 	DPSW_ACL_ACTION_ACCEPT,
725 	DPSW_ACL_ACTION_REDIRECT_TO_CTRL_IF
726 };
727 
728 /**
729  * struct dpsw_acl_result - ACL action
730  * @action: Action should be taken when	ACL entry hit
731  * @if_id:  Interface IDs to redirect frame. Valid only if redirect selected for
732  *		 action
733  */
734 struct dpsw_acl_result {
735 	enum dpsw_acl_action action;
736 	u16 if_id;
737 };
738 
739 /**
740  * struct dpsw_acl_entry_cfg - ACL entry
741  * @key_iova: I/O virtual address of DMA-able memory filled with key after call
742  *				to dpsw_acl_prepare_entry_cfg()
743  * @result: Required action when entry hit occurs
744  * @precedence: Precedence inside ACL 0 is lowest; This priority can not change
745  *		during the lifetime of a Policy. It is user responsibility to
746  *		space the priorities according to consequent rule additions.
747  */
748 struct dpsw_acl_entry_cfg {
749 	u64 key_iova;
750 	struct dpsw_acl_result result;
751 	int precedence;
752 };
753 
754 void dpsw_acl_prepare_entry_cfg(const struct dpsw_acl_key *key,
755 				u8 *entry_cfg_buf);
756 
757 int dpsw_acl_add_entry(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
758 		       u16 acl_id, const struct dpsw_acl_entry_cfg *cfg);
759 
760 int dpsw_acl_remove_entry(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
761 			  u16 acl_id, const struct dpsw_acl_entry_cfg *cfg);
762 
763 /**
764  * enum dpsw_reflection_filter - Filter type for frames to be reflected
765  * @DPSW_REFLECTION_FILTER_INGRESS_ALL: Reflect all frames
766  * @DPSW_REFLECTION_FILTER_INGRESS_VLAN: Reflect only frames that belong to
767  *	the particular VLAN defined by vid parameter
768  *
769  */
770 enum dpsw_reflection_filter {
771 	DPSW_REFLECTION_FILTER_INGRESS_ALL = 0,
772 	DPSW_REFLECTION_FILTER_INGRESS_VLAN = 1
773 };
774 
775 /**
776  * struct dpsw_reflection_cfg - Structure representing the mirroring config
777  * @filter: Filter type for frames to be mirrored
778  * @vlan_id: VLAN ID to mirror; valid only when the type is DPSW_INGRESS_VLAN
779  */
780 struct dpsw_reflection_cfg {
781 	enum dpsw_reflection_filter filter;
782 	u16 vlan_id;
783 };
784 
785 int dpsw_set_reflection_if(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
786 			   u16 if_id);
787 
788 int dpsw_if_add_reflection(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
789 			   u16 if_id, const struct dpsw_reflection_cfg *cfg);
790 
791 int dpsw_if_remove_reflection(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
792 			      u16 if_id, const struct dpsw_reflection_cfg *cfg);
793 
794 /* Link Aggregation Group configuration */
795 
796 #define DPSW_LAG_SET_PHASE_APPLY 0
797 #define DPSW_LAG_SET_PHASE_CHECK 1
798 
799 /**
800  * struct dpsw_lag_cfg - Configuration structure for a LAG group
801  * @group_id: Link aggregation group ID. Valid values are in the
802  * [1, DPSW_MAX_LAG_IFS] range.
803  * @num_ifs: Number of interfaces in this LAG group, valid range is
804  * [0, DPSW_MAX_LAG_IFS].
805  * @if_id: Array containing the interface IDs of the ports part of a LAG group
806  * @phase: Use DPSW_LAG_SET_PHASE_APPLY for LAG configuration processing or
807  * DPSW_LAG_SET_PHASE_CHECK for LAG configuration validation.
808  */
809 struct dpsw_lag_cfg {
810 	u8 group_id;
811 	u8 num_ifs;
812 	u8 if_id[DPSW_MAX_LAG_IFS];
813 	u8 phase;
814 };
815 
816 int dpsw_lag_set(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
817 		 const struct dpsw_lag_cfg *cfg);
818 
819 int dpsw_if_set_lag_state(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
820 			  u16 if_id, u8 tx_enabled);
821 #endif /* __FSL_DPSW_H */
822