Linux Audio

Check our new training course

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