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