dc067b81cd7e09e55a820ea0be30971d296d690d
[dpdk.git] / drivers / net / dpaa2 / mc / fsl_dpdmux.h
1 /* SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0)
2  *
3  * Copyright 2013-2016 Freescale Semiconductor Inc.
4  * Copyright 2018-2021 NXP
5  *
6  */
7 #ifndef __FSL_DPDMUX_H
8 #define __FSL_DPDMUX_H
9
10 #include <fsl_net.h>
11
12 struct fsl_mc_io;
13
14 /** @addtogroup dpdmux Data Path Demux API
15  * Contains API for handling DPDMUX topology and functionality
16  * @{
17  */
18
19 int dpdmux_open(struct fsl_mc_io *mc_io,
20                 uint32_t  cmd_flags,
21                 int  dpdmux_id,
22                 uint16_t  *token);
23
24 int dpdmux_close(struct fsl_mc_io *mc_io,
25                  uint32_t cmd_flags,
26                  uint16_t token);
27
28 /**
29  * DPDMUX general options
30  */
31
32 /**
33  * Enable bridging between internal interfaces
34  */
35 #define DPDMUX_OPT_BRIDGE_EN    0x0000000000000002ULL
36
37 /**
38  * Mask support for classification
39  */
40 #define DPDMUX_OPT_CLS_MASK_SUPPORT             0x0000000000000020ULL
41
42 #define DPDMUX_IRQ_INDEX_IF     0x0000
43 #define DPDMUX_IRQ_INDEX        0x0001
44
45 /**
46  * IRQ event - Indicates that the link state changed
47  */
48 #define DPDMUX_IRQ_EVENT_LINK_CHANGED   0x0001
49
50 /**
51  * enum dpdmux_manip - DPDMUX manipulation operations
52  * @DPDMUX_MANIP_NONE:  No manipulation on frames
53  * @DPDMUX_MANIP_ADD_REMOVE_S_VLAN: Add S-VLAN on egress, remove it on ingress
54  */
55 enum dpdmux_manip {
56         DPDMUX_MANIP_NONE = 0x0,
57         DPDMUX_MANIP_ADD_REMOVE_S_VLAN = 0x1
58 };
59
60 /**
61  * enum dpdmux_method - DPDMUX method options
62  * @DPDMUX_METHOD_NONE: no DPDMUX method
63  * @DPDMUX_METHOD_C_VLAN_MAC: DPDMUX based on C-VLAN and MAC address
64  * @DPDMUX_METHOD_MAC: DPDMUX based on MAC address
65  * @DPDMUX_METHOD_C_VLAN: DPDMUX based on C-VLAN
66  * @DPDMUX_METHOD_S_VLAN: DPDMUX based on S-VLAN
67  */
68 enum dpdmux_method {
69         DPDMUX_METHOD_NONE = 0x0,
70         DPDMUX_METHOD_C_VLAN_MAC = 0x1,
71         DPDMUX_METHOD_MAC = 0x2,
72         DPDMUX_METHOD_C_VLAN = 0x3,
73         DPDMUX_METHOD_S_VLAN = 0x4,
74         DPDMUX_METHOD_CUSTOM = 0x5,
75 };
76
77 /**
78  * struct dpdmux_cfg - DPDMUX configuration parameters
79  * @method: Defines the operation method for the DPDMUX address table
80  * @manip: Required manipulation operation
81  * @num_ifs: Number of interfaces (excluding the uplink interface)
82  * @default_if: Default interface number (different from uplink,
83         maximum value num_ifs)
84  * @adv: Advanced parameters; default is all zeros;
85  *      use this structure to change default settings
86  * @adv.options: DPDMUX options - combination of 'DPDMUX_OPT_<X>' flags.
87  * @adv.max_dmat_entries: Maximum entries in DPDMUX address table
88  *      0 - indicates default: 64 entries per interface.
89  * @adv.max_mc_groups: Number of multicast groups in DPDMUX table
90  *      0 - indicates default: 32 multicast groups.
91  * @adv.max_vlan_ids: Maximum vlan ids allowed in the system -
92  *      relevant only case of working in mac+vlan method.
93  *      0 - indicates default 16 vlan ids.
94  * @adv.mem_size: Size of the memory used for internal buffers expressed as
95  * number of 256byte buffers.
96  */
97 struct dpdmux_cfg {
98         enum dpdmux_method method;
99         enum dpdmux_manip manip;
100         uint16_t num_ifs;
101         uint16_t default_if;
102         struct {
103                 uint64_t options;
104                 uint16_t max_dmat_entries;
105                 uint16_t max_mc_groups;
106                 uint16_t max_vlan_ids;
107                 uint16_t mem_size;
108         } adv;
109 };
110
111 int dpdmux_create(struct fsl_mc_io *mc_io,
112                   uint16_t dprc_token,
113                   uint32_t cmd_flags,
114                   const struct dpdmux_cfg *cfg,
115                   uint32_t *obj_id);
116
117 int dpdmux_destroy(struct fsl_mc_io *mc_io,
118                    uint16_t dprc_token,
119                    uint32_t cmd_flags,
120                    uint32_t object_id);
121
122 int dpdmux_enable(struct fsl_mc_io *mc_io,
123                   uint32_t cmd_flags,
124                   uint16_t token);
125
126 int dpdmux_disable(struct fsl_mc_io *mc_io,
127                    uint32_t cmd_flags,
128                    uint16_t token);
129
130 int dpdmux_is_enabled(struct fsl_mc_io *mc_io,
131                       uint32_t cmd_flags,
132                       uint16_t token,
133                       int *en);
134
135 int dpdmux_reset(struct fsl_mc_io *mc_io,
136                  uint32_t cmd_flags,
137                  uint16_t token);
138
139 /**
140  *Setting 1 DPDMUX_RESET will not reset default interface
141  */
142 #define DPDMUX_SKIP_DEFAULT_INTERFACE   0x01
143 /**
144  *Setting 1 DPDMUX_RESET will not reset unicast rules
145  */
146 #define DPDMUX_SKIP_UNICAST_RULES       0x02
147 /**
148  *Setting 1 DPDMUX_RESET will not reset multicast rules
149  */
150 #define DPDMUX_SKIP_MULTICAST_RULES     0x04
151
152 int dpdmux_set_resetable(struct fsl_mc_io *mc_io,
153                                   uint32_t cmd_flags,
154                                   uint16_t token,
155                                   uint8_t skip_reset_flags);
156
157 int dpdmux_get_resetable(struct fsl_mc_io *mc_io,
158                                   uint32_t cmd_flags,
159                                   uint16_t token,
160                                   uint8_t *skip_reset_flags);
161
162 /**
163  * struct dpdmux_attr - Structure representing DPDMUX attributes
164  * @id: DPDMUX object ID
165  * @options: Configuration options (bitmap)
166  * @method: DPDMUX address table method
167  * @manip: DPDMUX manipulation type
168  * @num_ifs: Number of interfaces (excluding the uplink interface)
169  * @mem_size: DPDMUX frame storage memory size
170  * @default_if: Default interface number (different from uplink,
171         maximum value num_ifs)
172  */
173 struct dpdmux_attr {
174         int id;
175         uint64_t options;
176         enum dpdmux_method method;
177         enum dpdmux_manip manip;
178         uint16_t num_ifs;
179         uint16_t mem_size;
180         uint16_t default_if;
181 };
182
183 int dpdmux_get_attributes(struct fsl_mc_io *mc_io,
184                           uint32_t cmd_flags,
185                           uint16_t token,
186                           struct dpdmux_attr *attr);
187
188 int dpdmux_set_max_frame_length(struct fsl_mc_io *mc_io,
189                                 uint32_t cmd_flags,
190                                 uint16_t token,
191                                 uint16_t max_frame_length);
192
193 /**
194  * enum dpdmux_counter_type - Counter types
195  * @DPDMUX_CNT_ING_FRAME: Counts ingress frames
196  * @DPDMUX_CNT_ING_BYTE: Counts ingress bytes
197  * @DPDMUX_CNT_ING_FLTR_FRAME: Counts filtered ingress frames
198  * @DPDMUX_CNT_ING_FRAME_DISCARD: Counts discarded ingress frames
199  * @DPDMUX_CNT_ING_MCAST_FRAME: Counts ingress multicast frames
200  * @DPDMUX_CNT_ING_MCAST_BYTE: Counts ingress multicast bytes
201  * @DPDMUX_CNT_ING_BCAST_FRAME: Counts ingress broadcast frames
202  * @DPDMUX_CNT_ING_BCAST_BYTES: Counts ingress broadcast bytes
203  * @DPDMUX_CNT_EGR_FRAME: Counts egress frames
204  * @DPDMUX_CNT_EGR_BYTE: Counts egress bytes
205  * @DPDMUX_CNT_EGR_FRAME_DISCARD: Counts discarded egress frames
206  */
207 enum dpdmux_counter_type {
208         DPDMUX_CNT_ING_FRAME = 0x0,
209         DPDMUX_CNT_ING_BYTE = 0x1,
210         DPDMUX_CNT_ING_FLTR_FRAME = 0x2,
211         DPDMUX_CNT_ING_FRAME_DISCARD = 0x3,
212         DPDMUX_CNT_ING_MCAST_FRAME = 0x4,
213         DPDMUX_CNT_ING_MCAST_BYTE = 0x5,
214         DPDMUX_CNT_ING_BCAST_FRAME = 0x6,
215         DPDMUX_CNT_ING_BCAST_BYTES = 0x7,
216         DPDMUX_CNT_EGR_FRAME = 0x8,
217         DPDMUX_CNT_EGR_BYTE = 0x9,
218         DPDMUX_CNT_EGR_FRAME_DISCARD = 0xa
219 };
220
221 /**
222  * enum dpdmux_accepted_frames_type - DPDMUX frame types
223  * @DPDMUX_ADMIT_ALL: The device accepts VLAN tagged, untagged and
224  *                      priority-tagged frames
225  * @DPDMUX_ADMIT_ONLY_VLAN_TAGGED: The device discards untagged frames or
226  *                              priority-tagged frames that are received on this
227  *                              interface
228  * @DPDMUX_ADMIT_ONLY_UNTAGGED: Untagged frames or priority-tagged frames
229  *                              received on this interface are accepted
230  */
231 enum dpdmux_accepted_frames_type {
232         DPDMUX_ADMIT_ALL = 0,
233         DPDMUX_ADMIT_ONLY_VLAN_TAGGED = 1,
234         DPDMUX_ADMIT_ONLY_UNTAGGED = 2
235 };
236
237 /**
238  * enum dpdmux_action - DPDMUX action for un-accepted frames
239  * @DPDMUX_ACTION_DROP: Drop un-accepted frames
240  * @DPDMUX_ACTION_REDIRECT_TO_CTRL: Redirect un-accepted frames to the
241  *                                      control interface
242  */
243 enum dpdmux_action {
244         DPDMUX_ACTION_DROP = 0,
245         DPDMUX_ACTION_REDIRECT_TO_CTRL = 1
246 };
247
248 /**
249  * struct dpdmux_accepted_frames - Frame types configuration
250  * @type: Defines ingress accepted frames
251  * @unaccept_act: Defines action on frames not accepted
252  */
253 struct dpdmux_accepted_frames {
254         enum dpdmux_accepted_frames_type type;
255         enum dpdmux_action unaccept_act;
256 };
257
258 int dpdmux_if_set_accepted_frames(struct fsl_mc_io *mc_io,
259                                   uint32_t cmd_flags,
260                                   uint16_t token,
261                                   uint16_t if_id,
262                                   const struct dpdmux_accepted_frames *cfg);
263
264 /**
265  * struct dpdmux_if_attr - Structure representing frame types configuration
266  * @rate: Configured interface rate (in bits per second)
267  * @enabled: Indicates if interface is enabled
268  * @accept_frame_type: Indicates type of accepted frames for the interface
269  */
270 struct dpdmux_if_attr {
271         uint32_t rate;
272         int enabled;
273         int is_default;
274         enum dpdmux_accepted_frames_type accept_frame_type;
275 };
276
277 int dpdmux_if_get_attributes(struct fsl_mc_io *mc_io,
278                              uint32_t cmd_flags,
279                              uint16_t token,
280                              uint16_t if_id,
281                              struct dpdmux_if_attr *attr);
282
283 int dpdmux_if_enable(struct fsl_mc_io *mc_io,
284                      uint32_t cmd_flags,
285                      uint16_t token,
286                      uint16_t if_id);
287
288 int dpdmux_if_disable(struct fsl_mc_io *mc_io,
289                       uint32_t cmd_flags,
290                       uint16_t token,
291                       uint16_t if_id);
292
293 /**
294  * struct dpdmux_l2_rule - Structure representing L2 rule
295  * @mac_addr: MAC address
296  * @vlan_id: VLAN ID
297  */
298 struct dpdmux_l2_rule {
299         uint8_t mac_addr[6];
300         uint16_t vlan_id;
301 };
302
303 int dpdmux_if_remove_l2_rule(struct fsl_mc_io *mc_io,
304                              uint32_t cmd_flags,
305                              uint16_t token,
306                              uint16_t if_id,
307                              const struct dpdmux_l2_rule *rule);
308
309 int dpdmux_if_add_l2_rule(struct fsl_mc_io *mc_io,
310                           uint32_t cmd_flags,
311                           uint16_t token,
312                           uint16_t if_id,
313                           const struct dpdmux_l2_rule *rule);
314
315 int dpdmux_if_get_counter(struct fsl_mc_io *mc_io,
316                           uint32_t cmd_flags,
317                           uint16_t token,
318                           uint16_t if_id,
319                           enum dpdmux_counter_type counter_type,
320                           uint64_t *counter);
321
322 int dpdmux_ul_reset_counters(struct fsl_mc_io *mc_io,
323                              uint32_t cmd_flags,
324                              uint16_t token);
325
326 /**
327  * Enable auto-negotiation
328  */
329 #define DPDMUX_LINK_OPT_AUTONEG         0x0000000000000001ULL
330 /**
331  * Enable half-duplex mode
332  */
333 #define DPDMUX_LINK_OPT_HALF_DUPLEX     0x0000000000000002ULL
334 /**
335  * Enable pause frames
336  */
337 #define DPDMUX_LINK_OPT_PAUSE           0x0000000000000004ULL
338 /**
339  * Enable a-symmetric pause frames
340  */
341 #define DPDMUX_LINK_OPT_ASYM_PAUSE      0x0000000000000008ULL
342
343 /**
344  * struct dpdmux_link_cfg - Structure representing DPDMUX link configuration
345  * @rate: Rate
346  * @options: Mask of available options; use 'DPDMUX_LINK_OPT_<X>' values
347  */
348 struct dpdmux_link_cfg {
349         uint32_t rate;
350         uint64_t options;
351         uint64_t advertising;
352 };
353
354 int dpdmux_if_set_link_cfg(struct fsl_mc_io *mc_io,
355                            uint32_t cmd_flags,
356                            uint16_t token,
357                            uint16_t if_id,
358                            struct dpdmux_link_cfg *cfg);
359 /**
360  * struct dpdmux_link_state - Structure representing DPDMUX link state
361  * @rate: Rate
362  * @options: Mask of available options; use 'DPDMUX_LINK_OPT_<X>' values
363  * @up: 0 - down, 1 - up
364  * @state_valid: Ignore/Update the state of the link
365  * @supported: Speeds capability of the phy (bitmap)
366  * @advertising: Speeds that are advertised for autoneg (bitmap)
367  */
368 struct dpdmux_link_state {
369         uint32_t rate;
370         uint64_t options;
371         int      up;
372         int      state_valid;
373         uint64_t supported;
374         uint64_t advertising;
375 };
376
377 int dpdmux_if_get_link_state(struct fsl_mc_io *mc_io,
378                              uint32_t cmd_flags,
379                              uint16_t token,
380                              uint16_t if_id,
381                              struct dpdmux_link_state *state);
382
383 int dpdmux_if_set_default(struct fsl_mc_io *mc_io,
384                 uint32_t cmd_flags,
385                 uint16_t token,
386                 uint16_t if_id);
387
388 int dpdmux_if_get_default(struct fsl_mc_io *mc_io,
389                 uint32_t cmd_flags,
390                 uint16_t token,
391                 uint16_t *if_id);
392
393 int dpdmux_set_custom_key(struct fsl_mc_io *mc_io,
394                         uint32_t cmd_flags,
395                         uint16_t token,
396                         uint64_t key_cfg_iova);
397
398 /**
399  * struct dpdmux_rule_cfg - Custom classification rule.
400  *
401  * @key_iova: DMA address of buffer storing the look-up value
402  * @mask_iova: DMA address of the mask used for TCAM classification. This
403  *  parameter is used only if dpdmux was created using option
404  *  DPDMUX_OPT_CLS_MASK_SUPPORT.
405  * @key_size: size, in bytes, of the look-up value. This must match the size
406  *      of the look-up key defined using dpdmux_set_custom_key, otherwise the
407  *      entry will never be hit
408  * @entry_index: rule index into the table. This parameter is used only when
409  *  dpdmux object was created using option DPDMUX_OPT_CLS_MASK_SUPPORT. In
410  *  this case the rule is masking and the current frame may be a hit for
411  *  multiple rules. This parameter determines the order in which the rules
412  *  will be checked (smaller entry_index first).
413  */
414 struct dpdmux_rule_cfg {
415         uint64_t key_iova;
416         uint64_t mask_iova;
417         uint8_t key_size;
418         uint16_t entry_index;
419 };
420
421 /**
422  * struct dpdmux_cls_action - Action to execute for frames matching the
423  *      classification entry
424  *
425  * @dest_if: Interface to forward the frames to. Port numbering is similar to
426  *      the one used to connect interfaces:
427  *      - 0 is the uplink port,
428  *      - all others are downlink ports.
429  */
430 struct dpdmux_cls_action {
431         uint16_t dest_if;
432 };
433
434 int dpdmux_add_custom_cls_entry(struct fsl_mc_io *mc_io,
435                 uint32_t cmd_flags,
436                 uint16_t token,
437                 struct dpdmux_rule_cfg *rule,
438                 struct dpdmux_cls_action *action);
439
440 int dpdmux_remove_custom_cls_entry(struct fsl_mc_io *mc_io,
441                 uint32_t cmd_flags,
442                 uint16_t token,
443                 struct dpdmux_rule_cfg *rule);
444
445 int dpdmux_get_api_version(struct fsl_mc_io *mc_io,
446                            uint32_t cmd_flags,
447                            uint16_t *major_ver,
448                            uint16_t *minor_ver);
449
450 #endif /* __FSL_DPDMUX_H */