net/dpaa2: support soft parser in MC
[dpdk.git] / drivers / net / dpaa2 / mc / fsl_dpni.h
1 /* SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0)
2  *
3  * Copyright 2013-2016 Freescale Semiconductor Inc.
4  * Copyright 2016-2017 NXP
5  *
6  */
7 #ifndef __FSL_DPNI_H
8 #define __FSL_DPNI_H
9
10 #include <fsl_dpkg.h>
11 #include <fsl_dpopr.h>
12
13 struct fsl_mc_io;
14
15 /**
16  * Data Path Network Interface API
17  * Contains initialization APIs and runtime control APIs for DPNI
18  */
19
20 /** General DPNI macros */
21
22 /**
23  * Maximum number of traffic classes
24  */
25 #define DPNI_MAX_TC                             8
26 /**
27  * Maximum number of buffer pools per DPNI
28  */
29 #define DPNI_MAX_DPBP                           8
30 /**
31  * Maximum number of storage-profiles per DPNI
32  */
33 #define DPNI_MAX_SP                             2
34
35 /**
36  * All traffic classes considered; see dpni_set_queue()
37  */
38 #define DPNI_ALL_TCS                            (uint8_t)(-1)
39 /**
40  * All flows within traffic class considered; see dpni_set_queue()
41  */
42 #define DPNI_ALL_TC_FLOWS                       (uint16_t)(-1)
43
44 /**
45  * Tx traffic is always released to a buffer pool on transmit, there are no
46  * resources allocated to have the frames confirmed back to the source after
47  * transmission.
48  */
49 #define DPNI_OPT_TX_FRM_RELEASE                 0x000001
50 /**
51  * Disables support for MAC address filtering for addresses other than primary
52  * MAC address. This affects both unicast and multicast. Promiscuous mode can
53  * still be enabled/disabled for both unicast and multicast. If promiscuous mode
54  * is disabled, only traffic matching the primary MAC address will be accepted.
55  */
56 #define DPNI_OPT_NO_MAC_FILTER                  0x000002
57 /**
58  * Allocate policers for this DPNI. They can be used to rate-limit traffic per
59  * traffic class (TC) basis.
60  */
61 #define DPNI_OPT_HAS_POLICING                   0x000004
62 /**
63  * Congestion can be managed in several ways, allowing the buffer pool to
64  * deplete on ingress, taildrop on each queue or use congestion groups for sets
65  * of queues. If set, it configures a single congestion groups across all TCs.
66  * If reset, a congestion group is allocated for each TC. Only relevant if the
67  * DPNI has multiple traffic classes.
68  */
69 #define DPNI_OPT_SHARED_CONGESTION              0x000008
70 /**
71  * Enables TCAM for Flow Steering and QoS look-ups. If not specified, all
72  * look-ups are exact match. Note that TCAM is not available on LS1088 and its
73  * variants. Setting this bit on these SoCs will trigger an error.
74  */
75 #define DPNI_OPT_HAS_KEY_MASKING                0x000010
76 /**
77  * Disables the flow steering table.
78  */
79 #define DPNI_OPT_NO_FS                          0x000020
80
81 /**
82  * Enable the Order Restoration support
83  */
84 #define DPNI_OPT_HAS_OPR                                0x000040
85
86 /**
87  * Order Point Records are shared for the entire TC
88  */
89 #define DPNI_OPT_OPR_PER_TC                             0x000080
90 /**
91  * All Tx traffic classes will use a single sender (ignore num_queueus for tx)
92  */
93 #define DPNI_OPT_SINGLE_SENDER                  0x000100
94 /**
95  * Define a custom number of congestion groups
96  */
97 #define DPNI_OPT_CUSTOM_CG                              0x000200
98
99
100 /**
101  * Software sequence maximum layout size
102  */
103 #define DPNI_SW_SEQUENCE_LAYOUT_SIZE 33
104
105 int dpni_open(struct fsl_mc_io *mc_io,
106               uint32_t cmd_flags,
107               int dpni_id,
108               uint16_t *token);
109
110 int dpni_close(struct fsl_mc_io *mc_io,
111                uint32_t cmd_flags,
112                uint16_t token);
113
114 /**
115  * struct dpni_cfg - Structure representing DPNI configuration
116  * @options: Any combination of the following options:
117  *              DPNI_OPT_TX_FRM_RELEASE
118  *              DPNI_OPT_NO_MAC_FILTER
119  *              DPNI_OPT_HAS_POLICING
120  *              DPNI_OPT_SHARED_CONGESTION
121  *              DPNI_OPT_HAS_KEY_MASKING
122  *              DPNI_OPT_NO_FS
123  *              DPNI_OPT_SINGLE_SENDER
124  * @fs_entries: Number of entries in the flow steering table.
125  *              This table is used to select the ingress queue for
126  *              ingress traffic, targeting a GPP core or another.
127  *              In addition it can be used to discard traffic that
128  *              matches the set rule. It is either an exact match table
129  *              or a TCAM table, depending on DPNI_OPT_ HAS_KEY_MASKING
130  *              bit in OPTIONS field. This field is ignored if
131  *              DPNI_OPT_NO_FS bit is set in OPTIONS field. Otherwise,
132  *              value 0 defaults to 64. Maximum supported value is 1024.
133  *              Note that the total number of entries is limited on the
134  *              SoC to as low as 512 entries if TCAM is used.
135  * @vlan_filter_entries: Number of entries in the VLAN address filtering
136  *              table. This is an exact match table used to filter
137  *              ingress traffic based on VLAN IDs. Value 0 disables VLAN
138  *              filtering. Maximum supported value is 16.
139  * @mac_filter_entries: Number of entries in the MAC address filtering
140  *              table. This is an exact match table and allows both
141  *              unicast and multicast entries. The primary MAC address
142  *              of the network interface is not part of this table,
143  *              this contains only entries in addition to it. This
144  *              field is ignored if DPNI_OPT_ NO_MAC_FILTER is set in
145  *              OPTIONS field. Otherwise, value 0 defaults to 80.
146  *              Maximum supported value is 80.
147  * @num_queues: Number of Tx and Rx queues used for traffic
148  *              distribution. This is orthogonal to QoS and is only
149  *              used to distribute traffic to multiple GPP cores.
150  *              This configuration affects the number of Tx queues
151  *              (logical FQs, all associated with a single CEETM queue),
152  *              Rx queues and Tx confirmation queues, if applicable.
153  *              Value 0 defaults to one queue. Maximum supported value
154  *              is 8.
155  * @num_tcs: Number of traffic classes (TCs), reserved for the DPNI.
156  *              TCs can have different priority levels for the purpose
157  *              of Tx scheduling (see DPNI_SET_TX_PRIORITIES), different
158  *              BPs (DPNI_ SET_POOLS), policers. There are dedicated QM
159  *              queues for traffic classes (including class queues on
160  *              Tx). Value 0 defaults to one TC. Maximum supported value
161  *              is 16. There are maximum 16 TCs for Tx and 8 TCs for Rx.
162  *              When num_tcs>8 Tx will use this value but Rx will have
163  *              only 8 traffic classes.
164  * @num_rx_tcs: if set to other value than zero represents number
165  *              of TCs used for Rx. Maximum value is 8. If set to zero the
166  *              number of Rx TCs will be initialized with the value provided
167  *              in num_tcs parameter.
168  * @qos_entries: Number of entries in the QoS classification table. This
169  *              table is used to select the TC for ingress traffic. It
170  *              is either an exact match or a TCAM table, depending on
171  *              DPNI_OPT_ HAS_KEY_MASKING bit in OPTIONS field. This
172  *              field is ignored if the DPNI has a single TC. Otherwise,
173  *              a value of 0 defaults to 64. Maximum supported value
174  *              is 64.
175  */
176 struct dpni_cfg {
177         uint32_t options;
178         uint16_t fs_entries;
179         uint8_t  vlan_filter_entries;
180         uint8_t  mac_filter_entries;
181         uint8_t  num_queues;
182         uint8_t  num_tcs;
183         uint8_t  num_rx_tcs;
184         uint8_t  qos_entries;
185         uint8_t  num_cgs;
186 };
187
188 int dpni_create(struct fsl_mc_io *mc_io,
189                 uint16_t dprc_token,
190                 uint32_t cmd_flags,
191                 const struct dpni_cfg *cfg,
192                 uint32_t *obj_id);
193
194 int dpni_destroy(struct fsl_mc_io *mc_io,
195                  uint16_t dprc_token,
196                  uint32_t cmd_flags,
197                  uint32_t object_id);
198
199 /**
200  * struct dpni_pools_cfg - Structure representing buffer pools configuration
201  * @num_dpbp:   Number of DPBPs
202  * @pools:      Array of buffer pools parameters; The number of valid entries
203  *              must match 'num_dpbp' value
204  * @pools.dpbp_id:     DPBP object ID
205  * @pools.priority:    Priority mask that indicates TC's used with this buffer.
206  *                     I set to 0x00 MC will assume value 0xff.
207  * @pools.buffer_size: Buffer size
208  * @pools.backup_pool: Backup pool
209  */
210 struct dpni_pools_cfg {
211         uint8_t num_dpbp;
212         struct {
213                 int             dpbp_id;
214                 uint8_t         priority_mask;
215                 uint16_t        buffer_size;
216                 int             backup_pool;
217         } pools[DPNI_MAX_DPBP];
218 };
219
220 int dpni_set_pools(struct fsl_mc_io *mc_io,
221                    uint32_t cmd_flags,
222                    uint16_t token,
223                    const struct dpni_pools_cfg *cfg);
224
225 int dpni_enable(struct fsl_mc_io *mc_io,
226                 uint32_t cmd_flags,
227                 uint16_t token);
228
229 int dpni_disable(struct fsl_mc_io *mc_io,
230                  uint32_t cmd_flags,
231                  uint16_t token);
232
233 int dpni_is_enabled(struct fsl_mc_io *mc_io,
234                     uint32_t cmd_flags,
235                     uint16_t token,
236                     int *en);
237
238 int dpni_reset(struct fsl_mc_io *mc_io,
239                uint32_t cmd_flags,
240                uint16_t token);
241
242 /**
243  * DPNI IRQ Index and Events
244  */
245
246 /**
247  * IRQ index
248  */
249 #define DPNI_IRQ_INDEX                          0
250 /**
251  * IRQ event - indicates a change in link state
252  */
253 #define DPNI_IRQ_EVENT_LINK_CHANGED             0x00000001
254
255 int dpni_set_irq_enable(struct fsl_mc_io *mc_io,
256                         uint32_t cmd_flags,
257                         uint16_t token,
258                         uint8_t irq_index,
259                         uint8_t en);
260
261 int dpni_get_irq_enable(struct fsl_mc_io *mc_io,
262                         uint32_t cmd_flags,
263                         uint16_t token,
264                         uint8_t irq_index,
265                         uint8_t *en);
266
267 int dpni_set_irq_mask(struct fsl_mc_io *mc_io,
268                       uint32_t cmd_flags,
269                       uint16_t token,
270                       uint8_t irq_index,
271                       uint32_t mask);
272
273 int dpni_get_irq_mask(struct fsl_mc_io *mc_io,
274                       uint32_t cmd_flags,
275                       uint16_t token,
276                       uint8_t irq_index,
277                       uint32_t *mask);
278
279 int dpni_get_irq_status(struct fsl_mc_io *mc_io,
280                         uint32_t cmd_flags,
281                         uint16_t token,
282                         uint8_t irq_index,
283                         uint32_t *status);
284
285 int dpni_clear_irq_status(struct fsl_mc_io *mc_io,
286                           uint32_t cmd_flags,
287                           uint16_t token,
288                           uint8_t irq_index,
289                           uint32_t status);
290
291 /**
292  * struct dpni_attr - Structure representing DPNI attributes
293  * @options: Any combination of the following options:
294  *              DPNI_OPT_TX_FRM_RELEASE
295  *              DPNI_OPT_NO_MAC_FILTER
296  *              DPNI_OPT_HAS_POLICING
297  *              DPNI_OPT_SHARED_CONGESTION
298  *              DPNI_OPT_HAS_KEY_MASKING
299  *              DPNI_OPT_NO_FS
300  * @num_queues: Number of Tx and Rx queues used for traffic distribution.
301  * @num_rx_tcs: Number of RX traffic classes (TCs), reserved for the DPNI.
302  * @num_tx_tcs: Number of TX traffic classes (TCs), reserved for the DPNI.
303  * @mac_filter_entries: Number of entries in the MAC address filtering
304  *              table.
305  * @vlan_filter_entries: Number of entries in the VLAN address filtering
306  *              table.
307  * @qos_entries: Number of entries in the QoS classification table.
308  * @fs_entries: Number of entries in the flow steering table.
309  * @qos_key_size: Size, in bytes, of the QoS look-up key. Defining a key larger
310  *                      than this when adding QoS entries will result
311  *                      in an error.
312  * @fs_key_size: Size, in bytes, of the flow steering look-up key. Defining a
313  *                      key larger than this when composing the hash + FS key
314  *                      will result in an error.
315  * @wriop_version: Version of WRIOP HW block.
316  *                      The 3 version values are stored on 6, 5, 5 bits
317  *                      respectively.
318  *                      Values returned:
319  *                      - 0x400 - WRIOP version 1.0.0, used on LS2080 and
320  *                      variants,
321  *                      - 0x421 - WRIOP version 1.1.1, used on LS2088 and
322  *                      variants,
323  *                      - 0x422 - WRIOP version 1.1.2, used on LS1088 and
324  *                      variants.
325  *                      - 0xC00 - WRIOP version 3.0.0, used on LX2160 and
326  *                      variants.
327  */
328 struct dpni_attr {
329         uint32_t options;
330         uint8_t  num_queues;
331         uint8_t  num_rx_tcs;
332         uint8_t  num_tx_tcs;
333         uint8_t  mac_filter_entries;
334         uint8_t  vlan_filter_entries;
335         uint8_t  qos_entries;
336         uint16_t fs_entries;
337         uint8_t  qos_key_size;
338         uint8_t  fs_key_size;
339         uint16_t wriop_version;
340         uint8_t  num_cgs;
341 };
342
343 int dpni_get_attributes(struct fsl_mc_io *mc_io,
344                         uint32_t cmd_flags,
345                         uint16_t token,
346                         struct dpni_attr *attr);
347
348 /**
349  * DPNI errors
350  */
351
352 /**
353  * Discard error. When set all discarded frames in wriop will be enqueued to
354  * error queue. To be used in dpni_set_errors_behavior() only if error_action
355  * parameter is set to DPNI_ERROR_ACTION_SEND_TO_ERROR_QUEUE.
356  */
357 #define DPNI_ERROR_DISC         0x80000000
358
359 /**
360  * Extract out of frame header error
361  */
362 #define DPNI_ERROR_EOFHE        0x00020000
363 /**
364  * Frame length error
365  */
366 #define DPNI_ERROR_FLE          0x00002000
367 /**
368  * Frame physical error
369  */
370 #define DPNI_ERROR_FPE          0x00001000
371 /**
372  * Parsing header error
373  */
374 #define DPNI_ERROR_PHE          0x00000020
375 /**
376  * Parser L3 checksum error
377  */
378 #define DPNI_ERROR_L3CE         0x00000004
379 /**
380  * Parser L3 checksum error
381  */
382 #define DPNI_ERROR_L4CE         0x00000001
383
384 /**
385  * enum dpni_error_action - Defines DPNI behavior for errors
386  * @DPNI_ERROR_ACTION_DISCARD: Discard the frame
387  * @DPNI_ERROR_ACTION_CONTINUE: Continue with the normal flow
388  * @DPNI_ERROR_ACTION_SEND_TO_ERROR_QUEUE: Send the frame to the error queue
389  */
390 enum dpni_error_action {
391         DPNI_ERROR_ACTION_DISCARD = 0,
392         DPNI_ERROR_ACTION_CONTINUE = 1,
393         DPNI_ERROR_ACTION_SEND_TO_ERROR_QUEUE = 2
394 };
395
396 /**
397  * struct dpni_error_cfg - Structure representing DPNI errors treatment
398  * @errors:                     Errors mask; use 'DPNI_ERROR__<X>
399  * @error_action:               The desired action for the errors mask
400  * @set_frame_annotation:       Set to '1' to mark the errors in frame
401  *                              annotation status (FAS); relevant only
402  *                              for the non-discard action
403  */
404 struct dpni_error_cfg {
405         uint32_t errors;
406         enum dpni_error_action error_action;
407         int set_frame_annotation;
408 };
409
410 int dpni_set_errors_behavior(struct fsl_mc_io *mc_io,
411                              uint32_t cmd_flags,
412                              uint16_t token,
413                              struct dpni_error_cfg *cfg);
414
415 /**
416  * DPNI buffer layout modification options
417  */
418
419 /**
420  * Select to modify the time-stamp setting
421  */
422 #define DPNI_BUF_LAYOUT_OPT_TIMESTAMP           0x00000001
423 /**
424  * Select to modify the parser-result setting; not applicable for Tx
425  */
426 #define DPNI_BUF_LAYOUT_OPT_PARSER_RESULT       0x00000002
427 /**
428  * Select to modify the frame-status setting
429  */
430 #define DPNI_BUF_LAYOUT_OPT_FRAME_STATUS        0x00000004
431 /**
432  * Select to modify the private-data-size setting
433  */
434 #define DPNI_BUF_LAYOUT_OPT_PRIVATE_DATA_SIZE   0x00000008
435 /**
436  * Select to modify the data-alignment setting
437  */
438 #define DPNI_BUF_LAYOUT_OPT_DATA_ALIGN          0x00000010
439 /**
440  * Select to modify the data-head-room setting
441  */
442 #define DPNI_BUF_LAYOUT_OPT_DATA_HEAD_ROOM      0x00000020
443 /**
444  * Select to modify the data-tail-room setting
445  */
446 #define DPNI_BUF_LAYOUT_OPT_DATA_TAIL_ROOM      0x00000040
447 /**
448  * Select to modify the sw-opaque value setting
449  */
450 #define DPNI_BUF_LAYOUT_OPT_SW_OPAQUE           0x00000080
451
452 /**
453  * struct dpni_buffer_layout - Structure representing DPNI buffer layout
454  * @options:            Flags representing the suggested modifications to the
455  *                      buffer layout;
456  *                      Use any combination of 'DPNI_BUF_LAYOUT_OPT_<X>' flags
457  * @pass_timestamp:     Pass timestamp value
458  * @pass_parser_result: Pass parser results
459  * @pass_frame_status:  Pass frame status
460  * @private_data_size:  Size kept for private data (in bytes)
461  * @data_align:         Data alignment
462  * @data_head_room:     Data head room
463  * @data_tail_room:     Data tail room
464  */
465 struct dpni_buffer_layout {
466         uint32_t options;
467         int pass_timestamp;
468         int pass_parser_result;
469         int pass_frame_status;
470         int pass_sw_opaque;
471         uint16_t private_data_size;
472         uint16_t data_align;
473         uint16_t data_head_room;
474         uint16_t data_tail_room;
475 };
476
477 /**
478  * enum dpni_queue_type - Identifies a type of queue targeted by the command
479  * @DPNI_QUEUE_RX: Rx queue
480  * @DPNI_QUEUE_TX: Tx queue
481  * @DPNI_QUEUE_TX_CONFIRM: Tx confirmation queue
482  * @DPNI_QUEUE_RX_ERR: Rx error queue
483  */
484 enum dpni_queue_type {
485         DPNI_QUEUE_RX,
486         DPNI_QUEUE_TX,
487         DPNI_QUEUE_TX_CONFIRM,
488         DPNI_QUEUE_RX_ERR,
489 };
490
491 int dpni_get_buffer_layout(struct fsl_mc_io *mc_io,
492                            uint32_t cmd_flags,
493                            uint16_t token,
494                            enum dpni_queue_type qtype,
495                            struct dpni_buffer_layout *layout);
496
497 int dpni_set_buffer_layout(struct fsl_mc_io *mc_io,
498                            uint32_t cmd_flags,
499                            uint16_t token,
500                            enum dpni_queue_type qtype,
501                            const struct dpni_buffer_layout *layout);
502
503 /**
504  * enum dpni_offload - Identifies a type of offload targeted by the command
505  * @DPNI_OFF_RX_L3_CSUM: Rx L3 checksum validation
506  * @DPNI_OFF_RX_L4_CSUM: Rx L4 checksum validation
507  * @DPNI_OFF_TX_L3_CSUM: Tx L3 checksum generation
508  * @DPNI_OFF_TX_L4_CSUM: Tx L4 checksum generation
509  * @DPNI_OPT_FLCTYPE_HASH: flow context will be generated by WRIOP for AIOP or
510  *                         for CPU
511  */
512 enum dpni_offload {
513         DPNI_OFF_RX_L3_CSUM,
514         DPNI_OFF_RX_L4_CSUM,
515         DPNI_OFF_TX_L3_CSUM,
516         DPNI_OFF_TX_L4_CSUM,
517         DPNI_FLCTYPE_HASH,
518 };
519
520 int dpni_set_offload(struct fsl_mc_io *mc_io,
521                      uint32_t cmd_flags,
522                      uint16_t token,
523                      enum dpni_offload type,
524                      uint32_t config);
525
526 int dpni_get_offload(struct fsl_mc_io *mc_io,
527                      uint32_t cmd_flags,
528                      uint16_t token,
529                      enum dpni_offload type,
530                      uint32_t *config);
531
532 int dpni_get_qdid(struct fsl_mc_io *mc_io,
533                   uint32_t cmd_flags,
534                   uint16_t token,
535                   enum dpni_queue_type qtype,
536                   uint16_t *qdid);
537
538 int dpni_get_tx_data_offset(struct fsl_mc_io *mc_io,
539                             uint32_t cmd_flags,
540                             uint16_t token,
541                             uint16_t *data_offset);
542
543 #define DPNI_STATISTICS_CNT             7
544
545 /**
546  * union dpni_statistics - Union describing the DPNI statistics
547  * @page_0: Page_0 statistics structure
548  * @page_0.ingress_all_frames: Ingress frame count
549  * @page_0.ingress_all_bytes: Ingress byte count
550  * @page_0.ingress_multicast_frames: Ingress multicast frame count
551  * @page_0.ingress_multicast_bytes: Ingress multicast byte count
552  * @page_0.ingress_broadcast_frames: Ingress broadcast frame count
553  * @page_0.ingress_broadcast_bytes: Ingress broadcast byte count
554  * @page_1: Page_1 statistics structure
555  * @page_1.egress_all_frames: Egress frame count
556  * @page_1.egress_all_bytes: Egress byte count
557  * @page_1.egress_multicast_frames: Egress multicast frame count
558  * @page_1.egress_multicast_bytes: Egress multicast byte count
559  * @page_1.egress_broadcast_frames: Egress broadcast frame count
560  * @page_1.egress_broadcast_bytes: Egress broadcast byte count
561  * @page_2: Page_2 statistics structure
562  * @page_2.ingress_filtered_frames: Ingress filtered frame count
563  * @page_2.ingress_discarded_frames: Ingress discarded frame count
564  * @page_2.ingress_nobuffer_discards: Ingress discarded frame count due to
565  *      lack of buffers
566  * @page_2.egress_discarded_frames: Egress discarded frame count
567  * @page_2.egress_confirmed_frames: Egress confirmed frame count
568  * @page_3: Page_3 statistics structure with values for the selected TC
569  * @page_3.ceetm_dequeue_bytes: Cumulative count of the number of bytes dequeued
570  * @page_3.ceetm_dequeue_frames: Cumulative count of the number of frames
571  *      dequeued
572  * @page_3.ceetm_reject_bytes: Cumulative count of the number of bytes in all
573  *      frames whose enqueue was rejected
574  * @page_3.ceetm_reject_frames: Cumulative count of all frame enqueues rejected
575  * @page_4: congestion point drops for seleted TC
576  * @page_4.cgr_reject_frames: number of rejected frames due to congestion point
577  * @page_4.cgr_reject_bytes: number of rejected bytes due to congestion point
578  * @page_5: policer statistics per TC
579  * @page_5.policer_cnt_red: NUmber of red colored frames
580  * @page_5.policer_cnt_yellow: number of yellow colored frames
581  * @page_5.policer_cnt_green: number of green colored frames
582  * @page_5.policer_cnt_re_red: number of recolored red frames
583  * @page_5.policer_cnt_re_yellow: number of recolored yellow frames
584  * @raw: raw statistics structure, used to index counters
585  */
586 union dpni_statistics {
587         struct {
588                 uint64_t ingress_all_frames;
589                 uint64_t ingress_all_bytes;
590                 uint64_t ingress_multicast_frames;
591                 uint64_t ingress_multicast_bytes;
592                 uint64_t ingress_broadcast_frames;
593                 uint64_t ingress_broadcast_bytes;
594         } page_0;
595         struct {
596                 uint64_t egress_all_frames;
597                 uint64_t egress_all_bytes;
598                 uint64_t egress_multicast_frames;
599                 uint64_t egress_multicast_bytes;
600                 uint64_t egress_broadcast_frames;
601                 uint64_t egress_broadcast_bytes;
602         } page_1;
603         struct {
604                 uint64_t ingress_filtered_frames;
605                 uint64_t ingress_discarded_frames;
606                 uint64_t ingress_nobuffer_discards;
607                 uint64_t egress_discarded_frames;
608                 uint64_t egress_confirmed_frames;
609         } page_2;
610         struct {
611                 uint64_t ceetm_dequeue_bytes;
612                 uint64_t ceetm_dequeue_frames;
613                 uint64_t ceetm_reject_bytes;
614                 uint64_t ceetm_reject_frames;
615         } page_3;
616         struct {
617                 uint64_t cgr_reject_frames;
618                 uint64_t cgr_reject_bytes;
619         } page_4;
620         struct {
621                 uint64_t policer_cnt_red;
622                 uint64_t policer_cnt_yellow;
623                 uint64_t policer_cnt_green;
624                 uint64_t policer_cnt_re_red;
625                 uint64_t policer_cnt_re_yellow;
626         } page_5;
627         struct {
628                 uint64_t counter[DPNI_STATISTICS_CNT];
629         } raw;
630 };
631
632 /**
633  * Enable auto-negotiation
634  */
635 #define DPNI_LINK_OPT_AUTONEG           0x0000000000000001ULL
636 /**
637  * Enable half-duplex mode
638  */
639 #define DPNI_LINK_OPT_HALF_DUPLEX       0x0000000000000002ULL
640 /**
641  * Enable pause frames
642  */
643 #define DPNI_LINK_OPT_PAUSE             0x0000000000000004ULL
644 /**
645  * Enable a-symmetric pause frames
646  */
647 #define DPNI_LINK_OPT_ASYM_PAUSE        0x0000000000000008ULL
648 /**
649  * Enable priority flow control pause frames
650  */
651 #define DPNI_LINK_OPT_PFC_PAUSE 0x0000000000000010ULL
652
653 /**
654  * Advertise 10MB full duplex
655  */
656 #define DPNI_ADVERTISED_10BASET_FULL           0x0000000000000001ULL
657 /**
658  * Advertise 100MB full duplex
659  */
660 #define DPNI_ADVERTISED_100BASET_FULL          0x0000000000000002ULL
661 /**
662  * Advertise 1GB full duplex
663  */
664 #define DPNI_ADVERTISED_1000BASET_FULL         0x0000000000000004ULL
665 /**
666  * Advertise auto-negotiation enable
667  */
668 #define DPNI_ADVERTISED_AUTONEG                0x0000000000000008ULL
669 /**
670  * Advertise 10GB full duplex
671  */
672 #define DPNI_ADVERTISED_10000BASET_FULL        0x0000000000000010ULL
673 /**
674  * Advertise 2.5GB full duplex
675  */
676 #define DPNI_ADVERTISED_2500BASEX_FULL         0x0000000000000020ULL
677 /**
678  * Advertise 5GB full duplex
679  */
680 #define DPNI_ADVERTISED_5000BASET_FULL         0x0000000000000040ULL
681
682
683 /**
684  * struct - Structure representing DPNI link configuration
685  * @rate: Rate
686  * @options: Mask of available options; use 'DPNI_LINK_OPT_<X>' values
687  * @advertising: Speeds that are advertised for autoneg (bitmap)
688  */
689 struct dpni_link_cfg {
690         uint32_t rate;
691         uint64_t options;
692         uint64_t advertising;
693 };
694
695 int dpni_set_link_cfg(struct fsl_mc_io *mc_io,
696                       uint32_t cmd_flags,
697                       uint16_t token,
698                       const struct dpni_link_cfg *cfg);
699
700 /**
701  * struct dpni_link_state - Structure representing DPNI link state
702  * @rate:       Rate
703  * @options:    Mask of available options; use 'DPNI_LINK_OPT_<X>' values
704  * @up:         Link state; '0' for down, '1' for up
705  * @state_valid: Ignore/Update the state of the link
706  * @supported: Speeds capability of the phy (bitmap)
707  * @advertising: Speeds that are advertised for autoneg (bitmap)
708  */
709 struct dpni_link_state {
710         uint32_t rate;
711         uint64_t options;
712         int up;
713         int state_valid;
714         uint64_t supported;
715         uint64_t advertising;
716 };
717
718 int dpni_get_link_state(struct fsl_mc_io *mc_io,
719                         uint32_t cmd_flags,
720                         uint16_t token,
721                         struct dpni_link_state *state);
722
723 int dpni_set_max_frame_length(struct fsl_mc_io *mc_io,
724                               uint32_t cmd_flags,
725                               uint16_t token,
726                               uint16_t max_frame_length);
727
728 int dpni_get_max_frame_length(struct fsl_mc_io *mc_io,
729                               uint32_t cmd_flags,
730                               uint16_t token,
731                               uint16_t *max_frame_length);
732
733 int dpni_set_mtu(struct fsl_mc_io *mc_io,
734                  uint32_t cmd_flags,
735                  uint16_t token,
736                  uint16_t mtu);
737
738 int dpni_get_mtu(struct fsl_mc_io *mc_io,
739                  uint32_t cmd_flags,
740                  uint16_t token,
741                  uint16_t *mtu);
742
743 int dpni_set_multicast_promisc(struct fsl_mc_io *mc_io,
744                                uint32_t cmd_flags,
745                                uint16_t token,
746                                int en);
747
748 int dpni_get_multicast_promisc(struct fsl_mc_io *mc_io,
749                                uint32_t cmd_flags,
750                                uint16_t token,
751                                int *en);
752
753 int dpni_set_unicast_promisc(struct fsl_mc_io *mc_io,
754                              uint32_t cmd_flags,
755                              uint16_t token,
756                              int en);
757
758 int dpni_get_unicast_promisc(struct fsl_mc_io *mc_io,
759                              uint32_t cmd_flags,
760                              uint16_t token,
761                              int *en);
762
763 int dpni_set_primary_mac_addr(struct fsl_mc_io *mc_io,
764                               uint32_t cmd_flags,
765                               uint16_t token,
766                               const uint8_t mac_addr[6]);
767
768 int dpni_get_primary_mac_addr(struct fsl_mc_io *mc_io,
769                               uint32_t cmd_flags,
770                               uint16_t token,
771                               uint8_t mac_addr[6]);
772
773 int dpni_add_mac_addr(struct fsl_mc_io *mc_io,
774                       uint32_t cmd_flags,
775                       uint16_t token,
776                       const uint8_t mac_addr[6]);
777
778 int dpni_remove_mac_addr(struct fsl_mc_io *mc_io,
779                          uint32_t cmd_flags,
780                          uint16_t token,
781                          const uint8_t mac_addr[6]);
782
783 int dpni_clear_mac_filters(struct fsl_mc_io *mc_io,
784                            uint32_t cmd_flags,
785                            uint16_t token,
786                            int unicast,
787                            int multicast);
788
789 int dpni_get_port_mac_addr(struct fsl_mc_io *mc_io,
790                            uint32_t cmd_flags,
791                            uint16_t token,
792                            uint8_t mac_addr[6]);
793
794 int dpni_enable_vlan_filter(struct fsl_mc_io *mc_io,
795                             uint32_t cmd_flags,
796                             uint16_t token,
797                             int en);
798
799 int dpni_add_vlan_id(struct fsl_mc_io *mc_io,
800                      uint32_t cmd_flags,
801                      uint16_t token,
802                      uint16_t vlan_id);
803
804 int dpni_remove_vlan_id(struct fsl_mc_io *mc_io,
805                         uint32_t cmd_flags,
806                         uint16_t token,
807                         uint16_t vlan_id);
808
809 int dpni_clear_vlan_filters(struct fsl_mc_io *mc_io,
810                             uint32_t cmd_flags,
811                             uint16_t token);
812
813 /**
814  * enum dpni_dist_mode - DPNI distribution mode
815  * @DPNI_DIST_MODE_NONE: No distribution
816  * @DPNI_DIST_MODE_HASH: Use hash distribution; only relevant if
817  *              the 'DPNI_OPT_DIST_HASH' option was set at DPNI creation
818  * @DPNI_DIST_MODE_FS:  Use explicit flow steering; only relevant if
819  *       the 'DPNI_OPT_DIST_FS' option was set at DPNI creation
820  */
821 enum dpni_dist_mode {
822         DPNI_DIST_MODE_NONE = 0,
823         DPNI_DIST_MODE_HASH = 1,
824         DPNI_DIST_MODE_FS = 2
825 };
826
827 /**
828  * enum dpni_fs_miss_action -   DPNI Flow Steering miss action
829  * @DPNI_FS_MISS_DROP: In case of no-match, drop the frame
830  * @DPNI_FS_MISS_EXPLICIT_FLOWID: In case of no-match, use explicit flow-id
831  * @DPNI_FS_MISS_HASH: In case of no-match, distribute using hash
832  */
833 enum dpni_fs_miss_action {
834         DPNI_FS_MISS_DROP = 0,
835         DPNI_FS_MISS_EXPLICIT_FLOWID = 1,
836         DPNI_FS_MISS_HASH = 2
837 };
838
839 /**
840  * struct dpni_fs_tbl_cfg - Flow Steering table configuration
841  * @miss_action:        Miss action selection
842  * @default_flow_id:    Used when 'miss_action = DPNI_FS_MISS_EXPLICIT_FLOWID'
843  * @keep_hash_key: used only when miss_action is set to DPNI_FS_MISS_HASH. When
844  *      set to one unclassified frames will be distributed according to previous
845  *      used hash key. If set to zero hash key will be replaced with the key
846  *      provided for flow steering.
847  * @keep_entries: if set to one command will not delete the entries that already
848  *      exist into FS table. Use this option with caution: if the table
849  *      entries are not compatible with the distribution key the packets
850  *      will not be classified properly.
851  */
852 struct dpni_fs_tbl_cfg {
853         enum dpni_fs_miss_action miss_action;
854         uint16_t default_flow_id;
855         char keep_hash_key;
856         uint8_t keep_entries;
857 };
858
859 /**
860  * struct dpni_rx_tc_dist_cfg - Rx traffic class distribution configuration
861  * @dist_size: Set the distribution size;
862  *      supported values: 1,2,3,4,6,7,8,12,14,16,24,28,32,48,56,64,96,
863  *      112,128,192,224,256,384,448,512,768,896,1024
864  * @dist_mode: Distribution mode
865  * @key_cfg_iova: I/O virtual address of 256 bytes DMA-able memory filled with
866  *              the extractions to be used for the distribution key by calling
867  *              dpkg_prepare_key_cfg() relevant only when
868  *              'dist_mode != DPNI_DIST_MODE_NONE', otherwise it can be '0'
869  * @fs_cfg: Flow Steering table configuration; only relevant if
870  *              'dist_mode = DPNI_DIST_MODE_FS'
871  */
872 struct dpni_rx_tc_dist_cfg {
873         uint16_t dist_size;
874         enum dpni_dist_mode dist_mode;
875         uint64_t key_cfg_iova;
876         struct dpni_fs_tbl_cfg fs_cfg;
877 };
878
879 int dpni_set_rx_tc_dist(struct fsl_mc_io *mc_io,
880                         uint32_t cmd_flags,
881                         uint16_t token,
882                         uint8_t tc_id,
883                         const struct dpni_rx_tc_dist_cfg *cfg);
884
885 /**
886  * enum dpni_congestion_unit - DPNI congestion units
887  * @DPNI_CONGESTION_UNIT_BYTES: bytes units
888  * @DPNI_CONGESTION_UNIT_FRAMES: frames units
889  */
890 enum dpni_congestion_unit {
891         DPNI_CONGESTION_UNIT_BYTES = 0,
892         DPNI_CONGESTION_UNIT_FRAMES
893 };
894
895 /**
896  * enum dpni_dest - DPNI destination types
897  * @DPNI_DEST_NONE: Unassigned destination; The queue is set in parked mode and
898  *              does not generate FQDAN notifications; user is expected to
899  *              dequeue from the queue based on polling or other user-defined
900  *              method
901  * @DPNI_DEST_DPIO: The queue is set in schedule mode and generates FQDAN
902  *              notifications to the specified DPIO; user is expected to dequeue
903  *              from the queue only after notification is received
904  * @DPNI_DEST_DPCON: The queue is set in schedule mode and does not generate
905  *              FQDAN notifications, but is connected to the specified DPCON
906  *              object; user is expected to dequeue from the DPCON channel
907  */
908 enum dpni_dest {
909         DPNI_DEST_NONE = 0,
910         DPNI_DEST_DPIO = 1,
911         DPNI_DEST_DPCON = 2
912 };
913
914 /**
915  * struct dpni_dest_cfg - Structure representing DPNI destination parameters
916  * @dest_type: Destination type
917  * @dest_id: Either DPIO ID or DPCON ID, depending on the destination type
918  * @priority: Priority selection within the DPIO or DPCON channel; valid values
919  *              are 0-1 or 0-7, depending on the number of priorities in that
920  *              channel; not relevant for 'DPNI_DEST_NONE' option
921  */
922 struct dpni_dest_cfg {
923         enum dpni_dest dest_type;
924         int dest_id;
925         uint8_t priority;
926 };
927
928 /* DPNI congestion options */
929
930 /**
931  * CSCN message is written to message_iova once entering a
932  * congestion state (see 'threshold_entry')
933  */
934 #define DPNI_CONG_OPT_WRITE_MEM_ON_ENTER        0x00000001
935 /**
936  * CSCN message is written to message_iova once exiting a
937  * congestion state (see 'threshold_exit')
938  */
939 #define DPNI_CONG_OPT_WRITE_MEM_ON_EXIT         0x00000002
940 /**
941  * CSCN write will attempt to allocate into a cache (coherent write);
942  * valid only if 'DPNI_CONG_OPT_WRITE_MEM_<X>' is selected
943  */
944 #define DPNI_CONG_OPT_COHERENT_WRITE            0x00000004
945 /**
946  * if 'dest_cfg.dest_type != DPNI_DEST_NONE' CSCN message is sent to
947  * DPIO/DPCON's WQ channel once entering a congestion state
948  * (see 'threshold_entry')
949  */
950 #define DPNI_CONG_OPT_NOTIFY_DEST_ON_ENTER      0x00000008
951 /**
952  * if 'dest_cfg.dest_type != DPNI_DEST_NONE' CSCN message is sent to
953  * DPIO/DPCON's WQ channel once exiting a congestion state
954  * (see 'threshold_exit')
955  */
956 #define DPNI_CONG_OPT_NOTIFY_DEST_ON_EXIT       0x00000010
957 /**
958  * if 'dest_cfg.dest_type != DPNI_DEST_NONE' when the CSCN is written to the
959  * sw-portal's DQRR, the DQRI interrupt is asserted immediately (if enabled)
960  */
961 #define DPNI_CONG_OPT_INTR_COALESCING_DISABLED  0x00000020
962 /**
963  * This congestion will trigger flow control or priority flow control. This
964  * will have effect only if flow control is enabled with dpni_set_link_cfg()
965  */
966 #define DPNI_CONG_OPT_FLOW_CONTROL      0x00000040
967
968 /**
969  * enum dpni_congestion_point - Structure representing congestion point
970  * @DPNI_CP_QUEUE:      Set congestion per queue, identified by QUEUE_TYPE, TC
971  *                      and QUEUE_INDEX
972  * @DPNI_CP_GROUP:      Set congestion per queue group. Depending on options
973  *                      used to define the DPNI this can be either per
974  *                      TC (default) or per interface
975  *                      (DPNI_OPT_SHARED_CONGESTION set at DPNI create).
976  *                      QUEUE_INDEX is ignored if this type is used.
977  * @DPNI_CP_CONGESTION_GROUP: Set per congestion group id. This will work
978  *              only if the DPNI is created with  DPNI_OPT_CUSTOM_CG option
979  */
980
981 enum dpni_congestion_point {
982         DPNI_CP_QUEUE,
983         DPNI_CP_GROUP,
984         DPNI_CP_CONGESTION_GROUP,
985 };
986
987 /**
988  * struct dpni_congestion_notification_cfg - congestion notification
989  *              configuration
990  * @units: units type
991  * @threshold_entry: above this threshold we enter a congestion state.
992  *      set it to '0' to disable it
993  * @threshold_exit: below this threshold we exit the congestion state.
994  * @message_ctx: The context that will be part of the CSCN message
995  * @message_iova: I/O virtual address (must be in DMA-able memory),
996  *      must be 16B aligned; valid only if 'DPNI_CONG_OPT_WRITE_MEM_<X>' is
997  *      contained in 'options'
998  * @dest_cfg: CSCN can be send to either DPIO or DPCON WQ channel
999  * @notification_mode: Mask of available options; use 'DPNI_CONG_OPT_<X>' values
1000  * @cg_point: Congestion point settings
1001  * @cgid: id of the congestion group. The index is relative to dpni.
1002  */
1003
1004 struct dpni_congestion_notification_cfg {
1005         enum dpni_congestion_unit units;
1006         uint32_t threshold_entry;
1007         uint32_t threshold_exit;
1008         uint64_t message_ctx;
1009         uint64_t message_iova;
1010         struct dpni_dest_cfg dest_cfg;
1011         uint16_t notification_mode;
1012         enum dpni_congestion_point cg_point;
1013         int cgid;
1014 };
1015
1016 int dpni_set_congestion_notification(struct fsl_mc_io *mc_io,
1017                                      uint32_t cmd_flags,
1018                                      uint16_t token,
1019                                      enum dpni_queue_type qtype,
1020                                      uint8_t tc_id,
1021                         const struct dpni_congestion_notification_cfg *cfg);
1022
1023 int dpni_get_congestion_notification(struct fsl_mc_io *mc_io,
1024                                      uint32_t cmd_flags,
1025                                      uint16_t token,
1026                                      enum dpni_queue_type qtype,
1027                                      uint8_t tc_id,
1028                                 struct dpni_congestion_notification_cfg *cfg);
1029
1030 /* DPNI FLC stash options */
1031
1032 /**
1033  * stashes the whole annotation area (up to 192 bytes)
1034  */
1035 #define DPNI_FLC_STASH_FRAME_ANNOTATION 0x00000001
1036
1037 /**
1038  * struct dpni_queue - Queue structure
1039  * @destination - Destination structure
1040  * @destination.id: ID of the destination, only relevant if DEST_TYPE is > 0.
1041  *      Identifies either a DPIO or a DPCON object.
1042  *      Not relevant for Tx queues.
1043  * @destination.type:   May be one of the following:
1044  *      0 - No destination, queue can be manually
1045  *              queried, but will not push traffic or
1046  *              notifications to a DPIO;
1047  *      1 - The destination is a DPIO. When traffic
1048  *              becomes available in the queue a FQDAN
1049  *              (FQ data available notification) will be
1050  *              generated to selected DPIO;
1051  *      2 - The destination is a DPCON. The queue is
1052  *              associated with a DPCON object for the
1053  *              purpose of scheduling between multiple
1054  *              queues. The DPCON may be independently
1055  *              configured to generate notifications.
1056  *              Not relevant for Tx queues.
1057  * @destination.hold_active: Hold active, maintains a queue scheduled for longer
1058  *      in a DPIO during dequeue to reduce spread of traffic.
1059  *      Only relevant if queues are
1060  *      not affined to a single DPIO.
1061  * @user_context: User data, presented to the user along with any frames
1062  *      from this queue. Not relevant for Tx queues.
1063  * @flc: FD FLow Context structure
1064  * @flc.value: Default FLC value for traffic dequeued from
1065  *      this queue.  Please check description of FD
1066  *      structure for more information.
1067  *      Note that FLC values set using dpni_add_fs_entry,
1068  *      if any, take precedence over values per queue.
1069  * @flc.stash_control: Boolean, indicates whether the 6 lowest
1070  *      - significant bits are used for stash control.
1071  *      significant bits are used for stash control.  If set, the 6
1072  *      least significant bits in value are interpreted as follows:
1073  *      - bits 0-1: indicates the number of 64 byte units of context
1074  *      that are stashed.  FLC value is interpreted as a memory address
1075  *      in this case, excluding the 6 LS bits.
1076  *      - bits 2-3: indicates the number of 64 byte units of frame
1077  *      annotation to be stashed.  Annotation is placed at FD[ADDR].
1078  *      - bits 4-5: indicates the number of 64 byte units of frame
1079  *      data to be stashed.  Frame data is placed at FD[ADDR] +
1080  *      FD[OFFSET].
1081  *      For more details check the Frame Descriptor section in the
1082  *      hardware documentation.
1083  *@cgid :indicate the cgid to set relative to dpni
1084  */
1085 struct dpni_queue {
1086         struct {
1087                 uint16_t id;
1088                 enum dpni_dest type;
1089                 char hold_active;
1090                 uint8_t priority;
1091         } destination;
1092         uint64_t user_context;
1093         struct {
1094                 uint64_t value;
1095                 char stash_control;
1096         } flc;
1097         int cgid;
1098 };
1099
1100 /**
1101  * struct dpni_queue_id - Queue identification, used for enqueue commands
1102  *                              or queue control
1103  * @fqid:       FQID used for enqueueing to and/or configuration of this
1104  *                      specific FQ
1105  * @qdbin:      Queueing bin, used to enqueue using QDID, DQBIN, QPRI.
1106  *                      Only relevant for Tx queues.
1107  */
1108 struct dpni_queue_id {
1109         uint32_t fqid;
1110         uint16_t qdbin;
1111 };
1112
1113 /**
1114  * enum dpni_confirmation_mode - Defines DPNI options supported for Tx
1115  * confirmation
1116  * @DPNI_CONF_AFFINE: For each Tx queue set associated with a sender there is
1117  * an affine Tx Confirmation queue
1118  * @DPNI_CONF_SINGLE: All Tx queues are associated with a single Tx
1119  * confirmation queue
1120  * @DPNI_CONF_DISABLE: Tx frames are not confirmed.  This must be associated
1121  * with proper FD set-up to have buffers release to a Buffer Pool, otherwise
1122  * buffers will be leaked
1123  */
1124 enum dpni_confirmation_mode {
1125         DPNI_CONF_AFFINE,
1126         DPNI_CONF_SINGLE,
1127         DPNI_CONF_DISABLE,
1128 };
1129
1130 int dpni_set_tx_confirmation_mode(struct fsl_mc_io *mc_io,
1131                                   uint32_t cmd_flags,
1132                                   uint16_t token,
1133                                   enum dpni_confirmation_mode mode);
1134
1135 int dpni_get_tx_confirmation_mode(struct fsl_mc_io *mc_io,
1136                                   uint32_t cmd_flags,
1137                                   uint16_t token,
1138                                   enum dpni_confirmation_mode *mode);
1139
1140 /**
1141  * struct dpni_qos_tbl_cfg - Structure representing QOS table configuration
1142  * @key_cfg_iova: I/O virtual address of 256 bytes DMA-able memory filled with
1143  *              key extractions to be used as the QoS criteria by calling
1144  *              dpkg_prepare_key_cfg()
1145  * @discard_on_miss: Set to '1' to discard frames in case of no match (miss);
1146  *              '0' to use the 'default_tc' in such cases
1147  * @keep_entries: if set to one will not delele existing table entries. This
1148  *              option will work properly only for dpni objects created with
1149  *              DPNI_OPT_HAS_KEY_MASKING option. All previous QoS entries must
1150  *              be compatible with new key composition rule.
1151  *              It is the caller's job to delete incompatible entries before
1152  *              executing this function.
1153  * @default_tc: Used in case of no-match and 'discard_on_miss'= 0
1154  */
1155 struct dpni_qos_tbl_cfg {
1156         uint64_t key_cfg_iova;
1157         int discard_on_miss;
1158         int keep_entries;
1159         uint8_t default_tc;
1160 };
1161
1162 int dpni_set_qos_table(struct fsl_mc_io *mc_io,
1163                        uint32_t cmd_flags,
1164                        uint16_t token,
1165                        const struct dpni_qos_tbl_cfg *cfg);
1166
1167 /**
1168  * struct dpni_rule_cfg - Rule configuration for table lookup
1169  * @key_iova: I/O virtual address of the key (must be in DMA-able memory)
1170  * @mask_iova: I/O virtual address of the mask (must be in DMA-able memory)
1171  * @key_size: key and mask size (in bytes)
1172  */
1173 struct dpni_rule_cfg {
1174         uint64_t key_iova;
1175         uint64_t mask_iova;
1176         uint8_t key_size;
1177 };
1178
1179 int dpni_add_qos_entry(struct fsl_mc_io *mc_io,
1180                        uint32_t cmd_flags,
1181                        uint16_t token,
1182                        const struct dpni_rule_cfg *cfg,
1183                        uint8_t tc_id,
1184                        uint16_t index);
1185
1186 int dpni_remove_qos_entry(struct fsl_mc_io *mc_io,
1187                           uint32_t cmd_flags,
1188                           uint16_t token,
1189                           const struct dpni_rule_cfg *cfg);
1190
1191 int dpni_clear_qos_table(struct fsl_mc_io *mc_io,
1192                          uint32_t cmd_flags,
1193                          uint16_t token);
1194
1195 /**
1196  * Discard matching traffic.  If set, this takes precedence over any other
1197  * configuration and matching traffic is always discarded.
1198  */
1199  #define DPNI_FS_OPT_DISCARD            0x1
1200
1201 /**
1202  * Set FLC value.  If set, flc member of truct dpni_fs_action_cfg is used to
1203  * override the FLC value set per queue.
1204  * For more details check the Frame Descriptor section in the hardware
1205  * documentation.
1206  */
1207 #define DPNI_FS_OPT_SET_FLC            0x2
1208
1209 /*
1210  * Indicates whether the 6 lowest significant bits of FLC are used for stash
1211  * control.  If set, the 6 least significant bits in value are interpreted as
1212  * follows:
1213  *     - bits 0-1: indicates the number of 64 byte units of context that are
1214  *     stashed.  FLC value is interpreted as a memory address in this case,
1215  *     excluding the 6 LS bits.
1216  *     - bits 2-3: indicates the number of 64 byte units of frame annotation
1217  *     to be stashed.  Annotation is placed at FD[ADDR].
1218  *     - bits 4-5: indicates the number of 64 byte units of frame data to be
1219  *     stashed.  Frame data is placed at FD[ADDR] + FD[OFFSET].
1220  * This flag is ignored if DPNI_FS_OPT_SET_FLC is not specified.
1221  */
1222 #define DPNI_FS_OPT_SET_STASH_CONTROL  0x4
1223
1224 /**
1225  * struct dpni_fs_action_cfg - Action configuration for table look-up
1226  * @flc: FLC value for traffic matching this rule.  Please check the Frame
1227  * Descriptor section in the hardware documentation for more information.
1228  * @flow_id: Identifies the Rx queue used for matching traffic.  Supported
1229  *     values are in range 0 to num_queue-1.
1230  * @options: Any combination of DPNI_FS_OPT_ values.
1231  */
1232 struct dpni_fs_action_cfg {
1233         uint64_t flc;
1234         uint16_t flow_id;
1235         uint16_t options;
1236 };
1237
1238 int dpni_add_fs_entry(struct fsl_mc_io *mc_io,
1239                       uint32_t cmd_flags,
1240                       uint16_t token,
1241                       uint8_t tc_id,
1242                       uint16_t index,
1243                       const struct dpni_rule_cfg *cfg,
1244                       const struct dpni_fs_action_cfg *action);
1245
1246 int dpni_remove_fs_entry(struct fsl_mc_io *mc_io,
1247                          uint32_t cmd_flags,
1248                          uint16_t token,
1249                          uint8_t tc_id,
1250                          const struct dpni_rule_cfg *cfg);
1251
1252 int dpni_clear_fs_entries(struct fsl_mc_io *mc_io,
1253                           uint32_t cmd_flags,
1254                           uint16_t token,
1255                           uint8_t tc_id);
1256
1257 int dpni_get_api_version(struct fsl_mc_io *mc_io,
1258                          uint32_t cmd_flags,
1259                          uint16_t *major_ver,
1260                          uint16_t *minor_ver);
1261
1262 /**
1263  * Set User Context
1264  */
1265 #define DPNI_QUEUE_OPT_USER_CTX         0x00000001
1266
1267 /**
1268  * Set queue destination configuration
1269  */
1270 #define DPNI_QUEUE_OPT_DEST             0x00000002
1271
1272 /**
1273  * Set FD[FLC] configuration for traffic on this queue.  Note that FLC values
1274  * set with dpni_add_fs_entry, if any, take precedence over values per queue.
1275  */
1276 #define DPNI_QUEUE_OPT_FLC              0x00000004
1277
1278 /**
1279  * Set the queue to hold active mode.  This prevents the queue from being
1280  * rescheduled between DPIOs while it carries traffic and is active on one
1281  * DPNI.  Can help reduce reordering when servicing one queue on multiple
1282  * CPUs, but the queue is also less likely to push data to multiple CPUs
1283  * especially when congested.
1284  */
1285 #define DPNI_QUEUE_OPT_HOLD_ACTIVE      0x00000008
1286
1287 #define DPNI_QUEUE_OPT_SET_CGID                         0x00000040
1288 #define DPNI_QUEUE_OPT_CLEAR_CGID                       0x00000080
1289
1290 int dpni_set_queue(struct fsl_mc_io *mc_io,
1291                    uint32_t cmd_flags,
1292                    uint16_t token,
1293                    enum dpni_queue_type qtype,
1294                    uint8_t tc,
1295                    uint8_t index,
1296                    uint8_t options,
1297                    const struct dpni_queue *queue);
1298
1299 int dpni_get_queue(struct fsl_mc_io *mc_io,
1300                    uint32_t cmd_flags,
1301                    uint16_t token,
1302                    enum dpni_queue_type qtype,
1303                    uint8_t tc,
1304                    uint8_t index,
1305                    struct dpni_queue *queue,
1306                    struct dpni_queue_id *qid);
1307
1308 int dpni_get_statistics(struct fsl_mc_io *mc_io,
1309                         uint32_t cmd_flags,
1310                         uint16_t token,
1311                         uint8_t page,
1312                         uint16_t param,
1313                         union dpni_statistics *stat);
1314
1315 int dpni_reset_statistics(struct fsl_mc_io *mc_io,
1316                           uint32_t cmd_flags,
1317                           uint16_t token);
1318
1319 /**
1320  * struct dpni_taildrop - Structure representing the taildrop
1321  * @enable:     Indicates whether the taildrop is active or not.
1322  * @units:      Indicates the unit of THRESHOLD. Queue taildrop only
1323  *              supports byte units, this field is ignored and
1324  *              assumed = 0 if CONGESTION_POINT is 0.
1325  * @threshold:  Threshold value, in units identified by UNITS field. Value 0
1326  *              cannot be used as a valid taildrop threshold,
1327  *              THRESHOLD must be > 0 if the taildrop is
1328  *              enabled.
1329  * @oal :       Overhead Accounting Length, a 12-bit, 2's complement value
1330  *              with range (-2048 to +2047) representing a fixed per-frame
1331  *              overhead to be added to the actual length of a frame when
1332  *              performing WRED and tail drop calculations and threshold
1333  *              comparisons.
1334  */
1335 struct dpni_taildrop {
1336         char enable;
1337         enum dpni_congestion_unit units;
1338         uint32_t threshold;
1339         int16_t oal;
1340 };
1341
1342 int dpni_set_taildrop(struct fsl_mc_io *mc_io,
1343                       uint32_t cmd_flags,
1344                       uint16_t token,
1345                       enum dpni_congestion_point cg_point,
1346                       enum dpni_queue_type q_type,
1347                       uint8_t tc,
1348                       uint8_t q_index,
1349                       struct dpni_taildrop *taildrop);
1350
1351 int dpni_get_taildrop(struct fsl_mc_io *mc_io,
1352                       uint32_t cmd_flags,
1353                       uint16_t token,
1354                       enum dpni_congestion_point cg_point,
1355                       enum dpni_queue_type q_type,
1356                       uint8_t tc,
1357                       uint8_t q_index,
1358                       struct dpni_taildrop *taildrop);
1359
1360 int dpni_set_opr(struct fsl_mc_io *mc_io,
1361                  uint32_t cmd_flags,
1362                  uint16_t token,
1363                  uint8_t tc,
1364                  uint8_t index,
1365                  uint8_t options,
1366                  struct opr_cfg *cfg);
1367
1368 int dpni_get_opr(struct fsl_mc_io *mc_io,
1369                  uint32_t cmd_flags,
1370                  uint16_t token,
1371                  uint8_t tc,
1372                  uint8_t index,
1373                  struct opr_cfg *cfg,
1374                  struct opr_qry *qry);
1375
1376 /**
1377  * When used for queue_idx in function dpni_set_rx_dist_default_queue will
1378  * signal to dpni to drop all unclassified frames
1379  */
1380 #define DPNI_FS_MISS_DROP               ((uint16_t)-1)
1381
1382 /**
1383  * struct dpni_rx_dist_cfg - distribution configuration
1384  * @dist_size:  distribution size; supported values: 1,2,3,4,6,7,8,
1385  *              12,14,16,24,28,32,48,56,64,96,112,128,192,224,256,384,448,
1386  *              512,768,896,1024
1387  * @key_cfg_iova: I/O virtual address of 256 bytes DMA-able memory filled with
1388  *              the extractions to be used for the distribution key by calling
1389  *              dpkg_prepare_key_cfg() relevant only when enable!=0 otherwise
1390  *              it can be '0'
1391  * @enable: enable/disable the distribution.
1392  * @tc: TC id for which distribution is set
1393  * @fs_miss_flow_id: when packet misses all rules from flow steering table and
1394  *              hash is disabled it will be put into this queue id; use
1395  *              DPNI_FS_MISS_DROP to drop frames. The value of this field is
1396  *              used only when flow steering distribution is enabled and hash
1397  *              distribution is disabled
1398  */
1399 struct dpni_rx_dist_cfg {
1400         uint16_t dist_size;
1401         uint64_t key_cfg_iova;
1402         uint8_t enable;
1403         uint8_t tc;
1404         uint16_t fs_miss_flow_id;
1405 };
1406
1407 int dpni_set_rx_fs_dist(struct fsl_mc_io *mc_io, uint32_t cmd_flags,
1408                 uint16_t token, const struct dpni_rx_dist_cfg *cfg);
1409
1410 int dpni_set_rx_hash_dist(struct fsl_mc_io *mc_io, uint32_t cmd_flags,
1411                 uint16_t token, const struct dpni_rx_dist_cfg *cfg);
1412
1413 int dpni_add_custom_tpid(struct fsl_mc_io *mc_io, uint32_t cmd_flags,
1414                 uint16_t token, uint16_t tpid);
1415
1416 int dpni_remove_custom_tpid(struct fsl_mc_io *mc_io, uint32_t cmd_flags,
1417                 uint16_t token, uint16_t tpid);
1418
1419 /**
1420  * struct dpni_custom_tpid_cfg - custom TPID configuration. Contains custom TPID
1421  *      values used in current dpni object to detect 802.1q frames.
1422  *      @tpid1: first tag. Not used if zero.
1423  *      @tpid2: second tag. Not used if zero.
1424  */
1425 struct dpni_custom_tpid_cfg {
1426         uint16_t tpid1;
1427         uint16_t tpid2;
1428 };
1429
1430 int dpni_get_custom_tpid(struct fsl_mc_io *mc_io, uint32_t cmd_flags,
1431                 uint16_t token, struct dpni_custom_tpid_cfg *tpid);
1432
1433 /**
1434  * enum dpni_soft_sequence_dest - Enumeration of WRIOP software sequence
1435  *                              destinations
1436  * @DPNI_SS_INGRESS: Ingress parser
1437  * @DPNI_SS_EGRESS: Egress parser
1438  */
1439 enum dpni_soft_sequence_dest {
1440         DPNI_SS_INGRESS = 0,
1441         DPNI_SS_EGRESS = 1,
1442 };
1443
1444 /**
1445  * struct dpni_load_ss_cfg - Structure for Software Sequence load configuration
1446  * @dest:       Destination of the Software Sequence: ingress or egress parser
1447  * @ss_size: Size of the Software Sequence
1448  * @ss_offset:  The offset where to load the Software Sequence (0x20-0x7FD)
1449  * @ss_iova: I/O virtual address of the Software Sequence
1450  */
1451 struct dpni_load_ss_cfg {
1452         enum dpni_soft_sequence_dest dest;
1453         uint16_t ss_size;
1454         uint16_t ss_offset;
1455         uint64_t ss_iova;
1456 };
1457
1458 /**
1459  * struct dpni_enable_ss_cfg - Structure for software sequence enable
1460  *                              configuration
1461  * @dest:       Destination of the Software Sequence: ingress or egress parser
1462  * @hxs: HXS to attach the software sequence to
1463  * @set_start: If the Software Sequence or HDR it is attached to is set as
1464  *              parser start
1465  *              If hxs=DUMMY_LAST_HXS the ss_offset is set directly as parser
1466  *                      start else the hdr index code is set as parser start
1467  * @ss_offset: The offset of the Software Sequence to enable or set as parse
1468  *              start
1469  * @param_size: Size of the software sequence parameters
1470  * @param_offset: Offset in the parameter zone for the software sequence
1471  *                      parameters
1472  * @param_iova: I/O virtual address of the parameters
1473  */
1474 struct dpni_enable_ss_cfg {
1475         enum dpni_soft_sequence_dest dest;
1476         uint16_t hxs;
1477         uint8_t set_start;
1478         uint16_t ss_offset;
1479         uint8_t param_size;
1480         uint8_t param_offset;
1481         uint64_t param_iova;
1482 };
1483
1484 /**
1485  * dpni_load_sw_sequence() - Loads a software sequence in parser memory.
1486  * @mc_io:      Pointer to MC portal's I/O object
1487  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
1488  * @token:      Token of DPNI object
1489  * @cfg:        Software sequence load configuration
1490  * Return:      '0' on Success; Error code otherwise.
1491  */
1492 int dpni_load_sw_sequence(struct fsl_mc_io *mc_io,
1493               uint32_t cmd_flags,
1494               uint16_t token,
1495                   struct dpni_load_ss_cfg *cfg);
1496
1497 /**
1498  * dpni_eanble_sw_sequence() - Enables a software sequence in the parser
1499  *                              profile
1500  * corresponding to the ingress or egress of the DPNI.
1501  * @mc_io:      Pointer to MC portal's I/O object
1502  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
1503  * @token:      Token of DPNI object
1504  * @cfg:        Software sequence enable configuration
1505  * Return:      '0' on Success; Error code otherwise.
1506  */
1507 int dpni_enable_sw_sequence(struct fsl_mc_io *mc_io,
1508                             uint32_t cmd_flags,
1509                             uint16_t token,
1510                             struct dpni_enable_ss_cfg *cfg);
1511
1512 /**
1513  * struct dpni_sw_sequence_layout - Structure for software sequence enable
1514  *                              configuration
1515  * @num_ss:     Number of software sequences returned
1516  * @ss: Array of software sequence entries. The number of valid entries
1517  *                      must match 'num_ss' value
1518  */
1519 struct dpni_sw_sequence_layout {
1520         uint8_t num_ss;
1521         struct {
1522                 uint16_t ss_offset;
1523                 uint16_t ss_size;
1524                 uint8_t param_offset;
1525                 uint8_t param_size;
1526         } ss[DPNI_SW_SEQUENCE_LAYOUT_SIZE];
1527 };
1528
1529 /**
1530  * dpni_get_sw_sequence_layout() - Get the soft sequence layout
1531  * @mc_io:      Pointer to MC portal's I/O object
1532  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
1533  * @token:      Token of DPNI object
1534  * @src:        Source of the layout (WRIOP Rx or Tx)
1535  * @ss_layout_iova:  I/O virtual address of 264 bytes DMA-able memory
1536  *
1537  * warning: After calling this function, call dpni_extract_sw_sequence_layout()
1538  *              to get the layout
1539  *
1540  * Return:      '0' on Success; error code otherwise.
1541  */
1542 int dpni_get_sw_sequence_layout(struct fsl_mc_io *mc_io,
1543                                 uint32_t cmd_flags,
1544                                 uint16_t token,
1545                                 enum dpni_soft_sequence_dest src,
1546                                 uint64_t ss_layout_iova);
1547
1548 /**
1549  * dpni_extract_sw_sequence_layout() - extract the software sequence layout
1550  * @layout:             software sequence layout
1551  * @sw_sequence_layout_buf:     Zeroed 264 bytes of memory before mapping it
1552  *                              to DMA
1553  *
1554  * This function has to be called after dpni_get_sw_sequence_layout
1555  *
1556  */
1557 void dpni_extract_sw_sequence_layout(struct dpni_sw_sequence_layout *layout,
1558                                      const uint8_t *sw_sequence_layout_buf);
1559
1560 #endif /* __FSL_DPNI_H */