1 /* SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause) */
2 /* Copyright 2013-2016 Freescale Semiconductor Inc.
13 * Data Path Network Interface API
14 * Contains initialization APIs and runtime control APIs for DPNI
17 /** General DPNI macros */
20 * Maximum number of traffic classes
24 * Maximum number of buffer pools per DPNI
26 #define DPNI_MAX_DPBP 8
29 * All traffic classes considered; see dpni_set_queue()
31 #define DPNI_ALL_TCS (u8)(-1)
33 * All flows within traffic class considered; see dpni_set_queue()
35 #define DPNI_ALL_TC_FLOWS (u16)(-1)
37 * Generate new flow ID; see dpni_set_queue()
39 #define DPNI_NEW_FLOW_ID (u16)(-1)
42 * Tx traffic is always released to a buffer pool on transmit, there are no
43 * resources allocated to have the frames confirmed back to the source after
46 #define DPNI_OPT_TX_FRM_RELEASE 0x000001
48 * Disables support for MAC address filtering for addresses other than primary
49 * MAC address. This affects both unicast and multicast. Promiscuous mode can
50 * still be enabled/disabled for both unicast and multicast. If promiscuous mode
51 * is disabled, only traffic matching the primary MAC address will be accepted.
53 #define DPNI_OPT_NO_MAC_FILTER 0x000002
55 * Allocate policers for this DPNI. They can be used to rate-limit traffic per
56 * traffic class (TC) basis.
58 #define DPNI_OPT_HAS_POLICING 0x000004
60 * Congestion can be managed in several ways, allowing the buffer pool to
61 * deplete on ingress, taildrop on each queue or use congestion groups for sets
62 * of queues. If set, it configures a single congestion groups across all TCs.
63 * If reset, a congestion group is allocated for each TC. Only relevant if the
64 * DPNI has multiple traffic classes.
66 #define DPNI_OPT_SHARED_CONGESTION 0x000008
68 * Enables TCAM for Flow Steering and QoS look-ups. If not specified, all
69 * look-ups are exact match. Note that TCAM is not available on LS1088 and its
70 * variants. Setting this bit on these SoCs will trigger an error.
72 #define DPNI_OPT_HAS_KEY_MASKING 0x000010
74 * Disables the flow steering table.
76 #define DPNI_OPT_NO_FS 0x000020
78 int dpni_open(struct fsl_mc_io *mc_io,
83 int dpni_close(struct fsl_mc_io *mc_io,
88 * struct dpni_pools_cfg - Structure representing buffer pools configuration
89 * @num_dpbp: Number of DPBPs
90 * @pools: Array of buffer pools parameters; The number of valid entries
91 * must match 'num_dpbp' value
92 * @pools.dpbp_id: DPBP object ID
93 * @pools.buffer_size: Buffer size
94 * @pools.backup_pool: Backup pool
96 struct dpni_pools_cfg {
102 } pools[DPNI_MAX_DPBP];
105 int dpni_set_pools(struct fsl_mc_io *mc_io,
108 const struct dpni_pools_cfg *cfg);
110 int dpni_enable(struct fsl_mc_io *mc_io,
114 int dpni_disable(struct fsl_mc_io *mc_io,
118 int dpni_is_enabled(struct fsl_mc_io *mc_io,
123 int dpni_reset(struct fsl_mc_io *mc_io,
128 * DPNI IRQ Index and Events
134 #define DPNI_IRQ_INDEX 0
136 * IRQ event - indicates a change in link state
138 #define DPNI_IRQ_EVENT_LINK_CHANGED 0x00000001
140 int dpni_set_irq_enable(struct fsl_mc_io *mc_io,
146 int dpni_get_irq_enable(struct fsl_mc_io *mc_io,
152 int dpni_set_irq_mask(struct fsl_mc_io *mc_io,
158 int dpni_get_irq_mask(struct fsl_mc_io *mc_io,
164 int dpni_get_irq_status(struct fsl_mc_io *mc_io,
170 int dpni_clear_irq_status(struct fsl_mc_io *mc_io,
177 * struct dpni_attr - Structure representing DPNI attributes
178 * @options: Any combination of the following options:
179 * DPNI_OPT_TX_FRM_RELEASE
180 * DPNI_OPT_NO_MAC_FILTER
181 * DPNI_OPT_HAS_POLICING
182 * DPNI_OPT_SHARED_CONGESTION
183 * DPNI_OPT_HAS_KEY_MASKING
185 * @num_queues: Number of Tx and Rx queues used for traffic distribution.
186 * @num_tcs: Number of traffic classes (TCs), reserved for the DPNI.
187 * @mac_filter_entries: Number of entries in the MAC address filtering table.
188 * @vlan_filter_entries: Number of entries in the VLAN address filtering table.
189 * @qos_entries: Number of entries in the QoS classification table.
190 * @fs_entries: Number of entries in the flow steering table.
191 * @qos_key_size: Size, in bytes, of the QoS look-up key. Defining a key larger
192 * than this when adding QoS entries will result in an error.
193 * @fs_key_size: Size, in bytes, of the flow steering look-up key. Defining a
194 * key larger than this when composing the hash + FS key will
195 * result in an error.
196 * @wriop_version: Version of WRIOP HW block. The 3 version values are stored
197 * on 6, 5, 5 bits respectively.
203 u8 mac_filter_entries;
204 u8 vlan_filter_entries;
212 int dpni_get_attributes(struct fsl_mc_io *mc_io,
215 struct dpni_attr *attr);
222 * Extract out of frame header error
224 #define DPNI_ERROR_EOFHE 0x00020000
228 #define DPNI_ERROR_FLE 0x00002000
230 * Frame physical error
232 #define DPNI_ERROR_FPE 0x00001000
234 * Parsing header error
236 #define DPNI_ERROR_PHE 0x00000020
238 * Parser L3 checksum error
240 #define DPNI_ERROR_L3CE 0x00000004
242 * Parser L3 checksum error
244 #define DPNI_ERROR_L4CE 0x00000001
247 * enum dpni_error_action - Defines DPNI behavior for errors
248 * @DPNI_ERROR_ACTION_DISCARD: Discard the frame
249 * @DPNI_ERROR_ACTION_CONTINUE: Continue with the normal flow
250 * @DPNI_ERROR_ACTION_SEND_TO_ERROR_QUEUE: Send the frame to the error queue
252 enum dpni_error_action {
253 DPNI_ERROR_ACTION_DISCARD = 0,
254 DPNI_ERROR_ACTION_CONTINUE = 1,
255 DPNI_ERROR_ACTION_SEND_TO_ERROR_QUEUE = 2
259 * struct dpni_error_cfg - Structure representing DPNI errors treatment
260 * @errors: Errors mask; use 'DPNI_ERROR__<X>
261 * @error_action: The desired action for the errors mask
262 * @set_frame_annotation: Set to '1' to mark the errors in frame annotation
263 * status (FAS); relevant only for the non-discard action
265 struct dpni_error_cfg {
267 enum dpni_error_action error_action;
268 int set_frame_annotation;
271 int dpni_set_errors_behavior(struct fsl_mc_io *mc_io,
274 struct dpni_error_cfg *cfg);
277 * DPNI buffer layout modification options
281 * Select to modify the time-stamp setting
283 #define DPNI_BUF_LAYOUT_OPT_TIMESTAMP 0x00000001
285 * Select to modify the parser-result setting; not applicable for Tx
287 #define DPNI_BUF_LAYOUT_OPT_PARSER_RESULT 0x00000002
289 * Select to modify the frame-status setting
291 #define DPNI_BUF_LAYOUT_OPT_FRAME_STATUS 0x00000004
293 * Select to modify the private-data-size setting
295 #define DPNI_BUF_LAYOUT_OPT_PRIVATE_DATA_SIZE 0x00000008
297 * Select to modify the data-alignment setting
299 #define DPNI_BUF_LAYOUT_OPT_DATA_ALIGN 0x00000010
301 * Select to modify the data-head-room setting
303 #define DPNI_BUF_LAYOUT_OPT_DATA_HEAD_ROOM 0x00000020
305 * Select to modify the data-tail-room setting
307 #define DPNI_BUF_LAYOUT_OPT_DATA_TAIL_ROOM 0x00000040
310 * struct dpni_buffer_layout - Structure representing DPNI buffer layout
311 * @options: Flags representing the suggested modifications to the buffer
312 * layout; Use any combination of 'DPNI_BUF_LAYOUT_OPT_<X>' flags
313 * @pass_timestamp: Pass timestamp value
314 * @pass_parser_result: Pass parser results
315 * @pass_frame_status: Pass frame status
316 * @private_data_size: Size kept for private data (in bytes)
317 * @data_align: Data alignment
318 * @data_head_room: Data head room
319 * @data_tail_room: Data tail room
321 struct dpni_buffer_layout {
324 int pass_parser_result;
325 int pass_frame_status;
326 u16 private_data_size;
333 * enum dpni_queue_type - Identifies a type of queue targeted by the command
334 * @DPNI_QUEUE_RX: Rx queue
335 * @DPNI_QUEUE_TX: Tx queue
336 * @DPNI_QUEUE_TX_CONFIRM: Tx confirmation queue
337 * @DPNI_QUEUE_RX_ERR: Rx error queue
338 */enum dpni_queue_type {
341 DPNI_QUEUE_TX_CONFIRM,
345 int dpni_get_buffer_layout(struct fsl_mc_io *mc_io,
348 enum dpni_queue_type qtype,
349 struct dpni_buffer_layout *layout);
351 int dpni_set_buffer_layout(struct fsl_mc_io *mc_io,
354 enum dpni_queue_type qtype,
355 const struct dpni_buffer_layout *layout);
358 * enum dpni_offload - Identifies a type of offload targeted by the command
359 * @DPNI_OFF_RX_L3_CSUM: Rx L3 checksum validation
360 * @DPNI_OFF_RX_L4_CSUM: Rx L4 checksum validation
361 * @DPNI_OFF_TX_L3_CSUM: Tx L3 checksum generation
362 * @DPNI_OFF_TX_L4_CSUM: Tx L4 checksum generation
371 int dpni_set_offload(struct fsl_mc_io *mc_io,
374 enum dpni_offload type,
377 int dpni_get_offload(struct fsl_mc_io *mc_io,
380 enum dpni_offload type,
383 int dpni_get_qdid(struct fsl_mc_io *mc_io,
386 enum dpni_queue_type qtype,
389 int dpni_get_tx_data_offset(struct fsl_mc_io *mc_io,
394 #define DPNI_STATISTICS_CNT 7
397 * union dpni_statistics - Union describing the DPNI statistics
398 * @page_0: Page_0 statistics structure
399 * @page_0.ingress_all_frames: Ingress frame count
400 * @page_0.ingress_all_bytes: Ingress byte count
401 * @page_0.ingress_multicast_frames: Ingress multicast frame count
402 * @page_0.ingress_multicast_bytes: Ingress multicast byte count
403 * @page_0.ingress_broadcast_frames: Ingress broadcast frame count
404 * @page_0.ingress_broadcast_bytes: Ingress broadcast byte count
405 * @page_1: Page_1 statistics structure
406 * @page_1.egress_all_frames: Egress frame count
407 * @page_1.egress_all_bytes: Egress byte count
408 * @page_1.egress_multicast_frames: Egress multicast frame count
409 * @page_1.egress_multicast_bytes: Egress multicast byte count
410 * @page_1.egress_broadcast_frames: Egress broadcast frame count
411 * @page_1.egress_broadcast_bytes: Egress broadcast byte count
412 * @page_2: Page_2 statistics structure
413 * @page_2.ingress_filtered_frames: Ingress filtered frame count
414 * @page_2.ingress_discarded_frames: Ingress discarded frame count
415 * @page_2.ingress_nobuffer_discards: Ingress discarded frame count due to
417 * @page_2.egress_discarded_frames: Egress discarded frame count
418 * @page_2.egress_confirmed_frames: Egress confirmed frame count
419 * @raw: raw statistics structure, used to index counters
421 union dpni_statistics {
423 u64 ingress_all_frames;
424 u64 ingress_all_bytes;
425 u64 ingress_multicast_frames;
426 u64 ingress_multicast_bytes;
427 u64 ingress_broadcast_frames;
428 u64 ingress_broadcast_bytes;
431 u64 egress_all_frames;
432 u64 egress_all_bytes;
433 u64 egress_multicast_frames;
434 u64 egress_multicast_bytes;
435 u64 egress_broadcast_frames;
436 u64 egress_broadcast_bytes;
439 u64 ingress_filtered_frames;
440 u64 ingress_discarded_frames;
441 u64 ingress_nobuffer_discards;
442 u64 egress_discarded_frames;
443 u64 egress_confirmed_frames;
446 u64 counter[DPNI_STATISTICS_CNT];
450 int dpni_get_statistics(struct fsl_mc_io *mc_io,
454 union dpni_statistics *stat);
457 * Enable auto-negotiation
459 #define DPNI_LINK_OPT_AUTONEG 0x0000000000000001ULL
461 * Enable half-duplex mode
463 #define DPNI_LINK_OPT_HALF_DUPLEX 0x0000000000000002ULL
465 * Enable pause frames
467 #define DPNI_LINK_OPT_PAUSE 0x0000000000000004ULL
469 * Enable a-symmetric pause frames
471 #define DPNI_LINK_OPT_ASYM_PAUSE 0x0000000000000008ULL
474 * struct - Structure representing DPNI link configuration
476 * @options: Mask of available options; use 'DPNI_LINK_OPT_<X>' values
478 struct dpni_link_cfg {
483 int dpni_set_link_cfg(struct fsl_mc_io *mc_io,
486 const struct dpni_link_cfg *cfg);
489 * struct dpni_link_state - Structure representing DPNI link state
491 * @options: Mask of available options; use 'DPNI_LINK_OPT_<X>' values
492 * @up: Link state; '0' for down, '1' for up
494 struct dpni_link_state {
500 int dpni_get_link_state(struct fsl_mc_io *mc_io,
503 struct dpni_link_state *state);
505 int dpni_set_max_frame_length(struct fsl_mc_io *mc_io,
508 u16 max_frame_length);
510 int dpni_get_max_frame_length(struct fsl_mc_io *mc_io,
513 u16 *max_frame_length);
515 int dpni_set_multicast_promisc(struct fsl_mc_io *mc_io,
520 int dpni_get_multicast_promisc(struct fsl_mc_io *mc_io,
525 int dpni_set_unicast_promisc(struct fsl_mc_io *mc_io,
530 int dpni_get_unicast_promisc(struct fsl_mc_io *mc_io,
535 int dpni_set_primary_mac_addr(struct fsl_mc_io *mc_io,
538 const u8 mac_addr[6]);
540 int dpni_get_primary_mac_addr(struct fsl_mc_io *mc_io,
545 int dpni_get_port_mac_addr(struct fsl_mc_io *mc_io,
550 int dpni_add_mac_addr(struct fsl_mc_io *mc_io,
553 const u8 mac_addr[6]);
555 int dpni_remove_mac_addr(struct fsl_mc_io *mc_io,
558 const u8 mac_addr[6]);
560 int dpni_clear_mac_filters(struct fsl_mc_io *mc_io,
567 * enum dpni_dist_mode - DPNI distribution mode
568 * @DPNI_DIST_MODE_NONE: No distribution
569 * @DPNI_DIST_MODE_HASH: Use hash distribution; only relevant if
570 * the 'DPNI_OPT_DIST_HASH' option was set at DPNI creation
571 * @DPNI_DIST_MODE_FS: Use explicit flow steering; only relevant if
572 * the 'DPNI_OPT_DIST_FS' option was set at DPNI creation
574 enum dpni_dist_mode {
575 DPNI_DIST_MODE_NONE = 0,
576 DPNI_DIST_MODE_HASH = 1,
577 DPNI_DIST_MODE_FS = 2
581 * enum dpni_fs_miss_action - DPNI Flow Steering miss action
582 * @DPNI_FS_MISS_DROP: In case of no-match, drop the frame
583 * @DPNI_FS_MISS_EXPLICIT_FLOWID: In case of no-match, use explicit flow-id
584 * @DPNI_FS_MISS_HASH: In case of no-match, distribute using hash
586 enum dpni_fs_miss_action {
587 DPNI_FS_MISS_DROP = 0,
588 DPNI_FS_MISS_EXPLICIT_FLOWID = 1,
589 DPNI_FS_MISS_HASH = 2
593 * struct dpni_fs_tbl_cfg - Flow Steering table configuration
594 * @miss_action: Miss action selection
595 * @default_flow_id: Used when 'miss_action = DPNI_FS_MISS_EXPLICIT_FLOWID'
597 struct dpni_fs_tbl_cfg {
598 enum dpni_fs_miss_action miss_action;
602 int dpni_prepare_key_cfg(const struct dpkg_profile_cfg *cfg,
606 * struct dpni_rx_tc_dist_cfg - Rx traffic class distribution configuration
607 * @dist_size: Set the distribution size;
608 * supported values: 1,2,3,4,6,7,8,12,14,16,24,28,32,48,56,64,96,
609 * 112,128,192,224,256,384,448,512,768,896,1024
610 * @dist_mode: Distribution mode
611 * @key_cfg_iova: I/O virtual address of 256 bytes DMA-able memory filled with
612 * the extractions to be used for the distribution key by calling
613 * dpni_prepare_key_cfg() relevant only when
614 * 'dist_mode != DPNI_DIST_MODE_NONE', otherwise it can be '0'
615 * @fs_cfg: Flow Steering table configuration; only relevant if
616 * 'dist_mode = DPNI_DIST_MODE_FS'
618 struct dpni_rx_tc_dist_cfg {
620 enum dpni_dist_mode dist_mode;
622 struct dpni_fs_tbl_cfg fs_cfg;
625 int dpni_set_rx_tc_dist(struct fsl_mc_io *mc_io,
629 const struct dpni_rx_tc_dist_cfg *cfg);
632 * enum dpni_dest - DPNI destination types
633 * @DPNI_DEST_NONE: Unassigned destination; The queue is set in parked mode and
634 * does not generate FQDAN notifications; user is expected to
635 * dequeue from the queue based on polling or other user-defined
637 * @DPNI_DEST_DPIO: The queue is set in schedule mode and generates FQDAN
638 * notifications to the specified DPIO; user is expected to dequeue
639 * from the queue only after notification is received
640 * @DPNI_DEST_DPCON: The queue is set in schedule mode and does not generate
641 * FQDAN notifications, but is connected to the specified DPCON
642 * object; user is expected to dequeue from the DPCON channel
651 * struct dpni_queue - Queue structure
652 * @destination - Destination structure
653 * @destination.id: ID of the destination, only relevant if DEST_TYPE is > 0.
654 * Identifies either a DPIO or a DPCON object.
655 * Not relevant for Tx queues.
656 * @destination.type: May be one of the following:
657 * 0 - No destination, queue can be manually
658 * queried, but will not push traffic or
659 * notifications to a DPIO;
660 * 1 - The destination is a DPIO. When traffic
661 * becomes available in the queue a FQDAN
662 * (FQ data available notification) will be
663 * generated to selected DPIO;
664 * 2 - The destination is a DPCON. The queue is
665 * associated with a DPCON object for the
666 * purpose of scheduling between multiple
667 * queues. The DPCON may be independently
668 * configured to generate notifications.
669 * Not relevant for Tx queues.
670 * @destination.hold_active: Hold active, maintains a queue scheduled for longer
671 * in a DPIO during dequeue to reduce spread of traffic.
672 * Only relevant if queues are
673 * not affined to a single DPIO.
674 * @user_context: User data, presented to the user along with any frames
675 * from this queue. Not relevant for Tx queues.
676 * @flc: FD FLow Context structure
677 * @flc.value: Default FLC value for traffic dequeued from
678 * this queue. Please check description of FD
679 * structure for more information.
680 * Note that FLC values set using dpni_add_fs_entry,
681 * if any, take precedence over values per queue.
682 * @flc.stash_control: Boolean, indicates whether the 6 lowest
683 * - significant bits are used for stash control.
684 * significant bits are used for stash control. If set, the 6
685 * least significant bits in value are interpreted as follows:
686 * - bits 0-1: indicates the number of 64 byte units of context
687 * that are stashed. FLC value is interpreted as a memory address
688 * in this case, excluding the 6 LS bits.
689 * - bits 2-3: indicates the number of 64 byte units of frame
690 * annotation to be stashed. Annotation is placed at FD[ADDR].
691 * - bits 4-5: indicates the number of 64 byte units of frame
692 * data to be stashed. Frame data is placed at FD[ADDR] +
694 * For more details check the Frame Descriptor section in the
695 * hardware documentation.
712 * struct dpni_queue_id - Queue identification, used for enqueue commands
714 * @fqid: FQID used for enqueueing to and/or configuration of this specific FQ
715 * @qdbin: Queueing bin, used to enqueue using QDID, DQBIN, QPRI. Only relevant
718 struct dpni_queue_id {
726 #define DPNI_QUEUE_OPT_USER_CTX 0x00000001
727 #define DPNI_QUEUE_OPT_DEST 0x00000002
728 #define DPNI_QUEUE_OPT_FLC 0x00000004
729 #define DPNI_QUEUE_OPT_HOLD_ACTIVE 0x00000008
731 int dpni_set_queue(struct fsl_mc_io *mc_io,
734 enum dpni_queue_type qtype,
738 const struct dpni_queue *queue);
740 int dpni_get_queue(struct fsl_mc_io *mc_io,
743 enum dpni_queue_type qtype,
746 struct dpni_queue *queue,
747 struct dpni_queue_id *qid);
750 * enum dpni_congestion_unit - DPNI congestion units
751 * @DPNI_CONGESTION_UNIT_BYTES: bytes units
752 * @DPNI_CONGESTION_UNIT_FRAMES: frames units
754 enum dpni_congestion_unit {
755 DPNI_CONGESTION_UNIT_BYTES = 0,
756 DPNI_CONGESTION_UNIT_FRAMES
760 * enum dpni_congestion_point - Structure representing congestion point
761 * @DPNI_CP_QUEUE: Set taildrop per queue, identified by QUEUE_TYPE, TC and
763 * @DPNI_CP_GROUP: Set taildrop per queue group. Depending on options used to
764 * define the DPNI this can be either per TC (default) or per
765 * interface (DPNI_OPT_SHARED_CONGESTION set at DPNI create).
766 * QUEUE_INDEX is ignored if this type is used.
768 enum dpni_congestion_point {
774 * struct dpni_taildrop - Structure representing the taildrop
775 * @enable: Indicates whether the taildrop is active or not.
776 * @units: Indicates the unit of THRESHOLD. Queue taildrop only supports
777 * byte units, this field is ignored and assumed = 0 if
778 * CONGESTION_POINT is 0.
779 * @threshold: Threshold value, in units identified by UNITS field. Value 0
780 * cannot be used as a valid taildrop threshold, THRESHOLD must
781 * be > 0 if the taildrop is enabled.
783 struct dpni_taildrop {
785 enum dpni_congestion_unit units;
789 int dpni_set_taildrop(struct fsl_mc_io *mc_io,
792 enum dpni_congestion_point cg_point,
793 enum dpni_queue_type q_type,
796 struct dpni_taildrop *taildrop);
798 int dpni_get_taildrop(struct fsl_mc_io *mc_io,
801 enum dpni_congestion_point cg_point,
802 enum dpni_queue_type q_type,
805 struct dpni_taildrop *taildrop);
808 * struct dpni_rule_cfg - Rule configuration for table lookup
809 * @key_iova: I/O virtual address of the key (must be in DMA-able memory)
810 * @mask_iova: I/O virtual address of the mask (must be in DMA-able memory)
811 * @key_size: key and mask size (in bytes)
813 struct dpni_rule_cfg {
819 int dpni_get_api_version(struct fsl_mc_io *mc_io,
824 #endif /* __FSL_DPNI_H */