1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Copyright 2014-2016 Freescale Semiconductor Inc.
4  * Copyright 2017-2018 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 /**
18  * DPSW general definitions
19  */
20 
21 /**
22  * Maximum number of traffic class priorities
23  */
24 #define DPSW_MAX_PRIORITIES	8
25 /**
26  * Maximum number of interfaces
27  */
28 #define DPSW_MAX_IF		64
29 
30 int dpsw_open(struct fsl_mc_io *mc_io,
31 	      u32 cmd_flags,
32 	      int dpsw_id,
33 	      u16 *token);
34 
35 int dpsw_close(struct fsl_mc_io *mc_io,
36 	       u32 cmd_flags,
37 	       u16 token);
38 
39 /**
40  * DPSW options
41  */
42 
43 /**
44  * Disable flooding
45  */
46 #define DPSW_OPT_FLOODING_DIS		0x0000000000000001ULL
47 /**
48  * Disable Multicast
49  */
50 #define DPSW_OPT_MULTICAST_DIS		0x0000000000000004ULL
51 /**
52  * Support control interface
53  */
54 #define DPSW_OPT_CTRL_IF_DIS		0x0000000000000010ULL
55 /**
56  * Disable flooding metering
57  */
58 #define DPSW_OPT_FLOODING_METERING_DIS  0x0000000000000020ULL
59 /**
60  * Enable metering
61  */
62 #define DPSW_OPT_METERING_EN            0x0000000000000040ULL
63 
64 /**
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
70  *   Provider Bridge
71  *
72  */
73 enum dpsw_component_type {
74 	DPSW_COMPONENT_TYPE_C_VLAN = 0,
75 	DPSW_COMPONENT_TYPE_S_VLAN
76 };
77 
78 /**
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
94  */
95 struct dpsw_cfg {
96 	u16 num_ifs;
97 	struct {
98 		u64 options;
99 		u16 max_vlans;
100 		u8 max_meters_per_if;
101 		u8 max_fdbs;
102 		u16 max_fdb_entries;
103 		u16 fdb_aging_time;
104 		u16 max_fdb_mc_groups;
105 		enum dpsw_component_type component_type;
106 	} adv;
107 };
108 
109 int dpsw_enable(struct fsl_mc_io *mc_io,
110 		u32 cmd_flags,
111 		u16 token);
112 
113 int dpsw_disable(struct fsl_mc_io *mc_io,
114 		 u32 cmd_flags,
115 		 u16 token);
116 
117 int dpsw_reset(struct fsl_mc_io *mc_io,
118 	       u32 cmd_flags,
119 	       u16 token);
120 
121 /**
122  * DPSW IRQ Index and Events
123  */
124 
125 #define DPSW_IRQ_INDEX_IF		0x0000
126 #define DPSW_IRQ_INDEX_L2SW		0x0001
127 
128 /**
129  * IRQ event - Indicates that the link state changed
130  */
131 #define DPSW_IRQ_EVENT_LINK_CHANGED	0x0001
132 
133 /**
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
138  */
139 struct dpsw_irq_cfg {
140 	u64 addr;
141 	u32 val;
142 	int irq_num;
143 };
144 
145 int dpsw_set_irq_enable(struct fsl_mc_io *mc_io,
146 			u32 cmd_flags,
147 			u16 token,
148 			u8 irq_index,
149 			u8 en);
150 
151 int dpsw_set_irq_mask(struct fsl_mc_io *mc_io,
152 		      u32 cmd_flags,
153 		      u16 token,
154 		      u8 irq_index,
155 		      u32 mask);
156 
157 int dpsw_get_irq_status(struct fsl_mc_io *mc_io,
158 			u32 cmd_flags,
159 			u16 token,
160 			u8 irq_index,
161 			u32 *status);
162 
163 int dpsw_clear_irq_status(struct fsl_mc_io *mc_io,
164 			  u32 cmd_flags,
165 			  u16 token,
166 			  u8 irq_index,
167 			  u32 status);
168 
169 /**
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
187  */
188 struct dpsw_attr {
189 	int id;
190 	u64 options;
191 	u16 max_vlans;
192 	u8 max_meters_per_if;
193 	u8 max_fdbs;
194 	u16 max_fdb_entries;
195 	u16 fdb_aging_time;
196 	u16 max_fdb_mc_groups;
197 	u16 num_ifs;
198 	u16 mem_size;
199 	u16 num_vlans;
200 	u8 num_fdbs;
201 	enum dpsw_component_type component_type;
202 };
203 
204 int dpsw_get_attributes(struct fsl_mc_io *mc_io,
205 			u32 cmd_flags,
206 			u16 token,
207 			struct dpsw_attr *attr);
208 
209 /**
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
213  */
214 enum dpsw_action {
215 	DPSW_ACTION_DROP = 0,
216 	DPSW_ACTION_REDIRECT = 1
217 };
218 
219 /**
220  * Enable auto-negotiation
221  */
222 #define DPSW_LINK_OPT_AUTONEG		0x0000000000000001ULL
223 /**
224  * Enable half-duplex mode
225  */
226 #define DPSW_LINK_OPT_HALF_DUPLEX	0x0000000000000002ULL
227 /**
228  * Enable pause frames
229  */
230 #define DPSW_LINK_OPT_PAUSE		0x0000000000000004ULL
231 /**
232  * Enable a-symmetric pause frames
233  */
234 #define DPSW_LINK_OPT_ASYM_PAUSE	0x0000000000000008ULL
235 
236 /**
237  * struct dpsw_link_cfg - Structure representing DPSW link configuration
238  * @rate: Rate
239  * @options: Mask of available options; use 'DPSW_LINK_OPT_<X>' values
240  */
241 struct dpsw_link_cfg {
242 	u32 rate;
243 	u64 options;
244 };
245 
246 int dpsw_if_set_link_cfg(struct fsl_mc_io *mc_io,
247 			 u32 cmd_flags,
248 			 u16 token,
249 			 u16 if_id,
250 			 struct dpsw_link_cfg *cfg);
251 /**
252  * struct dpsw_link_state - Structure representing DPSW link state
253  * @rate: Rate
254  * @options: Mask of available options; use 'DPSW_LINK_OPT_<X>' values
255  * @up: 0 - covers two cases: down and disconnected, 1 - up
256  */
257 struct dpsw_link_state {
258 	u32 rate;
259 	u64 options;
260 	u8 up;
261 };
262 
263 int dpsw_if_get_link_state(struct fsl_mc_io *mc_io,
264 			   u32 cmd_flags,
265 			   u16 token,
266 			   u16 if_id,
267 			   struct dpsw_link_state *state);
268 
269 int dpsw_if_set_flooding(struct fsl_mc_io *mc_io,
270 			 u32 cmd_flags,
271 			 u16 token,
272 			 u16 if_id,
273 			 u8 en);
274 
275 int dpsw_if_set_broadcast(struct fsl_mc_io *mc_io,
276 			  u32 cmd_flags,
277 			  u16 token,
278 			  u16 if_id,
279 			  u8 en);
280 
281 /**
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
293  */
294 struct dpsw_tci_cfg {
295 	u8 pcp;
296 	u8 dei;
297 	u16 vlan_id;
298 };
299 
300 int dpsw_if_set_tci(struct fsl_mc_io *mc_io,
301 		    u32 cmd_flags,
302 		    u16 token,
303 		    u16 if_id,
304 		    const struct dpsw_tci_cfg *cfg);
305 
306 int dpsw_if_get_tci(struct fsl_mc_io *mc_io,
307 		    u32 cmd_flags,
308 		    u16 token,
309 		    u16 if_id,
310 		    struct dpsw_tci_cfg *cfg);
311 
312 /**
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
318  *
319  */
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
326 };
327 
328 /**
329  * struct dpsw_stp_cfg - Spanning Tree Protocol (STP) Configuration
330  * @vlan_id: VLAN ID STP state
331  * @state: STP state
332  */
333 struct dpsw_stp_cfg {
334 	u16 vlan_id;
335 	enum dpsw_stp_state state;
336 };
337 
338 int dpsw_if_set_stp(struct fsl_mc_io *mc_io,
339 		    u32 cmd_flags,
340 		    u16 token,
341 		    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 eEgress bytes
369  * @DPSW_CNT_EGR_FRAME_DISCARD: Counts discarded egress frames
370  * @DPSW_CNT_EGR_STP_FRAME_DISCARD: Counts egress STP discarded frames
371  */
372 enum dpsw_counter {
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
385 };
386 
387 int dpsw_if_get_counter(struct fsl_mc_io *mc_io,
388 			u32 cmd_flags,
389 			u16 token,
390 			u16 if_id,
391 			enum dpsw_counter type,
392 			u64 *counter);
393 
394 int dpsw_if_enable(struct fsl_mc_io *mc_io,
395 		   u32 cmd_flags,
396 		   u16 token,
397 		   u16 if_id);
398 
399 int dpsw_if_disable(struct fsl_mc_io *mc_io,
400 		    u32 cmd_flags,
401 		    u16 token,
402 		    u16 if_id);
403 
404 int dpsw_if_set_max_frame_length(struct fsl_mc_io *mc_io,
405 				 u32 cmd_flags,
406 				 u16 token,
407 				 u16 if_id,
408 				 u16 frame_length);
409 
410 /**
411  * struct dpsw_vlan_cfg - VLAN Configuration
412  * @fdb_id: Forwarding Data Base
413  */
414 struct dpsw_vlan_cfg {
415 	u16 fdb_id;
416 };
417 
418 int dpsw_vlan_add(struct fsl_mc_io *mc_io,
419 		  u32 cmd_flags,
420 		  u16 token,
421 		  u16 vlan_id,
422 		  const struct dpsw_vlan_cfg *cfg);
423 
424 /**
425  * struct dpsw_vlan_if_cfg - Set of VLAN Interfaces
426  * @num_ifs: The number of interfaces that are assigned to the egress
427  *		list for this VLAN
428  * @if_id: The set of interfaces that are
429  *		assigned to the egress list for this VLAN
430  */
431 struct dpsw_vlan_if_cfg {
432 	u16 num_ifs;
433 	u16 if_id[DPSW_MAX_IF];
434 };
435 
436 int dpsw_vlan_add_if(struct fsl_mc_io *mc_io,
437 		     u32 cmd_flags,
438 		     u16 token,
439 		     u16 vlan_id,
440 		     const struct dpsw_vlan_if_cfg *cfg);
441 
442 int dpsw_vlan_add_if_untagged(struct fsl_mc_io *mc_io,
443 			      u32 cmd_flags,
444 			      u16 token,
445 			      u16 vlan_id,
446 			      const struct dpsw_vlan_if_cfg *cfg);
447 
448 int dpsw_vlan_remove_if(struct fsl_mc_io *mc_io,
449 			u32 cmd_flags,
450 			u16 token,
451 			u16 vlan_id,
452 			const struct dpsw_vlan_if_cfg *cfg);
453 
454 int dpsw_vlan_remove_if_untagged(struct fsl_mc_io *mc_io,
455 				 u32 cmd_flags,
456 				 u16 token,
457 				 u16 vlan_id,
458 				 const struct dpsw_vlan_if_cfg *cfg);
459 
460 int dpsw_vlan_remove(struct fsl_mc_io *mc_io,
461 		     u32 cmd_flags,
462 		     u16 token,
463 		     u16 vlan_id);
464 
465 /**
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
469  */
470 enum dpsw_fdb_entry_type {
471 	DPSW_FDB_ENTRY_STATIC = 0,
472 	DPSW_FDB_ENTRY_DINAMIC = 1
473 };
474 
475 /**
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
480  */
481 struct dpsw_fdb_unicast_cfg {
482 	enum dpsw_fdb_entry_type type;
483 	u8 mac_addr[6];
484 	u16 if_egress;
485 };
486 
487 int dpsw_fdb_add_unicast(struct fsl_mc_io *mc_io,
488 			 u32 cmd_flags,
489 			 u16 token,
490 			 u16 fdb_id,
491 			 const struct dpsw_fdb_unicast_cfg *cfg);
492 
493 int dpsw_fdb_remove_unicast(struct fsl_mc_io *mc_io,
494 			    u32 cmd_flags,
495 			    u16 token,
496 			    u16 fdb_id,
497 			    const struct dpsw_fdb_unicast_cfg *cfg);
498 
499 /**
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
505  */
506 struct dpsw_fdb_multicast_cfg {
507 	enum dpsw_fdb_entry_type type;
508 	u8 mac_addr[6];
509 	u16 num_ifs;
510 	u16 if_id[DPSW_MAX_IF];
511 };
512 
513 int dpsw_fdb_add_multicast(struct fsl_mc_io *mc_io,
514 			   u32 cmd_flags,
515 			   u16 token,
516 			   u16 fdb_id,
517 			   const struct dpsw_fdb_multicast_cfg *cfg);
518 
519 int dpsw_fdb_remove_multicast(struct fsl_mc_io *mc_io,
520 			      u32 cmd_flags,
521 			      u16 token,
522 			      u16 fdb_id,
523 			      const struct dpsw_fdb_multicast_cfg *cfg);
524 
525 /**
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
531  *
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
544  *	SECURE LEARING
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
554  */
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
560 };
561 
562 int dpsw_fdb_set_learning_mode(struct fsl_mc_io *mc_io,
563 			       u32 cmd_flags,
564 			       u16 token,
565 			       u16 fdb_id,
566 			       enum dpsw_fdb_learning_mode mode);
567 
568 /**
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
575  */
576 struct dpsw_fdb_attr {
577 	u16 max_fdb_entries;
578 	u16 fdb_aging_time;
579 	enum dpsw_fdb_learning_mode learning_mode;
580 	u16 num_fdb_mc_groups;
581 	u16 max_fdb_mc_groups;
582 };
583 
584 int dpsw_get_api_version(struct fsl_mc_io *mc_io,
585 			 u32 cmd_flags,
586 			 u16 *major_ver,
587 			 u16 *minor_ver);
588 
589 #endif /* __FSL_DPSW_H */
590