Path: blob/main/sys/contrib/ncsw/inc/flib/fsl_fman_tgec.h
48378 views
/*1* Copyright 2008-2012 Freescale Semiconductor Inc.2*3* Redistribution and use in source and binary forms, with or without4* modification, are permitted provided that the following conditions are met:5* * Redistributions of source code must retain the above copyright6* notice, this list of conditions and the following disclaimer.7* * Redistributions in binary form must reproduce the above copyright8* notice, this list of conditions and the following disclaimer in the9* documentation and/or other materials provided with the distribution.10* * Neither the name of Freescale Semiconductor nor the11* names of its contributors may be used to endorse or promote products12* derived from this software without specific prior written permission.13*14*15* ALTERNATIVELY, this software may be distributed under the terms of the16* GNU General Public License ("GPL") as published by the Free Software17* Foundation, either version 2 of that License or (at your option) any18* later version.19*20* THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY21* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED22* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE23* DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY24* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES25* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;26* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND27* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT28* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS29* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.30*/3132#ifndef __FSL_FMAN_TGEC_H33#define __FSL_FMAN_TGEC_H3435#include "common/general.h"36#include "fsl_enet.h"373839/* Transmit Inter-Packet Gap Length Register (TX_IPG_LENGTH) */40#define TGEC_TX_IPG_LENGTH_MASK 0x000003ff4142enum tgec_counters {43E_TGEC_COUNTER_R64,44E_TGEC_COUNTER_R127,45E_TGEC_COUNTER_R255,46E_TGEC_COUNTER_R511,47E_TGEC_COUNTER_R1023,48E_TGEC_COUNTER_R1518,49E_TGEC_COUNTER_R1519X,50E_TGEC_COUNTER_TRFRG,51E_TGEC_COUNTER_TRJBR,52E_TGEC_COUNTER_RDRP,53E_TGEC_COUNTER_RALN,54E_TGEC_COUNTER_TRUND,55E_TGEC_COUNTER_TROVR,56E_TGEC_COUNTER_RXPF,57E_TGEC_COUNTER_TXPF,58E_TGEC_COUNTER_ROCT,59E_TGEC_COUNTER_RMCA,60E_TGEC_COUNTER_RBCA,61E_TGEC_COUNTER_RPKT,62E_TGEC_COUNTER_RUCA,63E_TGEC_COUNTER_RERR,64E_TGEC_COUNTER_TOCT,65E_TGEC_COUNTER_TMCA,66E_TGEC_COUNTER_TBCA,67E_TGEC_COUNTER_TUCA,68E_TGEC_COUNTER_TERR69};7071/* Command and Configuration Register (COMMAND_CONFIG) */72#define CMD_CFG_EN_TIMESTAMP 0x0010000073#define CMD_CFG_TX_ADDR_INS_SEL 0x0008000074#define CMD_CFG_NO_LEN_CHK 0x0002000075#define CMD_CFG_SEND_IDLE 0x0001000076#define CMD_CFG_RX_ER_DISC 0x0000400077#define CMD_CFG_CMD_FRM_EN 0x0000200078#define CMD_CFG_STAT_CLR 0x0000100079#define CMD_CFG_LOOPBACK_EN 0x0000040080#define CMD_CFG_TX_ADDR_INS 0x0000020081#define CMD_CFG_PAUSE_IGNORE 0x0000010082#define CMD_CFG_PAUSE_FWD 0x0000008083#define CMD_CFG_PROMIS_EN 0x0000001084#define CMD_CFG_WAN_MODE 0x0000000885#define CMD_CFG_RX_EN 0x0000000286#define CMD_CFG_TX_EN 0x000000018788/* Interrupt Mask Register (IMASK) */89#define TGEC_IMASK_MDIO_SCAN_EVENT 0x0001000090#define TGEC_IMASK_MDIO_CMD_CMPL 0x0000800091#define TGEC_IMASK_REM_FAULT 0x0000400092#define TGEC_IMASK_LOC_FAULT 0x0000200093#define TGEC_IMASK_TX_ECC_ER 0x0000100094#define TGEC_IMASK_TX_FIFO_UNFL 0x0000080095#define TGEC_IMASK_TX_FIFO_OVFL 0x0000040096#define TGEC_IMASK_TX_ER 0x0000020097#define TGEC_IMASK_RX_FIFO_OVFL 0x0000010098#define TGEC_IMASK_RX_ECC_ER 0x0000008099#define TGEC_IMASK_RX_JAB_FRM 0x00000040100#define TGEC_IMASK_RX_OVRSZ_FRM 0x00000020101#define TGEC_IMASK_RX_RUNT_FRM 0x00000010102#define TGEC_IMASK_RX_FRAG_FRM 0x00000008103#define TGEC_IMASK_RX_LEN_ER 0x00000004104#define TGEC_IMASK_RX_CRC_ER 0x00000002105#define TGEC_IMASK_RX_ALIGN_ER 0x00000001106107#define TGEC_EVENTS_MASK \108((uint32_t)(TGEC_IMASK_MDIO_SCAN_EVENT | \109TGEC_IMASK_MDIO_CMD_CMPL | \110TGEC_IMASK_REM_FAULT | \111TGEC_IMASK_LOC_FAULT | \112TGEC_IMASK_TX_ECC_ER | \113TGEC_IMASK_TX_FIFO_UNFL | \114TGEC_IMASK_TX_FIFO_OVFL | \115TGEC_IMASK_TX_ER | \116TGEC_IMASK_RX_FIFO_OVFL | \117TGEC_IMASK_RX_ECC_ER | \118TGEC_IMASK_RX_JAB_FRM | \119TGEC_IMASK_RX_OVRSZ_FRM | \120TGEC_IMASK_RX_RUNT_FRM | \121TGEC_IMASK_RX_FRAG_FRM | \122TGEC_IMASK_RX_LEN_ER | \123TGEC_IMASK_RX_CRC_ER | \124TGEC_IMASK_RX_ALIGN_ER))125126/* Hashtable Control Register (HASHTABLE_CTRL) */127#define TGEC_HASH_MCAST_SHIFT 23128#define TGEC_HASH_MCAST_EN 0x00000200129#define TGEC_HASH_ADR_MSK 0x000001ff130131#define DEFAULT_WAN_MODE_ENABLE FALSE132#define DEFAULT_PROMISCUOUS_MODE_ENABLE FALSE133#define DEFAULT_PAUSE_FORWARD_ENABLE FALSE134#define DEFAULT_PAUSE_IGNORE FALSE135#define DEFAULT_TX_ADDR_INS_ENABLE FALSE136#define DEFAULT_LOOPBACK_ENABLE FALSE137#define DEFAULT_CMD_FRAME_ENABLE FALSE138#define DEFAULT_RX_ERROR_DISCARD FALSE139#define DEFAULT_SEND_IDLE_ENABLE FALSE140#define DEFAULT_NO_LENGTH_CHECK_ENABLE TRUE141#define DEFAULT_LGTH_CHECK_NOSTDR FALSE142#define DEFAULT_TIME_STAMP_ENABLE FALSE143#define DEFAULT_TX_IPG_LENGTH 12144#define DEFAULT_MAX_FRAME_LENGTH 0x600145#define DEFAULT_PAUSE_QUANT 0xf000146147/*148* 10G memory map149*/150struct tgec_regs {151uint32_t tgec_id; /* 0x000 Controller ID */152uint32_t reserved001[1]; /* 0x004 */153uint32_t command_config; /* 0x008 Control and configuration */154uint32_t mac_addr_0; /* 0x00c Lower 32 bits of the MAC adr */155uint32_t mac_addr_1; /* 0x010 Upper 16 bits of the MAC adr */156uint32_t maxfrm; /* 0x014 Maximum frame length */157uint32_t pause_quant; /* 0x018 Pause quanta */158uint32_t rx_fifo_sections; /* 0x01c */159uint32_t tx_fifo_sections; /* 0x020 */160uint32_t rx_fifo_almost_f_e; /* 0x024 */161uint32_t tx_fifo_almost_f_e; /* 0x028 */162uint32_t hashtable_ctrl; /* 0x02c Hash table control*/163uint32_t mdio_cfg_status; /* 0x030 */164uint32_t mdio_command; /* 0x034 */165uint32_t mdio_data; /* 0x038 */166uint32_t mdio_regaddr; /* 0x03c */167uint32_t status; /* 0x040 */168uint32_t tx_ipg_len; /* 0x044 Transmitter inter-packet-gap */169uint32_t mac_addr_2; /* 0x048 Lower 32 bits of 2nd MAC adr */170uint32_t mac_addr_3; /* 0x04c Upper 16 bits of 2nd MAC adr */171uint32_t rx_fifo_ptr_rd; /* 0x050 */172uint32_t rx_fifo_ptr_wr; /* 0x054 */173uint32_t tx_fifo_ptr_rd; /* 0x058 */174uint32_t tx_fifo_ptr_wr; /* 0x05c */175uint32_t imask; /* 0x060 Interrupt mask */176uint32_t ievent; /* 0x064 Interrupt event */177uint32_t udp_port; /* 0x068 Defines a UDP Port number */178uint32_t type_1588v2; /* 0x06c Type field for 1588v2 */179uint32_t reserved070[4]; /* 0x070 */180/*10Ge Statistics Counter */181uint32_t tfrm_u; /* 80 aFramesTransmittedOK */182uint32_t tfrm_l; /* 84 aFramesTransmittedOK */183uint32_t rfrm_u; /* 88 aFramesReceivedOK */184uint32_t rfrm_l; /* 8c aFramesReceivedOK */185uint32_t rfcs_u; /* 90 aFrameCheckSequenceErrors */186uint32_t rfcs_l; /* 94 aFrameCheckSequenceErrors */187uint32_t raln_u; /* 98 aAlignmentErrors */188uint32_t raln_l; /* 9c aAlignmentErrors */189uint32_t txpf_u; /* A0 aPAUSEMACCtrlFramesTransmitted */190uint32_t txpf_l; /* A4 aPAUSEMACCtrlFramesTransmitted */191uint32_t rxpf_u; /* A8 aPAUSEMACCtrlFramesReceived */192uint32_t rxpf_l; /* Ac aPAUSEMACCtrlFramesReceived */193uint32_t rlong_u; /* B0 aFrameTooLongErrors */194uint32_t rlong_l; /* B4 aFrameTooLongErrors */195uint32_t rflr_u; /* B8 aInRangeLengthErrors */196uint32_t rflr_l; /* Bc aInRangeLengthErrors */197uint32_t tvlan_u; /* C0 VLANTransmittedOK */198uint32_t tvlan_l; /* C4 VLANTransmittedOK */199uint32_t rvlan_u; /* C8 VLANReceivedOK */200uint32_t rvlan_l; /* Cc VLANReceivedOK */201uint32_t toct_u; /* D0 ifOutOctets */202uint32_t toct_l; /* D4 ifOutOctets */203uint32_t roct_u; /* D8 ifInOctets */204uint32_t roct_l; /* Dc ifInOctets */205uint32_t ruca_u; /* E0 ifInUcastPkts */206uint32_t ruca_l; /* E4 ifInUcastPkts */207uint32_t rmca_u; /* E8 ifInMulticastPkts */208uint32_t rmca_l; /* Ec ifInMulticastPkts */209uint32_t rbca_u; /* F0 ifInBroadcastPkts */210uint32_t rbca_l; /* F4 ifInBroadcastPkts */211uint32_t terr_u; /* F8 ifOutErrors */212uint32_t terr_l; /* Fc ifOutErrors */213uint32_t reserved100[2]; /* 100-108*/214uint32_t tuca_u; /* 108 ifOutUcastPkts */215uint32_t tuca_l; /* 10c ifOutUcastPkts */216uint32_t tmca_u; /* 110 ifOutMulticastPkts */217uint32_t tmca_l; /* 114 ifOutMulticastPkts */218uint32_t tbca_u; /* 118 ifOutBroadcastPkts */219uint32_t tbca_l; /* 11c ifOutBroadcastPkts */220uint32_t rdrp_u; /* 120 etherStatsDropEvents */221uint32_t rdrp_l; /* 124 etherStatsDropEvents */222uint32_t reoct_u; /* 128 etherStatsOctets */223uint32_t reoct_l; /* 12c etherStatsOctets */224uint32_t rpkt_u; /* 130 etherStatsPkts */225uint32_t rpkt_l; /* 134 etherStatsPkts */226uint32_t trund_u; /* 138 etherStatsUndersizePkts */227uint32_t trund_l; /* 13c etherStatsUndersizePkts */228uint32_t r64_u; /* 140 etherStatsPkts64Octets */229uint32_t r64_l; /* 144 etherStatsPkts64Octets */230uint32_t r127_u; /* 148 etherStatsPkts65to127Octets */231uint32_t r127_l; /* 14c etherStatsPkts65to127Octets */232uint32_t r255_u; /* 150 etherStatsPkts128to255Octets */233uint32_t r255_l; /* 154 etherStatsPkts128to255Octets */234uint32_t r511_u; /* 158 etherStatsPkts256to511Octets */235uint32_t r511_l; /* 15c etherStatsPkts256to511Octets */236uint32_t r1023_u; /* 160 etherStatsPkts512to1023Octets */237uint32_t r1023_l; /* 164 etherStatsPkts512to1023Octets */238uint32_t r1518_u; /* 168 etherStatsPkts1024to1518Octets */239uint32_t r1518_l; /* 16c etherStatsPkts1024to1518Octets */240uint32_t r1519x_u; /* 170 etherStatsPkts1519toX */241uint32_t r1519x_l; /* 174 etherStatsPkts1519toX */242uint32_t trovr_u; /* 178 etherStatsOversizePkts */243uint32_t trovr_l; /* 17c etherStatsOversizePkts */244uint32_t trjbr_u; /* 180 etherStatsJabbers */245uint32_t trjbr_l; /* 184 etherStatsJabbers */246uint32_t trfrg_u; /* 188 etherStatsFragments */247uint32_t trfrg_l; /* 18C etherStatsFragments */248uint32_t rerr_u; /* 190 ifInErrors */249uint32_t rerr_l; /* 194 ifInErrors */250};251252/**253* struct tgec_cfg - TGEC configuration254*255* @rx_error_discard: Receive Erroneous Frame Discard Enable. When set to 1256* any frame received with an error is discarded in the257* Core and not forwarded to the Client interface.258* When set to 0 (Reset value), erroneous Frames are259* forwarded to the Client interface with ff_rx_err260* asserted.261* @pause_ignore: Ignore Pause Frame Quanta. If set to 1 received pause262* frames are ignored by the MAC. When set to 0263* (Reset value) the transmit process is stopped for the264* amount of time specified in the pause quanta received265* within a pause frame.266* @pause_forward_enable:267* Terminate / Forward Pause Frames. If set to 1 pause268* frames are forwarded to the user application. When set269* to 0 (Reset value) pause frames are terminated and270* discarded within the MAC.271* @no_length_check_enable:272* Payload Length Check Disable. When set to 0273* (Reset value), the Core checks the frame's payload274* length with the Frame Length/Type field, when set to 1275* the payload length check is disabled.276* @cmd_frame_enable: Enables reception of all command frames. When set to 1277* all Command Frames are accepted, when set to 0278* (Reset Value) only Pause Frames are accepted and all279* other Command Frames are rejected.280* @send_idle_enable: Force Idle Generation. When set to 1, the MAC281* permanently sends XGMII Idle sequences even when faults282* are received.283* @wan_mode_enable: WAN Mode Enable. Sets WAN mode (1) or LAN mode284* (0, default) of operation.285* @promiscuous_mode_enable:286* Enables MAC promiscuous operation. When set to 1, all287* frames are received without any MAC address filtering,288* when set to 0 (Reset value) Unicast Frames with a289* destination address not matching the Core MAC Address290* (MAC Address programmed in Registers MAC_ADDR_0 and291* MAC_ADDR_1 or the MAC address programmed in Registers292* MAC_ADDR_2 and MAC_ADDR_3) are rejected.293* @tx_addr_ins_enable: Set Source MAC Address on Transmit. If set to 1 the294* MAC overwrites the source MAC address received from the295* Client Interface with one of the MAC addresses. If set296* to 0 (Reset value), the source MAC address from the297* Client Interface is transmitted unmodified to the line.298* @loopback_enable: PHY Interface Loopback. When set to 1, the signal299* loop_ena is set to '1', when set to 0 (Reset value)300* the signal loop_ena is set to 0.301* @lgth_check_nostdr: The Core interprets the Length/Type field differently302* depending on the value of this Bit303* @time_stamp_enable: This bit selects between enabling and disabling the304* IEEE 1588 functionality. 1: IEEE 1588 is enabled305* 0: IEEE 1588 is disabled306* @max_frame_length: Maximum supported received frame length.307* The 10GEC MAC supports reception of any frame size up308* to 16,352 bytes (0x3FE0). Typical settings are309* 0x05EE (1,518 bytes) for standard frames.310* Default setting is 0x0600 (1,536 bytes).311* Received frames that exceed this stated maximum312* are truncated.313* @pause_quant: Pause quanta value used with transmitted pause frames.314* Each quanta represents a 512 bit-times.315* @tx_ipg_length: Transmit Inter-Packet-Gap (IPG) value. A 6-bit value:316* Depending on LAN or WAN mode of operation the value has317* the following meaning: - LAN Mode: Number of octets in318* steps of 4. Valid values are 8, 12, 16, ... 100. DIC is319* fully supported (see 10.6.1 page 49) for any setting. A320* default of 12 (reset value) must be set to conform to321* IEEE802.3ae. Warning: When set to 8, PCS layers may not322* be able to perform clock rate compensation. - WAN Mode:323* Stretch factor. Valid values are 4..15. The stretch324* factor is calculated as (value+1)*8. A default of 12325* (reset value) must be set to conform to IEEE 802.3ae326* (i.e. 13*8=104). A larger value shrinks the IPG327* (increasing bandwidth).328*329* This structure contains basic TGEC configuration and must be passed to330* fman_tgec_init() function. A default set of configuration values can be331* obtained by calling fman_tgec_defconfig().332*/333struct tgec_cfg {334bool rx_error_discard;335bool pause_ignore;336bool pause_forward_enable;337bool no_length_check_enable;338bool cmd_frame_enable;339bool send_idle_enable;340bool wan_mode_enable;341bool promiscuous_mode_enable;342bool tx_addr_ins_enable;343bool loopback_enable;344bool lgth_check_nostdr;345bool time_stamp_enable;346uint16_t max_frame_length;347uint16_t pause_quant;348uint32_t tx_ipg_length;349bool skip_fman11_workaround;350};351352353void fman_tgec_defconfig(struct tgec_cfg *cfg);354355/**356* fman_tgec_init() - Init tgec hardware block357* @regs: Pointer to tgec register block358* @cfg: tgec configuration data359* @exceptions_mask: initial exceptions mask360*361* This function initializes the tgec controller and applies its362* basic configuration.363*364* Returns: 0 if successful, an error code otherwise.365*/366367int fman_tgec_init(struct tgec_regs *regs, struct tgec_cfg *cfg,368uint32_t exception_mask);369370void fman_tgec_enable(struct tgec_regs *regs, bool apply_rx, bool apply_tx);371372void fman_tgec_disable(struct tgec_regs *regs, bool apply_rx, bool apply_tx);373374uint32_t fman_tgec_get_revision(struct tgec_regs *regs);375376void fman_tgec_set_mac_address(struct tgec_regs *regs, uint8_t *macaddr);377378void fman_tgec_set_promiscuous(struct tgec_regs *regs, bool val);379380/**381* fman_tgec_reset_stat() - Completely resets all TGEC HW counters382* @regs: Pointer to TGEC register block383*/384void fman_tgec_reset_stat(struct tgec_regs *regs);385386/**387* fman_tgec_get_counter() - Reads TGEC HW counters388* @regs: Pointer to TGEC register block389* @reg_name: Counter name according to the appropriate enum390*391* Returns: Required counter value392*/393uint64_t fman_tgec_get_counter(struct tgec_regs *regs,394enum tgec_counters reg_name);395396/**397* fman_tgec_set_hash_table() - Sets the Hashtable Control Register398* @regs: Pointer to TGEC register block399* @value: Value to be written in Hashtable Control Register400*/401void fman_tgec_set_hash_table(struct tgec_regs *regs, uint32_t value);402403/**404* fman_tgec_set_tx_pause_frames() - Sets the Pause Quanta Register405* @regs: Pointer to TGEC register block406* @pause_time: Pause quanta value used with transmitted pause frames.407* Each quanta represents a 512 bit-times408*/409void fman_tgec_set_tx_pause_frames(struct tgec_regs *regs, uint16_t pause_time);410411/**412* fman_tgec_set_rx_ignore_pause_frames() - Changes the policy WRT pause frames413* @regs: Pointer to TGEC register block414* @en: Ignore/Respond to pause frame quanta415*416* Sets the value of PAUSE_IGNORE field in the COMMAND_CONFIG Register417* 0 - MAC stops transmit process for the duration specified418* in the Pause frame quanta of a received Pause frame.419* 1 - MAC ignores received Pause frames.420*/421void fman_tgec_set_rx_ignore_pause_frames(struct tgec_regs *regs, bool en);422423/**424* fman_tgec_enable_1588_time_stamp() - change timestamp functionality425* @regs: Pointer to TGEC register block426* @en: enable/disable timestamp functionality427*428* Sets the value of EN_TIMESTAMP field in the COMMAND_CONFIG Register429* IEEE 1588 timestamp functionality control:430* 0 disabled, 1 enabled431*/432433void fman_tgec_enable_1588_time_stamp(struct tgec_regs *regs, bool en);434435uint32_t fman_tgec_get_event(struct tgec_regs *regs, uint32_t ev_mask);436437void fman_tgec_ack_event(struct tgec_regs *regs, uint32_t ev_mask);438439uint32_t fman_tgec_get_interrupt_mask(struct tgec_regs *regs);440441/**442* fman_tgec_add_addr_in_paddr() - Sets additional exact match MAC address443* @regs: Pointer to TGEC register block444* @addr_ptr: Pointer to 6-byte array containing the MAC address445*446* Sets the additional station MAC address447*/448void fman_tgec_add_addr_in_paddr(struct tgec_regs *regs, uint8_t *addr_ptr);449450void fman_tgec_clear_addr_in_paddr(struct tgec_regs *regs);451452void fman_tgec_enable_interrupt(struct tgec_regs *regs, uint32_t ev_mask);453454void fman_tgec_disable_interrupt(struct tgec_regs *regs, uint32_t ev_mask);455456void fman_tgec_reset_filter_table(struct tgec_regs *regs);457458void fman_tgec_set_hash_table_entry(struct tgec_regs *regs, uint32_t crc);459460461/**462* fman_tgec_get_max_frame_len() - Returns the maximum frame length value463* @regs: Pointer to TGEC register block464*/465uint16_t fman_tgec_get_max_frame_len(struct tgec_regs *regs);466467/**468* fman_tgec_set_erratum_tx_fifo_corruption_10gmac_a007() - Initialize the469* main tgec configuration parameters470* @regs: Pointer to TGEC register block471*472* TODO473*/474void fman_tgec_set_erratum_tx_fifo_corruption_10gmac_a007(struct tgec_regs475*regs);476477478#endif /* __FSL_FMAN_TGEC_H */479480481