New upstream version 17.11-rc3
[deb_dpdk.git] / drivers / net / dpaa2 / mc / fsl_dpni.h
1 /*-
2  * This file is provided under a dual BSD/GPLv2 license. When using or
3  * redistributing this file, you may do so under either license.
4  *
5  *   BSD LICENSE
6  *
7  * Copyright 2013-2016 Freescale Semiconductor Inc.
8  * Copyright 2016-2017 NXP.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions are met:
12  * * Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  * * Redistributions in binary form must reproduce the above copyright
15  * notice, this list of conditions and the following disclaimer in the
16  * documentation and/or other materials provided with the distribution.
17  * * Neither the name of the above-listed copyright holders nor the
18  * names of any contributors may be used to endorse or promote products
19  * derived from this software without specific prior written permission.
20  *
21  *   GPL LICENSE SUMMARY
22  *
23  * ALTERNATIVELY, this software may be distributed under the terms of the
24  * GNU General Public License ("GPL") as published by the Free Software
25  * Foundation, either version 2 of that License or (at your option) any
26  * later version.
27  *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
29  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
32  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
33  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
34  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
35  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
36  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
37  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38  * POSSIBILITY OF SUCH DAMAGE.
39  */
40 #ifndef __FSL_DPNI_H
41 #define __FSL_DPNI_H
42
43 #include <fsl_dpkg.h>
44
45 struct fsl_mc_io;
46
47 /**
48  * Data Path Network Interface API
49  * Contains initialization APIs and runtime control APIs for DPNI
50  */
51
52 /** General DPNI macros */
53
54 /**
55  * Maximum number of traffic classes
56  */
57 #define DPNI_MAX_TC                             8
58 /**
59  * Maximum number of buffer pools per DPNI
60  */
61 #define DPNI_MAX_DPBP                           8
62 /**
63  * Maximum number of storage-profiles per DPNI
64  */
65 #define DPNI_MAX_SP                             2
66
67 /**
68  * All traffic classes considered; see dpni_set_queue()
69  */
70 #define DPNI_ALL_TCS                            (uint8_t)(-1)
71 /**
72  * All flows within traffic class considered; see dpni_set_queue()
73  */
74 #define DPNI_ALL_TC_FLOWS                       (uint16_t)(-1)
75
76 /**
77  * Tx traffic is always released to a buffer pool on transmit, there are no
78  * resources allocated to have the frames confirmed back to the source after
79  * transmission.
80  */
81 #define DPNI_OPT_TX_FRM_RELEASE                 0x000001
82 /**
83  * Disables support for MAC address filtering for addresses other than primary
84  * MAC address. This affects both unicast and multicast. Promiscuous mode can
85  * still be enabled/disabled for both unicast and multicast. If promiscuous mode
86  * is disabled, only traffic matching the primary MAC address will be accepted.
87  */
88 #define DPNI_OPT_NO_MAC_FILTER                  0x000002
89 /**
90  * Allocate policers for this DPNI. They can be used to rate-limit traffic per
91  * traffic class (TC) basis.
92  */
93 #define DPNI_OPT_HAS_POLICING                   0x000004
94 /**
95  * Congestion can be managed in several ways, allowing the buffer pool to
96  * deplete on ingress, taildrop on each queue or use congestion groups for sets
97  * of queues. If set, it configures a single congestion groups across all TCs.
98  * If reset, a congestion group is allocated for each TC. Only relevant if the
99  * DPNI has multiple traffic classes.
100  */
101 #define DPNI_OPT_SHARED_CONGESTION              0x000008
102 /**
103  * Enables TCAM for Flow Steering and QoS look-ups. If not specified, all
104  * look-ups are exact match. Note that TCAM is not available on LS1088 and its
105  * variants. Setting this bit on these SoCs will trigger an error.
106  */
107 #define DPNI_OPT_HAS_KEY_MASKING                0x000010
108 /**
109  * Disables the flow steering table.
110  */
111 #define DPNI_OPT_NO_FS                          0x000020
112
113 int dpni_open(struct fsl_mc_io *mc_io,
114               uint32_t cmd_flags,
115               int dpni_id,
116               uint16_t *token);
117
118 int dpni_close(struct fsl_mc_io *mc_io,
119                uint32_t cmd_flags,
120                uint16_t token);
121
122 /**
123  * struct dpni_cfg - Structure representing DPNI configuration
124  * @mac_addr:   Primary MAC address
125  * @adv:        Advanced parameters; default is all zeros;
126  *              use this structure to change default settings
127  */
128 struct dpni_cfg {
129         /**
130          * @options: Any combination of the following options:
131          *              DPNI_OPT_TX_FRM_RELEASE
132          *              DPNI_OPT_NO_MAC_FILTER
133          *              DPNI_OPT_HAS_POLICING
134          *              DPNI_OPT_SHARED_CONGESTION
135          *              DPNI_OPT_HAS_KEY_MASKING
136          *              DPNI_OPT_NO_FS
137          * @fs_entries: Number of entries in the flow steering table.
138          *              This table is used to select the ingress queue for
139          *              ingress traffic, targeting a GPP core or another.
140          *              In addition it can be used to discard traffic that
141          *              matches the set rule. It is either an exact match table
142          *              or a TCAM table, depending on DPNI_OPT_ HAS_KEY_MASKING
143          *              bit in OPTIONS field. This field is ignored if
144          *              DPNI_OPT_NO_FS bit is set in OPTIONS field. Otherwise,
145          *              value 0 defaults to 64. Maximum supported value is 1024.
146          *              Note that the total number of entries is limited on the
147          *              SoC to as low as 512 entries if TCAM is used.
148          * @vlan_filter_entries: Number of entries in the VLAN address filtering
149          *              table. This is an exact match table used to filter
150          *              ingress traffic based on VLAN IDs. Value 0 disables VLAN
151          *              filtering. Maximum supported value is 16.
152          * @mac_filter_entries: Number of entries in the MAC address filtering
153          *              table. This is an exact match table and allows both
154          *              unicast and multicast entries. The primary MAC address
155          *              of the network interface is not part of this table,
156          *              this contains only entries in addition to it. This
157          *              field is ignored if DPNI_OPT_ NO_MAC_FILTER is set in
158          *              OPTIONS field. Otherwise, value 0 defaults to 80.
159          *              Maximum supported value is 80.
160          * @num_queues: Number of Tx and Rx queues used for traffic
161          *              distribution. This is orthogonal to QoS and is only
162          *              used to distribute traffic to multiple GPP cores.
163          *              This configuration affects the number of Tx queues
164          *              (logical FQs, all associated with a single CEETM queue),
165          *              Rx queues and Tx confirmation queues, if applicable.
166          *              Value 0 defaults to one queue. Maximum supported value
167          *              is 8.
168          * @num_tcs: Number of traffic classes (TCs), reserved for the DPNI.
169          *              TCs can have different priority levels for the purpose
170          *              of Tx scheduling (see DPNI_SET_TX_SELECTION), different
171          *              BPs (DPNI_ SET_POOLS), policers. There are dedicated QM
172          *              queues for traffic classes (including class queues on
173          *              Tx). Value 0 defaults to one TC. Maximum supported value
174          *              is 8.
175          * @qos_entries: Number of entries in the QoS classification table. This
176          *              table is used to select the TC for ingress traffic. It
177          *              is either an exact match or a TCAM table, depending on
178          *              DPNI_OPT_ HAS_KEY_MASKING bit in OPTIONS field. This
179          *              field is ignored if the DPNI has a single TC. Otherwise,
180          *              a value of 0 defaults to 64. Maximum supported value
181          *              is 64.
182          */
183         uint32_t options;
184         uint16_t fs_entries;
185         uint8_t  vlan_filter_entries;
186         uint8_t  mac_filter_entries;
187         uint8_t  num_queues;
188         uint8_t  num_tcs;
189         uint8_t  qos_entries;
190 };
191
192 int dpni_create(struct fsl_mc_io *mc_io,
193                 uint16_t dprc_token,
194                 uint32_t cmd_flags,
195                 const struct dpni_cfg *cfg,
196                 uint32_t *obj_id);
197
198 int dpni_destroy(struct fsl_mc_io *mc_io,
199                  uint16_t dprc_token,
200                  uint32_t cmd_flags,
201                  uint32_t object_id);
202
203 /**
204  * struct dpni_pools_cfg - Structure representing buffer pools configuration
205  * @num_dpbp:   Number of DPBPs
206  * @pools:      Array of buffer pools parameters; The number of valid entries
207  *              must match 'num_dpbp' value
208  */
209 struct dpni_pools_cfg {
210         uint8_t num_dpbp;
211         /**
212          * struct pools - Buffer pools parameters
213          * @dpbp_id: DPBP object ID
214          * @priority: priority mask that indicates TC's used with this buffer.
215          * I set to 0x00 MC will assume value 0xff.
216          * @buffer_size: Buffer size
217          * @backup_pool: Backup pool
218          */
219         struct {
220                 int             dpbp_id;
221                 uint8_t         priority_mask;
222                 uint16_t        buffer_size;
223                 int             backup_pool;
224         } pools[DPNI_MAX_DPBP];
225 };
226
227 int dpni_set_pools(struct fsl_mc_io *mc_io,
228                    uint32_t cmd_flags,
229                    uint16_t token,
230                    const struct dpni_pools_cfg *cfg);
231
232 int dpni_enable(struct fsl_mc_io *mc_io,
233                 uint32_t cmd_flags,
234                 uint16_t token);
235
236 int dpni_disable(struct fsl_mc_io *mc_io,
237                  uint32_t cmd_flags,
238                  uint16_t token);
239
240 int dpni_is_enabled(struct fsl_mc_io *mc_io,
241                     uint32_t cmd_flags,
242                     uint16_t token,
243                     int *en);
244
245 int dpni_reset(struct fsl_mc_io *mc_io,
246                uint32_t cmd_flags,
247                uint16_t token);
248
249 /**
250  * DPNI IRQ Index and Events
251  */
252
253 /**
254  * IRQ index
255  */
256 #define DPNI_IRQ_INDEX                          0
257 /**
258  * IRQ event - indicates a change in link state
259  */
260 #define DPNI_IRQ_EVENT_LINK_CHANGED             0x00000001
261
262 int dpni_set_irq_enable(struct fsl_mc_io *mc_io,
263                         uint32_t cmd_flags,
264                         uint16_t token,
265                         uint8_t irq_index,
266                         uint8_t en);
267
268 int dpni_get_irq_enable(struct fsl_mc_io *mc_io,
269                         uint32_t cmd_flags,
270                         uint16_t token,
271                         uint8_t irq_index,
272                         uint8_t *en);
273
274 int dpni_set_irq_mask(struct fsl_mc_io *mc_io,
275                       uint32_t cmd_flags,
276                       uint16_t token,
277                       uint8_t irq_index,
278                       uint32_t mask);
279
280 int dpni_get_irq_mask(struct fsl_mc_io *mc_io,
281                       uint32_t cmd_flags,
282                       uint16_t token,
283                       uint8_t irq_index,
284                       uint32_t *mask);
285
286 int dpni_get_irq_status(struct fsl_mc_io *mc_io,
287                         uint32_t cmd_flags,
288                         uint16_t token,
289                         uint8_t irq_index,
290                         uint32_t *status);
291
292 int dpni_clear_irq_status(struct fsl_mc_io *mc_io,
293                           uint32_t cmd_flags,
294                           uint16_t token,
295                           uint8_t irq_index,
296                           uint32_t status);
297
298 /**
299  * struct dpni_attr - Structure representing DPNI attributes
300  * @options: Any combination of the following options:
301  *              DPNI_OPT_TX_FRM_RELEASE
302  *              DPNI_OPT_NO_MAC_FILTER
303  *              DPNI_OPT_HAS_POLICING
304  *              DPNI_OPT_SHARED_CONGESTION
305  *              DPNI_OPT_HAS_KEY_MASKING
306  *              DPNI_OPT_NO_FS
307  * @num_queues: Number of Tx and Rx queues used for traffic distribution.
308  * @num_rx_tcs: Number of RX traffic classes (TCs), reserved for the DPNI.
309  * @num_tx_tcs: Number of TX traffic classes (TCs), reserved for the DPNI.
310  * @mac_filter_entries: Number of entries in the MAC address filtering
311  *              table.
312  * @vlan_filter_entries: Number of entries in the VLAN address filtering
313  *              table.
314  * @qos_entries: Number of entries in the QoS classification table.
315  * @fs_entries: Number of entries in the flow steering table.
316  * @qos_key_size: Size, in bytes, of the QoS look-up key. Defining a key larger
317  *                      than this when adding QoS entries will result
318  *                      in an error.
319  * @fs_key_size: Size, in bytes, of the flow steering look-up key. Defining a
320  *                      key larger than this when composing the hash + FS key
321  *                      will result in an error.
322  * @wriop_version: Version of WRIOP HW block.
323  *                      The 3 version values are stored on 6, 5, 5 bits
324  *                      respectively.
325  *                      Values returned:
326  *                      - 0x400 - WRIOP version 1.0.0, used on LS2080 and
327  *                      variants,
328  *                      - 0x421 - WRIOP version 1.1.1, used on LS2088 and
329  *                      variants,
330  *                      - 0x422 - WRIOP version 1.1.2, used on LS1088 and
331  *                      variants.
332  */
333 struct dpni_attr {
334         uint32_t options;
335         uint8_t  num_queues;
336         uint8_t  num_rx_tcs;
337         uint8_t  num_tx_tcs;
338         uint8_t  mac_filter_entries;
339         uint8_t  vlan_filter_entries;
340         uint8_t  qos_entries;
341         uint16_t fs_entries;
342         uint8_t  qos_key_size;
343         uint8_t  fs_key_size;
344         uint16_t wriop_version;
345 };
346
347 int dpni_get_attributes(struct fsl_mc_io *mc_io,
348                         uint32_t cmd_flags,
349                         uint16_t token,
350                         struct dpni_attr *attr);
351
352 /**
353  * DPNI errors
354  */
355
356 /**
357  * Extract out of frame header error
358  */
359 #define DPNI_ERROR_EOFHE        0x00020000
360 /**
361  * Frame length error
362  */
363 #define DPNI_ERROR_FLE          0x00002000
364 /**
365  * Frame physical error
366  */
367 #define DPNI_ERROR_FPE          0x00001000
368 /**
369  * Parsing header error
370  */
371 #define DPNI_ERROR_PHE          0x00000020
372 /**
373  * Parser L3 checksum error
374  */
375 #define DPNI_ERROR_L3CE         0x00000004
376 /**
377  * Parser L3 checksum error
378  */
379 #define DPNI_ERROR_L4CE         0x00000001
380
381 /**
382  * enum dpni_error_action - Defines DPNI behavior for errors
383  * @DPNI_ERROR_ACTION_DISCARD: Discard the frame
384  * @DPNI_ERROR_ACTION_CONTINUE: Continue with the normal flow
385  * @DPNI_ERROR_ACTION_SEND_TO_ERROR_QUEUE: Send the frame to the error queue
386  */
387 enum dpni_error_action {
388         DPNI_ERROR_ACTION_DISCARD = 0,
389         DPNI_ERROR_ACTION_CONTINUE = 1,
390         DPNI_ERROR_ACTION_SEND_TO_ERROR_QUEUE = 2
391 };
392
393 /**
394  * struct dpni_error_cfg - Structure representing DPNI errors treatment
395  * @errors:                     Errors mask; use 'DPNI_ERROR__<X>
396  * @error_action:               The desired action for the errors mask
397  * @set_frame_annotation:       Set to '1' to mark the errors in frame
398  *                              annotation status (FAS); relevant only
399  *                              for the non-discard action
400  */
401 struct dpni_error_cfg {
402         uint32_t errors;
403         enum dpni_error_action error_action;
404         int set_frame_annotation;
405 };
406
407 int dpni_set_errors_behavior(struct fsl_mc_io *mc_io,
408                              uint32_t cmd_flags,
409                              uint16_t token,
410                              struct dpni_error_cfg *cfg);
411
412 /**
413  * DPNI buffer layout modification options
414  */
415
416 /**
417  * Select to modify the time-stamp setting
418  */
419 #define DPNI_BUF_LAYOUT_OPT_TIMESTAMP           0x00000001
420 /**
421  * Select to modify the parser-result setting; not applicable for Tx
422  */
423 #define DPNI_BUF_LAYOUT_OPT_PARSER_RESULT       0x00000002
424 /**
425  * Select to modify the frame-status setting
426  */
427 #define DPNI_BUF_LAYOUT_OPT_FRAME_STATUS        0x00000004
428 /**
429  * Select to modify the private-data-size setting
430  */
431 #define DPNI_BUF_LAYOUT_OPT_PRIVATE_DATA_SIZE   0x00000008
432 /**
433  * Select to modify the data-alignment setting
434  */
435 #define DPNI_BUF_LAYOUT_OPT_DATA_ALIGN          0x00000010
436 /**
437  * Select to modify the data-head-room setting
438  */
439 #define DPNI_BUF_LAYOUT_OPT_DATA_HEAD_ROOM      0x00000020
440 /**
441  * Select to modify the data-tail-room setting
442  */
443 #define DPNI_BUF_LAYOUT_OPT_DATA_TAIL_ROOM      0x00000040
444
445 /**
446  * struct dpni_buffer_layout - Structure representing DPNI buffer layout
447  * @options:            Flags representing the suggested modifications to the
448  *                      buffer layout;
449  *                      Use any combination of 'DPNI_BUF_LAYOUT_OPT_<X>' flags
450  * @pass_timestamp:     Pass timestamp value
451  * @pass_parser_result: Pass parser results
452  * @pass_frame_status:  Pass frame status
453  * @private_data_size:  Size kept for private data (in bytes)
454  * @data_align:         Data alignment
455  * @data_head_room:     Data head room
456  * @data_tail_room:     Data tail room
457  */
458 struct dpni_buffer_layout {
459         uint32_t options;
460         int pass_timestamp;
461         int pass_parser_result;
462         int pass_frame_status;
463         uint16_t private_data_size;
464         uint16_t data_align;
465         uint16_t data_head_room;
466         uint16_t data_tail_room;
467 };
468
469 /**
470  * enum dpni_queue_type - Identifies a type of queue targeted by the command
471  * @DPNI_QUEUE_RX: Rx queue
472  * @DPNI_QUEUE_TX: Tx queue
473  * @DPNI_QUEUE_TX_CONFIRM: Tx confirmation queue
474  * @DPNI_QUEUE_RX_ERR: Rx error queue
475  */
476 enum dpni_queue_type {
477         DPNI_QUEUE_RX,
478         DPNI_QUEUE_TX,
479         DPNI_QUEUE_TX_CONFIRM,
480         DPNI_QUEUE_RX_ERR,
481 };
482
483 int dpni_get_buffer_layout(struct fsl_mc_io *mc_io,
484                            uint32_t cmd_flags,
485                            uint16_t token,
486                            enum dpni_queue_type qtype,
487                            struct dpni_buffer_layout *layout);
488
489 int dpni_set_buffer_layout(struct fsl_mc_io *mc_io,
490                            uint32_t cmd_flags,
491                            uint16_t token,
492                            enum dpni_queue_type qtype,
493                            const struct dpni_buffer_layout *layout);
494
495 /**
496  * enum dpni_offload - Identifies a type of offload targeted by the command
497  * @DPNI_OFF_RX_L3_CSUM: Rx L3 checksum validation
498  * @DPNI_OFF_RX_L4_CSUM: Rx L4 checksum validation
499  * @DPNI_OFF_TX_L3_CSUM: Tx L3 checksum generation
500  * @DPNI_OFF_TX_L4_CSUM: Tx L4 checksum generation
501  * @DPNI_OPT_FLCTYPE_HASH: flow context will be generated by WRIOP for AIOP or
502  *                         for CPU
503  */
504 enum dpni_offload {
505         DPNI_OFF_RX_L3_CSUM,
506         DPNI_OFF_RX_L4_CSUM,
507         DPNI_OFF_TX_L3_CSUM,
508         DPNI_OFF_TX_L4_CSUM,
509         DPNI_FLCTYPE_HASH,
510 };
511
512 int dpni_set_offload(struct fsl_mc_io *mc_io,
513                      uint32_t cmd_flags,
514                      uint16_t token,
515                      enum dpni_offload type,
516                      uint32_t config);
517
518 int dpni_get_offload(struct fsl_mc_io *mc_io,
519                      uint32_t cmd_flags,
520                      uint16_t token,
521                      enum dpni_offload type,
522                      uint32_t *config);
523
524 int dpni_get_qdid(struct fsl_mc_io *mc_io,
525                   uint32_t cmd_flags,
526                   uint16_t token,
527                   enum dpni_queue_type qtype,
528                   uint16_t *qdid);
529
530 int dpni_get_tx_data_offset(struct fsl_mc_io *mc_io,
531                             uint32_t cmd_flags,
532                             uint16_t token,
533                             uint16_t *data_offset);
534
535 #define DPNI_STATISTICS_CNT             7
536
537 union dpni_statistics {
538         /**
539          * struct page_0 - Page_0 statistics structure
540          * @ingress_all_frames: Ingress frame count
541          * @ingress_all_bytes: Ingress byte count
542          * @ingress_multicast_frames: Ingress multicast frame count
543          * @ingress_multicast_bytes: Ingress multicast byte count
544          * @ingress_broadcast_frames: Ingress broadcast frame count
545          * @ingress_broadcast_bytes: Ingress broadcast byte count
546          */
547         struct {
548                 uint64_t ingress_all_frames;
549                 uint64_t ingress_all_bytes;
550                 uint64_t ingress_multicast_frames;
551                 uint64_t ingress_multicast_bytes;
552                 uint64_t ingress_broadcast_frames;
553                 uint64_t ingress_broadcast_bytes;
554         } page_0;
555         /**
556          * struct page_1 - Page_1 statistics structure
557          * @egress_all_frames: Egress frame count
558          * @egress_all_bytes: Egress byte count
559          * @egress_multicast_frames: Egress multicast frame count
560          * @egress_multicast_bytes: Egress multicast byte count
561          * @egress_broadcast_frames: Egress broadcast frame count
562          * @egress_broadcast_bytes: Egress broadcast byte count
563          */
564         struct {
565                 uint64_t egress_all_frames;
566                 uint64_t egress_all_bytes;
567                 uint64_t egress_multicast_frames;
568                 uint64_t egress_multicast_bytes;
569                 uint64_t egress_broadcast_frames;
570                 uint64_t egress_broadcast_bytes;
571         } page_1;
572         /**
573          * struct page_2 - Page_2 statistics structure
574          * @ingress_filtered_frames: Ingress filtered frame count
575          * @ingress_discarded_frames: Ingress discarded frame count
576          * @ingress_nobuffer_discards: Ingress discarded frame count due to
577          *                                      lack of buffers
578          * @egress_discarded_frames: Egress discarded frame count
579          * @egress_confirmed_frames: Egress confirmed frame count
580          */
581         struct {
582                 uint64_t ingress_filtered_frames;
583                 uint64_t ingress_discarded_frames;
584                 uint64_t ingress_nobuffer_discards;
585                 uint64_t egress_discarded_frames;
586                 uint64_t egress_confirmed_frames;
587         } page_2;
588         /**
589          * struct page_3 - Page_3 statistics structure with values for the
590          *                      selected TC
591          * @ceetm_dequeue_bytes: Cumulative count of the number of bytes
592          *                      dequeued
593          * @ceetm_dequeue_frames: Cumulative count of the number of frames
594          *                      dequeued
595          * @ceetm_reject_bytes: Cumulative count of the number of bytes in all
596          *                      frames whose enqueue was rejected
597          * @ceetm_reject_frames: Cumulative count of all frame enqueues rejected
598          */
599         struct {
600                 uint64_t ceetm_dequeue_bytes;
601                 uint64_t ceetm_dequeue_frames;
602                 uint64_t ceetm_reject_bytes;
603                 uint64_t ceetm_reject_frames;
604         } page_3;
605         /**
606          * struct raw - raw statistics structure, used to index counters
607          */
608         struct {
609                 uint64_t counter[DPNI_STATISTICS_CNT];
610         } raw;
611 };
612
613 /**
614  * Enable auto-negotiation
615  */
616 #define DPNI_LINK_OPT_AUTONEG           0x0000000000000001ULL
617 /**
618  * Enable half-duplex mode
619  */
620 #define DPNI_LINK_OPT_HALF_DUPLEX       0x0000000000000002ULL
621 /**
622  * Enable pause frames
623  */
624 #define DPNI_LINK_OPT_PAUSE             0x0000000000000004ULL
625 /**
626  * Enable a-symmetric pause frames
627  */
628 #define DPNI_LINK_OPT_ASYM_PAUSE        0x0000000000000008ULL
629 /**
630  * Enable priority flow control pause frames
631  */
632 #define DPNI_LINK_OPT_PFC_PAUSE 0x0000000000000010ULL
633
634 /**
635  * struct - Structure representing DPNI link configuration
636  * @rate: Rate
637  * @options: Mask of available options; use 'DPNI_LINK_OPT_<X>' values
638  */
639 struct dpni_link_cfg {
640         uint32_t rate;
641         uint64_t options;
642 };
643
644 int dpni_set_link_cfg(struct fsl_mc_io *mc_io,
645                       uint32_t cmd_flags,
646                       uint16_t token,
647                       const struct dpni_link_cfg *cfg);
648
649 /**
650  * struct dpni_link_state - Structure representing DPNI link state
651  * @rate:       Rate
652  * @options:    Mask of available options; use 'DPNI_LINK_OPT_<X>' values
653  * @up:         Link state; '0' for down, '1' for up
654  */
655 struct dpni_link_state {
656         uint32_t rate;
657         uint64_t options;
658         int up;
659 };
660
661 int dpni_get_link_state(struct fsl_mc_io *mc_io,
662                         uint32_t cmd_flags,
663                         uint16_t token,
664                         struct dpni_link_state *state);
665
666 int dpni_set_max_frame_length(struct fsl_mc_io *mc_io,
667                               uint32_t cmd_flags,
668                               uint16_t token,
669                               uint16_t max_frame_length);
670
671 int dpni_get_max_frame_length(struct fsl_mc_io *mc_io,
672                               uint32_t cmd_flags,
673                               uint16_t token,
674                               uint16_t *max_frame_length);
675
676 int dpni_set_mtu(struct fsl_mc_io *mc_io,
677                  uint32_t cmd_flags,
678                  uint16_t token,
679                  uint16_t mtu);
680
681 int dpni_get_mtu(struct fsl_mc_io *mc_io,
682                  uint32_t cmd_flags,
683                  uint16_t token,
684                  uint16_t *mtu);
685
686 int dpni_set_multicast_promisc(struct fsl_mc_io *mc_io,
687                                uint32_t cmd_flags,
688                                uint16_t token,
689                                int en);
690
691 int dpni_get_multicast_promisc(struct fsl_mc_io *mc_io,
692                                uint32_t cmd_flags,
693                                uint16_t token,
694                                int *en);
695
696 int dpni_set_unicast_promisc(struct fsl_mc_io *mc_io,
697                              uint32_t cmd_flags,
698                              uint16_t token,
699                              int en);
700
701 int dpni_get_unicast_promisc(struct fsl_mc_io *mc_io,
702                              uint32_t cmd_flags,
703                              uint16_t token,
704                              int *en);
705
706 int dpni_set_primary_mac_addr(struct fsl_mc_io *mc_io,
707                               uint32_t cmd_flags,
708                               uint16_t token,
709                               const uint8_t mac_addr[6]);
710
711 int dpni_get_primary_mac_addr(struct fsl_mc_io *mc_io,
712                               uint32_t cmd_flags,
713                               uint16_t token,
714                               uint8_t mac_addr[6]);
715
716 int dpni_add_mac_addr(struct fsl_mc_io *mc_io,
717                       uint32_t cmd_flags,
718                       uint16_t token,
719                       const uint8_t mac_addr[6]);
720
721 int dpni_remove_mac_addr(struct fsl_mc_io *mc_io,
722                          uint32_t cmd_flags,
723                          uint16_t token,
724                          const uint8_t mac_addr[6]);
725
726 int dpni_clear_mac_filters(struct fsl_mc_io *mc_io,
727                            uint32_t cmd_flags,
728                            uint16_t token,
729                            int unicast,
730                            int multicast);
731
732 int dpni_get_port_mac_addr(struct fsl_mc_io *mc_io,
733                            uint32_t cmd_flags,
734                            uint16_t token,
735                            uint8_t mac_addr[6]);
736
737 int dpni_enable_vlan_filter(struct fsl_mc_io *mc_io,
738                             uint32_t cmd_flags,
739                             uint16_t token,
740                             int en);
741
742 int dpni_add_vlan_id(struct fsl_mc_io *mc_io,
743                      uint32_t cmd_flags,
744                      uint16_t token,
745                      uint16_t vlan_id);
746
747 int dpni_remove_vlan_id(struct fsl_mc_io *mc_io,
748                         uint32_t cmd_flags,
749                         uint16_t token,
750                         uint16_t vlan_id);
751
752 int dpni_clear_vlan_filters(struct fsl_mc_io *mc_io,
753                             uint32_t cmd_flags,
754                             uint16_t token);
755
756 /**
757  * enum dpni_dist_mode - DPNI distribution mode
758  * @DPNI_DIST_MODE_NONE: No distribution
759  * @DPNI_DIST_MODE_HASH: Use hash distribution; only relevant if
760  *              the 'DPNI_OPT_DIST_HASH' option was set at DPNI creation
761  * @DPNI_DIST_MODE_FS:  Use explicit flow steering; only relevant if
762  *       the 'DPNI_OPT_DIST_FS' option was set at DPNI creation
763  */
764 enum dpni_dist_mode {
765         DPNI_DIST_MODE_NONE = 0,
766         DPNI_DIST_MODE_HASH = 1,
767         DPNI_DIST_MODE_FS = 2
768 };
769
770 /**
771  * enum dpni_fs_miss_action -   DPNI Flow Steering miss action
772  * @DPNI_FS_MISS_DROP: In case of no-match, drop the frame
773  * @DPNI_FS_MISS_EXPLICIT_FLOWID: In case of no-match, use explicit flow-id
774  * @DPNI_FS_MISS_HASH: In case of no-match, distribute using hash
775  */
776 enum dpni_fs_miss_action {
777         DPNI_FS_MISS_DROP = 0,
778         DPNI_FS_MISS_EXPLICIT_FLOWID = 1,
779         DPNI_FS_MISS_HASH = 2
780 };
781
782 /**
783  * struct dpni_fs_tbl_cfg - Flow Steering table configuration
784  * @miss_action:        Miss action selection
785  * @default_flow_id:    Used when 'miss_action = DPNI_FS_MISS_EXPLICIT_FLOWID'
786  */
787 struct dpni_fs_tbl_cfg {
788         enum dpni_fs_miss_action miss_action;
789         uint16_t default_flow_id;
790         char keep_hash_key;
791 };
792
793 /**
794  * struct dpni_rx_tc_dist_cfg - Rx traffic class distribution configuration
795  * @dist_size: Set the distribution size;
796  *      supported values: 1,2,3,4,6,7,8,12,14,16,24,28,32,48,56,64,96,
797  *      112,128,192,224,256,384,448,512,768,896,1024
798  * @dist_mode: Distribution mode
799  * @key_cfg_iova: I/O virtual address of 256 bytes DMA-able memory filled with
800  *              the extractions to be used for the distribution key by calling
801  *              dpkg_prepare_key_cfg() relevant only when
802  *              'dist_mode != DPNI_DIST_MODE_NONE', otherwise it can be '0'
803  * @fs_cfg: Flow Steering table configuration; only relevant if
804  *              'dist_mode = DPNI_DIST_MODE_FS'
805  */
806 struct dpni_rx_tc_dist_cfg {
807         uint16_t dist_size;
808         enum dpni_dist_mode dist_mode;
809         uint64_t key_cfg_iova;
810         struct dpni_fs_tbl_cfg fs_cfg;
811 };
812
813 int dpni_set_rx_tc_dist(struct fsl_mc_io *mc_io,
814                         uint32_t cmd_flags,
815                         uint16_t token,
816                         uint8_t tc_id,
817                         const struct dpni_rx_tc_dist_cfg *cfg);
818
819 /**
820  * enum dpni_congestion_unit - DPNI congestion units
821  * @DPNI_CONGESTION_UNIT_BYTES: bytes units
822  * @DPNI_CONGESTION_UNIT_FRAMES: frames units
823  */
824 enum dpni_congestion_unit {
825         DPNI_CONGESTION_UNIT_BYTES = 0,
826         DPNI_CONGESTION_UNIT_FRAMES
827 };
828
829
830 /**
831  * enum dpni_dest - DPNI destination types
832  * @DPNI_DEST_NONE: Unassigned destination; The queue is set in parked mode and
833  *              does not generate FQDAN notifications; user is expected to
834  *              dequeue from the queue based on polling or other user-defined
835  *              method
836  * @DPNI_DEST_DPIO: The queue is set in schedule mode and generates FQDAN
837  *              notifications to the specified DPIO; user is expected to dequeue
838  *              from the queue only after notification is received
839  * @DPNI_DEST_DPCON: The queue is set in schedule mode and does not generate
840  *              FQDAN notifications, but is connected to the specified DPCON
841  *              object; user is expected to dequeue from the DPCON channel
842  */
843 enum dpni_dest {
844         DPNI_DEST_NONE = 0,
845         DPNI_DEST_DPIO = 1,
846         DPNI_DEST_DPCON = 2
847 };
848
849 /**
850  * struct dpni_dest_cfg - Structure representing DPNI destination parameters
851  * @dest_type: Destination type
852  * @dest_id: Either DPIO ID or DPCON ID, depending on the destination type
853  * @priority: Priority selection within the DPIO or DPCON channel; valid values
854  *              are 0-1 or 0-7, depending on the number of priorities in that
855  *              channel; not relevant for 'DPNI_DEST_NONE' option
856  */
857 struct dpni_dest_cfg {
858         enum dpni_dest dest_type;
859         int dest_id;
860         uint8_t priority;
861 };
862
863 /* DPNI congestion options */
864
865 /**
866  * CSCN message is written to message_iova once entering a
867  * congestion state (see 'threshold_entry')
868  */
869 #define DPNI_CONG_OPT_WRITE_MEM_ON_ENTER        0x00000001
870 /**
871  * CSCN message is written to message_iova once exiting a
872  * congestion state (see 'threshold_exit')
873  */
874 #define DPNI_CONG_OPT_WRITE_MEM_ON_EXIT         0x00000002
875 /**
876  * CSCN write will attempt to allocate into a cache (coherent write);
877  * valid only if 'DPNI_CONG_OPT_WRITE_MEM_<X>' is selected
878  */
879 #define DPNI_CONG_OPT_COHERENT_WRITE            0x00000004
880 /**
881  * if 'dest_cfg.dest_type != DPNI_DEST_NONE' CSCN message is sent to
882  * DPIO/DPCON's WQ channel once entering a congestion state
883  * (see 'threshold_entry')
884  */
885 #define DPNI_CONG_OPT_NOTIFY_DEST_ON_ENTER      0x00000008
886 /**
887  * if 'dest_cfg.dest_type != DPNI_DEST_NONE' CSCN message is sent to
888  * DPIO/DPCON's WQ channel once exiting a congestion state
889  * (see 'threshold_exit')
890  */
891 #define DPNI_CONG_OPT_NOTIFY_DEST_ON_EXIT       0x00000010
892 /**
893  * if 'dest_cfg.dest_type != DPNI_DEST_NONE' when the CSCN is written to the
894  * sw-portal's DQRR, the DQRI interrupt is asserted immediately (if enabled)
895  */
896 #define DPNI_CONG_OPT_INTR_COALESCING_DISABLED  0x00000020
897 /**
898  * This congestion will trigger flow control or priority flow control. This
899  * will have effect only if flow control is enabled with dpni_set_link_cfg()
900  */
901 #define DPNI_CONG_OPT_FLOW_CONTROL      0x00000040
902
903 /**
904  * struct dpni_congestion_notification_cfg - congestion notification
905  *              configuration
906  * @units: units type
907  * @threshold_entry: above this threshold we enter a congestion state.
908  *      set it to '0' to disable it
909  * @threshold_exit: below this threshold we exit the congestion state.
910  * @message_ctx: The context that will be part of the CSCN message
911  * @message_iova: I/O virtual address (must be in DMA-able memory),
912  *      must be 16B aligned; valid only if 'DPNI_CONG_OPT_WRITE_MEM_<X>' is
913  *      contained in 'options'
914  * @dest_cfg: CSCN can be send to either DPIO or DPCON WQ channel
915  * @notification_mode: Mask of available options; use 'DPNI_CONG_OPT_<X>' values
916  */
917
918 struct dpni_congestion_notification_cfg {
919         enum dpni_congestion_unit units;
920         uint32_t threshold_entry;
921         uint32_t threshold_exit;
922         uint64_t message_ctx;
923         uint64_t message_iova;
924         struct dpni_dest_cfg dest_cfg;
925         uint16_t notification_mode;
926 };
927
928 int dpni_set_congestion_notification(struct fsl_mc_io *mc_io,
929                                      uint32_t cmd_flags,
930                                      uint16_t token,
931                                      enum dpni_queue_type qtype,
932                                      uint8_t tc_id,
933                         const struct dpni_congestion_notification_cfg *cfg);
934
935 int dpni_get_congestion_notification(struct fsl_mc_io *mc_io,
936                                      uint32_t cmd_flags,
937                                      uint16_t token,
938                                      enum dpni_queue_type qtype,
939                                      uint8_t tc_id,
940                                 struct dpni_congestion_notification_cfg *cfg);
941
942 /* DPNI FLC stash options */
943
944 /**
945  * stashes the whole annotation area (up to 192 bytes)
946  */
947 #define DPNI_FLC_STASH_FRAME_ANNOTATION 0x00000001
948
949 /**
950  * struct dpni_queue - Queue structure
951  * @user_context:       User data, presented to the user along with any frames
952  *                      from this queue. Not relevant for Tx queues.
953  */
954 struct dpni_queue {
955         /**
956          * struct destination - Destination structure
957          * @id: ID of the destination, only relevant if DEST_TYPE is > 0.
958          *                      Identifies either a DPIO or a DPCON object.
959          *                      Not relevant for Tx queues.
960          * @type:       May be one of the following:
961          *                      0 - No destination, queue can be manually
962          *                              queried, but will not push traffic or
963          *                              notifications to a DPIO;
964          *                      1 - The destination is a DPIO. When traffic
965          *                              becomes available in the queue a FQDAN
966          *                              (FQ data available notification) will be
967          *                              generated to selected DPIO;
968          *                      2 - The destination is a DPCON. The queue is
969          *                              associated with a DPCON object for the
970          *                              purpose of scheduling between multiple
971          *                              queues. The DPCON may be independently
972          *                              configured to generate notifications.
973          *                              Not relevant for Tx queues.
974          * @hold_active: Hold active, maintains a queue scheduled for longer
975          *              in a DPIO during dequeue to reduce spread of traffic.
976          *              Only relevant if queues are
977          *              not affined to a single DPIO.
978          */
979         struct {
980                 uint16_t id;
981                 enum dpni_dest type;
982                 char hold_active;
983                 uint8_t priority;
984         } destination;
985         uint64_t user_context;
986         /**
987          * struct flc - FD FLow Context structure
988          * @value: Default FLC value for traffic dequeued from
989          *      this queue.  Please check description of FD
990          *      structure for more information.
991          *      Note that FLC values set using dpni_add_fs_entry,
992          *      if any, take precedence over values per queue.
993          * @stash_control: Boolean, indicates whether the 6 lowest
994          *      - significant bits are used for stash control.
995          *      significant bits are used for stash control.  If set, the 6
996          *      least significant bits in value are interpreted as follows:
997          *      - bits 0-1: indicates the number of 64 byte units of context
998          *      that are stashed.  FLC value is interpreted as a memory address
999          *      in this case, excluding the 6 LS bits.
1000          *      - bits 2-3: indicates the number of 64 byte units of frame
1001          *      annotation to be stashed.  Annotation is placed at FD[ADDR].
1002          *      - bits 4-5: indicates the number of 64 byte units of frame
1003          *      data to be stashed.  Frame data is placed at FD[ADDR] +
1004          *      FD[OFFSET].
1005          *      For more details check the Frame Descriptor section in the
1006          *      hardware documentation.
1007          */
1008         struct {
1009                 uint64_t value;
1010                 char stash_control;
1011         } flc;
1012 };
1013
1014 /**
1015  * struct dpni_queue_id - Queue identification, used for enqueue commands
1016  *                              or queue control
1017  * @fqid:       FQID used for enqueueing to and/or configuration of this
1018  *                      specific FQ
1019  * @qdbin:      Queueing bin, used to enqueue using QDID, DQBIN, QPRI.
1020  *                      Only relevant for Tx queues.
1021  */
1022 struct dpni_queue_id {
1023         uint32_t fqid;
1024         uint16_t qdbin;
1025 };
1026
1027 /**
1028  * enum dpni_confirmation_mode - Defines DPNI options supported for Tx
1029  * confirmation
1030  * @DPNI_CONF_AFFINE: For each Tx queue set associated with a sender there is
1031  * an affine Tx Confirmation queue
1032  * @DPNI_CONF_SINGLE: All Tx queues are associated with a single Tx
1033  * confirmation queue
1034  * @DPNI_CONF_DISABLE: Tx frames are not confirmed.  This must be associated
1035  * with proper FD set-up to have buffers release to a Buffer Pool, otherwise
1036  * buffers will be leaked
1037  */
1038 enum dpni_confirmation_mode {
1039         DPNI_CONF_AFFINE,
1040         DPNI_CONF_SINGLE,
1041         DPNI_CONF_DISABLE,
1042 };
1043
1044 int dpni_set_tx_confirmation_mode(struct fsl_mc_io *mc_io,
1045                                   uint32_t cmd_flags,
1046                                   uint16_t token,
1047                                   enum dpni_confirmation_mode mode);
1048
1049 int dpni_get_tx_confirmation_mode(struct fsl_mc_io *mc_io,
1050                                   uint32_t cmd_flags,
1051                                   uint16_t token,
1052                                   enum dpni_confirmation_mode *mode);
1053
1054 int dpni_get_api_version(struct fsl_mc_io *mc_io,
1055                          uint32_t cmd_flags,
1056                          uint16_t *major_ver,
1057                          uint16_t *minor_ver);
1058
1059 /**
1060  * Set User Context
1061  */
1062 #define DPNI_QUEUE_OPT_USER_CTX         0x00000001
1063
1064 /**
1065  * Set queue destination configuration
1066  */
1067 #define DPNI_QUEUE_OPT_DEST             0x00000002
1068
1069 /**
1070  * Set FD[FLC] configuration for traffic on this queue.  Note that FLC values
1071  * set with dpni_add_fs_entry, if any, take precedence over values per queue.
1072  */
1073 #define DPNI_QUEUE_OPT_FLC              0x00000004
1074
1075 /**
1076  * Set the queue to hold active mode.  This prevents the queue from being
1077  * rescheduled between DPIOs while it carries traffic and is active on one
1078  * DPNI.  Can help reduce reordering when servicing one queue on multiple
1079  * CPUs, but the queue is also less likely to push data to multiple CPUs
1080  * especially when congested.
1081  */
1082 #define DPNI_QUEUE_OPT_HOLD_ACTIVE      0x00000008
1083
1084 int dpni_set_queue(struct fsl_mc_io *mc_io,
1085                    uint32_t cmd_flags,
1086                    uint16_t token,
1087                    enum dpni_queue_type qtype,
1088                    uint8_t tc,
1089                    uint8_t index,
1090                    uint8_t options,
1091                    const struct dpni_queue *queue);
1092
1093 int dpni_get_queue(struct fsl_mc_io *mc_io,
1094                    uint32_t cmd_flags,
1095                    uint16_t token,
1096                    enum dpni_queue_type qtype,
1097                    uint8_t tc,
1098                    uint8_t index,
1099                    struct dpni_queue *queue,
1100                    struct dpni_queue_id *qid);
1101
1102 int dpni_get_statistics(struct fsl_mc_io *mc_io,
1103                         uint32_t cmd_flags,
1104                         uint16_t token,
1105                         uint8_t page,
1106                         uint8_t param,
1107                         union dpni_statistics *stat);
1108
1109 int dpni_reset_statistics(struct fsl_mc_io *mc_io,
1110                           uint32_t cmd_flags,
1111                           uint16_t token);
1112
1113 /**
1114  * enum dpni_congestion_point - Structure representing congestion point
1115  * @DPNI_CP_QUEUE:      Set taildrop per queue, identified by QUEUE_TYPE, TC and
1116  *                              QUEUE_INDEX
1117  * @DPNI_CP_GROUP:      Set taildrop per queue group. Depending on options used
1118  *                              to define the DPNI this can be either per
1119  *                              TC (default) or per interface
1120  *                              (DPNI_OPT_SHARED_CONGESTION set at DPNI create).
1121  *                              QUEUE_INDEX is ignored if this type is used.
1122  */
1123 enum dpni_congestion_point {
1124         DPNI_CP_QUEUE,
1125         DPNI_CP_GROUP,
1126 };
1127
1128 /**
1129  * struct dpni_taildrop - Structure representing the taildrop
1130  * @enable:     Indicates whether the taildrop is active or not.
1131  * @units:      Indicates the unit of THRESHOLD. Queue taildrop only
1132  *              supports byte units, this field is ignored and
1133  *              assumed = 0 if CONGESTION_POINT is 0.
1134  * @threshold:  Threshold value, in units identified by UNITS field. Value 0
1135  *              cannot be used as a valid taildrop threshold,
1136  *              THRESHOLD must be > 0 if the taildrop is
1137  *              enabled.
1138  * @oal :       Overhead Accounting Length, a 12-bit, 2's complement value
1139  *              with range (-2048 to +2047) representing a fixed per-frame
1140  *              overhead to be added to the actual length of a frame when
1141  *              performing WRED and tail drop calculations and threshold
1142  *              comparisons.
1143  */
1144 struct dpni_taildrop {
1145         char enable;
1146         enum dpni_congestion_unit units;
1147         uint32_t threshold;
1148         int16_t oal;
1149 };
1150
1151 int dpni_set_taildrop(struct fsl_mc_io *mc_io,
1152                       uint32_t cmd_flags,
1153                       uint16_t token,
1154                       enum dpni_congestion_point cg_point,
1155                       enum dpni_queue_type q_type,
1156                       uint8_t tc,
1157                       uint8_t q_index,
1158                       struct dpni_taildrop *taildrop);
1159
1160 int dpni_get_taildrop(struct fsl_mc_io *mc_io,
1161                       uint32_t cmd_flags,
1162                       uint16_t token,
1163                       enum dpni_congestion_point cg_point,
1164                       enum dpni_queue_type q_type,
1165                       uint8_t tc,
1166                       uint8_t q_index,
1167                       struct dpni_taildrop *taildrop);
1168 #endif /* __FSL_DPNI_H */