Merge branch 'printk-rework' into for-linus
[linux-2.6-microblaze.git] / drivers / staging / fsl-dpaa2 / ethsw / dpsw.h
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 int dpsw_enable(struct fsl_mc_io *mc_io,
79                 u32 cmd_flags,
80                 u16 token);
81
82 int dpsw_disable(struct fsl_mc_io *mc_io,
83                  u32 cmd_flags,
84                  u16 token);
85
86 int dpsw_reset(struct fsl_mc_io *mc_io,
87                u32 cmd_flags,
88                u16 token);
89
90 /**
91  * DPSW IRQ Index and Events
92  */
93
94 #define DPSW_IRQ_INDEX_IF               0x0000
95 #define DPSW_IRQ_INDEX_L2SW             0x0001
96
97 /**
98  * IRQ event - Indicates that the link state changed
99  */
100 #define DPSW_IRQ_EVENT_LINK_CHANGED     0x0001
101
102 /**
103  * struct dpsw_irq_cfg - IRQ configuration
104  * @addr:       Address that must be written to signal a message-based interrupt
105  * @val:        Value to write into irq_addr address
106  * @irq_num: A user defined number associated with this IRQ
107  */
108 struct dpsw_irq_cfg {
109         u64 addr;
110         u32 val;
111         int irq_num;
112 };
113
114 int dpsw_set_irq_enable(struct fsl_mc_io *mc_io,
115                         u32 cmd_flags,
116                         u16 token,
117                         u8 irq_index,
118                         u8 en);
119
120 int dpsw_set_irq_mask(struct fsl_mc_io *mc_io,
121                       u32 cmd_flags,
122                       u16 token,
123                       u8 irq_index,
124                       u32 mask);
125
126 int dpsw_get_irq_status(struct fsl_mc_io *mc_io,
127                         u32 cmd_flags,
128                         u16 token,
129                         u8 irq_index,
130                         u32 *status);
131
132 int dpsw_clear_irq_status(struct fsl_mc_io *mc_io,
133                           u32 cmd_flags,
134                           u16 token,
135                           u8 irq_index,
136                           u32 status);
137
138 /**
139  * struct dpsw_attr - Structure representing DPSW attributes
140  * @id: DPSW object ID
141  * @options: Enable/Disable DPSW features
142  * @max_vlans: Maximum Number of VLANs
143  * @max_meters_per_if:  Number of meters per interface
144  * @max_fdbs: Maximum Number of FDBs
145  * @max_fdb_entries: Number of FDB entries for default FDB table;
146  *                      0 - indicates default 1024 entries.
147  * @fdb_aging_time: Default FDB aging time for default FDB table;
148  *                      0 - indicates default 300 seconds
149  * @max_fdb_mc_groups: Number of multicast groups in each FDB table;
150  *                      0 - indicates default 32
151  * @mem_size: DPSW frame storage memory size
152  * @num_ifs: Number of interfaces
153  * @num_vlans: Current number of VLANs
154  * @num_fdbs: Current number of FDBs
155  * @component_type: Component type of this bridge
156  */
157 struct dpsw_attr {
158         int id;
159         u64 options;
160         u16 max_vlans;
161         u8 max_meters_per_if;
162         u8 max_fdbs;
163         u16 max_fdb_entries;
164         u16 fdb_aging_time;
165         u16 max_fdb_mc_groups;
166         u16 num_ifs;
167         u16 mem_size;
168         u16 num_vlans;
169         u8 num_fdbs;
170         enum dpsw_component_type component_type;
171 };
172
173 int dpsw_get_attributes(struct fsl_mc_io *mc_io,
174                         u32 cmd_flags,
175                         u16 token,
176                         struct dpsw_attr *attr);
177
178 /**
179  * enum dpsw_action - Action selection for special/control frames
180  * @DPSW_ACTION_DROP: Drop frame
181  * @DPSW_ACTION_REDIRECT: Redirect frame to control port
182  */
183 enum dpsw_action {
184         DPSW_ACTION_DROP = 0,
185         DPSW_ACTION_REDIRECT = 1
186 };
187
188 /**
189  * Enable auto-negotiation
190  */
191 #define DPSW_LINK_OPT_AUTONEG           0x0000000000000001ULL
192 /**
193  * Enable half-duplex mode
194  */
195 #define DPSW_LINK_OPT_HALF_DUPLEX       0x0000000000000002ULL
196 /**
197  * Enable pause frames
198  */
199 #define DPSW_LINK_OPT_PAUSE             0x0000000000000004ULL
200 /**
201  * Enable a-symmetric pause frames
202  */
203 #define DPSW_LINK_OPT_ASYM_PAUSE        0x0000000000000008ULL
204
205 /**
206  * struct dpsw_link_cfg - Structure representing DPSW link configuration
207  * @rate: Rate
208  * @options: Mask of available options; use 'DPSW_LINK_OPT_<X>' values
209  */
210 struct dpsw_link_cfg {
211         u32 rate;
212         u64 options;
213 };
214
215 int dpsw_if_set_link_cfg(struct fsl_mc_io *mc_io,
216                          u32 cmd_flags,
217                          u16 token,
218                          u16 if_id,
219                          struct dpsw_link_cfg *cfg);
220 /**
221  * struct dpsw_link_state - Structure representing DPSW link state
222  * @rate: Rate
223  * @options: Mask of available options; use 'DPSW_LINK_OPT_<X>' values
224  * @up: 0 - covers two cases: down and disconnected, 1 - up
225  */
226 struct dpsw_link_state {
227         u32 rate;
228         u64 options;
229         u8 up;
230 };
231
232 int dpsw_if_get_link_state(struct fsl_mc_io *mc_io,
233                            u32 cmd_flags,
234                            u16 token,
235                            u16 if_id,
236                            struct dpsw_link_state *state);
237
238 int dpsw_if_set_flooding(struct fsl_mc_io *mc_io,
239                          u32 cmd_flags,
240                          u16 token,
241                          u16 if_id,
242                          u8 en);
243
244 int dpsw_if_set_broadcast(struct fsl_mc_io *mc_io,
245                           u32 cmd_flags,
246                           u16 token,
247                           u16 if_id,
248                           u8 en);
249
250 /**
251  * struct dpsw_tci_cfg - Tag Control Information (TCI) configuration
252  * @pcp: Priority Code Point (PCP): a 3-bit field which refers
253  *               to the IEEE 802.1p priority
254  * @dei: Drop Eligible Indicator (DEI): a 1-bit field. May be used
255  *               separately or in conjunction with PCP to indicate frames
256  *               eligible to be dropped in the presence of congestion
257  * @vlan_id: VLAN Identifier (VID): a 12-bit field specifying the VLAN
258  *                      to which the frame belongs. The hexadecimal values
259  *                      of 0x000 and 0xFFF are reserved;
260  *                      all other values may be used as VLAN identifiers,
261  *                      allowing up to 4,094 VLANs
262  */
263 struct dpsw_tci_cfg {
264         u8 pcp;
265         u8 dei;
266         u16 vlan_id;
267 };
268
269 int dpsw_if_set_tci(struct fsl_mc_io *mc_io,
270                     u32 cmd_flags,
271                     u16 token,
272                     u16 if_id,
273                     const struct dpsw_tci_cfg *cfg);
274
275 int dpsw_if_get_tci(struct fsl_mc_io *mc_io,
276                     u32 cmd_flags,
277                     u16 token,
278                     u16 if_id,
279                     struct dpsw_tci_cfg *cfg);
280
281 /**
282  * enum dpsw_stp_state - Spanning Tree Protocol (STP) states
283  * @DPSW_STP_STATE_BLOCKING: Blocking state
284  * @DPSW_STP_STATE_LISTENING: Listening state
285  * @DPSW_STP_STATE_LEARNING: Learning state
286  * @DPSW_STP_STATE_FORWARDING: Forwarding state
287  *
288  */
289 enum dpsw_stp_state {
290         DPSW_STP_STATE_DISABLED = 0,
291         DPSW_STP_STATE_LISTENING = 1,
292         DPSW_STP_STATE_LEARNING = 2,
293         DPSW_STP_STATE_FORWARDING = 3,
294         DPSW_STP_STATE_BLOCKING = 0
295 };
296
297 /**
298  * struct dpsw_stp_cfg - Spanning Tree Protocol (STP) Configuration
299  * @vlan_id: VLAN ID STP state
300  * @state: STP state
301  */
302 struct dpsw_stp_cfg {
303         u16 vlan_id;
304         enum dpsw_stp_state state;
305 };
306
307 int dpsw_if_set_stp(struct fsl_mc_io *mc_io,
308                     u32 cmd_flags,
309                     u16 token,
310                     u16 if_id,
311                     const struct dpsw_stp_cfg *cfg);
312
313 /**
314  * enum dpsw_accepted_frames - Types of frames to accept
315  * @DPSW_ADMIT_ALL: The device accepts VLAN tagged, untagged and
316  *                      priority tagged frames
317  * @DPSW_ADMIT_ONLY_VLAN_TAGGED: The device discards untagged frames or
318  *                      Priority-Tagged frames received on this interface.
319  *
320  */
321 enum dpsw_accepted_frames {
322         DPSW_ADMIT_ALL = 1,
323         DPSW_ADMIT_ONLY_VLAN_TAGGED = 3
324 };
325
326 /**
327  * enum dpsw_counter  - Counters types
328  * @DPSW_CNT_ING_FRAME: Counts ingress frames
329  * @DPSW_CNT_ING_BYTE: Counts ingress bytes
330  * @DPSW_CNT_ING_FLTR_FRAME: Counts filtered ingress frames
331  * @DPSW_CNT_ING_FRAME_DISCARD: Counts discarded ingress frame
332  * @DPSW_CNT_ING_MCAST_FRAME: Counts ingress multicast frames
333  * @DPSW_CNT_ING_MCAST_BYTE: Counts ingress multicast bytes
334  * @DPSW_CNT_ING_BCAST_FRAME: Counts ingress broadcast frames
335  * @DPSW_CNT_ING_BCAST_BYTES: Counts ingress broadcast bytes
336  * @DPSW_CNT_EGR_FRAME: Counts egress frames
337  * @DPSW_CNT_EGR_BYTE: Counts egress bytes
338  * @DPSW_CNT_EGR_FRAME_DISCARD: Counts discarded egress frames
339  * @DPSW_CNT_EGR_STP_FRAME_DISCARD: Counts egress STP discarded frames
340  * @DPSW_CNT_ING_NO_BUFF_DISCARD: Counts ingress no buffer discarded frames
341  */
342 enum dpsw_counter {
343         DPSW_CNT_ING_FRAME = 0x0,
344         DPSW_CNT_ING_BYTE = 0x1,
345         DPSW_CNT_ING_FLTR_FRAME = 0x2,
346         DPSW_CNT_ING_FRAME_DISCARD = 0x3,
347         DPSW_CNT_ING_MCAST_FRAME = 0x4,
348         DPSW_CNT_ING_MCAST_BYTE = 0x5,
349         DPSW_CNT_ING_BCAST_FRAME = 0x6,
350         DPSW_CNT_ING_BCAST_BYTES = 0x7,
351         DPSW_CNT_EGR_FRAME = 0x8,
352         DPSW_CNT_EGR_BYTE = 0x9,
353         DPSW_CNT_EGR_FRAME_DISCARD = 0xa,
354         DPSW_CNT_EGR_STP_FRAME_DISCARD = 0xb,
355         DPSW_CNT_ING_NO_BUFF_DISCARD = 0xc,
356 };
357
358 int dpsw_if_get_counter(struct fsl_mc_io *mc_io,
359                         u32 cmd_flags,
360                         u16 token,
361                         u16 if_id,
362                         enum dpsw_counter type,
363                         u64 *counter);
364
365 int dpsw_if_enable(struct fsl_mc_io *mc_io,
366                    u32 cmd_flags,
367                    u16 token,
368                    u16 if_id);
369
370 int dpsw_if_disable(struct fsl_mc_io *mc_io,
371                     u32 cmd_flags,
372                     u16 token,
373                     u16 if_id);
374
375 int dpsw_if_set_max_frame_length(struct fsl_mc_io *mc_io,
376                                  u32 cmd_flags,
377                                  u16 token,
378                                  u16 if_id,
379                                  u16 frame_length);
380
381 /**
382  * struct dpsw_vlan_cfg - VLAN Configuration
383  * @fdb_id: Forwarding Data Base
384  */
385 struct dpsw_vlan_cfg {
386         u16 fdb_id;
387 };
388
389 int dpsw_vlan_add(struct fsl_mc_io *mc_io,
390                   u32 cmd_flags,
391                   u16 token,
392                   u16 vlan_id,
393                   const struct dpsw_vlan_cfg *cfg);
394
395 /**
396  * struct dpsw_vlan_if_cfg - Set of VLAN Interfaces
397  * @num_ifs: The number of interfaces that are assigned to the egress
398  *              list for this VLAN
399  * @if_id: The set of interfaces that are
400  *              assigned to the egress list for this VLAN
401  */
402 struct dpsw_vlan_if_cfg {
403         u16 num_ifs;
404         u16 if_id[DPSW_MAX_IF];
405 };
406
407 int dpsw_vlan_add_if(struct fsl_mc_io *mc_io,
408                      u32 cmd_flags,
409                      u16 token,
410                      u16 vlan_id,
411                      const struct dpsw_vlan_if_cfg *cfg);
412
413 int dpsw_vlan_add_if_untagged(struct fsl_mc_io *mc_io,
414                               u32 cmd_flags,
415                               u16 token,
416                               u16 vlan_id,
417                               const struct dpsw_vlan_if_cfg *cfg);
418
419 int dpsw_vlan_remove_if(struct fsl_mc_io *mc_io,
420                         u32 cmd_flags,
421                         u16 token,
422                         u16 vlan_id,
423                         const struct dpsw_vlan_if_cfg *cfg);
424
425 int dpsw_vlan_remove_if_untagged(struct fsl_mc_io *mc_io,
426                                  u32 cmd_flags,
427                                  u16 token,
428                                  u16 vlan_id,
429                                  const struct dpsw_vlan_if_cfg *cfg);
430
431 int dpsw_vlan_remove(struct fsl_mc_io *mc_io,
432                      u32 cmd_flags,
433                      u16 token,
434                      u16 vlan_id);
435
436 /**
437  * enum dpsw_fdb_entry_type - FDB Entry type - Static/Dynamic
438  * @DPSW_FDB_ENTRY_STATIC: Static entry
439  * @DPSW_FDB_ENTRY_DINAMIC: Dynamic entry
440  */
441 enum dpsw_fdb_entry_type {
442         DPSW_FDB_ENTRY_STATIC = 0,
443         DPSW_FDB_ENTRY_DINAMIC = 1
444 };
445
446 /**
447  * struct dpsw_fdb_unicast_cfg - Unicast entry configuration
448  * @type: Select static or dynamic entry
449  * @mac_addr: MAC address
450  * @if_egress: Egress interface ID
451  */
452 struct dpsw_fdb_unicast_cfg {
453         enum dpsw_fdb_entry_type type;
454         u8 mac_addr[6];
455         u16 if_egress;
456 };
457
458 int dpsw_fdb_add_unicast(struct fsl_mc_io *mc_io,
459                          u32 cmd_flags,
460                          u16 token,
461                          u16 fdb_id,
462                          const struct dpsw_fdb_unicast_cfg *cfg);
463
464 int dpsw_fdb_remove_unicast(struct fsl_mc_io *mc_io,
465                             u32 cmd_flags,
466                             u16 token,
467                             u16 fdb_id,
468                             const struct dpsw_fdb_unicast_cfg *cfg);
469
470 #define DPSW_FDB_ENTRY_TYPE_DYNAMIC  BIT(0)
471 #define DPSW_FDB_ENTRY_TYPE_UNICAST  BIT(1)
472
473 /**
474  * struct fdb_dump_entry - fdb snapshot entry
475  * @mac_addr: MAC address
476  * @type: bit0 - DINAMIC(1)/STATIC(0), bit1 - UNICAST(1)/MULTICAST(0)
477  * @if_info: unicast - egress interface, multicast - number of egress interfaces
478  * @if_mask: multicast - egress interface mask
479  */
480 struct fdb_dump_entry {
481         u8 mac_addr[6];
482         u8 type;
483         u8 if_info;
484         u8 if_mask[8];
485 };
486
487 int dpsw_fdb_dump(struct fsl_mc_io *mc_io,
488                   u32 cmd_flags,
489                   u16 token,
490                   u16 fdb_id,
491                   u64 iova_addr,
492                   u32 iova_size,
493                   u16 *num_entries);
494
495 /**
496  * struct dpsw_fdb_multicast_cfg - Multi-cast entry configuration
497  * @type: Select static or dynamic entry
498  * @mac_addr: MAC address
499  * @num_ifs: Number of external and internal interfaces
500  * @if_id: Egress interface IDs
501  */
502 struct dpsw_fdb_multicast_cfg {
503         enum dpsw_fdb_entry_type type;
504         u8 mac_addr[6];
505         u16 num_ifs;
506         u16 if_id[DPSW_MAX_IF];
507 };
508
509 int dpsw_fdb_add_multicast(struct fsl_mc_io *mc_io,
510                            u32 cmd_flags,
511                            u16 token,
512                            u16 fdb_id,
513                            const struct dpsw_fdb_multicast_cfg *cfg);
514
515 int dpsw_fdb_remove_multicast(struct fsl_mc_io *mc_io,
516                               u32 cmd_flags,
517                               u16 token,
518                               u16 fdb_id,
519                               const struct dpsw_fdb_multicast_cfg *cfg);
520
521 /**
522  * enum dpsw_fdb_learning_mode - Auto-learning modes
523  * @DPSW_FDB_LEARNING_MODE_DIS: Disable Auto-learning
524  * @DPSW_FDB_LEARNING_MODE_HW: Enable HW auto-Learning
525  * @DPSW_FDB_LEARNING_MODE_NON_SECURE: Enable None secure learning by CPU
526  * @DPSW_FDB_LEARNING_MODE_SECURE: Enable secure learning by CPU
527  *
528  *      NONE - SECURE LEARNING
529  *      SMAC found      DMAC found      CTLU Action
530  *      v               v       Forward frame to
531  *                                              1.  DMAC destination
532  *      -               v       Forward frame to
533  *                                              1.  DMAC destination
534  *                                              2.  Control interface
535  *      v               -       Forward frame to
536  *                                              1.  Flooding list of interfaces
537  *      -               -       Forward frame to
538  *                                              1.  Flooding list of interfaces
539  *                                              2.  Control interface
540  *      SECURE LEARING
541  *      SMAC found      DMAC found      CTLU Action
542  *      v               v               Forward frame to
543  *                                              1.  DMAC destination
544  *      -               v               Forward frame to
545  *                                              1.  Control interface
546  *      v               -               Forward frame to
547  *                                              1.  Flooding list of interfaces
548  *      -               -               Forward frame to
549  *                                              1.  Control interface
550  */
551 enum dpsw_fdb_learning_mode {
552         DPSW_FDB_LEARNING_MODE_DIS = 0,
553         DPSW_FDB_LEARNING_MODE_HW = 1,
554         DPSW_FDB_LEARNING_MODE_NON_SECURE = 2,
555         DPSW_FDB_LEARNING_MODE_SECURE = 3
556 };
557
558 int dpsw_fdb_set_learning_mode(struct fsl_mc_io *mc_io,
559                                u32 cmd_flags,
560                                u16 token,
561                                u16 fdb_id,
562                                enum dpsw_fdb_learning_mode mode);
563
564 /**
565  * struct dpsw_fdb_attr - FDB Attributes
566  * @max_fdb_entries: Number of FDB entries
567  * @fdb_aging_time: Aging time in seconds
568  * @learning_mode: Learning mode
569  * @num_fdb_mc_groups: Current number of multicast groups
570  * @max_fdb_mc_groups: Maximum number of multicast groups
571  */
572 struct dpsw_fdb_attr {
573         u16 max_fdb_entries;
574         u16 fdb_aging_time;
575         enum dpsw_fdb_learning_mode learning_mode;
576         u16 num_fdb_mc_groups;
577         u16 max_fdb_mc_groups;
578 };
579
580 int dpsw_get_api_version(struct fsl_mc_io *mc_io,
581                          u32 cmd_flags,
582                          u16 *major_ver,
583                          u16 *minor_ver);
584
585 int dpsw_if_get_port_mac_addr(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
586                               u16 if_id, u8 mac_addr[6]);
587
588 int dpsw_if_get_primary_mac_addr(struct fsl_mc_io *mc_io, u32 cmd_flags,
589                                  u16 token, u16 if_id, u8 mac_addr[6]);
590
591 int dpsw_if_set_primary_mac_addr(struct fsl_mc_io *mc_io, u32 cmd_flags,
592                                  u16 token, u16 if_id, u8 mac_addr[6]);
593
594 #endif /* __FSL_DPSW_H */