64db70dc16ae7df3dd907ef20d90e907f21b8e45
[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 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 /**
114  * dpni_open() - Open a control session for the specified object
115  * @mc_io:      Pointer to MC portal's I/O object
116  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
117  * @dpni_id:    DPNI unique ID
118  * @token:      Returned token; use in subsequent API calls
119  *
120  * This function can be used to open a control session for an
121  * already created object; an object may have been declared in
122  * the DPL or by calling the dpni_create() function.
123  * This function returns a unique authentication token,
124  * associated with the specific object ID and the specific MC
125  * portal; this token must be used in all subsequent commands for
126  * this specific object.
127  *
128  * Return:      '0' on Success; Error code otherwise.
129  */
130 int dpni_open(struct fsl_mc_io  *mc_io,
131               uint32_t          cmd_flags,
132               int               dpni_id,
133               uint16_t          *token);
134
135 /**
136  * dpni_close() - Close the control session of the object
137  * @mc_io:      Pointer to MC portal's I/O object
138  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
139  * @token:      Token of DPNI object
140  *
141  * After this function is called, no further operations are
142  * allowed on the object without opening a new control session.
143  *
144  * Return:      '0' on Success; Error code otherwise.
145  */
146 int dpni_close(struct fsl_mc_io *mc_io,
147                uint32_t         cmd_flags,
148                uint16_t         token);
149
150 /**
151  * struct dpni_cfg - Structure representing DPNI configuration
152  * @mac_addr: Primary MAC address
153  * @adv: Advanced parameters; default is all zeros;
154  *              use this structure to change default settings
155  */
156 struct dpni_cfg {
157         /**
158          * @options: Any combination of the following options:
159          *              DPNI_OPT_TX_FRM_RELEASE
160          *              DPNI_OPT_NO_MAC_FILTER
161          *              DPNI_OPT_HAS_POLICING
162          *              DPNI_OPT_SHARED_CONGESTION
163          *              DPNI_OPT_HAS_KEY_MASKING
164          *              DPNI_OPT_NO_FS
165          * @fs_entries: Number of entries in the flow steering table.
166          *              This table is used to select the ingress queue for
167          *              ingress traffic, targeting a GPP core or another.
168          *              In addition it can be used to discard traffic that
169          *              matches the set rule. It is either an exact match table
170          *              or a TCAM table, depending on DPNI_OPT_ HAS_KEY_MASKING
171          *              bit in OPTIONS field. This field is ignored if
172          *              DPNI_OPT_NO_FS bit is set in OPTIONS field. Otherwise,
173          *              value 0 defaults to 64. Maximum supported value is 1024.
174          *              Note that the total number of entries is limited on the
175          *              SoC to as low as 512 entries if TCAM is used.
176          * @vlan_filter_entries: Number of entries in the VLAN address filtering
177          *              table. This is an exact match table used to filter
178          *              ingress traffic based on VLAN IDs. Value 0 disables VLAN
179          *              filtering. Maximum supported value is 16.
180          * @mac_filter_entries: Number of entries in the MAC address filtering
181          *              table. This is an exact match table and allows both
182          *              unicast and multicast entries. The primary MAC address
183          *              of the network interface is not part of this table,
184          *              this contains only entries in addition to it. This
185          *              field is ignored if DPNI_OPT_ NO_MAC_FILTER is set in
186          *              OPTIONS field. Otherwise, value 0 defaults to 80.
187          *              Maximum supported value is 80.
188          * @num_queues: Number of Tx and Rx queues used for traffic
189          *              distribution. This is orthogonal to QoS and is only
190          *              used to distribute traffic to multiple GPP cores.
191          *              This configuration affects the number of Tx queues
192          *              (logical FQs, all associated with a single CEETM queue),
193          *              Rx queues and Tx confirmation queues, if applicable.
194          *              Value 0 defaults to one queue. Maximum supported value
195          *              is 8.
196          * @num_tcs: Number of traffic classes (TCs), reserved for the DPNI.
197          *              TCs can have different priority levels for the purpose
198          *              of Tx scheduling (see DPNI_SET_TX_SELECTION), different
199          *              BPs (DPNI_ SET_POOLS), policers. There are dedicated QM
200          *              queues for traffic classes (including class queues on
201          *              Tx). Value 0 defaults to one TC. Maximum supported value
202          *              is 8.
203          * @qos_entries: Number of entries in the QoS classification table. This
204          *              table is used to select the TC for ingress traffic. It
205          *              is either an exact match or a TCAM table, depending on
206          *              DPNI_OPT_ HAS_KEY_MASKING bit in OPTIONS field. This
207          *              field is ignored if the DPNI has a single TC. Otherwise,
208          *              a value of 0 defaults to 64. Maximum supported value
209          *              is 64.
210          */
211         uint32_t options;
212         uint16_t fs_entries;
213         uint8_t  vlan_filter_entries;
214         uint8_t  mac_filter_entries;
215         uint8_t  num_queues;
216         uint8_t  num_tcs;
217         uint8_t  qos_entries;
218 };
219
220 /**
221  * dpni_create() - Create the DPNI object
222  * @mc_io:      Pointer to MC portal's I/O object
223  * @dprc_token: Parent container token; '0' for default container
224  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
225  * @cfg:        Configuration structure
226  * @obj_id: returned object id
227  *
228  * Create the DPNI object, allocate required resources and
229  * perform required initialization.
230  *
231  * The object can be created either by declaring it in the
232  * DPL file, or by calling this function.
233  *
234  * The function accepts an authentication token of a parent
235  * container that this object should be assigned to. The token
236  * can be '0' so the object will be assigned to the default container.
237  * The newly created object can be opened with the returned
238  * object id and using the container's associated tokens and MC portals.
239  *
240  * Return:      '0' on Success; Error code otherwise.
241  */
242 int dpni_create(struct fsl_mc_io        *mc_io,
243                 uint16_t                dprc_token,
244                 uint32_t                cmd_flags,
245                 const struct dpni_cfg   *cfg,
246                 uint32_t                *obj_id);
247
248 /**
249  * dpni_destroy() - Destroy the DPNI object and release all its resources.
250  * @mc_io:      Pointer to MC portal's I/O object
251  * @dprc_token: Parent container token; '0' for default container
252  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
253  * @object_id:  The object id; it must be a valid id within the container that
254  * created this object;
255  *
256  * The function accepts the authentication token of the parent container that
257  * created the object (not the one that currently owns the object). The object
258  * is searched within parent using the provided 'object_id'.
259  * All tokens to the object must be closed before calling destroy.
260  *
261  * Return:      '0' on Success; error code otherwise.
262  */
263 int dpni_destroy(struct fsl_mc_io       *mc_io,
264                  uint16_t               dprc_token,
265                  uint32_t               cmd_flags,
266                  uint32_t               object_id);
267
268 /**
269  * struct dpni_pools_cfg - Structure representing buffer pools configuration
270  * @num_dpbp: Number of DPBPs
271  * @pools: Array of buffer pools parameters; The number of valid entries
272  *      must match 'num_dpbp' value
273  */
274 struct dpni_pools_cfg {
275         uint8_t         num_dpbp;
276         /**
277          * struct pools - Buffer pools parameters
278          * @dpbp_id: DPBP object ID
279          * @buffer_size: Buffer size
280          * @backup_pool: Backup pool
281          */
282         struct {
283                 int             dpbp_id;
284                 uint16_t        buffer_size;
285                 int             backup_pool;
286         } pools[DPNI_MAX_DPBP];
287 };
288
289 /**
290  * dpni_set_pools() - Set buffer pools configuration
291  * @mc_io:      Pointer to MC portal's I/O object
292  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
293  * @token:      Token of DPNI object
294  * @cfg:        Buffer pools configuration
295  *
296  * mandatory for DPNI operation
297  * warning:Allowed only when DPNI is disabled
298  *
299  * Return:      '0' on Success; Error code otherwise.
300  */
301 int dpni_set_pools(struct fsl_mc_io             *mc_io,
302                    uint32_t                     cmd_flags,
303                    uint16_t                     token,
304                    const struct dpni_pools_cfg  *cfg);
305
306 /**
307  * dpni_enable() - Enable the DPNI, allow sending and receiving frames.
308  * @mc_io:      Pointer to MC portal's I/O object
309  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
310  * @token:              Token of DPNI object
311  *
312  * Return:      '0' on Success; Error code otherwise.
313  */
314 int dpni_enable(struct fsl_mc_io        *mc_io,
315                 uint32_t                cmd_flags,
316                 uint16_t                token);
317
318 /**
319  * dpni_disable() - Disable the DPNI, stop sending and receiving frames.
320  * @mc_io:      Pointer to MC portal's I/O object
321  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
322  * @token:      Token of DPNI object
323  *
324  * Return:      '0' on Success; Error code otherwise.
325  */
326 int dpni_disable(struct fsl_mc_io       *mc_io,
327                  uint32_t               cmd_flags,
328                  uint16_t               token);
329
330 /**
331  * dpni_is_enabled() - Check if the DPNI is enabled.
332  * @mc_io:      Pointer to MC portal's I/O object
333  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
334  * @token:      Token of DPNI object
335  * @en:         Returns '1' if object is enabled; '0' otherwise
336  *
337  * Return:      '0' on Success; Error code otherwise.
338  */
339 int dpni_is_enabled(struct fsl_mc_io    *mc_io,
340                     uint32_t            cmd_flags,
341                     uint16_t            token,
342                     int                 *en);
343
344 /**
345  * dpni_reset() - Reset the DPNI, returns the object to initial state.
346  * @mc_io:      Pointer to MC portal's I/O object
347  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
348  * @token:      Token of DPNI object
349  *
350  * Return:      '0' on Success; Error code otherwise.
351  */
352 int dpni_reset(struct fsl_mc_io *mc_io,
353                uint32_t         cmd_flags,
354                uint16_t         token);
355
356 /**
357  * struct dpni_attr - Structure representing DPNI attributes
358  * @options: Any combination of the following options:
359  *              DPNI_OPT_TX_FRM_RELEASE
360  *              DPNI_OPT_NO_MAC_FILTER
361  *              DPNI_OPT_HAS_POLICING
362  *              DPNI_OPT_SHARED_CONGESTION
363  *              DPNI_OPT_HAS_KEY_MASKING
364  *              DPNI_OPT_NO_FS
365  * @num_queues: Number of Tx and Rx queues used for traffic distribution.
366  * @num_tcs: Number of traffic classes (TCs), reserved for the DPNI.
367  * @mac_filter_entries: Number of entries in the MAC address filtering
368  *              table.
369  * @vlan_filter_entries: Number of entries in the VLAN address filtering
370  *              table.
371  * @qos_entries: Number of entries in the QoS classification table.
372  * @fs_entries: Number of entries in the flow steering table.
373  * @qos_key_size: Size, in bytes, of the QoS look-up key. Defining a key larger
374  *                      than this when adding QoS entries will result
375  *                      in an error.
376  * @fs_key_size: Size, in bytes, of the flow steering look-up key. Defining a
377  *                      key larger than this when composing the hash + FS key
378  *                      will result in an error.
379  * @wriop_version: Version of WRIOP HW block.
380  *                      The 3 version values are stored on 6, 5, 5 bits
381  *                      respectively.
382  *                      Values returned:
383  *                      - 0x400 - WRIOP version 1.0.0, used on LS2080 and
384  *                      variants,
385  *                      - 0x421 - WRIOP version 1.1.1, used on LS2088 and
386  *                      variants,
387  *                      - 0x422 - WRIOP version 1.1.2, used on LS1088 and
388  *                      variants.
389  */
390 struct dpni_attr {
391         uint32_t options;
392         uint8_t  num_queues;
393         uint8_t  num_tcs;
394         uint8_t  mac_filter_entries;
395         uint8_t  vlan_filter_entries;
396         uint8_t  qos_entries;
397         uint16_t fs_entries;
398         uint8_t  qos_key_size;
399         uint8_t  fs_key_size;
400         uint16_t wriop_version;
401 };
402
403 /**
404  * dpni_get_attributes() - Retrieve DPNI attributes.
405  * @mc_io:      Pointer to MC portal's I/O object
406  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
407  * @token:      Token of DPNI object
408  * @attr:       Object's attributes
409  *
410  * Return:      '0' on Success; Error code otherwise.
411  */
412 int dpni_get_attributes(struct fsl_mc_io        *mc_io,
413                         uint32_t                cmd_flags,
414                         uint16_t                token,
415                         struct dpni_attr        *attr);
416
417 /**
418  * DPNI errors
419  */
420
421 /**
422  * Extract out of frame header error
423  */
424 #define DPNI_ERROR_EOFHE        0x00020000
425 /**
426  * Frame length error
427  */
428 #define DPNI_ERROR_FLE          0x00002000
429 /**
430  * Frame physical error
431  */
432 #define DPNI_ERROR_FPE          0x00001000
433 /**
434  * Parsing header error
435  */
436 #define DPNI_ERROR_PHE          0x00000020
437 /**
438  * Parser L3 checksum error
439  */
440 #define DPNI_ERROR_L3CE         0x00000004
441 /**
442  * Parser L3 checksum error
443  */
444 #define DPNI_ERROR_L4CE         0x00000001
445
446 /**
447  * enum dpni_error_action - Defines DPNI behavior for errors
448  * @DPNI_ERROR_ACTION_DISCARD: Discard the frame
449  * @DPNI_ERROR_ACTION_CONTINUE: Continue with the normal flow
450  * @DPNI_ERROR_ACTION_SEND_TO_ERROR_QUEUE: Send the frame to the error queue
451  */
452 enum dpni_error_action {
453         DPNI_ERROR_ACTION_DISCARD = 0,
454         DPNI_ERROR_ACTION_CONTINUE = 1,
455         DPNI_ERROR_ACTION_SEND_TO_ERROR_QUEUE = 2
456 };
457
458 /**
459  * struct dpni_error_cfg - Structure representing DPNI errors treatment
460  * @errors: Errors mask; use 'DPNI_ERROR__<X>
461  * @error_action: The desired action for the errors mask
462  * @set_frame_annotation: Set to '1' to mark the errors in frame annotation
463  *              status (FAS); relevant only for the non-discard action
464  */
465 struct dpni_error_cfg {
466         uint32_t                errors;
467         enum dpni_error_action  error_action;
468         int                     set_frame_annotation;
469 };
470
471 /**
472  * dpni_set_errors_behavior() - Set errors behavior
473  * @mc_io:      Pointer to MC portal's I/O object
474  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
475  * @token:      Token of DPNI object
476  * @cfg:        Errors configuration
477  *
478  * this function may be called numerous times with different
479  * error masks
480  *
481  * Return:      '0' on Success; Error code otherwise.
482  */
483 int dpni_set_errors_behavior(struct fsl_mc_io           *mc_io,
484                              uint32_t                   cmd_flags,
485                              uint16_t                   token,
486                              struct dpni_error_cfg      *cfg);
487
488 /**
489  * DPNI buffer layout modification options
490  */
491
492 /**
493  * Select to modify the time-stamp setting
494  */
495 #define DPNI_BUF_LAYOUT_OPT_TIMESTAMP           0x00000001
496 /**
497  * Select to modify the parser-result setting; not applicable for Tx
498  */
499 #define DPNI_BUF_LAYOUT_OPT_PARSER_RESULT       0x00000002
500 /**
501  * Select to modify the frame-status setting
502  */
503 #define DPNI_BUF_LAYOUT_OPT_FRAME_STATUS        0x00000004
504 /**
505  * Select to modify the private-data-size setting
506  */
507 #define DPNI_BUF_LAYOUT_OPT_PRIVATE_DATA_SIZE   0x00000008
508 /**
509  * Select to modify the data-alignment setting
510  */
511 #define DPNI_BUF_LAYOUT_OPT_DATA_ALIGN          0x00000010
512 /**
513  * Select to modify the data-head-room setting
514  */
515 #define DPNI_BUF_LAYOUT_OPT_DATA_HEAD_ROOM      0x00000020
516 /**
517  * Select to modify the data-tail-room setting
518  */
519 #define DPNI_BUF_LAYOUT_OPT_DATA_TAIL_ROOM      0x00000040
520
521 /**
522  * struct dpni_buffer_layout - Structure representing DPNI buffer layout
523  * @options: Flags representing the suggested modifications to the buffer
524  *              layout; Use any combination of 'DPNI_BUF_LAYOUT_OPT_<X>' flags
525  * @pass_timestamp: Pass timestamp value
526  * @pass_parser_result: Pass parser results
527  * @pass_frame_status: Pass frame status
528  * @private_data_size: Size kept for private data (in bytes)
529  * @data_align: Data alignment
530  * @data_head_room: Data head room
531  * @data_tail_room: Data tail room
532  */
533 struct dpni_buffer_layout {
534         uint32_t        options;
535         int             pass_timestamp;
536         int             pass_parser_result;
537         int             pass_frame_status;
538         uint16_t        private_data_size;
539         uint16_t        data_align;
540         uint16_t        data_head_room;
541         uint16_t        data_tail_room;
542 };
543
544 /**
545  * enum dpni_queue_type - Identifies a type of queue targeted by the command
546  * @DPNI_QUEUE_RX: Rx queue
547  * @DPNI_QUEUE_TX: Tx queue
548  * @DPNI_QUEUE_TX_CONFIRM: Tx confirmation queue
549  * @DPNI_QUEUE_RX_ERR: Rx error queue
550  */enum dpni_queue_type {
551         DPNI_QUEUE_RX,
552         DPNI_QUEUE_TX,
553         DPNI_QUEUE_TX_CONFIRM,
554         DPNI_QUEUE_RX_ERR,
555 };
556
557 /**
558  * dpni_get_buffer_layout() - Retrieve buffer layout attributes.
559  * @mc_io:      Pointer to MC portal's I/O object
560  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
561  * @token:      Token of DPNI object
562  * @qtype:      Type of queue to get the layout from
563  * @layout:     Returns buffer layout attributes
564  *
565  * Return:      '0' on Success; Error code otherwise.
566  */
567 int dpni_get_buffer_layout(struct fsl_mc_io             *mc_io,
568                            uint32_t                     cmd_flags,
569                            uint16_t                     token,
570                            enum dpni_queue_type         qtype,
571                            struct dpni_buffer_layout    *layout);
572
573 /**
574  * dpni_set_buffer_layout() - Set buffer layout configuration.
575  * @mc_io:      Pointer to MC portal's I/O object
576  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
577  * @token:      Token of DPNI object
578  * @qtype:      Type of queue to set layout on
579  * @layout:     Buffer layout configuration
580  *
581  * Return:      '0' on Success; Error code otherwise.
582  *
583  * @warning     Allowed only when DPNI is disabled
584  */
585 int dpni_set_buffer_layout(struct fsl_mc_io                *mc_io,
586                            uint32_t                        cmd_flags,
587                            uint16_t                        token,
588                            enum dpni_queue_type            qtype,
589                            const struct dpni_buffer_layout *layout);
590
591 /**
592  * enum dpni_offload - Identifies a type of offload targeted by the command
593  * @DPNI_OFF_RX_L3_CSUM: Rx L3 checksum validation
594  * @DPNI_OFF_RX_L4_CSUM: Rx L4 checksum validation
595  * @DPNI_OFF_TX_L3_CSUM: Tx L3 checksum generation
596  * @DPNI_OFF_TX_L4_CSUM: Tx L4 checksum generation
597  */
598 enum dpni_offload {
599         DPNI_OFF_RX_L3_CSUM,
600         DPNI_OFF_RX_L4_CSUM,
601         DPNI_OFF_TX_L3_CSUM,
602         DPNI_OFF_TX_L4_CSUM,
603 };
604
605 /**
606  * dpni_set_offload() - Set DPNI offload configuration.
607  * @mc_io:      Pointer to MC portal's I/O object
608  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
609  * @token:      Token of DPNI object
610  * @type:       Type of DPNI offload
611  * @config:     Offload configuration.
612  *                      For checksum offloads, non-zero value enables
613  *                      the offload.
614  *
615  * Return:      '0' on Success; Error code otherwise.
616  *
617  * @warning     Allowed only when DPNI is disabled
618  */
619 int dpni_set_offload(struct fsl_mc_io *mc_io,
620                      uint32_t cmd_flags,
621                      uint16_t token,
622                      enum dpni_offload type,
623                      uint32_t config);
624
625 /**
626  * dpni_get_offload() - Get DPNI offload configuration.
627  * @mc_io:      Pointer to MC portal's I/O object
628  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
629  * @token:      Token of DPNI object
630  * @type:       Type of DPNI offload
631  * @config:     Offload configuration.
632  *                      For checksum offloads, a value of 1 indicates that the
633  *                      offload is enabled.
634  *
635  * Return:      '0' on Success; Error code otherwise.
636  *
637  * @warning     Allowed only when DPNI is disabled
638  */
639 int dpni_get_offload(struct fsl_mc_io *mc_io,
640                      uint32_t cmd_flags,
641                      uint16_t token,
642                      enum dpni_offload type,
643                      uint32_t *config);
644
645 /**
646  * dpni_get_qdid() - Get the Queuing Destination ID (QDID) that should be used
647  *                      for enqueue operations
648  * @mc_io:      Pointer to MC portal's I/O object
649  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
650  * @token:      Token of DPNI object
651  * @qtype:      Type of queue to get QDID for.  For applications lookig to
652  *              transmit traffic this should be set to DPNI_QUEUE_TX
653  * @qdid:       Returned virtual QDID value that should be used as an argument
654  *                      in all enqueue operations
655  *
656  * Return:      '0' on Success; Error code otherwise.
657  */
658 int dpni_get_qdid(struct fsl_mc_io      *mc_io,
659                   uint32_t              cmd_flags,
660                   uint16_t              token,
661                   enum dpni_queue_type  qtype,
662                   uint16_t              *qdid);
663
664 #define DPNI_STATISTICS_CNT             7
665
666 union dpni_statistics {
667         /**
668          * struct page_0 - Page_0 statistics structure
669          * @ingress_all_frames: Ingress frame count
670          * @ingress_all_bytes: Ingress byte count
671          * @ingress_multicast_frames: Ingress multicast frame count
672          * @ingress_multicast_bytes: Ingress multicast byte count
673          * @ingress_broadcast_frames: Ingress broadcast frame count
674          * @ingress_broadcast_bytes: Ingress broadcast byte count
675          */
676         struct {
677                 uint64_t ingress_all_frames;
678                 uint64_t ingress_all_bytes;
679                 uint64_t ingress_multicast_frames;
680                 uint64_t ingress_multicast_bytes;
681                 uint64_t ingress_broadcast_frames;
682                 uint64_t ingress_broadcast_bytes;
683         } page_0;
684         /**
685          * struct page_1 - Page_1 statistics structure
686          * @egress_all_frames: Egress frame count
687          * @egress_all_bytes: Egress byte count
688          * @egress_multicast_frames: Egress multicast frame count
689          * @egress_multicast_bytes: Egress multicast byte count
690          * @egress_broadcast_frames: Egress broadcast frame count
691          * @egress_broadcast_bytes: Egress broadcast byte count
692          */
693         struct {
694                 uint64_t egress_all_frames;
695                 uint64_t egress_all_bytes;
696                 uint64_t egress_multicast_frames;
697                 uint64_t egress_multicast_bytes;
698                 uint64_t egress_broadcast_frames;
699                 uint64_t egress_broadcast_bytes;
700         } page_1;
701         /**
702          * struct page_2 - Page_2 statistics structure
703          * @ingress_filtered_frames: Ingress filtered frame count
704          * @ingress_discarded_frames: Ingress discarded frame count
705          * @ingress_nobuffer_discards: Ingress discarded frame count due to
706          *                                      lack of buffers
707          * @egress_discarded_frames: Egress discarded frame count
708          * @egress_confirmed_frames: Egress confirmed frame count
709          */
710         struct {
711                 uint64_t ingress_filtered_frames;
712                 uint64_t ingress_discarded_frames;
713                 uint64_t ingress_nobuffer_discards;
714                 uint64_t egress_discarded_frames;
715                 uint64_t egress_confirmed_frames;
716         } page_2;
717         /**
718          * struct raw - raw statistics structure, used to index counters
719          */
720         struct {
721                 uint64_t counter[DPNI_STATISTICS_CNT];
722         } raw;
723 };
724
725 /**
726  * Enable auto-negotiation
727  */
728 #define DPNI_LINK_OPT_AUTONEG           0x0000000000000001ULL
729 /**
730  * Enable half-duplex mode
731  */
732 #define DPNI_LINK_OPT_HALF_DUPLEX       0x0000000000000002ULL
733 /**
734  * Enable pause frames
735  */
736 #define DPNI_LINK_OPT_PAUSE             0x0000000000000004ULL
737 /**
738  * Enable a-symmetric pause frames
739  */
740 #define DPNI_LINK_OPT_ASYM_PAUSE        0x0000000000000008ULL
741
742 /**
743  * struct - Structure representing DPNI link configuration
744  * @rate: Rate
745  * @options: Mask of available options; use 'DPNI_LINK_OPT_<X>' values
746  */
747 struct dpni_link_cfg {
748         uint32_t rate;
749         uint64_t options;
750 };
751
752 /**
753  * dpni_set_link_cfg() - set the link configuration.
754  * @mc_io:      Pointer to MC portal's I/O object
755  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
756  * @token:      Token of DPNI object
757  * @cfg:        Link configuration
758  *
759  * Return:      '0' on Success; Error code otherwise.
760  */
761 int dpni_set_link_cfg(struct fsl_mc_io                  *mc_io,
762                       uint32_t                          cmd_flags,
763                       uint16_t                          token,
764                       const struct dpni_link_cfg        *cfg);
765
766 /**
767  * struct dpni_link_state - Structure representing DPNI link state
768  * @rate: Rate
769  * @options: Mask of available options; use 'DPNI_LINK_OPT_<X>' values
770  * @up: Link state; '0' for down, '1' for up
771  */
772 struct dpni_link_state {
773         uint32_t        rate;
774         uint64_t        options;
775         int             up;
776 };
777
778 /**
779  * dpni_get_link_state() - Return the link state (either up or down)
780  * @mc_io:      Pointer to MC portal's I/O object
781  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
782  * @token:      Token of DPNI object
783  * @state:      Returned link state;
784  *
785  * Return:      '0' on Success; Error code otherwise.
786  */
787 int dpni_get_link_state(struct fsl_mc_io        *mc_io,
788                         uint32_t                cmd_flags,
789                         uint16_t                token,
790                         struct dpni_link_state  *state);
791
792 /**
793  * dpni_set_max_frame_length() - Set the maximum received frame length.
794  * @mc_io:      Pointer to MC portal's I/O object
795  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
796  * @token:      Token of DPNI object
797  * @max_frame_length:   Maximum received frame length (in
798  *                              bytes); frame is discarded if its
799  *                              length exceeds this value
800  *
801  * Return:      '0' on Success; Error code otherwise.
802  */
803 int dpni_set_max_frame_length(struct fsl_mc_io  *mc_io,
804                               uint32_t          cmd_flags,
805                               uint16_t          token,
806                               uint16_t          max_frame_length);
807
808 /**
809  * dpni_get_max_frame_length() - Get the maximum received frame length.
810  * @mc_io:      Pointer to MC portal's I/O object
811  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
812  * @token:      Token of DPNI object
813  * @max_frame_length:   Maximum received frame length (in
814  *                              bytes); frame is discarded if its
815  *                              length exceeds this value
816  *
817  * Return:      '0' on Success; Error code otherwise.
818  */
819 int dpni_get_max_frame_length(struct fsl_mc_io  *mc_io,
820                               uint32_t          cmd_flags,
821                               uint16_t          token,
822                               uint16_t          *max_frame_length);
823
824 /**
825  * dpni_set_multicast_promisc() - Enable/disable multicast promiscuous mode
826  * @mc_io:      Pointer to MC portal's I/O object
827  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
828  * @token:      Token of DPNI object
829  * @en:         Set to '1' to enable; '0' to disable
830  *
831  * Return:      '0' on Success; Error code otherwise.
832  */
833 int dpni_set_multicast_promisc(struct fsl_mc_io *mc_io,
834                                uint32_t         cmd_flags,
835                                uint16_t         token,
836                                int              en);
837
838 /**
839  * dpni_get_multicast_promisc() - Get multicast promiscuous mode
840  * @mc_io:      Pointer to MC portal's I/O object
841  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
842  * @token:      Token of DPNI object
843  * @en:         Returns '1' if enabled; '0' otherwise
844  *
845  * Return:      '0' on Success; Error code otherwise.
846  */
847 int dpni_get_multicast_promisc(struct fsl_mc_io *mc_io,
848                                uint32_t         cmd_flags,
849                                uint16_t         token,
850                                int              *en);
851
852 /**
853  * dpni_set_unicast_promisc() - Enable/disable unicast promiscuous mode
854  * @mc_io:      Pointer to MC portal's I/O object
855  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
856  * @token:      Token of DPNI object
857  * @en:         Set to '1' to enable; '0' to disable
858  *
859  * Return:      '0' on Success; Error code otherwise.
860  */
861 int dpni_set_unicast_promisc(struct fsl_mc_io   *mc_io,
862                              uint32_t           cmd_flags,
863                              uint16_t           token,
864                              int                en);
865
866 /**
867  * dpni_get_unicast_promisc() - Get unicast promiscuous mode
868  * @mc_io:      Pointer to MC portal's I/O object
869  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
870  * @token:      Token of DPNI object
871  * @en:         Returns '1' if enabled; '0' otherwise
872  *
873  * Return:      '0' on Success; Error code otherwise.
874  */
875 int dpni_get_unicast_promisc(struct fsl_mc_io   *mc_io,
876                              uint32_t           cmd_flags,
877                              uint16_t           token,
878                              int                *en);
879
880 /**
881  * dpni_set_primary_mac_addr() - Set the primary MAC address
882  * @mc_io:      Pointer to MC portal's I/O object
883  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
884  * @token:      Token of DPNI object
885  * @mac_addr:   MAC address to set as primary address
886  *
887  * Return:      '0' on Success; Error code otherwise.
888  */
889 int dpni_set_primary_mac_addr(struct fsl_mc_io  *mc_io,
890                               uint32_t          cmd_flags,
891                               uint16_t          token,
892                               const uint8_t     mac_addr[6]);
893
894 /**
895  * dpni_get_primary_mac_addr() - Get the primary MAC address
896  * @mc_io:      Pointer to MC portal's I/O object
897  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
898  * @token:      Token of DPNI object
899  * @mac_addr:   Returned MAC address
900  *
901  * Return:      '0' on Success; Error code otherwise.
902  */
903 int dpni_get_primary_mac_addr(struct fsl_mc_io  *mc_io,
904                               uint32_t          cmd_flags,
905                               uint16_t          token,
906                               uint8_t           mac_addr[6]);
907
908 /**
909  * dpni_add_mac_addr() - Add MAC address filter
910  * @mc_io:      Pointer to MC portal's I/O object
911  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
912  * @token:      Token of DPNI object
913  * @mac_addr:   MAC address to add
914  *
915  * Return:      '0' on Success; Error code otherwise.
916  */
917 int dpni_add_mac_addr(struct fsl_mc_io  *mc_io,
918                       uint32_t          cmd_flags,
919                       uint16_t          token,
920                       const uint8_t     mac_addr[6]);
921
922 /**
923  * dpni_remove_mac_addr() - Remove MAC address filter
924  * @mc_io:      Pointer to MC portal's I/O object
925  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
926  * @token:      Token of DPNI object
927  * @mac_addr:   MAC address to remove
928  *
929  * Return:      '0' on Success; Error code otherwise.
930  */
931 int dpni_remove_mac_addr(struct fsl_mc_io       *mc_io,
932                          uint32_t               cmd_flags,
933                          uint16_t               token,
934                          const uint8_t          mac_addr[6]);
935
936 /**
937  * dpni_clear_mac_filters() - Clear all unicast and/or multicast MAC filters
938  * @mc_io:      Pointer to MC portal's I/O object
939  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
940  * @token:      Token of DPNI object
941  * @unicast:    Set to '1' to clear unicast addresses
942  * @multicast:  Set to '1' to clear multicast addresses
943  *
944  * The primary MAC address is not cleared by this operation.
945  *
946  * Return:      '0' on Success; Error code otherwise.
947  */
948 int dpni_clear_mac_filters(struct fsl_mc_io     *mc_io,
949                            uint32_t             cmd_flags,
950                            uint16_t             token,
951                            int                  unicast,
952                            int                  multicast);
953
954 /**
955  * dpni_get_port_mac_addr() - Retrieve MAC address associated to the physical
956  *              port the DPNI is attached to
957  * @mc_io:      Pointer to MC portal's I/O object
958  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
959  * @token:      Token of DPNI object
960  * @mac_addr:   MAC address of the physical port, if any, otherwise 0
961  *
962  * The primary MAC address is not modified by this operation.
963  *
964  * Return:      '0' on Success; Error code otherwise.
965  */
966 int dpni_get_port_mac_addr(struct fsl_mc_io     *mc_io,
967                            uint32_t             cmd_flags,
968                            uint16_t             token,
969                            uint8_t              mac_addr[6]);
970
971 /**
972  * dpni_enable_vlan_filter() - Enable/disable VLAN filtering mode
973  * @mc_io:      Pointer to MC portal's I/O object
974  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
975  * @token:      Token of DPNI object
976  * @en:         Set to '1' to enable; '0' to disable
977  *
978  * Return:      '0' on Success; Error code otherwise.
979  */
980 int dpni_enable_vlan_filter(struct fsl_mc_io    *mc_io,
981                             uint32_t            cmd_flags,
982                             uint16_t            token,
983                             int                 en);
984
985 /**
986  * dpni_add_vlan_id() - Add VLAN ID filter
987  * @mc_io:      Pointer to MC portal's I/O object
988  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
989  * @token:      Token of DPNI object
990  * @vlan_id:    VLAN ID to add
991  *
992  * Return:      '0' on Success; Error code otherwise.
993  */
994 int dpni_add_vlan_id(struct fsl_mc_io   *mc_io,
995                      uint32_t           cmd_flags,
996                      uint16_t           token,
997                      uint16_t           vlan_id);
998
999 /**
1000  * dpni_remove_vlan_id() - Remove VLAN ID filter
1001  * @mc_io:      Pointer to MC portal's I/O object
1002  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
1003  * @token:      Token of DPNI object
1004  * @vlan_id:    VLAN ID to remove
1005  *
1006  * Return:      '0' on Success; Error code otherwise.
1007  */
1008 int dpni_remove_vlan_id(struct fsl_mc_io        *mc_io,
1009                         uint32_t                cmd_flags,
1010                         uint16_t                token,
1011                         uint16_t                vlan_id);
1012
1013 /**
1014  * dpni_clear_vlan_filters() - Clear all VLAN filters
1015  * @mc_io:      Pointer to MC portal's I/O object
1016  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
1017  * @token:      Token of DPNI object
1018  *
1019  * Return:      '0' on Success; Error code otherwise.
1020  */
1021 int dpni_clear_vlan_filters(struct fsl_mc_io    *mc_io,
1022                             uint32_t            cmd_flags,
1023                             uint16_t            token);
1024
1025 /**
1026  * enum dpni_dist_mode - DPNI distribution mode
1027  * @DPNI_DIST_MODE_NONE: No distribution
1028  * @DPNI_DIST_MODE_HASH: Use hash distribution; only relevant if
1029  *              the 'DPNI_OPT_DIST_HASH' option was set at DPNI creation
1030  * @DPNI_DIST_MODE_FS:  Use explicit flow steering; only relevant if
1031  *       the 'DPNI_OPT_DIST_FS' option was set at DPNI creation
1032  */
1033 enum dpni_dist_mode {
1034         DPNI_DIST_MODE_NONE = 0,
1035         DPNI_DIST_MODE_HASH = 1,
1036         DPNI_DIST_MODE_FS = 2
1037 };
1038
1039 /**
1040  * enum dpni_fs_miss_action -   DPNI Flow Steering miss action
1041  * @DPNI_FS_MISS_DROP: In case of no-match, drop the frame
1042  * @DPNI_FS_MISS_EXPLICIT_FLOWID: In case of no-match, use explicit flow-id
1043  * @DPNI_FS_MISS_HASH: In case of no-match, distribute using hash
1044  */
1045 enum dpni_fs_miss_action {
1046         DPNI_FS_MISS_DROP = 0,
1047         DPNI_FS_MISS_EXPLICIT_FLOWID = 1,
1048         DPNI_FS_MISS_HASH = 2
1049 };
1050
1051 /**
1052  * struct dpni_fs_tbl_cfg - Flow Steering table configuration
1053  * @miss_action: Miss action selection
1054  * @default_flow_id: Used when 'miss_action = DPNI_FS_MISS_EXPLICIT_FLOWID'
1055  */
1056 struct dpni_fs_tbl_cfg {
1057         enum dpni_fs_miss_action        miss_action;
1058         uint16_t                        default_flow_id;
1059 };
1060
1061 /**
1062  * dpni_prepare_key_cfg() - function prepare extract parameters
1063  * @cfg: defining a full Key Generation profile (rule)
1064  * @key_cfg_buf: Zeroed 256 bytes of memory before mapping it to DMA
1065  *
1066  * This function has to be called before the following functions:
1067  *      - dpni_set_rx_tc_dist()
1068  *      - dpni_set_qos_table()
1069  */
1070 int dpni_prepare_key_cfg(const struct dpkg_profile_cfg  *cfg,
1071                          uint8_t                        *key_cfg_buf);
1072
1073 /**
1074  * struct dpni_rx_tc_dist_cfg - Rx traffic class distribution configuration
1075  * @dist_size: Set the distribution size;
1076  *      supported values: 1,2,3,4,6,7,8,12,14,16,24,28,32,48,56,64,96,
1077  *      112,128,192,224,256,384,448,512,768,896,1024
1078  * @dist_mode: Distribution mode
1079  * @key_cfg_iova: I/O virtual address of 256 bytes DMA-able memory filled with
1080  *              the extractions to be used for the distribution key by calling
1081  *              dpni_prepare_key_cfg() relevant only when
1082  *              'dist_mode != DPNI_DIST_MODE_NONE', otherwise it can be '0'
1083  * @fs_cfg: Flow Steering table configuration; only relevant if
1084  *              'dist_mode = DPNI_DIST_MODE_FS'
1085  */
1086 struct dpni_rx_tc_dist_cfg {
1087         uint16_t                dist_size;
1088         enum dpni_dist_mode     dist_mode;
1089         uint64_t                key_cfg_iova;
1090         struct dpni_fs_tbl_cfg  fs_cfg;
1091 };
1092
1093 /**
1094  * dpni_set_rx_tc_dist() - Set Rx traffic class distribution configuration
1095  * @mc_io:      Pointer to MC portal's I/O object
1096  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
1097  * @token:      Token of DPNI object
1098  * @tc_id:      Traffic class selection (0-7)
1099  * @cfg:        Traffic class distribution configuration
1100  *
1101  * warning: if 'dist_mode != DPNI_DIST_MODE_NONE', call dpni_prepare_key_cfg()
1102  *                      first to prepare the key_cfg_iova parameter
1103  *
1104  * Return:      '0' on Success; error code otherwise.
1105  */
1106 int dpni_set_rx_tc_dist(struct fsl_mc_io                        *mc_io,
1107                         uint32_t                                cmd_flags,
1108                         uint16_t                                token,
1109                         uint8_t                                 tc_id,
1110                         const struct dpni_rx_tc_dist_cfg        *cfg);
1111 /**
1112  * enum dpni_congestion_unit - DPNI congestion units
1113  * @DPNI_CONGESTION_UNIT_BYTES: bytes units
1114  * @DPNI_CONGESTION_UNIT_FRAMES: frames units
1115  */
1116 enum dpni_congestion_unit {
1117         DPNI_CONGESTION_UNIT_BYTES = 0,
1118         DPNI_CONGESTION_UNIT_FRAMES
1119 };
1120
1121
1122 /**
1123  * enum dpni_dest - DPNI destination types
1124  * @DPNI_DEST_NONE: Unassigned destination; The queue is set in parked mode and
1125  *              does not generate FQDAN notifications; user is expected to
1126  *              dequeue from the queue based on polling or other user-defined
1127  *              method
1128  * @DPNI_DEST_DPIO: The queue is set in schedule mode and generates FQDAN
1129  *              notifications to the specified DPIO; user is expected to dequeue
1130  *              from the queue only after notification is received
1131  * @DPNI_DEST_DPCON: The queue is set in schedule mode and does not generate
1132  *              FQDAN notifications, but is connected to the specified DPCON
1133  *              object; user is expected to dequeue from the DPCON channel
1134  */
1135 enum dpni_dest {
1136         DPNI_DEST_NONE = 0,
1137         DPNI_DEST_DPIO = 1,
1138         DPNI_DEST_DPCON = 2
1139 };
1140
1141 /**
1142  * struct dpni_dest_cfg - Structure representing DPNI destination parameters
1143  * @dest_type: Destination type
1144  * @dest_id: Either DPIO ID or DPCON ID, depending on the destination type
1145  * @priority: Priority selection within the DPIO or DPCON channel; valid values
1146  *              are 0-1 or 0-7, depending on the number of priorities in that
1147  *              channel; not relevant for 'DPNI_DEST_NONE' option
1148  */
1149 struct dpni_dest_cfg {
1150         enum dpni_dest  dest_type;
1151         int             dest_id;
1152         uint8_t         priority;
1153 };
1154
1155 /* DPNI congestion options */
1156
1157 /**
1158  * CSCN message is written to message_iova once entering a
1159  * congestion state (see 'threshold_entry')
1160  */
1161 #define DPNI_CONG_OPT_WRITE_MEM_ON_ENTER        0x00000001
1162 /**
1163  * CSCN message is written to message_iova once exiting a
1164  * congestion state (see 'threshold_exit')
1165  */
1166 #define DPNI_CONG_OPT_WRITE_MEM_ON_EXIT         0x00000002
1167 /**
1168  * CSCN write will attempt to allocate into a cache (coherent write);
1169  * valid only if 'DPNI_CONG_OPT_WRITE_MEM_<X>' is selected
1170  */
1171 #define DPNI_CONG_OPT_COHERENT_WRITE            0x00000004
1172 /**
1173  * if 'dest_cfg.dest_type != DPNI_DEST_NONE' CSCN message is sent to
1174  * DPIO/DPCON's WQ channel once entering a congestion state
1175  * (see 'threshold_entry')
1176  */
1177 #define DPNI_CONG_OPT_NOTIFY_DEST_ON_ENTER      0x00000008
1178 /**
1179  * if 'dest_cfg.dest_type != DPNI_DEST_NONE' CSCN message is sent to
1180  * DPIO/DPCON's WQ channel once exiting a congestion state
1181  * (see 'threshold_exit')
1182  */
1183 #define DPNI_CONG_OPT_NOTIFY_DEST_ON_EXIT       0x00000010
1184 /**
1185  * if 'dest_cfg.dest_type != DPNI_DEST_NONE' when the CSCN is written to the
1186  * sw-portal's DQRR, the DQRI interrupt is asserted immediately (if enabled)
1187  */
1188 #define DPNI_CONG_OPT_INTR_COALESCING_DISABLED  0x00000020
1189
1190 /**
1191  * struct dpni_congestion_notification_cfg - congestion notification
1192  *              configuration
1193  * @units: units type
1194  * @threshold_entry: above this threshold we enter a congestion state.
1195  *      set it to '0' to disable it
1196  * @threshold_exit: below this threshold we exit the congestion state.
1197  * @message_ctx: The context that will be part of the CSCN message
1198  * @message_iova: I/O virtual address (must be in DMA-able memory),
1199  *      must be 16B aligned; valid only if 'DPNI_CONG_OPT_WRITE_MEM_<X>' is
1200  *      contained in 'options'
1201  * @dest_cfg: CSCN can be send to either DPIO or DPCON WQ channel
1202  * @notification_mode: Mask of available options; use 'DPNI_CONG_OPT_<X>' values
1203  */
1204
1205 struct dpni_congestion_notification_cfg {
1206         enum dpni_congestion_unit       units;
1207         uint32_t                        threshold_entry;
1208         uint32_t                        threshold_exit;
1209         uint64_t                        message_ctx;
1210         uint64_t                        message_iova;
1211         struct dpni_dest_cfg            dest_cfg;
1212         uint16_t                        notification_mode;
1213 };
1214
1215 /**
1216  * dpni_set_congestion_notification() - Set traffic class congestion
1217  *      notification configuration
1218  * @mc_io:      Pointer to MC portal's I/O object
1219  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
1220  * @token:      Token of DPNI object
1221  * @qtype:      Type of queue - Rx, Tx and Tx confirm types are supported
1222  * @tc_id:      Traffic class selection (0-7)
1223  * @cfg:        congestion notification configuration
1224  *
1225  * Return:      '0' on Success; error code otherwise.
1226  */
1227 int dpni_set_congestion_notification(
1228                         struct fsl_mc_io                *mc_io,
1229                         uint32_t                        cmd_flags,
1230                         uint16_t                        token,
1231                         enum dpni_queue_type            qtype,
1232                         uint8_t                         tc_id,
1233                         const struct dpni_congestion_notification_cfg *cfg);
1234
1235 /**
1236  * dpni_get_congestion_notification() - Get traffic class congestion
1237  *      notification configuration
1238  * @mc_io:      Pointer to MC portal's I/O object
1239  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
1240  * @token:      Token of DPNI object
1241  * @qtype:      Type of queue - Rx, Tx and Tx confirm types are supported
1242  * @tc_id:      Traffic class selection (0-7)
1243  * @cfg:        congestion notification configuration
1244  *
1245  * Return:      '0' on Success; error code otherwise.
1246  */
1247 int dpni_get_congestion_notification(struct fsl_mc_io           *mc_io,
1248                                      uint32_t                   cmd_flags,
1249                                      uint16_t                   token,
1250                                      enum dpni_queue_type       qtype,
1251                                      uint8_t                    tc_id,
1252                                 struct dpni_congestion_notification_cfg *cfg);
1253
1254
1255 /**
1256  * struct dpni_queue - Queue structure
1257  * @user_context:       User data, presented to the user along with any frames
1258  *                      from this queue. Not relevant for Tx queues.
1259  */
1260 struct dpni_queue {
1261         /**
1262          * struct destination - Destination structure
1263          * @id: ID of the destination, only relevant if DEST_TYPE is > 0.
1264          *                      Identifies either a DPIO or a DPCON object.
1265          *                      Not relevant for Tx queues.
1266          * @type:       May be one of the following:
1267          *                      0 - No destination, queue can be manually
1268          *                              queried, but will not push traffic or
1269          *                              notifications to a DPIO;
1270          *                      1 - The destination is a DPIO. When traffic
1271          *                              becomes available in the queue a FQDAN
1272          *                              (FQ data available notification) will be
1273          *                              generated to selected DPIO;
1274          *                      2 - The destination is a DPCON. The queue is
1275          *                              associated with a DPCON object for the
1276          *                              purpose of scheduling between multiple
1277          *                              queues. The DPCON may be independently
1278          *                              configured to generate notifications.
1279          *                              Not relevant for Tx queues.
1280          * @hold_active: Hold active, maintains a queue scheduled for longer
1281          *              in a DPIO during dequeue to reduce spread of traffic.
1282          *              Only relevant if queues are
1283          *              not affined to a single DPIO.
1284          */
1285         struct {
1286                 uint16_t id;
1287                 enum dpni_dest type;
1288                 char hold_active;
1289                 uint8_t priority;
1290         } destination;
1291         uint64_t user_context;
1292         /**
1293          * struct flc - FD FLow Context structure
1294          * @value:              FLC value to set
1295          * @stash_control:      Boolean, indicates whether the 6 lowest
1296          *                      significant bits are used for stash control.
1297          */
1298         struct {
1299                 uint64_t value;
1300                 char stash_control;
1301         } flc;
1302 };
1303
1304 /**
1305  * struct dpni_queue_id - Queue identification, used for enqueue commands
1306  *                              or queue control
1307  * @fqid:       FQID used for enqueueing to and/or configuration of this
1308  *                      specific FQ
1309  * @qdbin:      Queueing bin, used to enqueue using QDID, DQBIN, QPRI.
1310  *                      Only relevant for Tx queues.
1311  */
1312 struct dpni_queue_id {
1313         uint32_t fqid;
1314         uint16_t qdbin;
1315 };
1316
1317 /**
1318  * enum dpni_confirmation_mode - Defines DPNI options supported for Tx
1319  * confirmation
1320  * @DPNI_CONF_AFFINE: For each Tx queue set associated with a sender there is
1321  * an affine Tx Confirmation queue
1322  * @DPNI_CONF_SINGLE: All Tx queues are associated with a single Tx
1323  * confirmation queue
1324  * @DPNI_CONF_DISABLE: Tx frames are not confirmed.  This must be associated
1325  * with proper FD set-up to have buffers release to a Buffer Pool, otherwise
1326  * buffers will be leaked
1327  */
1328 enum dpni_confirmation_mode {
1329         DPNI_CONF_AFFINE,
1330         DPNI_CONF_SINGLE,
1331         DPNI_CONF_DISABLE,
1332 };
1333
1334 /**
1335  * dpni_set_tx_confirmation_mode() - Tx confirmation mode
1336  * @mc_io:      Pointer to MC portal's I/O object
1337  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
1338  * @token:      Token of DPNI object
1339  * @mode:       Tx confirmation mode
1340  *
1341  * This function is useful only when 'DPNI_OPT_TX_CONF_DISABLED' is not
1342  * selected at DPNI creation.
1343  * Calling this function with 'mode' set to DPNI_CONF_DISABLE disables all
1344  * transmit confirmation (including the private confirmation queues), regardless
1345  * of previous settings; Note that in this case, Tx error frames are still
1346  * enqueued to the general transmit errors queue.
1347  * Calling this function with 'mode' set to DPNI_CONF_SINGLE switches all
1348  * Tx confirmations to a shared Tx conf queue.  The ID of the queue when
1349  * calling dpni_set/get_queue is -1.
1350  * Tx confirmation mode can only be changed while the DPNI is disabled.
1351  * Executing this command while the DPNI is enabled will return an error.
1352  *
1353  * Return:      '0' on Success; Error code otherwise.
1354  */
1355 int dpni_set_tx_confirmation_mode(struct fsl_mc_io              *mc_io,
1356                                   uint32_t                      cmd_flags,
1357                                   uint16_t                      token,
1358                                   enum dpni_confirmation_mode   mode);
1359
1360 /**
1361  * dpni_get_api_version() - Get Data Path Network Interface API version
1362  * @mc_io:  Pointer to MC portal's I/O object
1363  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
1364  * @major_ver:  Major version of data path network interface API
1365  * @minor_ver:  Minor version of data path network interface API
1366  *
1367  * Return:  '0' on Success; Error code otherwise.
1368  */
1369 int dpni_get_api_version(struct fsl_mc_io *mc_io,
1370                          uint32_t cmd_flags,
1371                          uint16_t *major_ver,
1372                          uint16_t *minor_ver);
1373
1374 /**
1375  * Set User Context
1376  */
1377 #define DPNI_QUEUE_OPT_USER_CTX         0x00000001
1378
1379 /**
1380  * Set queue destination configuration
1381  */
1382 #define DPNI_QUEUE_OPT_DEST             0x00000002
1383
1384 /**
1385  * Set FD[FLC] configuration for traffic on this queue.  Note that FLC values
1386  * set with dpni_add_fs_entry, if any, take precedence over values per queue.
1387  */
1388 #define DPNI_QUEUE_OPT_FLC              0x00000004
1389
1390 /**
1391  * Set the queue to hold active mode.  This prevents the queue from being
1392  * rescheduled between DPIOs while it carries traffic and is active on one
1393  * DPNI.  Can help reduce reordering when servicing one queue on multiple
1394  * CPUs, but the queue is also less likely to push data to multiple CPUs
1395  * especially when congested.
1396  */
1397 #define DPNI_QUEUE_OPT_HOLD_ACTIVE      0x00000008
1398
1399 /**
1400  * dpni_set_queue() - Set queue parameters
1401  * @mc_io:              Pointer to MC portal's I/O object
1402  * @cmd_flags:          Command flags; one or more of 'MC_CMD_FLAG_'
1403  * @token:              Token of DPNI object
1404  * @qtype:              Type of queue - all queue types are supported, although
1405  *                              the command is ignored for Tx
1406  * @tc:                 Traffic class, in range 0 to NUM_TCS - 1
1407  * @index:              Selects the specific queue out of the set
1408  *                              allocated for the same TC.Value must be in
1409  *                              range 0 to NUM_QUEUES - 1
1410  * @options:            A combination of DPNI_QUEUE_OPT_ values that control
1411  *                              what configuration options are set on the queue
1412  * @queue:              Queue configuration structure
1413  *
1414  * Return:  '0' on Success; Error code otherwise.
1415  */
1416 int dpni_set_queue(struct fsl_mc_io *mc_io,
1417                    uint32_t cmd_flags,
1418                    uint16_t token,
1419                    enum dpni_queue_type qtype,
1420                    uint8_t tc,
1421                    uint8_t index,
1422                    uint8_t options,
1423                    const struct dpni_queue *queue);
1424
1425 /**
1426  * dpni_get_queue() - Get queue parameters
1427  * @mc_io:              Pointer to MC portal's I/O object
1428  * @cmd_flags:          Command flags; one or more of 'MC_CMD_FLAG_'
1429  * @token:              Token of DPNI object
1430  * @qtype:              Type of queue - all queue types are supported
1431  * @tc:                 Traffic class, in range 0 to NUM_TCS - 1
1432  * @index:              Selects the specific queue out of the set allocated
1433  *                              for the same TC. Value must be in range 0 to
1434  *                              NUM_QUEUES - 1
1435  * @queue:              Queue configuration structure
1436  * @qid:                Queue identification
1437  *
1438  * This function returns current queue configuration which can be changed by
1439  * calling dpni_set_queue, and queue identification information.
1440  * Returned qid.fqid and/or qid.qdbin values can be used to:
1441  * - enqueue traffic for Tx queues,
1442  * - perform volatile dequeue for Rx and, if applicable, Tx confirmation
1443  *   clean-up,
1444  * - retrieve queue state.
1445  *
1446  * All these operations are supported through the DPIO run-time API.
1447  *
1448  * Return:  '0' on Success; Error code otherwise.
1449  */
1450 int dpni_get_queue(struct fsl_mc_io *mc_io,
1451                    uint32_t cmd_flags,
1452                    uint16_t token,
1453                    enum dpni_queue_type qtype,
1454                    uint8_t tc,
1455                    uint8_t index,
1456                    struct dpni_queue *queue,
1457                    struct dpni_queue_id *qid);
1458
1459 /**
1460  * dpni_get_statistics() - Get DPNI statistics
1461  * @mc_io:              Pointer to MC portal's I/O object
1462  * @cmd_flags:          Command flags; one or more of 'MC_CMD_FLAG_'
1463  * @token:              Token of DPNI object
1464  * @page:               Selects the statistics page to retrieve, see
1465  *                              DPNI_GET_STATISTICS output.
1466  *                              Pages are numbered 0 to 2.
1467  * @stat:               Structure containing the statistics
1468  *
1469  * Return:  '0' on Success; Error code otherwise.
1470  */
1471 int dpni_get_statistics(struct fsl_mc_io *mc_io,
1472                         uint32_t cmd_flags,
1473                         uint16_t token,
1474                         uint8_t page,
1475                         union dpni_statistics *stat);
1476
1477 /**
1478  * dpni_reset_statistics() - Clears DPNI statistics
1479  * @mc_io:              Pointer to MC portal's I/O object
1480  * @cmd_flags:          Command flags; one or more of 'MC_CMD_FLAG_'
1481  * @token:              Token of DPNI object
1482  *
1483  * Return:  '0' on Success; Error code otherwise.
1484  */
1485 int dpni_reset_statistics(struct fsl_mc_io *mc_io,
1486                           uint32_t cmd_flags,
1487                           uint16_t token);
1488
1489 /**
1490  * enum dpni_congestion_point - Structure representing congestion point
1491  * @DPNI_CP_QUEUE:      Set taildrop per queue, identified by QUEUE_TYPE, TC and
1492  *                              QUEUE_INDEX
1493  * @DPNI_CP_GROUP:      Set taildrop per queue group. Depending on options used
1494  *                              to define the DPNI this can be either per
1495  *                              TC (default) or per interface
1496  *                              (DPNI_OPT_SHARED_CONGESTION set at DPNI create).
1497  *                              QUEUE_INDEX is ignored if this type is used.
1498  */
1499 enum dpni_congestion_point {
1500         DPNI_CP_QUEUE,
1501         DPNI_CP_GROUP,
1502 };
1503
1504 /**
1505  * struct dpni_taildrop - Structure representing the taildrop
1506  * @enable:     Indicates whether the taildrop is active or not.
1507  * @units:      Indicates the unit of THRESHOLD. Queue taildrop only
1508  *                      supports byte units, this field is ignored and
1509  *                      assumed = 0 if CONGESTION_POINT is 0.
1510  * @threshold:  Threshold value, in units identified by UNITS field. Value 0
1511  *                      cannot be used as a valid taildrop threshold,
1512  *                      THRESHOLD must be > 0 if the taildrop is
1513  *                      enabled.
1514  */
1515 struct dpni_taildrop {
1516         char enable;
1517         enum dpni_congestion_unit units;
1518         uint32_t threshold;
1519 };
1520
1521 /**
1522  * dpni_set_taildrop() - Set taildrop per queue or TC
1523  *
1524  * Setting a per-TC taildrop (cg_point = DPNI_CP_GROUP) will reset any current
1525  * congestion notification or early drop (WRED) configuration previously applied
1526  * to the same TC.
1527  *
1528  * @mc_io:      Pointer to MC portal's I/O object
1529  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
1530  * @token:      Token of DPNI object
1531  * @cg_point:   Congestion point.  DPNI_CP_QUEUE is only supported in
1532  *              combination with DPNI_QUEUE_RX.
1533  * @q_type:     Queue type, can be DPNI_QUEUE_RX or DPNI_QUEUE_TX.
1534  * @tc:         Traffic class to apply this taildrop to
1535  * @q_index:    Index of the queue if the DPNI supports multiple queues for
1536  *                      traffic distribution.
1537  *                      Ignored if CONGESTION_POINT is not DPNI_CP_QUEUE.
1538  * @taildrop:   Taildrop structure
1539  *
1540  * Return:  '0' on Success; Error code otherwise.
1541  */
1542 int dpni_set_taildrop(struct fsl_mc_io *mc_io,
1543                       uint32_t cmd_flags,
1544                       uint16_t token,
1545                       enum dpni_congestion_point cg_point,
1546                       enum dpni_queue_type q_type,
1547                       uint8_t tc,
1548                       uint8_t q_index,
1549                       struct dpni_taildrop *taildrop);
1550
1551 /**
1552  * dpni_get_taildrop() - Get taildrop information
1553  * @mc_io:      Pointer to MC portal's I/O object
1554  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
1555  * @token:      Token of DPNI object
1556  * @cg_point:   Congestion point
1557  * @q_type:
1558  * @tc:         Traffic class to apply this taildrop to
1559  * @q_index:    Index of the queue if the DPNI supports multiple queues for
1560  *                      traffic distribution. Ignored if CONGESTION_POINT
1561  *                      is not 0.
1562  * @taildrop:   Taildrop structure
1563  *
1564  * Return:  '0' on Success; Error code otherwise.
1565  */
1566 int dpni_get_taildrop(struct fsl_mc_io *mc_io,
1567                       uint32_t cmd_flags,
1568                       uint16_t token,
1569                       enum dpni_congestion_point cg_point,
1570                       enum dpni_queue_type q_type,
1571                       uint8_t tc,
1572                       uint8_t q_index,
1573                       struct dpni_taildrop *taildrop);
1574 #endif /* __FSL_DPNI_H */