092d3b30ba4d6178d3f5510253a1e8831ef960c9
[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  * struct dpni_attr - Structure representing DPNI attributes
251  * @options: Any combination of the following options:
252  *              DPNI_OPT_TX_FRM_RELEASE
253  *              DPNI_OPT_NO_MAC_FILTER
254  *              DPNI_OPT_HAS_POLICING
255  *              DPNI_OPT_SHARED_CONGESTION
256  *              DPNI_OPT_HAS_KEY_MASKING
257  *              DPNI_OPT_NO_FS
258  * @num_queues: Number of Tx and Rx queues used for traffic distribution.
259  * @num_rx_tcs: Number of RX traffic classes (TCs), reserved for the DPNI.
260  * @num_tx_tcs: Number of TX traffic classes (TCs), reserved for the DPNI.
261  * @mac_filter_entries: Number of entries in the MAC address filtering
262  *              table.
263  * @vlan_filter_entries: Number of entries in the VLAN address filtering
264  *              table.
265  * @qos_entries: Number of entries in the QoS classification table.
266  * @fs_entries: Number of entries in the flow steering table.
267  * @qos_key_size: Size, in bytes, of the QoS look-up key. Defining a key larger
268  *                      than this when adding QoS entries will result
269  *                      in an error.
270  * @fs_key_size: Size, in bytes, of the flow steering look-up key. Defining a
271  *                      key larger than this when composing the hash + FS key
272  *                      will result in an error.
273  * @wriop_version: Version of WRIOP HW block.
274  *                      The 3 version values are stored on 6, 5, 5 bits
275  *                      respectively.
276  *                      Values returned:
277  *                      - 0x400 - WRIOP version 1.0.0, used on LS2080 and
278  *                      variants,
279  *                      - 0x421 - WRIOP version 1.1.1, used on LS2088 and
280  *                      variants,
281  *                      - 0x422 - WRIOP version 1.1.2, used on LS1088 and
282  *                      variants.
283  */
284 struct dpni_attr {
285         uint32_t options;
286         uint8_t  num_queues;
287         uint8_t  num_rx_tcs;
288         uint8_t  num_tx_tcs;
289         uint8_t  mac_filter_entries;
290         uint8_t  vlan_filter_entries;
291         uint8_t  qos_entries;
292         uint16_t fs_entries;
293         uint8_t  qos_key_size;
294         uint8_t  fs_key_size;
295         uint16_t wriop_version;
296 };
297
298 int dpni_get_attributes(struct fsl_mc_io *mc_io,
299                         uint32_t cmd_flags,
300                         uint16_t token,
301                         struct dpni_attr *attr);
302
303 /**
304  * DPNI errors
305  */
306
307 /**
308  * Extract out of frame header error
309  */
310 #define DPNI_ERROR_EOFHE        0x00020000
311 /**
312  * Frame length error
313  */
314 #define DPNI_ERROR_FLE          0x00002000
315 /**
316  * Frame physical error
317  */
318 #define DPNI_ERROR_FPE          0x00001000
319 /**
320  * Parsing header error
321  */
322 #define DPNI_ERROR_PHE          0x00000020
323 /**
324  * Parser L3 checksum error
325  */
326 #define DPNI_ERROR_L3CE         0x00000004
327 /**
328  * Parser L3 checksum error
329  */
330 #define DPNI_ERROR_L4CE         0x00000001
331
332 /**
333  * enum dpni_error_action - Defines DPNI behavior for errors
334  * @DPNI_ERROR_ACTION_DISCARD: Discard the frame
335  * @DPNI_ERROR_ACTION_CONTINUE: Continue with the normal flow
336  * @DPNI_ERROR_ACTION_SEND_TO_ERROR_QUEUE: Send the frame to the error queue
337  */
338 enum dpni_error_action {
339         DPNI_ERROR_ACTION_DISCARD = 0,
340         DPNI_ERROR_ACTION_CONTINUE = 1,
341         DPNI_ERROR_ACTION_SEND_TO_ERROR_QUEUE = 2
342 };
343
344 /**
345  * struct dpni_error_cfg - Structure representing DPNI errors treatment
346  * @errors:                     Errors mask; use 'DPNI_ERROR__<X>
347  * @error_action:               The desired action for the errors mask
348  * @set_frame_annotation:       Set to '1' to mark the errors in frame
349  *                              annotation status (FAS); relevant only
350  *                              for the non-discard action
351  */
352 struct dpni_error_cfg {
353         uint32_t errors;
354         enum dpni_error_action error_action;
355         int set_frame_annotation;
356 };
357
358 int dpni_set_errors_behavior(struct fsl_mc_io *mc_io,
359                              uint32_t cmd_flags,
360                              uint16_t token,
361                              struct dpni_error_cfg *cfg);
362
363 /**
364  * DPNI buffer layout modification options
365  */
366
367 /**
368  * Select to modify the time-stamp setting
369  */
370 #define DPNI_BUF_LAYOUT_OPT_TIMESTAMP           0x00000001
371 /**
372  * Select to modify the parser-result setting; not applicable for Tx
373  */
374 #define DPNI_BUF_LAYOUT_OPT_PARSER_RESULT       0x00000002
375 /**
376  * Select to modify the frame-status setting
377  */
378 #define DPNI_BUF_LAYOUT_OPT_FRAME_STATUS        0x00000004
379 /**
380  * Select to modify the private-data-size setting
381  */
382 #define DPNI_BUF_LAYOUT_OPT_PRIVATE_DATA_SIZE   0x00000008
383 /**
384  * Select to modify the data-alignment setting
385  */
386 #define DPNI_BUF_LAYOUT_OPT_DATA_ALIGN          0x00000010
387 /**
388  * Select to modify the data-head-room setting
389  */
390 #define DPNI_BUF_LAYOUT_OPT_DATA_HEAD_ROOM      0x00000020
391 /**
392  * Select to modify the data-tail-room setting
393  */
394 #define DPNI_BUF_LAYOUT_OPT_DATA_TAIL_ROOM      0x00000040
395
396 /**
397  * struct dpni_buffer_layout - Structure representing DPNI buffer layout
398  * @options:            Flags representing the suggested modifications to the
399  *                      buffer layout;
400  *                      Use any combination of 'DPNI_BUF_LAYOUT_OPT_<X>' flags
401  * @pass_timestamp:     Pass timestamp value
402  * @pass_parser_result: Pass parser results
403  * @pass_frame_status:  Pass frame status
404  * @private_data_size:  Size kept for private data (in bytes)
405  * @data_align:         Data alignment
406  * @data_head_room:     Data head room
407  * @data_tail_room:     Data tail room
408  */
409 struct dpni_buffer_layout {
410         uint32_t options;
411         int pass_timestamp;
412         int pass_parser_result;
413         int pass_frame_status;
414         uint16_t private_data_size;
415         uint16_t data_align;
416         uint16_t data_head_room;
417         uint16_t data_tail_room;
418 };
419
420 /**
421  * enum dpni_queue_type - Identifies a type of queue targeted by the command
422  * @DPNI_QUEUE_RX: Rx queue
423  * @DPNI_QUEUE_TX: Tx queue
424  * @DPNI_QUEUE_TX_CONFIRM: Tx confirmation queue
425  * @DPNI_QUEUE_RX_ERR: Rx error queue
426  */
427 enum dpni_queue_type {
428         DPNI_QUEUE_RX,
429         DPNI_QUEUE_TX,
430         DPNI_QUEUE_TX_CONFIRM,
431         DPNI_QUEUE_RX_ERR,
432 };
433
434 int dpni_get_buffer_layout(struct fsl_mc_io *mc_io,
435                            uint32_t cmd_flags,
436                            uint16_t token,
437                            enum dpni_queue_type qtype,
438                            struct dpni_buffer_layout *layout);
439
440 int dpni_set_buffer_layout(struct fsl_mc_io *mc_io,
441                            uint32_t cmd_flags,
442                            uint16_t token,
443                            enum dpni_queue_type qtype,
444                            const struct dpni_buffer_layout *layout);
445
446 /**
447  * enum dpni_offload - Identifies a type of offload targeted by the command
448  * @DPNI_OFF_RX_L3_CSUM: Rx L3 checksum validation
449  * @DPNI_OFF_RX_L4_CSUM: Rx L4 checksum validation
450  * @DPNI_OFF_TX_L3_CSUM: Tx L3 checksum generation
451  * @DPNI_OFF_TX_L4_CSUM: Tx L4 checksum generation
452  * @DPNI_OPT_FLCTYPE_HASH: flow context will be generated by WRIOP for AIOP or
453  *                         for CPU
454  */
455 enum dpni_offload {
456         DPNI_OFF_RX_L3_CSUM,
457         DPNI_OFF_RX_L4_CSUM,
458         DPNI_OFF_TX_L3_CSUM,
459         DPNI_OFF_TX_L4_CSUM,
460         DPNI_FLCTYPE_HASH,
461 };
462
463 int dpni_set_offload(struct fsl_mc_io *mc_io,
464                      uint32_t cmd_flags,
465                      uint16_t token,
466                      enum dpni_offload type,
467                      uint32_t config);
468
469 int dpni_get_offload(struct fsl_mc_io *mc_io,
470                      uint32_t cmd_flags,
471                      uint16_t token,
472                      enum dpni_offload type,
473                      uint32_t *config);
474
475 int dpni_get_qdid(struct fsl_mc_io *mc_io,
476                   uint32_t cmd_flags,
477                   uint16_t token,
478                   enum dpni_queue_type qtype,
479                   uint16_t *qdid);
480
481 int dpni_get_tx_data_offset(struct fsl_mc_io *mc_io,
482                             uint32_t cmd_flags,
483                             uint16_t token,
484                             uint16_t *data_offset);
485
486 #define DPNI_STATISTICS_CNT             7
487
488 union dpni_statistics {
489         /**
490          * struct page_0 - Page_0 statistics structure
491          * @ingress_all_frames: Ingress frame count
492          * @ingress_all_bytes: Ingress byte count
493          * @ingress_multicast_frames: Ingress multicast frame count
494          * @ingress_multicast_bytes: Ingress multicast byte count
495          * @ingress_broadcast_frames: Ingress broadcast frame count
496          * @ingress_broadcast_bytes: Ingress broadcast byte count
497          */
498         struct {
499                 uint64_t ingress_all_frames;
500                 uint64_t ingress_all_bytes;
501                 uint64_t ingress_multicast_frames;
502                 uint64_t ingress_multicast_bytes;
503                 uint64_t ingress_broadcast_frames;
504                 uint64_t ingress_broadcast_bytes;
505         } page_0;
506         /**
507          * struct page_1 - Page_1 statistics structure
508          * @egress_all_frames: Egress frame count
509          * @egress_all_bytes: Egress byte count
510          * @egress_multicast_frames: Egress multicast frame count
511          * @egress_multicast_bytes: Egress multicast byte count
512          * @egress_broadcast_frames: Egress broadcast frame count
513          * @egress_broadcast_bytes: Egress broadcast byte count
514          */
515         struct {
516                 uint64_t egress_all_frames;
517                 uint64_t egress_all_bytes;
518                 uint64_t egress_multicast_frames;
519                 uint64_t egress_multicast_bytes;
520                 uint64_t egress_broadcast_frames;
521                 uint64_t egress_broadcast_bytes;
522         } page_1;
523         /**
524          * struct page_2 - Page_2 statistics structure
525          * @ingress_filtered_frames: Ingress filtered frame count
526          * @ingress_discarded_frames: Ingress discarded frame count
527          * @ingress_nobuffer_discards: Ingress discarded frame count due to
528          *                                      lack of buffers
529          * @egress_discarded_frames: Egress discarded frame count
530          * @egress_confirmed_frames: Egress confirmed frame count
531          */
532         struct {
533                 uint64_t ingress_filtered_frames;
534                 uint64_t ingress_discarded_frames;
535                 uint64_t ingress_nobuffer_discards;
536                 uint64_t egress_discarded_frames;
537                 uint64_t egress_confirmed_frames;
538         } page_2;
539         /**
540          * struct page_3 - Page_3 statistics structure with values for the
541          *                      selected TC
542          * @ceetm_dequeue_bytes: Cumulative count of the number of bytes
543          *                      dequeued
544          * @ceetm_dequeue_frames: Cumulative count of the number of frames
545          *                      dequeued
546          * @ceetm_reject_bytes: Cumulative count of the number of bytes in all
547          *                      frames whose enqueue was rejected
548          * @ceetm_reject_frames: Cumulative count of all frame enqueues rejected
549          */
550         struct {
551                 uint64_t ceetm_dequeue_bytes;
552                 uint64_t ceetm_dequeue_frames;
553                 uint64_t ceetm_reject_bytes;
554                 uint64_t ceetm_reject_frames;
555         } page_3;
556         /**
557          * struct raw - raw statistics structure, used to index counters
558          */
559         struct {
560                 uint64_t counter[DPNI_STATISTICS_CNT];
561         } raw;
562 };
563
564 /**
565  * Enable auto-negotiation
566  */
567 #define DPNI_LINK_OPT_AUTONEG           0x0000000000000001ULL
568 /**
569  * Enable half-duplex mode
570  */
571 #define DPNI_LINK_OPT_HALF_DUPLEX       0x0000000000000002ULL
572 /**
573  * Enable pause frames
574  */
575 #define DPNI_LINK_OPT_PAUSE             0x0000000000000004ULL
576 /**
577  * Enable a-symmetric pause frames
578  */
579 #define DPNI_LINK_OPT_ASYM_PAUSE        0x0000000000000008ULL
580 /**
581  * Enable priority flow control pause frames
582  */
583 #define DPNI_LINK_OPT_PFC_PAUSE 0x0000000000000010ULL
584
585 /**
586  * struct - Structure representing DPNI link configuration
587  * @rate: Rate
588  * @options: Mask of available options; use 'DPNI_LINK_OPT_<X>' values
589  */
590 struct dpni_link_cfg {
591         uint32_t rate;
592         uint64_t options;
593 };
594
595 int dpni_set_link_cfg(struct fsl_mc_io *mc_io,
596                       uint32_t cmd_flags,
597                       uint16_t token,
598                       const struct dpni_link_cfg *cfg);
599
600 /**
601  * struct dpni_link_state - Structure representing DPNI link state
602  * @rate:       Rate
603  * @options:    Mask of available options; use 'DPNI_LINK_OPT_<X>' values
604  * @up:         Link state; '0' for down, '1' for up
605  */
606 struct dpni_link_state {
607         uint32_t rate;
608         uint64_t options;
609         int up;
610 };
611
612 int dpni_get_link_state(struct fsl_mc_io *mc_io,
613                         uint32_t cmd_flags,
614                         uint16_t token,
615                         struct dpni_link_state *state);
616
617 int dpni_set_max_frame_length(struct fsl_mc_io *mc_io,
618                               uint32_t cmd_flags,
619                               uint16_t token,
620                               uint16_t max_frame_length);
621
622 int dpni_get_max_frame_length(struct fsl_mc_io *mc_io,
623                               uint32_t cmd_flags,
624                               uint16_t token,
625                               uint16_t *max_frame_length);
626
627 int dpni_set_mtu(struct fsl_mc_io *mc_io,
628                  uint32_t cmd_flags,
629                  uint16_t token,
630                  uint16_t mtu);
631
632 int dpni_get_mtu(struct fsl_mc_io *mc_io,
633                  uint32_t cmd_flags,
634                  uint16_t token,
635                  uint16_t *mtu);
636
637 int dpni_set_multicast_promisc(struct fsl_mc_io *mc_io,
638                                uint32_t cmd_flags,
639                                uint16_t token,
640                                int en);
641
642 int dpni_get_multicast_promisc(struct fsl_mc_io *mc_io,
643                                uint32_t cmd_flags,
644                                uint16_t token,
645                                int *en);
646
647 int dpni_set_unicast_promisc(struct fsl_mc_io *mc_io,
648                              uint32_t cmd_flags,
649                              uint16_t token,
650                              int en);
651
652 int dpni_get_unicast_promisc(struct fsl_mc_io *mc_io,
653                              uint32_t cmd_flags,
654                              uint16_t token,
655                              int *en);
656
657 int dpni_set_primary_mac_addr(struct fsl_mc_io *mc_io,
658                               uint32_t cmd_flags,
659                               uint16_t token,
660                               const uint8_t mac_addr[6]);
661
662 int dpni_get_primary_mac_addr(struct fsl_mc_io *mc_io,
663                               uint32_t cmd_flags,
664                               uint16_t token,
665                               uint8_t mac_addr[6]);
666
667 int dpni_add_mac_addr(struct fsl_mc_io *mc_io,
668                       uint32_t cmd_flags,
669                       uint16_t token,
670                       const uint8_t mac_addr[6]);
671
672 int dpni_remove_mac_addr(struct fsl_mc_io *mc_io,
673                          uint32_t cmd_flags,
674                          uint16_t token,
675                          const uint8_t mac_addr[6]);
676
677 int dpni_clear_mac_filters(struct fsl_mc_io *mc_io,
678                            uint32_t cmd_flags,
679                            uint16_t token,
680                            int unicast,
681                            int multicast);
682
683 int dpni_get_port_mac_addr(struct fsl_mc_io *mc_io,
684                            uint32_t cmd_flags,
685                            uint16_t token,
686                            uint8_t mac_addr[6]);
687
688 int dpni_enable_vlan_filter(struct fsl_mc_io *mc_io,
689                             uint32_t cmd_flags,
690                             uint16_t token,
691                             int en);
692
693 int dpni_add_vlan_id(struct fsl_mc_io *mc_io,
694                      uint32_t cmd_flags,
695                      uint16_t token,
696                      uint16_t vlan_id);
697
698 int dpni_remove_vlan_id(struct fsl_mc_io *mc_io,
699                         uint32_t cmd_flags,
700                         uint16_t token,
701                         uint16_t vlan_id);
702
703 int dpni_clear_vlan_filters(struct fsl_mc_io *mc_io,
704                             uint32_t cmd_flags,
705                             uint16_t token);
706
707 /**
708  * enum dpni_dist_mode - DPNI distribution mode
709  * @DPNI_DIST_MODE_NONE: No distribution
710  * @DPNI_DIST_MODE_HASH: Use hash distribution; only relevant if
711  *              the 'DPNI_OPT_DIST_HASH' option was set at DPNI creation
712  * @DPNI_DIST_MODE_FS:  Use explicit flow steering; only relevant if
713  *       the 'DPNI_OPT_DIST_FS' option was set at DPNI creation
714  */
715 enum dpni_dist_mode {
716         DPNI_DIST_MODE_NONE = 0,
717         DPNI_DIST_MODE_HASH = 1,
718         DPNI_DIST_MODE_FS = 2
719 };
720
721 /**
722  * enum dpni_fs_miss_action -   DPNI Flow Steering miss action
723  * @DPNI_FS_MISS_DROP: In case of no-match, drop the frame
724  * @DPNI_FS_MISS_EXPLICIT_FLOWID: In case of no-match, use explicit flow-id
725  * @DPNI_FS_MISS_HASH: In case of no-match, distribute using hash
726  */
727 enum dpni_fs_miss_action {
728         DPNI_FS_MISS_DROP = 0,
729         DPNI_FS_MISS_EXPLICIT_FLOWID = 1,
730         DPNI_FS_MISS_HASH = 2
731 };
732
733 /**
734  * struct dpni_fs_tbl_cfg - Flow Steering table configuration
735  * @miss_action:        Miss action selection
736  * @default_flow_id:    Used when 'miss_action = DPNI_FS_MISS_EXPLICIT_FLOWID'
737  */
738 struct dpni_fs_tbl_cfg {
739         enum dpni_fs_miss_action miss_action;
740         uint16_t default_flow_id;
741         char keep_hash_key;
742 };
743
744 /**
745  * struct dpni_rx_tc_dist_cfg - Rx traffic class distribution configuration
746  * @dist_size: Set the distribution size;
747  *      supported values: 1,2,3,4,6,7,8,12,14,16,24,28,32,48,56,64,96,
748  *      112,128,192,224,256,384,448,512,768,896,1024
749  * @dist_mode: Distribution mode
750  * @key_cfg_iova: I/O virtual address of 256 bytes DMA-able memory filled with
751  *              the extractions to be used for the distribution key by calling
752  *              dpkg_prepare_key_cfg() relevant only when
753  *              'dist_mode != DPNI_DIST_MODE_NONE', otherwise it can be '0'
754  * @fs_cfg: Flow Steering table configuration; only relevant if
755  *              'dist_mode = DPNI_DIST_MODE_FS'
756  */
757 struct dpni_rx_tc_dist_cfg {
758         uint16_t dist_size;
759         enum dpni_dist_mode dist_mode;
760         uint64_t key_cfg_iova;
761         struct dpni_fs_tbl_cfg fs_cfg;
762 };
763
764 int dpni_set_rx_tc_dist(struct fsl_mc_io *mc_io,
765                         uint32_t cmd_flags,
766                         uint16_t token,
767                         uint8_t tc_id,
768                         const struct dpni_rx_tc_dist_cfg *cfg);
769
770 /**
771  * enum dpni_congestion_unit - DPNI congestion units
772  * @DPNI_CONGESTION_UNIT_BYTES: bytes units
773  * @DPNI_CONGESTION_UNIT_FRAMES: frames units
774  */
775 enum dpni_congestion_unit {
776         DPNI_CONGESTION_UNIT_BYTES = 0,
777         DPNI_CONGESTION_UNIT_FRAMES
778 };
779
780
781 /**
782  * enum dpni_dest - DPNI destination types
783  * @DPNI_DEST_NONE: Unassigned destination; The queue is set in parked mode and
784  *              does not generate FQDAN notifications; user is expected to
785  *              dequeue from the queue based on polling or other user-defined
786  *              method
787  * @DPNI_DEST_DPIO: The queue is set in schedule mode and generates FQDAN
788  *              notifications to the specified DPIO; user is expected to dequeue
789  *              from the queue only after notification is received
790  * @DPNI_DEST_DPCON: The queue is set in schedule mode and does not generate
791  *              FQDAN notifications, but is connected to the specified DPCON
792  *              object; user is expected to dequeue from the DPCON channel
793  */
794 enum dpni_dest {
795         DPNI_DEST_NONE = 0,
796         DPNI_DEST_DPIO = 1,
797         DPNI_DEST_DPCON = 2
798 };
799
800 /**
801  * struct dpni_dest_cfg - Structure representing DPNI destination parameters
802  * @dest_type: Destination type
803  * @dest_id: Either DPIO ID or DPCON ID, depending on the destination type
804  * @priority: Priority selection within the DPIO or DPCON channel; valid values
805  *              are 0-1 or 0-7, depending on the number of priorities in that
806  *              channel; not relevant for 'DPNI_DEST_NONE' option
807  */
808 struct dpni_dest_cfg {
809         enum dpni_dest dest_type;
810         int dest_id;
811         uint8_t priority;
812 };
813
814 /* DPNI congestion options */
815
816 /**
817  * CSCN message is written to message_iova once entering a
818  * congestion state (see 'threshold_entry')
819  */
820 #define DPNI_CONG_OPT_WRITE_MEM_ON_ENTER        0x00000001
821 /**
822  * CSCN message is written to message_iova once exiting a
823  * congestion state (see 'threshold_exit')
824  */
825 #define DPNI_CONG_OPT_WRITE_MEM_ON_EXIT         0x00000002
826 /**
827  * CSCN write will attempt to allocate into a cache (coherent write);
828  * valid only if 'DPNI_CONG_OPT_WRITE_MEM_<X>' is selected
829  */
830 #define DPNI_CONG_OPT_COHERENT_WRITE            0x00000004
831 /**
832  * if 'dest_cfg.dest_type != DPNI_DEST_NONE' CSCN message is sent to
833  * DPIO/DPCON's WQ channel once entering a congestion state
834  * (see 'threshold_entry')
835  */
836 #define DPNI_CONG_OPT_NOTIFY_DEST_ON_ENTER      0x00000008
837 /**
838  * if 'dest_cfg.dest_type != DPNI_DEST_NONE' CSCN message is sent to
839  * DPIO/DPCON's WQ channel once exiting a congestion state
840  * (see 'threshold_exit')
841  */
842 #define DPNI_CONG_OPT_NOTIFY_DEST_ON_EXIT       0x00000010
843 /**
844  * if 'dest_cfg.dest_type != DPNI_DEST_NONE' when the CSCN is written to the
845  * sw-portal's DQRR, the DQRI interrupt is asserted immediately (if enabled)
846  */
847 #define DPNI_CONG_OPT_INTR_COALESCING_DISABLED  0x00000020
848 /**
849  * This congestion will trigger flow control or priority flow control. This
850  * will have effect only if flow control is enabled with dpni_set_link_cfg()
851  */
852 #define DPNI_CONG_OPT_FLOW_CONTROL      0x00000040
853
854 /**
855  * struct dpni_congestion_notification_cfg - congestion notification
856  *              configuration
857  * @units: units type
858  * @threshold_entry: above this threshold we enter a congestion state.
859  *      set it to '0' to disable it
860  * @threshold_exit: below this threshold we exit the congestion state.
861  * @message_ctx: The context that will be part of the CSCN message
862  * @message_iova: I/O virtual address (must be in DMA-able memory),
863  *      must be 16B aligned; valid only if 'DPNI_CONG_OPT_WRITE_MEM_<X>' is
864  *      contained in 'options'
865  * @dest_cfg: CSCN can be send to either DPIO or DPCON WQ channel
866  * @notification_mode: Mask of available options; use 'DPNI_CONG_OPT_<X>' values
867  */
868
869 struct dpni_congestion_notification_cfg {
870         enum dpni_congestion_unit units;
871         uint32_t threshold_entry;
872         uint32_t threshold_exit;
873         uint64_t message_ctx;
874         uint64_t message_iova;
875         struct dpni_dest_cfg dest_cfg;
876         uint16_t notification_mode;
877 };
878
879 int dpni_set_congestion_notification(struct fsl_mc_io *mc_io,
880                                      uint32_t cmd_flags,
881                                      uint16_t token,
882                                      enum dpni_queue_type qtype,
883                                      uint8_t tc_id,
884                         const struct dpni_congestion_notification_cfg *cfg);
885
886 int dpni_get_congestion_notification(struct fsl_mc_io *mc_io,
887                                      uint32_t cmd_flags,
888                                      uint16_t token,
889                                      enum dpni_queue_type qtype,
890                                      uint8_t tc_id,
891                                 struct dpni_congestion_notification_cfg *cfg);
892
893 /* DPNI FLC stash options */
894
895 /**
896  * stashes the whole annotation area (up to 192 bytes)
897  */
898 #define DPNI_FLC_STASH_FRAME_ANNOTATION 0x00000001
899
900 /**
901  * struct dpni_queue - Queue structure
902  * @user_context:       User data, presented to the user along with any frames
903  *                      from this queue. Not relevant for Tx queues.
904  */
905 struct dpni_queue {
906         /**
907          * struct destination - Destination structure
908          * @id: ID of the destination, only relevant if DEST_TYPE is > 0.
909          *                      Identifies either a DPIO or a DPCON object.
910          *                      Not relevant for Tx queues.
911          * @type:       May be one of the following:
912          *                      0 - No destination, queue can be manually
913          *                              queried, but will not push traffic or
914          *                              notifications to a DPIO;
915          *                      1 - The destination is a DPIO. When traffic
916          *                              becomes available in the queue a FQDAN
917          *                              (FQ data available notification) will be
918          *                              generated to selected DPIO;
919          *                      2 - The destination is a DPCON. The queue is
920          *                              associated with a DPCON object for the
921          *                              purpose of scheduling between multiple
922          *                              queues. The DPCON may be independently
923          *                              configured to generate notifications.
924          *                              Not relevant for Tx queues.
925          * @hold_active: Hold active, maintains a queue scheduled for longer
926          *              in a DPIO during dequeue to reduce spread of traffic.
927          *              Only relevant if queues are
928          *              not affined to a single DPIO.
929          */
930         struct {
931                 uint16_t id;
932                 enum dpni_dest type;
933                 char hold_active;
934                 uint8_t priority;
935         } destination;
936         uint64_t user_context;
937         /**
938          * struct flc - FD FLow Context structure
939          * @value: Default FLC value for traffic dequeued from
940          *      this queue.  Please check description of FD
941          *      structure for more information.
942          *      Note that FLC values set using dpni_add_fs_entry,
943          *      if any, take precedence over values per queue.
944          * @stash_control: Boolean, indicates whether the 6 lowest
945          *      - significant bits are used for stash control.
946          *      significant bits are used for stash control.  If set, the 6
947          *      least significant bits in value are interpreted as follows:
948          *      - bits 0-1: indicates the number of 64 byte units of context
949          *      that are stashed.  FLC value is interpreted as a memory address
950          *      in this case, excluding the 6 LS bits.
951          *      - bits 2-3: indicates the number of 64 byte units of frame
952          *      annotation to be stashed.  Annotation is placed at FD[ADDR].
953          *      - bits 4-5: indicates the number of 64 byte units of frame
954          *      data to be stashed.  Frame data is placed at FD[ADDR] +
955          *      FD[OFFSET].
956          *      For more details check the Frame Descriptor section in the
957          *      hardware documentation.
958          */
959         struct {
960                 uint64_t value;
961                 char stash_control;
962         } flc;
963 };
964
965 /**
966  * struct dpni_queue_id - Queue identification, used for enqueue commands
967  *                              or queue control
968  * @fqid:       FQID used for enqueueing to and/or configuration of this
969  *                      specific FQ
970  * @qdbin:      Queueing bin, used to enqueue using QDID, DQBIN, QPRI.
971  *                      Only relevant for Tx queues.
972  */
973 struct dpni_queue_id {
974         uint32_t fqid;
975         uint16_t qdbin;
976 };
977
978 /**
979  * enum dpni_confirmation_mode - Defines DPNI options supported for Tx
980  * confirmation
981  * @DPNI_CONF_AFFINE: For each Tx queue set associated with a sender there is
982  * an affine Tx Confirmation queue
983  * @DPNI_CONF_SINGLE: All Tx queues are associated with a single Tx
984  * confirmation queue
985  * @DPNI_CONF_DISABLE: Tx frames are not confirmed.  This must be associated
986  * with proper FD set-up to have buffers release to a Buffer Pool, otherwise
987  * buffers will be leaked
988  */
989 enum dpni_confirmation_mode {
990         DPNI_CONF_AFFINE,
991         DPNI_CONF_SINGLE,
992         DPNI_CONF_DISABLE,
993 };
994
995 int dpni_set_tx_confirmation_mode(struct fsl_mc_io *mc_io,
996                                   uint32_t cmd_flags,
997                                   uint16_t token,
998                                   enum dpni_confirmation_mode mode);
999
1000 int dpni_get_tx_confirmation_mode(struct fsl_mc_io *mc_io,
1001                                   uint32_t cmd_flags,
1002                                   uint16_t token,
1003                                   enum dpni_confirmation_mode *mode);
1004
1005 int dpni_get_api_version(struct fsl_mc_io *mc_io,
1006                          uint32_t cmd_flags,
1007                          uint16_t *major_ver,
1008                          uint16_t *minor_ver);
1009
1010 /**
1011  * Set User Context
1012  */
1013 #define DPNI_QUEUE_OPT_USER_CTX         0x00000001
1014
1015 /**
1016  * Set queue destination configuration
1017  */
1018 #define DPNI_QUEUE_OPT_DEST             0x00000002
1019
1020 /**
1021  * Set FD[FLC] configuration for traffic on this queue.  Note that FLC values
1022  * set with dpni_add_fs_entry, if any, take precedence over values per queue.
1023  */
1024 #define DPNI_QUEUE_OPT_FLC              0x00000004
1025
1026 /**
1027  * Set the queue to hold active mode.  This prevents the queue from being
1028  * rescheduled between DPIOs while it carries traffic and is active on one
1029  * DPNI.  Can help reduce reordering when servicing one queue on multiple
1030  * CPUs, but the queue is also less likely to push data to multiple CPUs
1031  * especially when congested.
1032  */
1033 #define DPNI_QUEUE_OPT_HOLD_ACTIVE      0x00000008
1034
1035 int dpni_set_queue(struct fsl_mc_io *mc_io,
1036                    uint32_t cmd_flags,
1037                    uint16_t token,
1038                    enum dpni_queue_type qtype,
1039                    uint8_t tc,
1040                    uint8_t index,
1041                    uint8_t options,
1042                    const struct dpni_queue *queue);
1043
1044 int dpni_get_queue(struct fsl_mc_io *mc_io,
1045                    uint32_t cmd_flags,
1046                    uint16_t token,
1047                    enum dpni_queue_type qtype,
1048                    uint8_t tc,
1049                    uint8_t index,
1050                    struct dpni_queue *queue,
1051                    struct dpni_queue_id *qid);
1052
1053 int dpni_get_statistics(struct fsl_mc_io *mc_io,
1054                         uint32_t cmd_flags,
1055                         uint16_t token,
1056                         uint8_t page,
1057                         uint8_t param,
1058                         union dpni_statistics *stat);
1059
1060 int dpni_reset_statistics(struct fsl_mc_io *mc_io,
1061                           uint32_t cmd_flags,
1062                           uint16_t token);
1063
1064 /**
1065  * enum dpni_congestion_point - Structure representing congestion point
1066  * @DPNI_CP_QUEUE:      Set taildrop per queue, identified by QUEUE_TYPE, TC and
1067  *                              QUEUE_INDEX
1068  * @DPNI_CP_GROUP:      Set taildrop per queue group. Depending on options used
1069  *                              to define the DPNI this can be either per
1070  *                              TC (default) or per interface
1071  *                              (DPNI_OPT_SHARED_CONGESTION set at DPNI create).
1072  *                              QUEUE_INDEX is ignored if this type is used.
1073  */
1074 enum dpni_congestion_point {
1075         DPNI_CP_QUEUE,
1076         DPNI_CP_GROUP,
1077 };
1078
1079 /**
1080  * struct dpni_taildrop - Structure representing the taildrop
1081  * @enable:     Indicates whether the taildrop is active or not.
1082  * @units:      Indicates the unit of THRESHOLD. Queue taildrop only
1083  *              supports byte units, this field is ignored and
1084  *              assumed = 0 if CONGESTION_POINT is 0.
1085  * @threshold:  Threshold value, in units identified by UNITS field. Value 0
1086  *              cannot be used as a valid taildrop threshold,
1087  *              THRESHOLD must be > 0 if the taildrop is
1088  *              enabled.
1089  * @oal :       Overhead Accounting Length, a 12-bit, 2's complement value
1090  *              with range (-2048 to +2047) representing a fixed per-frame
1091  *              overhead to be added to the actual length of a frame when
1092  *              performing WRED and tail drop calculations and threshold
1093  *              comparisons.
1094  */
1095 struct dpni_taildrop {
1096         char enable;
1097         enum dpni_congestion_unit units;
1098         uint32_t threshold;
1099         int16_t oal;
1100 };
1101
1102 int dpni_set_taildrop(struct fsl_mc_io *mc_io,
1103                       uint32_t cmd_flags,
1104                       uint16_t token,
1105                       enum dpni_congestion_point cg_point,
1106                       enum dpni_queue_type q_type,
1107                       uint8_t tc,
1108                       uint8_t q_index,
1109                       struct dpni_taildrop *taildrop);
1110
1111 int dpni_get_taildrop(struct fsl_mc_io *mc_io,
1112                       uint32_t cmd_flags,
1113                       uint16_t token,
1114                       enum dpni_congestion_point cg_point,
1115                       enum dpni_queue_type q_type,
1116                       uint8_t tc,
1117                       uint8_t q_index,
1118                       struct dpni_taildrop *taildrop);
1119 #endif /* __FSL_DPNI_H */