/* ================================================================== >>>>>>>>>>>>>>>>>>>>>>> COPYRIGHT NOTICE <<<<<<<<<<<<<<<<<<<<<<<<< ------------------------------------------------------------------ Copyright (c) 2024-2024 by Lattice Semiconductor Corporation ALL RIGHTS RESERVED ------------------------------------------------------------------ IMPORTANT: THIS FILE IS USED BY OR GENERATED BY the LATTICE PROPELâ„¢ DEVELOPMENT SUITE, WHICH INCLUDES PROPEL BUILDER AND PROPEL SDK. Lattice grants permission to use this code pursuant to the terms of the Lattice Propel License Agreement. DISCLAIMER: LATTICE MAKES NO WARRANTIES ON THIS FILE OR ITS CONTENTS, WHETHER EXPRESSED, IMPLIED, STATUTORY, OR IN ANY PROVISION OF THE LATTICE PROPEL LICENSE AGREEMENT OR COMMUNICATION WITH LICENSEE, AND LATTICE SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. LATTICE DOES NOT WARRANT THAT THE FUNCTIONS CONTAINED HEREIN WILL MEET LICENSEE 'S REQUIREMENTS, OR THAT LICENSEE' S OPERATION OF ANY DEVICE, SOFTWARE OR SYSTEM USING THIS FILE OR ITS CONTENTS WILL BE UNINTERRUPTED OR ERROR FREE, OR THAT DEFECTS HEREIN WILL BE CORRECTED. LICENSEE ASSUMES RESPONSIBILITY FOR SELECTION OF MATERIALS TO ACHIEVE ITS INTENDED RESULTS, AND FOR THE PROPER INSTALLATION, USE, AND RESULTS OBTAINED THEREFROM. LICENSEE ASSUMES THE ENTIRE RISK OF THE FILE AND ITS CONTENTS PROVING DEFECTIVE OR FAILING TO PERFORM PROPERLY AND IN SUCH EVENT, LICENSEE SHALL ASSUME THE ENTIRE COST AND RISK OF ANY REPAIR, SERVICE, CORRECTION, OR ANY OTHER LIABILITIES OR DAMAGES CAUSED BY OR ASSOCIATED WITH THE SOFTWARE.IN NO EVENT SHALL LATTICE BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS FILE OR ITS CONTENTS, EVEN IF LATTICE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. LATTICE 'S SOLE LIABILITY, AND LICENSEE' S SOLE REMEDY, IS SET FORTH ABOVE. LATTICE DOES NOT WARRANT OR REPRESENT THAT THIS FILE, ITS CONTENTS OR USE THEREOF DOES NOT INFRINGE ON THIRD PARTIES' INTELLECTUAL PROPERTY RIGHTS, INCLUDING ANY PATENT. IT IS THE USER' S RESPONSIBILITY TO VERIFY THE USER SOFTWARE DESIGN FOR CONSISTENCY AND FUNCTIONALITY THROUGH THE USE OF FORMAL SOFTWARE VALIDATION METHODS. ------------------------------------------------------------------ ================================================================== */ #include "xg_ethernet.h" #include "xg_ethernet_hw.h" #include #include #include #define CRC_POLYNOMIAL 0x04C11DB7 /** * @brief : This API is used to write data to a specific register. * @param : base_address - base address of 10Gb Ethernet IP. * offset - offset value of a specific register. * val - value to be written into specific register. * @return : None. */ void xg_ethernet_write32(unsigned int base_address, unsigned int offset, unsigned int val) { volatile unsigned int *const reg = (unsigned int*) (base_address + offset); *reg = val; } /** * @brief : This API is used to read data to a specific register. * @param : base_address - base address of 10Gb Ethernet IP. * offset - offset value of a specific register. * @return : None. */ unsigned int xg_ethernet_read32(unsigned int base_address, unsigned int offset) { volatile unsigned int *const reg = (unsigned int*) (base_address + offset); return *reg; } /** * @brief : This API is used to initialize the base address of the 10Gb Ethernet IP base address * and pass the IP capabilities configuration for the driver. * @param : this_xg_ethernet - Handle of the xg_ethernet_instance structure. * config - Base address and IP capabilities, which are configured in Propel Builder, are assigned to the controller. * @return : Return the success or failure status based on a condition. */ int xg_ethernet_init(xg_ethernet_instance *this_xg_ethernet, xg_ethernet_config *config) { if(this_xg_ethernet == NULL || config == NULL) return FAILURE; /* Clear xg_ethernet_instance memory and make copy of configuration */ memset(this_xg_ethernet, 0, sizeof(xg_ethernet_instance)); memcpy(&this_xg_ethernet->config, config, sizeof(xg_ethernet_config)); return SUCCESS; } /** * @brief : This API is used to activate of the TX MAC and RX MAC functionalities for the 10Gb Ethernet IP. * @param : this_xg_ethernet - Handle of the xg_ethernet_instance structure. * @return : Return the success or failure status based on a condition. */ int xg_ethernet_start(xg_ethernet_instance *this_xg_ethernet) { if(this_xg_ethernet == NULL) return FAILURE; unsigned int mode_val = xg_ethernet_read32(this_xg_ethernet->config.base_address, TEN_G_MODE); mode_val |= (MODE_TX_EN | MODE_RX_EN); xg_ethernet_write32(this_xg_ethernet->config.base_address, TEN_G_MODE, mode_val); return SUCCESS; } /** * @brief : This API is used to deactivate of the TX MAC and RX MAC functionalities for the 10Gb Ethernet IP. * @param : this_xg_ethernet - Handle of the xg_ethernet_instance structure. * @return : Return the success or failure status based on a condition. */ int xg_ethernet_stop(xg_ethernet_instance *this_xg_ethernet) { if(this_xg_ethernet == NULL) return FAILURE; unsigned int mode_val = xg_ethernet_read32(this_xg_ethernet->config.base_address, TEN_G_MODE); mode_val &= ~(MODE_TX_EN | MODE_RX_EN); xg_ethernet_write32(this_xg_ethernet->config.base_address, TEN_G_MODE, mode_val); return SUCCESS; } /** * @brief : This API is used to deactivate the TX MAC and RX MAC of the 10Gb Ethernet IP, reinitialize the xg_ethernet_instance parameter with new xg_ethernet_config. * @param : this_xg_ethernet - Handle of the xg_ethernet_instance structure. * config - Base address and IP capabilities, which are configured in Propel Builder, are assigned to the controller. * @return : Return the success or failure status based on a condition. */ int xg_ethernet_reset(xg_ethernet_instance *this_xg_ethernet, xg_ethernet_config *config) { if(this_xg_ethernet == NULL || config == NULL) return FAILURE; xg_ethernet_stop(this_xg_ethernet); xg_ethernet_init(this_xg_ethernet, config); return SUCCESS; } /** * @brief : This API is used to enable the TX and RX functionalities of the * 10Gb Ethernet IP control option as well as the mac_cfg_options. * @param : this_xg_ethernet - Handle of the xg_ethernet_instance structure. * options - TX control options and RX control options. * @return : Return the success or failure status based on a condition. */ int xg_ethernet_set_mac_options(xg_ethernet_instance *this_xg_ethernet, unsigned int options) { if(this_xg_ethernet == NULL) return FAILURE; unsigned int mode_val = xg_ethernet_read32(this_xg_ethernet->config.base_address, TEN_G_MODE); unsigned char is_TX_enabled = mode_val & MODE_TX_EN; if(is_TX_enabled) return FAILURE; unsigned char is_RX_enabled = mode_val & MODE_RX_EN; if(is_RX_enabled) return FAILURE; this_xg_ethernet->mac_cfg_options |= options; unsigned int tx_ctl_val = xg_ethernet_read32(this_xg_ethernet->config.base_address, TEN_G_TX_CTL); if(this_xg_ethernet->mac_cfg_options & MAC_CFG_OPTION_TX_PASS_PREARM) tx_ctl_val |= TX_PASS_PREARM; if(this_xg_ethernet->mac_cfg_options & MAC_CFG_OPTION_TX_SHORT) tx_ctl_val |= TX_TRANSMIT_SHORT; if(this_xg_ethernet->mac_cfg_options & MAC_CFG_OPTION_TX_IPG_STRETCH) tx_ctl_val |= TX_IPG_STRETCH; if(this_xg_ethernet->mac_cfg_options & MAC_CFG_OPTION_TX_FC_EN) tx_ctl_val |= TX_FC_EN; if(this_xg_ethernet->mac_cfg_options & MAC_CFG_OPTION_TX_PASS_FCS) tx_ctl_val |= TX_PASS_FCS; xg_ethernet_write32(this_xg_ethernet->config.base_address, TEN_G_TX_CTL, tx_ctl_val); unsigned int rx_ctl_val = xg_ethernet_read32(this_xg_ethernet->config.base_address, TEN_G_RX_CTL); if(this_xg_ethernet->mac_cfg_options & MAC_CFG_OPTION_RX_PASS_REARM) rx_ctl_val |= RX_PASS_PREARM; if(this_xg_ethernet->mac_cfg_options & MAC_CFG_OPTION_DROP_MAC_CTRL) rx_ctl_val |= RX_DROP_MAC_CTRL; if(this_xg_ethernet->mac_cfg_options & MAC_CFG_OPTION_RX_SHORT) rx_ctl_val |= RX_SHORT; if(this_xg_ethernet->mac_cfg_options & MAC_CFG_OPTION_RX_BC) rx_ctl_val |= RX_BC; if(this_xg_ethernet->mac_cfg_options & MAC_CFG_OPTION_RX_ALL_MC) rx_ctl_val |= RX_ALL_MC; if(this_xg_ethernet->mac_cfg_options & MAC_CFG_OPTION_RX_PAUSE_EN) rx_ctl_val |= RX_PAUSE_EN; if(this_xg_ethernet->mac_cfg_options & MAC_CFG_OPTION_RX_PASS_FCS) rx_ctl_val |= RX_PASS_FCS; if(this_xg_ethernet->mac_cfg_options & MAC_CFG_OPTION_PRMS) rx_ctl_val |= RX_PRMS; xg_ethernet_write32(this_xg_ethernet->config.base_address, TEN_G_RX_CTL, rx_ctl_val); return SUCCESS; } /** * @brief : This API is used to disable the TX and RX functionalities of the * 10Gb Ethernet IP control option as well as the mac_cfg_options. * @param : this_xg_ethernet - Handle of the xg_ethernet_instance structure. * options - TX control options and RX control options. * @return : Return the success or failure status based on a condition. */ int xg_ethernet_clear_mac_options(xg_ethernet_instance *this_xg_ethernet, unsigned int options) { if(this_xg_ethernet == NULL) return FAILURE; this_xg_ethernet->mac_cfg_options &= ~options; unsigned int tx_ctl_val = xg_ethernet_read32(this_xg_ethernet->config.base_address, TEN_G_TX_CTL); if(~this_xg_ethernet->mac_cfg_options & MAC_CFG_OPTION_TX_PASS_PREARM) tx_ctl_val &= ~TX_PASS_PREARM; if(~this_xg_ethernet->mac_cfg_options & MAC_CFG_OPTION_TX_SHORT) tx_ctl_val &= ~TX_TRANSMIT_SHORT; if(~this_xg_ethernet->mac_cfg_options & MAC_CFG_OPTION_TX_IPG_STRETCH) tx_ctl_val &= ~TX_IPG_STRETCH; if(~this_xg_ethernet->mac_cfg_options & MAC_CFG_OPTION_TX_FC_EN) tx_ctl_val &= ~TX_FC_EN; if(~this_xg_ethernet->mac_cfg_options & MAC_CFG_OPTION_TX_PASS_FCS) tx_ctl_val &= ~TX_PASS_FCS; xg_ethernet_write32(this_xg_ethernet->config.base_address, TEN_G_TX_CTL, tx_ctl_val); unsigned int rx_ctl_val = xg_ethernet_read32(this_xg_ethernet->config.base_address, TEN_G_RX_CTL); if(!(this_xg_ethernet->mac_cfg_options & MAC_CFG_OPTION_RX_PASS_REARM)) rx_ctl_val &= ~RX_PASS_PREARM; if(!(this_xg_ethernet->mac_cfg_options & MAC_CFG_OPTION_DROP_MAC_CTRL)) rx_ctl_val &= ~RX_DROP_MAC_CTRL; if(!(this_xg_ethernet->mac_cfg_options & MAC_CFG_OPTION_RX_SHORT)) rx_ctl_val &= ~RX_SHORT; if(!(this_xg_ethernet->mac_cfg_options & MAC_CFG_OPTION_RX_BC)) rx_ctl_val &= ~RX_BC; if(!(this_xg_ethernet->mac_cfg_options & MAC_CFG_OPTION_RX_ALL_MC)) rx_ctl_val &= ~RX_ALL_MC; if(!(this_xg_ethernet->mac_cfg_options & MAC_CFG_OPTION_RX_PAUSE_EN)) rx_ctl_val &= ~RX_PAUSE_EN; if(!(this_xg_ethernet->mac_cfg_options & MAC_CFG_OPTION_RX_PASS_FCS)) rx_ctl_val &= ~RX_PASS_FCS; if(!(this_xg_ethernet->mac_cfg_options & MAC_CFG_OPTION_PRMS)) rx_ctl_val &= ~RX_PRMS; xg_ethernet_write32(this_xg_ethernet->config.base_address, TEN_G_RX_CTL, rx_ctl_val); return SUCCESS; } /** * @brief : This API is used to set the MAC address of the 10Gb Ethernet IP. * @param : this_xg_ethernet - Handle of the xg_ethernet_instance structure. * mac_address - MAC address in char[6] format. * Example: if the MAC address is AC-DE-48-00-00-80, * Arrange it in char mac_address = {AC, DE, 48, 00, 00, 80}; * @return : Return the success or failure status based on a condition. */ int xg_ethernet_set_mac_address(xg_ethernet_instance *this_xg_ethernet, char *mac_address) { if(this_xg_ethernet == NULL || mac_address == NULL) return FAILURE; unsigned int mac_addr_lo = 0; mac_addr_lo = (unsigned int) mac_address[0]; mac_addr_lo |= (unsigned int) mac_address[1] << 8; mac_addr_lo |= (unsigned int) mac_address[2] << 16; mac_addr_lo |= (unsigned int) mac_address[3] << 24; unsigned int mac_addr_hi = 0; mac_addr_hi = (unsigned int) mac_address[4]; mac_addr_hi |= (unsigned int) mac_address[5] << 8; xg_ethernet_write32(this_xg_ethernet->config.base_address, TEN_G_MAC_ADDR_0, mac_addr_lo); xg_ethernet_write32(this_xg_ethernet->config.base_address, TEN_G_MAC_ADDR_1, mac_addr_hi); return SUCCESS; } /** * @brief : This API is used to get the MAC address of the 10Gb Ethernet IP. * @param : this_xg_ethernet - Handle of the xg_ethernet_instance structure. * mac_address - MAC address in char[6] format. * Example: if the obtained mac_address = {AC, DE, 48, 00, 00, 80}, * it would be equivalent to AC-DE-48-00-00-80. * @return : Return the success or failure status based on a condition. */ int xg_ethernet_get_mac_address(xg_ethernet_instance *this_xg_ethernet, char *mac_address) { if(this_xg_ethernet == NULL || mac_address == NULL) return FAILURE; unsigned int mac_addr_lo = xg_ethernet_read32(this_xg_ethernet->config.base_address, TEN_G_MAC_ADDR_0); unsigned int mac_addr_hi = xg_ethernet_read32(this_xg_ethernet->config.base_address, TEN_G_MAC_ADDR_1); mac_address[0] = (char) mac_addr_lo; mac_address[1] = (char) (mac_addr_lo >> 8); mac_address[2] = (char) (mac_addr_lo >> 16); mac_address[3] = (char) (mac_addr_lo >> 24); mac_address[4] = (char) mac_addr_hi; mac_address[5] = (char) (mac_addr_hi >> 8); return SUCCESS; } /** * @brief : This API is used to calculate CRC from MAC address. * @param : mac_address - MAC address in char[6] format. * Example: if the MAC address is AC-DE-48-00-00-80, * Arrange it in char mac_address = {AC, DE, 48, 00, 00, 80}; * @return : Return the computed CRC value. */ int xg_ethernet_conv_mac_to_crc(char *mac_address) { unsigned int crc = 0xFFFFFFFF; int carry = 0; int addr_index, bit_pos; for (addr_index = 0; addr_index < 6; ++addr_index) { for (bit_pos = 0; bit_pos < 8; ++bit_pos) { carry = (crc >> 31)^((mac_address[addr_index] & (1 << bit_pos)) >> bit_pos); crc <<= 1; if (carry){ crc = (crc ^ CRC_POLYNOMIAL) | carry; } } } return crc; } /** * @brief : This API is used to set or clear multicast filter based on CRC value. * @param : this_xg_ethernet - Handle of the xg_ethernet_instance structure. * crc - Represents the computed CRC value derived from the MAC address. * @return : Return the success or failure status based on a condition. */ int xg_ethernet_multicast_bit_modify(xg_ethernet_instance *this_xg_ethernet, unsigned int crc, unsigned char isSet) { if(this_xg_ethernet == NULL) return FAILURE; unsigned char table_num = ((crc >> 1) & 0x3F) >> 3; unsigned char bit_pos = ((crc >> 1) & 0x3F) & 0x07; unsigned int mc_table0_val = xg_ethernet_read32(this_xg_ethernet->config.base_address, TEN_G_MC_TABLE_0); unsigned int mc_table1_val = xg_ethernet_read32(this_xg_ethernet->config.base_address, TEN_G_MC_TABLE_1); unsigned long long mc_table_val = ((unsigned long long)mc_table1_val << 32) | (unsigned long long)mc_table0_val; unsigned char mc_table_array[sizeof(unsigned long long)]; memcpy(mc_table_array, &mc_table_val, sizeof(unsigned long long)); if (isSet) { mc_table_array[table_num] |= (1 << bit_pos); } else { mc_table_array[table_num] &= ~(1 << bit_pos); } memcpy(&mc_table_val, mc_table_array, sizeof(unsigned long long)); mc_table0_val = (unsigned int) mc_table_val; mc_table1_val = (unsigned int) (mc_table_val >> 32); xg_ethernet_write32(this_xg_ethernet->config.base_address, TEN_G_MC_TABLE_0, mc_table0_val); xg_ethernet_write32(this_xg_ethernet->config.base_address, TEN_G_MC_TABLE_1, mc_table1_val); return SUCCESS; } /** * @brief : This API is used to set multicast filter based on the MAC address. * @param : this_xg_ethernet - Handle of the xg_ethernet_instance structure. * mac_address - MAC address in char[6] format. * Example: if the MAC address is AC-DE-48-00-00-80, * @return : Return the success or failure status based on a condition. */ int xg_ethernet_set_multicast_filter(xg_ethernet_instance *this_xg_ethernet, char *mac_address) { if(this_xg_ethernet == NULL || mac_address == NULL) return FAILURE; if (!(mac_address[0] & 1)) return FAILURE; unsigned int crc = xg_ethernet_conv_mac_to_crc(mac_address); xg_ethernet_multicast_bit_modify(this_xg_ethernet, crc, true); return SUCCESS; } /** * @brief : This API is used to clear multicast filter based on the MAC address. * @param : this_xg_ethernet - Handle of the xg_ethernet_instance structure. * mac_address - MAC address in char[6] format. * Example: if the MAC address is AC-DE-48-00-00-80, * @return : Return the success or failure status based on a condition. */ int xg_ethernet_clear_multicast_filter(xg_ethernet_instance *this_xg_ethernet, char *mac_address) { if(this_xg_ethernet == NULL || mac_address == NULL) return FAILURE; if (!(mac_address[0] & 1)) return FAILURE; unsigned int crc = xg_ethernet_conv_mac_to_crc(mac_address); xg_ethernet_multicast_bit_modify(this_xg_ethernet, crc, false); return SUCCESS; } /** * @brief : This API is used to get the RX VLAN tag field of the most recent tagged frame that was received. * @param : this_xg_ethernet - Handle of the xg_ethernet_instance structure. * vlan_tag - VLAN tag ID of the most recent tagged frame. * @return : Return the success or failure status based on a condition. */ int xg_ethernet_get_rx_vlan_tag(xg_ethernet_instance *this_xg_ethernet, unsigned int *vlan_tag) { if(this_xg_ethernet == NULL || vlan_tag == NULL) return FAILURE; *vlan_tag = xg_ethernet_read32(this_xg_ethernet->config.base_address, TEN_G_VLAN_TAG); return SUCCESS; } /** * @brief : This API is used to get the status of RX MAC. * @param : this_xg_ethernet - Handle of the xg_ethernet_instance structure. * rx_idle - Status of the RX MAC. * Active: 0 * Inactive: 1 * @return : Return the success or failure status based on a condition. */ int xg_ethernet_get_rx_idle(xg_ethernet_instance *this_xg_ethernet, unsigned char *rx_idle) { if(this_xg_ethernet == NULL || rx_idle == NULL) return FAILURE; unsigned int tx_rx_sts = xg_ethernet_read32(this_xg_ethernet->config.base_address, TEN_G_TX_RX_STS); *rx_idle = !!(tx_rx_sts & RX_IDLE); return SUCCESS; } /** * @brief : This API is used to get the status of TX MAC. * @param : this_xg_ethernet - Handle of the xg_ethernet_instance structure. * tx_idle - Status of the TX MAC. * Active: 0 * Inactive: 1 * @return : Return the success or failure status based on a condition. */ int xg_ethernet_get_tx_idle(xg_ethernet_instance *this_xg_ethernet, unsigned char *tx_idle) { if(this_xg_ethernet == NULL || tx_idle == NULL) return FAILURE; unsigned int tx_rx_sts = xg_ethernet_read32(this_xg_ethernet->config.base_address, TEN_G_TX_RX_STS); *tx_idle = !!(tx_rx_sts & TX_IDLE); return SUCCESS; } /** * @brief : This API is used to enable the flow control functionality of the TX MAC. * @param : this_xg_ethernet - Handle of the xg_ethernet_instance structure. * @return : Return the success or failure status based on a condition. */ int xg_ethernet_set_flow_control(xg_ethernet_instance *this_xg_ethernet) { if(this_xg_ethernet == NULL) return FAILURE; unsigned int options = MAC_CFG_OPTION_TX_FC_EN; return xg_ethernet_set_mac_options(this_xg_ethernet, options); } /** * @brief : This API is used to enable the RX MAC to receive PAUSE frame. * @param : this_xg_ethernet - Handle of the xg_ethernet_instance structure. * @return : Return the success or failure status based on a condition. */ int xg_ethernet_set_rx_pause_en(xg_ethernet_instance *this_xg_ethernet) { if(this_xg_ethernet == NULL) return FAILURE; unsigned int options = MAC_CFG_OPTION_RX_PAUSE_EN; return xg_ethernet_set_mac_options(this_xg_ethernet, options); } /** * @brief : This API is used to configure the pause time for a flow control packet (sourced by TX MAC). * @param : this_xg_ethernet - Handle of the xg_ethernet_instance structure. * pause_time - Represents a 16-bits value used for flow control packet. * @return : Return the success or failure status based on a condition. */ int xg_ethernet_set_pause_tm(xg_ethernet_instance *this_xg_ethernet, int pause_time) { if(this_xg_ethernet == NULL) return FAILURE; if((pause_time < 0) | (pause_time > (BIT(14) - 1))) return FAILURE; xg_ethernet_write32(this_xg_ethernet->config.base_address, TEN_G_PAUSE_TM, pause_time); return SUCCESS; } /** * @brief : This API is used to enable TX MAC to transmit a PAUSE frame. * @param : this_xg_ethernet - Handle of the xg_ethernet_instance structure. * @return : Return the success or failure status based on a condition. */ int xg_ethernet_tx_pause_frm(xg_ethernet_instance *this_xg_ethernet) { if(this_xg_ethernet == NULL) return FAILURE; if (!(this_xg_ethernet->config.ip_cfg_options & MAC_CFG_OPTION_TX_FC_EN)) return FAILURE; if (!(this_xg_ethernet->config.ip_cfg_options & IP_CFG_OPTION_TX_PAUSE_FRAME_GENERATION)) return FAILURE; unsigned int options = MAC_CFG_OPTION_RX_PAUSE_EN; return xg_ethernet_set_mac_options(this_xg_ethernet, options); } /** * @brief : This API is used to configure the IPG value to be used by the TX MAC. * @param : this_xg_ethernet - Handle of the xg_ethernet_instance structure. * ipg_val - Represents a 5-bits value used for inter-frame gap. * @return : Return the success or failure status based on a condition. */ int xg_ethernet_set_ipg_val(xg_ethernet_instance *this_xg_ethernet, int ipg_val) { if(this_xg_ethernet == NULL) return FAILURE; if((ipg_val < 0) | (ipg_val > (BIT(5) - 1))) return FAILURE; xg_ethernet_write32(this_xg_ethernet->config.base_address, TEN_G_IPG_VAL, ipg_val); return SUCCESS; } /** * @brief : This API is used to configure the TX MAC to operate in the IFG stretch mode to match the data rates of OC-192. * @param : this_xg_ethernet - Handle of the xg_ethernet_instance structure. * @return : Return the success or failure status based on a condition. */ int xg_ethernet_set_ipg_stretch_mode(xg_ethernet_instance *this_xg_ethernet) { if(this_xg_ethernet == NULL) return FAILURE; unsigned int options = MAC_CFG_OPTION_TX_IPG_STRETCH; return xg_ethernet_set_mac_options(this_xg_ethernet, options); } /** * @brief : This API is used to read from value from specific statistic counter register. * @param : this_xg_ethernet - Handle of the xg_ethernet_instance structure. * reg_offset - Statistic counter register offset. * counter_val - Value of statistic counter. * @return : Return the success or failure status based on a condition. */ int xg_ethernet_get_statistic_counter(xg_ethernet_instance *this_xg_ethernet, unsigned int reg_offset, unsigned long long *counter_val) { unsigned int counter_val_lo = 0; unsigned int counter_val_hi = 0; if(this_xg_ethernet == NULL || counter_val == NULL) return FAILURE; // check the offset is in valid range if(reg_offset < TX_STAT_PKT_LNGTH || reg_offset > (RX_STAT_PKT_9217_16383 + 4)) return FAILURE; if (!(this_xg_ethernet->config.ip_cfg_options & IP_CFG_OPTION_TX_STATISTICS)) { if(reg_offset >= TX_STAT_PKT_LNGTH && reg_offset <= (TX_STAT_PKT_9217_16383 + 4)) return FAILURE; } if (!(this_xg_ethernet->config.ip_cfg_options & IP_CFG_OPTION_RX_STATISTICS)) { if(reg_offset >= RX_STAT_PKT_LNGTH && reg_offset <= (RX_STAT_PKT_9217_16383 + 4)) return FAILURE; } counter_val_lo = xg_ethernet_read32(this_xg_ethernet->config.base_address, reg_offset); if(this_xg_ethernet->config.ip_cfg_options & IP_CFG_OPTION_COUNTER_WIDTH_64_BITS) { counter_val_hi = xg_ethernet_read32(this_xg_ethernet->config.base_address, reg_offset + 4); } *counter_val = (((unsigned long long)counter_val_hi) << 32) | (unsigned long long)counter_val_lo; return SUCCESS; } /** * @brief : This API is used to print the name of the statistic counter register string, along with its corresponding register value. * @param : this_xg_ethernet - Handle of the xg_ethernet_instance structure. * reg_offset - Statistic counter register offset. * @return : Return the success or failure status based on a condition. */ int xg_ethernet_print_statistic_counter(xg_ethernet_instance *this_xg_ethernet, unsigned int reg_offset) { if(this_xg_ethernet == NULL) return FAILURE; unsigned long long counter_val = 0; int error = xg_ethernet_get_statistic_counter(this_xg_ethernet, reg_offset, &counter_val); printf("statics_counter %s = %16x\r\n", xg_ethernet_reg_name_str(reg_offset), counter_val); return error; }