1 /* Copyright 2013-2016 Freescale Semiconductor Inc.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 * * Redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer.
8 * * Redistributions in binary form must reproduce the above copyright
9 * notice, this list of conditions and the following disclaimer in the
10 * documentation and/or other materials provided with the distribution.
11 * * Neither the name of the above-listed copyright holders nor the
12 * names of any contributors may be used to endorse or promote products
13 * derived from this software without specific prior written permission.
16 * ALTERNATIVELY, this software may be distributed under the terms of the
17 * GNU General Public License ("GPL") as published by the Free Software
18 * Foundation, either version 2 of that License or (at your option) any
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
25 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
41 * Data Path Network Interface API
42 * Contains initialization APIs and runtime control APIs for DPNI
45 /** General DPNI macros */
48 * Maximum number of traffic classes
52 * Maximum number of buffer pools per DPNI
54 #define DPNI_MAX_DPBP 8
57 * All traffic classes considered; see dpni_set_queue()
59 #define DPNI_ALL_TCS (u8)(-1)
61 * All flows within traffic class considered; see dpni_set_queue()
63 #define DPNI_ALL_TC_FLOWS (u16)(-1)
65 * Generate new flow ID; see dpni_set_queue()
67 #define DPNI_NEW_FLOW_ID (u16)(-1)
70 * Tx traffic is always released to a buffer pool on transmit, there are no
71 * resources allocated to have the frames confirmed back to the source after
74 #define DPNI_OPT_TX_FRM_RELEASE 0x000001
76 * Disables support for MAC address filtering for addresses other than primary
77 * MAC address. This affects both unicast and multicast. Promiscuous mode can
78 * still be enabled/disabled for both unicast and multicast. If promiscuous mode
79 * is disabled, only traffic matching the primary MAC address will be accepted.
81 #define DPNI_OPT_NO_MAC_FILTER 0x000002
83 * Allocate policers for this DPNI. They can be used to rate-limit traffic per
84 * traffic class (TC) basis.
86 #define DPNI_OPT_HAS_POLICING 0x000004
88 * Congestion can be managed in several ways, allowing the buffer pool to
89 * deplete on ingress, taildrop on each queue or use congestion groups for sets
90 * of queues. If set, it configures a single congestion groups across all TCs.
91 * If reset, a congestion group is allocated for each TC. Only relevant if the
92 * DPNI has multiple traffic classes.
94 #define DPNI_OPT_SHARED_CONGESTION 0x000008
96 * Enables TCAM for Flow Steering and QoS look-ups. If not specified, all
97 * look-ups are exact match. Note that TCAM is not available on LS1088 and its
98 * variants. Setting this bit on these SoCs will trigger an error.
100 #define DPNI_OPT_HAS_KEY_MASKING 0x000010
102 * Disables the flow steering table.
104 #define DPNI_OPT_NO_FS 0x000020
106 int dpni_open(struct fsl_mc_io *mc_io,
111 int dpni_close(struct fsl_mc_io *mc_io,
116 * struct dpni_pools_cfg - Structure representing buffer pools configuration
117 * @num_dpbp: Number of DPBPs
118 * @pools: Array of buffer pools parameters; The number of valid entries
119 * must match 'num_dpbp' value
121 struct dpni_pools_cfg {
124 * struct pools - Buffer pools parameters
125 * @dpbp_id: DPBP object ID
126 * @buffer_size: Buffer size
127 * @backup_pool: Backup pool
133 } pools[DPNI_MAX_DPBP];
136 int dpni_set_pools(struct fsl_mc_io *mc_io,
139 const struct dpni_pools_cfg *cfg);
141 int dpni_enable(struct fsl_mc_io *mc_io,
145 int dpni_disable(struct fsl_mc_io *mc_io,
149 int dpni_is_enabled(struct fsl_mc_io *mc_io,
154 int dpni_reset(struct fsl_mc_io *mc_io,
159 * DPNI IRQ Index and Events
165 #define DPNI_IRQ_INDEX 0
167 * IRQ event - indicates a change in link state
169 #define DPNI_IRQ_EVENT_LINK_CHANGED 0x00000001
171 int dpni_set_irq_enable(struct fsl_mc_io *mc_io,
177 int dpni_get_irq_enable(struct fsl_mc_io *mc_io,
183 int dpni_set_irq_mask(struct fsl_mc_io *mc_io,
189 int dpni_get_irq_mask(struct fsl_mc_io *mc_io,
195 int dpni_get_irq_status(struct fsl_mc_io *mc_io,
201 int dpni_clear_irq_status(struct fsl_mc_io *mc_io,
208 * struct dpni_attr - Structure representing DPNI attributes
209 * @options: Any combination of the following options:
210 * DPNI_OPT_TX_FRM_RELEASE
211 * DPNI_OPT_NO_MAC_FILTER
212 * DPNI_OPT_HAS_POLICING
213 * DPNI_OPT_SHARED_CONGESTION
214 * DPNI_OPT_HAS_KEY_MASKING
216 * @num_queues: Number of Tx and Rx queues used for traffic distribution.
217 * @num_tcs: Number of traffic classes (TCs), reserved for the DPNI.
218 * @mac_filter_entries: Number of entries in the MAC address filtering table.
219 * @vlan_filter_entries: Number of entries in the VLAN address filtering table.
220 * @qos_entries: Number of entries in the QoS classification table.
221 * @fs_entries: Number of entries in the flow steering table.
222 * @qos_key_size: Size, in bytes, of the QoS look-up key. Defining a key larger
223 * than this when adding QoS entries will result in an error.
224 * @fs_key_size: Size, in bytes, of the flow steering look-up key. Defining a
225 * key larger than this when composing the hash + FS key will
226 * result in an error.
227 * @wriop_version: Version of WRIOP HW block. The 3 version values are stored
228 * on 6, 5, 5 bits respectively.
234 u8 mac_filter_entries;
235 u8 vlan_filter_entries;
243 int dpni_get_attributes(struct fsl_mc_io *mc_io,
246 struct dpni_attr *attr);
253 * Extract out of frame header error
255 #define DPNI_ERROR_EOFHE 0x00020000
259 #define DPNI_ERROR_FLE 0x00002000
261 * Frame physical error
263 #define DPNI_ERROR_FPE 0x00001000
265 * Parsing header error
267 #define DPNI_ERROR_PHE 0x00000020
269 * Parser L3 checksum error
271 #define DPNI_ERROR_L3CE 0x00000004
273 * Parser L3 checksum error
275 #define DPNI_ERROR_L4CE 0x00000001
278 * enum dpni_error_action - Defines DPNI behavior for errors
279 * @DPNI_ERROR_ACTION_DISCARD: Discard the frame
280 * @DPNI_ERROR_ACTION_CONTINUE: Continue with the normal flow
281 * @DPNI_ERROR_ACTION_SEND_TO_ERROR_QUEUE: Send the frame to the error queue
283 enum dpni_error_action {
284 DPNI_ERROR_ACTION_DISCARD = 0,
285 DPNI_ERROR_ACTION_CONTINUE = 1,
286 DPNI_ERROR_ACTION_SEND_TO_ERROR_QUEUE = 2
290 * struct dpni_error_cfg - Structure representing DPNI errors treatment
291 * @errors: Errors mask; use 'DPNI_ERROR__<X>
292 * @error_action: The desired action for the errors mask
293 * @set_frame_annotation: Set to '1' to mark the errors in frame annotation
294 * status (FAS); relevant only for the non-discard action
296 struct dpni_error_cfg {
298 enum dpni_error_action error_action;
299 int set_frame_annotation;
302 int dpni_set_errors_behavior(struct fsl_mc_io *mc_io,
305 struct dpni_error_cfg *cfg);
308 * DPNI buffer layout modification options
312 * Select to modify the time-stamp setting
314 #define DPNI_BUF_LAYOUT_OPT_TIMESTAMP 0x00000001
316 * Select to modify the parser-result setting; not applicable for Tx
318 #define DPNI_BUF_LAYOUT_OPT_PARSER_RESULT 0x00000002
320 * Select to modify the frame-status setting
322 #define DPNI_BUF_LAYOUT_OPT_FRAME_STATUS 0x00000004
324 * Select to modify the private-data-size setting
326 #define DPNI_BUF_LAYOUT_OPT_PRIVATE_DATA_SIZE 0x00000008
328 * Select to modify the data-alignment setting
330 #define DPNI_BUF_LAYOUT_OPT_DATA_ALIGN 0x00000010
332 * Select to modify the data-head-room setting
334 #define DPNI_BUF_LAYOUT_OPT_DATA_HEAD_ROOM 0x00000020
336 * Select to modify the data-tail-room setting
338 #define DPNI_BUF_LAYOUT_OPT_DATA_TAIL_ROOM 0x00000040
341 * struct dpni_buffer_layout - Structure representing DPNI buffer layout
342 * @options: Flags representing the suggested modifications to the buffer
343 * layout; Use any combination of 'DPNI_BUF_LAYOUT_OPT_<X>' flags
344 * @pass_timestamp: Pass timestamp value
345 * @pass_parser_result: Pass parser results
346 * @pass_frame_status: Pass frame status
347 * @private_data_size: Size kept for private data (in bytes)
348 * @data_align: Data alignment
349 * @data_head_room: Data head room
350 * @data_tail_room: Data tail room
352 struct dpni_buffer_layout {
355 int pass_parser_result;
356 int pass_frame_status;
357 u16 private_data_size;
364 * enum dpni_queue_type - Identifies a type of queue targeted by the command
365 * @DPNI_QUEUE_RX: Rx queue
366 * @DPNI_QUEUE_TX: Tx queue
367 * @DPNI_QUEUE_TX_CONFIRM: Tx confirmation queue
368 * @DPNI_QUEUE_RX_ERR: Rx error queue
369 */enum dpni_queue_type {
372 DPNI_QUEUE_TX_CONFIRM,
376 int dpni_get_buffer_layout(struct fsl_mc_io *mc_io,
379 enum dpni_queue_type qtype,
380 struct dpni_buffer_layout *layout);
382 int dpni_set_buffer_layout(struct fsl_mc_io *mc_io,
385 enum dpni_queue_type qtype,
386 const struct dpni_buffer_layout *layout);
389 * enum dpni_offload - Identifies a type of offload targeted by the command
390 * @DPNI_OFF_RX_L3_CSUM: Rx L3 checksum validation
391 * @DPNI_OFF_RX_L4_CSUM: Rx L4 checksum validation
392 * @DPNI_OFF_TX_L3_CSUM: Tx L3 checksum generation
393 * @DPNI_OFF_TX_L4_CSUM: Tx L4 checksum generation
402 int dpni_set_offload(struct fsl_mc_io *mc_io,
405 enum dpni_offload type,
408 int dpni_get_offload(struct fsl_mc_io *mc_io,
411 enum dpni_offload type,
414 int dpni_get_qdid(struct fsl_mc_io *mc_io,
417 enum dpni_queue_type qtype,
420 int dpni_get_tx_data_offset(struct fsl_mc_io *mc_io,
425 #define DPNI_STATISTICS_CNT 7
427 union dpni_statistics {
429 * struct page_0 - Page_0 statistics structure
430 * @ingress_all_frames: Ingress frame count
431 * @ingress_all_bytes: Ingress byte count
432 * @ingress_multicast_frames: Ingress multicast frame count
433 * @ingress_multicast_bytes: Ingress multicast byte count
434 * @ingress_broadcast_frames: Ingress broadcast frame count
435 * @ingress_broadcast_bytes: Ingress broadcast byte count
438 u64 ingress_all_frames;
439 u64 ingress_all_bytes;
440 u64 ingress_multicast_frames;
441 u64 ingress_multicast_bytes;
442 u64 ingress_broadcast_frames;
443 u64 ingress_broadcast_bytes;
446 * struct page_1 - Page_1 statistics structure
447 * @egress_all_frames: Egress frame count
448 * @egress_all_bytes: Egress byte count
449 * @egress_multicast_frames: Egress multicast frame count
450 * @egress_multicast_bytes: Egress multicast byte count
451 * @egress_broadcast_frames: Egress broadcast frame count
452 * @egress_broadcast_bytes: Egress broadcast byte count
455 u64 egress_all_frames;
456 u64 egress_all_bytes;
457 u64 egress_multicast_frames;
458 u64 egress_multicast_bytes;
459 u64 egress_broadcast_frames;
460 u64 egress_broadcast_bytes;
463 * struct page_2 - Page_2 statistics structure
464 * @ingress_filtered_frames: Ingress filtered frame count
465 * @ingress_discarded_frames: Ingress discarded frame count
466 * @ingress_nobuffer_discards: Ingress discarded frame count
467 * due to lack of buffers
468 * @egress_discarded_frames: Egress discarded frame count
469 * @egress_confirmed_frames: Egress confirmed frame count
472 u64 ingress_filtered_frames;
473 u64 ingress_discarded_frames;
474 u64 ingress_nobuffer_discards;
475 u64 egress_discarded_frames;
476 u64 egress_confirmed_frames;
479 * struct raw - raw statistics structure
482 u64 counter[DPNI_STATISTICS_CNT];
486 int dpni_get_statistics(struct fsl_mc_io *mc_io,
490 union dpni_statistics *stat);
493 * Enable auto-negotiation
495 #define DPNI_LINK_OPT_AUTONEG 0x0000000000000001ULL
497 * Enable half-duplex mode
499 #define DPNI_LINK_OPT_HALF_DUPLEX 0x0000000000000002ULL
501 * Enable pause frames
503 #define DPNI_LINK_OPT_PAUSE 0x0000000000000004ULL
505 * Enable a-symmetric pause frames
507 #define DPNI_LINK_OPT_ASYM_PAUSE 0x0000000000000008ULL
510 * struct - Structure representing DPNI link configuration
512 * @options: Mask of available options; use 'DPNI_LINK_OPT_<X>' values
514 struct dpni_link_cfg {
519 int dpni_set_link_cfg(struct fsl_mc_io *mc_io,
522 const struct dpni_link_cfg *cfg);
525 * struct dpni_link_state - Structure representing DPNI link state
527 * @options: Mask of available options; use 'DPNI_LINK_OPT_<X>' values
528 * @up: Link state; '0' for down, '1' for up
530 struct dpni_link_state {
536 int dpni_get_link_state(struct fsl_mc_io *mc_io,
539 struct dpni_link_state *state);
541 int dpni_set_max_frame_length(struct fsl_mc_io *mc_io,
544 u16 max_frame_length);
546 int dpni_get_max_frame_length(struct fsl_mc_io *mc_io,
549 u16 *max_frame_length);
551 int dpni_set_multicast_promisc(struct fsl_mc_io *mc_io,
556 int dpni_get_multicast_promisc(struct fsl_mc_io *mc_io,
561 int dpni_set_unicast_promisc(struct fsl_mc_io *mc_io,
566 int dpni_get_unicast_promisc(struct fsl_mc_io *mc_io,
571 int dpni_set_primary_mac_addr(struct fsl_mc_io *mc_io,
574 const u8 mac_addr[6]);
576 int dpni_get_primary_mac_addr(struct fsl_mc_io *mc_io,
581 int dpni_get_port_mac_addr(struct fsl_mc_io *mc_io,
586 int dpni_add_mac_addr(struct fsl_mc_io *mc_io,
589 const u8 mac_addr[6]);
591 int dpni_remove_mac_addr(struct fsl_mc_io *mc_io,
594 const u8 mac_addr[6]);
596 int dpni_clear_mac_filters(struct fsl_mc_io *mc_io,
603 * enum dpni_dist_mode - DPNI distribution mode
604 * @DPNI_DIST_MODE_NONE: No distribution
605 * @DPNI_DIST_MODE_HASH: Use hash distribution; only relevant if
606 * the 'DPNI_OPT_DIST_HASH' option was set at DPNI creation
607 * @DPNI_DIST_MODE_FS: Use explicit flow steering; only relevant if
608 * the 'DPNI_OPT_DIST_FS' option was set at DPNI creation
610 enum dpni_dist_mode {
611 DPNI_DIST_MODE_NONE = 0,
612 DPNI_DIST_MODE_HASH = 1,
613 DPNI_DIST_MODE_FS = 2
617 * enum dpni_fs_miss_action - DPNI Flow Steering miss action
618 * @DPNI_FS_MISS_DROP: In case of no-match, drop the frame
619 * @DPNI_FS_MISS_EXPLICIT_FLOWID: In case of no-match, use explicit flow-id
620 * @DPNI_FS_MISS_HASH: In case of no-match, distribute using hash
622 enum dpni_fs_miss_action {
623 DPNI_FS_MISS_DROP = 0,
624 DPNI_FS_MISS_EXPLICIT_FLOWID = 1,
625 DPNI_FS_MISS_HASH = 2
629 * struct dpni_fs_tbl_cfg - Flow Steering table configuration
630 * @miss_action: Miss action selection
631 * @default_flow_id: Used when 'miss_action = DPNI_FS_MISS_EXPLICIT_FLOWID'
633 struct dpni_fs_tbl_cfg {
634 enum dpni_fs_miss_action miss_action;
638 int dpni_prepare_key_cfg(const struct dpkg_profile_cfg *cfg,
642 * struct dpni_rx_tc_dist_cfg - Rx traffic class distribution configuration
643 * @dist_size: Set the distribution size;
644 * supported values: 1,2,3,4,6,7,8,12,14,16,24,28,32,48,56,64,96,
645 * 112,128,192,224,256,384,448,512,768,896,1024
646 * @dist_mode: Distribution mode
647 * @key_cfg_iova: I/O virtual address of 256 bytes DMA-able memory filled with
648 * the extractions to be used for the distribution key by calling
649 * dpni_prepare_key_cfg() relevant only when
650 * 'dist_mode != DPNI_DIST_MODE_NONE', otherwise it can be '0'
651 * @fs_cfg: Flow Steering table configuration; only relevant if
652 * 'dist_mode = DPNI_DIST_MODE_FS'
654 struct dpni_rx_tc_dist_cfg {
656 enum dpni_dist_mode dist_mode;
658 struct dpni_fs_tbl_cfg fs_cfg;
661 int dpni_set_rx_tc_dist(struct fsl_mc_io *mc_io,
665 const struct dpni_rx_tc_dist_cfg *cfg);
668 * enum dpni_dest - DPNI destination types
669 * @DPNI_DEST_NONE: Unassigned destination; The queue is set in parked mode and
670 * does not generate FQDAN notifications; user is expected to
671 * dequeue from the queue based on polling or other user-defined
673 * @DPNI_DEST_DPIO: The queue is set in schedule mode and generates FQDAN
674 * notifications to the specified DPIO; user is expected to dequeue
675 * from the queue only after notification is received
676 * @DPNI_DEST_DPCON: The queue is set in schedule mode and does not generate
677 * FQDAN notifications, but is connected to the specified DPCON
678 * object; user is expected to dequeue from the DPCON channel
687 * struct dpni_queue - Queue structure
688 * @user_context: User data, presented to the user along with any frames from
689 * this queue. Not relevant for Tx queues.
693 * struct destination - Destination structure
694 * @id: ID of the destination, only relevant if DEST_TYPE is > 0.
695 * Identifies either a DPIO or a DPCON object. Not relevant for
697 * @type: May be one of the following:
698 * 0 - No destination, queue can be manually queried, but will not
699 * push traffic or notifications to a DPIO;
700 * 1 - The destination is a DPIO. When traffic becomes available in
701 * the queue a FQDAN (FQ data available notification) will be
702 * generated to selected DPIO;
703 * 2 - The destination is a DPCON. The queue is associated with a
704 * DPCON object for the purpose of scheduling between multiple
705 * queues. The DPCON may be independently configured to
706 * generate notifications. Not relevant for Tx queues.
707 * @hold_active: Hold active, maintains a queue scheduled for longer
708 * in a DPIO during dequeue to reduce spread of traffic.
709 * Only relevant if queues are not affined to a single DPIO.
725 * struct dpni_queue_id - Queue identification, used for enqueue commands
727 * @fqid: FQID used for enqueueing to and/or configuration of this specific FQ
728 * @qdbin: Queueing bin, used to enqueue using QDID, DQBIN, QPRI. Only relevant
731 struct dpni_queue_id {
739 #define DPNI_QUEUE_OPT_USER_CTX 0x00000001
740 #define DPNI_QUEUE_OPT_DEST 0x00000002
741 #define DPNI_QUEUE_OPT_FLC 0x00000004
742 #define DPNI_QUEUE_OPT_HOLD_ACTIVE 0x00000008
744 int dpni_set_queue(struct fsl_mc_io *mc_io,
747 enum dpni_queue_type qtype,
751 const struct dpni_queue *queue);
753 int dpni_get_queue(struct fsl_mc_io *mc_io,
756 enum dpni_queue_type qtype,
759 struct dpni_queue *queue,
760 struct dpni_queue_id *qid);
763 * enum dpni_congestion_unit - DPNI congestion units
764 * @DPNI_CONGESTION_UNIT_BYTES: bytes units
765 * @DPNI_CONGESTION_UNIT_FRAMES: frames units
767 enum dpni_congestion_unit {
768 DPNI_CONGESTION_UNIT_BYTES = 0,
769 DPNI_CONGESTION_UNIT_FRAMES
773 * enum dpni_congestion_point - Structure representing congestion point
774 * @DPNI_CP_QUEUE: Set taildrop per queue, identified by QUEUE_TYPE, TC and
776 * @DPNI_CP_GROUP: Set taildrop per queue group. Depending on options used to
777 * define the DPNI this can be either per TC (default) or per
778 * interface (DPNI_OPT_SHARED_CONGESTION set at DPNI create).
779 * QUEUE_INDEX is ignored if this type is used.
781 enum dpni_congestion_point {
787 * struct dpni_taildrop - Structure representing the taildrop
788 * @enable: Indicates whether the taildrop is active or not.
789 * @units: Indicates the unit of THRESHOLD. Queue taildrop only supports
790 * byte units, this field is ignored and assumed = 0 if
791 * CONGESTION_POINT is 0.
792 * @threshold: Threshold value, in units identified by UNITS field. Value 0
793 * cannot be used as a valid taildrop threshold, THRESHOLD must
794 * be > 0 if the taildrop is enabled.
796 struct dpni_taildrop {
798 enum dpni_congestion_unit units;
802 int dpni_set_taildrop(struct fsl_mc_io *mc_io,
805 enum dpni_congestion_point cg_point,
806 enum dpni_queue_type q_type,
809 struct dpni_taildrop *taildrop);
811 int dpni_get_taildrop(struct fsl_mc_io *mc_io,
814 enum dpni_congestion_point cg_point,
815 enum dpni_queue_type q_type,
818 struct dpni_taildrop *taildrop);
821 * struct dpni_rule_cfg - Rule configuration for table lookup
822 * @key_iova: I/O virtual address of the key (must be in DMA-able memory)
823 * @mask_iova: I/O virtual address of the mask (must be in DMA-able memory)
824 * @key_size: key and mask size (in bytes)
826 struct dpni_rule_cfg {
832 int dpni_get_api_version(struct fsl_mc_io *mc_io,
837 #endif /* __FSL_DPNI_H */