1*0aeed3e9SJustin Hibbits /* Copyright (c) 2008-2011 Freescale Semiconductor, Inc. 2*0aeed3e9SJustin Hibbits * All rights reserved. 3*0aeed3e9SJustin Hibbits * 4*0aeed3e9SJustin Hibbits * Redistribution and use in source and binary forms, with or without 5*0aeed3e9SJustin Hibbits * modification, are permitted provided that the following conditions are met: 6*0aeed3e9SJustin Hibbits * * Redistributions of source code must retain the above copyright 7*0aeed3e9SJustin Hibbits * notice, this list of conditions and the following disclaimer. 8*0aeed3e9SJustin Hibbits * * Redistributions in binary form must reproduce the above copyright 9*0aeed3e9SJustin Hibbits * notice, this list of conditions and the following disclaimer in the 10*0aeed3e9SJustin Hibbits * documentation and/or other materials provided with the distribution. 11*0aeed3e9SJustin Hibbits * * Neither the name of Freescale Semiconductor nor the 12*0aeed3e9SJustin Hibbits * names of its contributors may be used to endorse or promote products 13*0aeed3e9SJustin Hibbits * derived from this software without specific prior written permission. 14*0aeed3e9SJustin Hibbits * 15*0aeed3e9SJustin Hibbits * 16*0aeed3e9SJustin Hibbits * ALTERNATIVELY, this software may be distributed under the terms of the 17*0aeed3e9SJustin Hibbits * GNU General Public License ("GPL") as published by the Free Software 18*0aeed3e9SJustin Hibbits * Foundation, either version 2 of that License or (at your option) any 19*0aeed3e9SJustin Hibbits * later version. 20*0aeed3e9SJustin Hibbits * 21*0aeed3e9SJustin Hibbits * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY 22*0aeed3e9SJustin Hibbits * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23*0aeed3e9SJustin Hibbits * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24*0aeed3e9SJustin Hibbits * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY 25*0aeed3e9SJustin Hibbits * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 26*0aeed3e9SJustin Hibbits * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 27*0aeed3e9SJustin Hibbits * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 28*0aeed3e9SJustin Hibbits * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29*0aeed3e9SJustin Hibbits * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30*0aeed3e9SJustin Hibbits * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31*0aeed3e9SJustin Hibbits */ 32*0aeed3e9SJustin Hibbits 33*0aeed3e9SJustin Hibbits /****************************************************************************** 34*0aeed3e9SJustin Hibbits @File dtsec.c 35*0aeed3e9SJustin Hibbits 36*0aeed3e9SJustin Hibbits @Description FM dTSEC ... 37*0aeed3e9SJustin Hibbits *//***************************************************************************/ 38*0aeed3e9SJustin Hibbits 39*0aeed3e9SJustin Hibbits #include "std_ext.h" 40*0aeed3e9SJustin Hibbits #include "error_ext.h" 41*0aeed3e9SJustin Hibbits #include "string_ext.h" 42*0aeed3e9SJustin Hibbits #include "xx_ext.h" 43*0aeed3e9SJustin Hibbits #include "endian_ext.h" 44*0aeed3e9SJustin Hibbits #include "crc_mac_addr_ext.h" 45*0aeed3e9SJustin Hibbits #include "debug_ext.h" 46*0aeed3e9SJustin Hibbits 47*0aeed3e9SJustin Hibbits #include "fm_common.h" 48*0aeed3e9SJustin Hibbits #include "dtsec.h" 49*0aeed3e9SJustin Hibbits 50*0aeed3e9SJustin Hibbits 51*0aeed3e9SJustin Hibbits /*****************************************************************************/ 52*0aeed3e9SJustin Hibbits /* Internal routines */ 53*0aeed3e9SJustin Hibbits /*****************************************************************************/ 54*0aeed3e9SJustin Hibbits 55*0aeed3e9SJustin Hibbits static t_Error CheckInitParameters(t_Dtsec *p_Dtsec) 56*0aeed3e9SJustin Hibbits { 57*0aeed3e9SJustin Hibbits if(ENET_SPEED_FROM_MODE(p_Dtsec->enetMode) >= e_ENET_SPEED_10000) 58*0aeed3e9SJustin Hibbits RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("Ethernet 1G MAC driver only supports 1G or lower speeds")); 59*0aeed3e9SJustin Hibbits if(p_Dtsec->macId >= FM_MAX_NUM_OF_1G_MACS) 60*0aeed3e9SJustin Hibbits RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("macId can not be greater than the number of 1G MACs")); 61*0aeed3e9SJustin Hibbits if(p_Dtsec->addr == 0) 62*0aeed3e9SJustin Hibbits RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("Ethernet MAC Must have a valid MAC Address")); 63*0aeed3e9SJustin Hibbits if(((p_Dtsec->enetMode == e_ENET_MODE_SGMII_1000) || 64*0aeed3e9SJustin Hibbits (p_Dtsec->enetMode == e_ENET_MODE_RGMII_1000) || 65*0aeed3e9SJustin Hibbits (p_Dtsec->enetMode == e_ENET_MODE_QSGMII_1000)) && 66*0aeed3e9SJustin Hibbits p_Dtsec->p_DtsecDriverParam->halfDuplex) 67*0aeed3e9SJustin Hibbits RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("Ethernet MAC 1G can't work in half duplex")); 68*0aeed3e9SJustin Hibbits if(p_Dtsec->p_DtsecDriverParam->halfDuplex && (p_Dtsec->p_DtsecDriverParam)->loopback) 69*0aeed3e9SJustin Hibbits RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("LoopBack is not supported in halfDuplex mode")); 70*0aeed3e9SJustin Hibbits #ifdef FM_NO_RX_PREAM_ERRATA_DTSECx1 71*0aeed3e9SJustin Hibbits if(p_Dtsec->p_DtsecDriverParam->preambleRxEn) 72*0aeed3e9SJustin Hibbits RETURN_ERROR(MAJOR, E_NOT_SUPPORTED, ("preambleRxEn")); 73*0aeed3e9SJustin Hibbits #endif /* FM_NO_RX_PREAM_ERRATA_DTSECx1 */ 74*0aeed3e9SJustin Hibbits if(((p_Dtsec->p_DtsecDriverParam)->preambleTxEn || (p_Dtsec->p_DtsecDriverParam)->preambleRxEn) &&( (p_Dtsec->p_DtsecDriverParam)->preambleLength != 0x7)) 75*0aeed3e9SJustin Hibbits RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("Preamble length should be 0x7 bytes")); 76*0aeed3e9SJustin Hibbits if((p_Dtsec->p_DtsecDriverParam)->fifoTxWatermarkH<((p_Dtsec->p_DtsecDriverParam)->fifoTxThr+8)) 77*0aeed3e9SJustin Hibbits RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("fifoTxWatermarkH has to be at least 8 larger than fifoTxThr")); 78*0aeed3e9SJustin Hibbits if((p_Dtsec->p_DtsecDriverParam)->halfDuplex && 79*0aeed3e9SJustin Hibbits (p_Dtsec->p_DtsecDriverParam->txTimeStampEn || p_Dtsec->p_DtsecDriverParam->rxTimeStampEn)) 80*0aeed3e9SJustin Hibbits RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("dTSEC in half duplex mode has to be with 1588 timeStamping diable")); 81*0aeed3e9SJustin Hibbits if((p_Dtsec->p_DtsecDriverParam)->actOnRxPauseFrame && (p_Dtsec->p_DtsecDriverParam)->controlFrameAccept ) 82*0aeed3e9SJustin Hibbits RETURN_ERROR(MAJOR, E_INVALID_STATE, ("Receive control frame are not passed to the system memory so it can not be accept ")); 83*0aeed3e9SJustin Hibbits if((p_Dtsec->p_DtsecDriverParam)->packetAlignmentPadding > MAX_PACKET_ALIGNMENT) 84*0aeed3e9SJustin Hibbits RETURN_ERROR(MAJOR, E_INVALID_STATE, ("packetAlignmentPadding can't be greater than %d ",MAX_PACKET_ALIGNMENT )); 85*0aeed3e9SJustin Hibbits if(((p_Dtsec->p_DtsecDriverParam)->nonBackToBackIpg1 > MAX_INTER_PACKET_GAP) || 86*0aeed3e9SJustin Hibbits ((p_Dtsec->p_DtsecDriverParam)->nonBackToBackIpg2 > MAX_INTER_PACKET_GAP) || 87*0aeed3e9SJustin Hibbits ((p_Dtsec->p_DtsecDriverParam)->backToBackIpg > MAX_INTER_PACKET_GAP)) 88*0aeed3e9SJustin Hibbits RETURN_ERROR(MAJOR, E_INVALID_STATE, ("Inter packet gap can't be greater than %d ",MAX_INTER_PACKET_GAP )); 89*0aeed3e9SJustin Hibbits if((p_Dtsec->p_DtsecDriverParam)->alternateBackoffVal > MAX_INTER_PALTERNATE_BEB) 90*0aeed3e9SJustin Hibbits RETURN_ERROR(MAJOR, E_INVALID_STATE, ("alternateBackoffVal can't be greater than %d ",MAX_INTER_PALTERNATE_BEB )); 91*0aeed3e9SJustin Hibbits if((p_Dtsec->p_DtsecDriverParam)->maxRetransmission > MAX_RETRANSMISSION) 92*0aeed3e9SJustin Hibbits RETURN_ERROR(MAJOR, E_INVALID_STATE, ("maxRetransmission can't be greater than %d ",MAX_RETRANSMISSION )); 93*0aeed3e9SJustin Hibbits if((p_Dtsec->p_DtsecDriverParam)->collisionWindow > MAX_COLLISION_WINDOW) 94*0aeed3e9SJustin Hibbits RETURN_ERROR(MAJOR, E_INVALID_STATE, ("collisionWindow can't be greater than %d ",MAX_COLLISION_WINDOW )); 95*0aeed3e9SJustin Hibbits 96*0aeed3e9SJustin Hibbits /* If Auto negotiation process is disabled, need to */ 97*0aeed3e9SJustin Hibbits /* Set up the PHY using the MII Management Interface */ 98*0aeed3e9SJustin Hibbits if (p_Dtsec->p_DtsecDriverParam->tbiPhyAddr > MAX_PHYS) 99*0aeed3e9SJustin Hibbits RETURN_ERROR(MAJOR, E_NOT_IN_RANGE, ("PHY address (should be 0-%d)", MAX_PHYS)); 100*0aeed3e9SJustin Hibbits if(!p_Dtsec->f_Exception) 101*0aeed3e9SJustin Hibbits RETURN_ERROR(MAJOR, E_INVALID_HANDLE, ("uninitialized f_Exception")); 102*0aeed3e9SJustin Hibbits if(!p_Dtsec->f_Event) 103*0aeed3e9SJustin Hibbits RETURN_ERROR(MAJOR, E_INVALID_HANDLE, ("uninitialized f_Event")); 104*0aeed3e9SJustin Hibbits return E_OK; 105*0aeed3e9SJustin Hibbits } 106*0aeed3e9SJustin Hibbits 107*0aeed3e9SJustin Hibbits static uint8_t GetMiiDiv(int32_t refClk) 108*0aeed3e9SJustin Hibbits { 109*0aeed3e9SJustin Hibbits uint32_t div,tmpClk; 110*0aeed3e9SJustin Hibbits int minRange; 111*0aeed3e9SJustin Hibbits 112*0aeed3e9SJustin Hibbits div = 1; 113*0aeed3e9SJustin Hibbits minRange = (int)(refClk/40 - 1); 114*0aeed3e9SJustin Hibbits 115*0aeed3e9SJustin Hibbits tmpClk = (uint32_t)ABS(refClk/60 - 1); 116*0aeed3e9SJustin Hibbits if (tmpClk < minRange) 117*0aeed3e9SJustin Hibbits { 118*0aeed3e9SJustin Hibbits div = 2; 119*0aeed3e9SJustin Hibbits minRange = (int)tmpClk; 120*0aeed3e9SJustin Hibbits } 121*0aeed3e9SJustin Hibbits tmpClk = (uint32_t)ABS(refClk/60 - 1); 122*0aeed3e9SJustin Hibbits if (tmpClk < minRange) 123*0aeed3e9SJustin Hibbits { 124*0aeed3e9SJustin Hibbits div = 3; 125*0aeed3e9SJustin Hibbits minRange = (int)tmpClk; 126*0aeed3e9SJustin Hibbits } 127*0aeed3e9SJustin Hibbits tmpClk = (uint32_t)ABS(refClk/80 - 1); 128*0aeed3e9SJustin Hibbits if (tmpClk < minRange) 129*0aeed3e9SJustin Hibbits { 130*0aeed3e9SJustin Hibbits div = 4; 131*0aeed3e9SJustin Hibbits minRange = (int)tmpClk; 132*0aeed3e9SJustin Hibbits } 133*0aeed3e9SJustin Hibbits tmpClk = (uint32_t)ABS(refClk/100 - 1); 134*0aeed3e9SJustin Hibbits if (tmpClk < minRange) 135*0aeed3e9SJustin Hibbits { 136*0aeed3e9SJustin Hibbits div = 5; 137*0aeed3e9SJustin Hibbits minRange = (int)tmpClk; 138*0aeed3e9SJustin Hibbits } 139*0aeed3e9SJustin Hibbits tmpClk = (uint32_t)ABS(refClk/140 - 1); 140*0aeed3e9SJustin Hibbits if (tmpClk < minRange) 141*0aeed3e9SJustin Hibbits { 142*0aeed3e9SJustin Hibbits div = 6; 143*0aeed3e9SJustin Hibbits minRange = (int)tmpClk; 144*0aeed3e9SJustin Hibbits } 145*0aeed3e9SJustin Hibbits tmpClk = (uint32_t)ABS(refClk/280 - 1); 146*0aeed3e9SJustin Hibbits if (tmpClk < minRange) 147*0aeed3e9SJustin Hibbits { 148*0aeed3e9SJustin Hibbits div = 7; 149*0aeed3e9SJustin Hibbits minRange = (int)tmpClk; 150*0aeed3e9SJustin Hibbits } 151*0aeed3e9SJustin Hibbits 152*0aeed3e9SJustin Hibbits return (uint8_t)div; 153*0aeed3e9SJustin Hibbits } 154*0aeed3e9SJustin Hibbits 155*0aeed3e9SJustin Hibbits /* ........................................................................... */ 156*0aeed3e9SJustin Hibbits 157*0aeed3e9SJustin Hibbits static void SetDefaultParam(t_DtsecDriverParam *p_DtsecDriverParam) 158*0aeed3e9SJustin Hibbits { 159*0aeed3e9SJustin Hibbits p_DtsecDriverParam->errorDisabled = DEFAULT_errorDisabled; 160*0aeed3e9SJustin Hibbits 161*0aeed3e9SJustin Hibbits p_DtsecDriverParam->promiscuousEnable = DEFAULT_promiscuousEnable; 162*0aeed3e9SJustin Hibbits 163*0aeed3e9SJustin Hibbits p_DtsecDriverParam->pauseExtended = DEFAULT_pauseExtended; 164*0aeed3e9SJustin Hibbits p_DtsecDriverParam->pauseTime = DEFAULT_pauseTime; 165*0aeed3e9SJustin Hibbits 166*0aeed3e9SJustin Hibbits p_DtsecDriverParam->halfDuplex = DEFAULT_halfDuplex; 167*0aeed3e9SJustin Hibbits p_DtsecDriverParam->halfDulexFlowControlEn = DEFAULT_halfDulexFlowControlEn; 168*0aeed3e9SJustin Hibbits p_DtsecDriverParam->txTimeStampEn = DEFAULT_txTimeStampEn; 169*0aeed3e9SJustin Hibbits p_DtsecDriverParam->rxTimeStampEn = DEFAULT_rxTimeStampEn; 170*0aeed3e9SJustin Hibbits 171*0aeed3e9SJustin Hibbits p_DtsecDriverParam->packetAlignmentPadding = DEFAULT_packetAlignment; 172*0aeed3e9SJustin Hibbits p_DtsecDriverParam->controlFrameAccept = DEFAULT_controlFrameAccept; 173*0aeed3e9SJustin Hibbits p_DtsecDriverParam->groupHashExtend = DEFAULT_groupHashExtend; 174*0aeed3e9SJustin Hibbits p_DtsecDriverParam->broadcReject = DEFAULT_broadcReject; 175*0aeed3e9SJustin Hibbits p_DtsecDriverParam->rxShortFrame = DEFAULT_rxShortFrame; 176*0aeed3e9SJustin Hibbits p_DtsecDriverParam->exactMatch = DEFAULT_exactMatch; 177*0aeed3e9SJustin Hibbits p_DtsecDriverParam->debugMode = DEFAULT_debugMode; 178*0aeed3e9SJustin Hibbits 179*0aeed3e9SJustin Hibbits p_DtsecDriverParam->loopback = DEFAULT_loopback; 180*0aeed3e9SJustin Hibbits p_DtsecDriverParam->tbiPhyAddr = DEFAULT_tbiPhyAddr; 181*0aeed3e9SJustin Hibbits p_DtsecDriverParam->actOnRxPauseFrame = DEFAULT_actOnRxPauseFrame; 182*0aeed3e9SJustin Hibbits p_DtsecDriverParam->actOnTxPauseFrame = DEFAULT_actOnTxPauseFrame; 183*0aeed3e9SJustin Hibbits 184*0aeed3e9SJustin Hibbits p_DtsecDriverParam->preambleLength = DEFAULT_PreAmLength; 185*0aeed3e9SJustin Hibbits p_DtsecDriverParam->preambleRxEn = DEFAULT_PreAmRxEn; 186*0aeed3e9SJustin Hibbits p_DtsecDriverParam->preambleTxEn = DEFAULT_PreAmTxEn; 187*0aeed3e9SJustin Hibbits p_DtsecDriverParam->lengthCheckEnable = DEFAULT_lengthCheckEnable; 188*0aeed3e9SJustin Hibbits p_DtsecDriverParam->padAndCrcEnable = DEFAULT_padAndCrcEnable; 189*0aeed3e9SJustin Hibbits p_DtsecDriverParam->crcEnable = DEFAULT_crcEnable; 190*0aeed3e9SJustin Hibbits 191*0aeed3e9SJustin Hibbits p_DtsecDriverParam->nonBackToBackIpg1 = DEFAULT_nonBackToBackIpg1; 192*0aeed3e9SJustin Hibbits p_DtsecDriverParam->nonBackToBackIpg2 = DEFAULT_nonBackToBackIpg2; 193*0aeed3e9SJustin Hibbits p_DtsecDriverParam->minIfgEnforcement = DEFAULT_minIfgEnforcement; 194*0aeed3e9SJustin Hibbits p_DtsecDriverParam->backToBackIpg = DEFAULT_backToBackIpg; 195*0aeed3e9SJustin Hibbits 196*0aeed3e9SJustin Hibbits p_DtsecDriverParam->alternateBackoffVal = DEFAULT_altBackoffVal; 197*0aeed3e9SJustin Hibbits p_DtsecDriverParam->alternateBackoffEnable = DEFAULT_altBackoffEnable; 198*0aeed3e9SJustin Hibbits p_DtsecDriverParam->backPressureNoBackoff = DEFAULT_backPressureNoBackoff; 199*0aeed3e9SJustin Hibbits p_DtsecDriverParam->noBackoff = DEFAULT_noBackoff; 200*0aeed3e9SJustin Hibbits p_DtsecDriverParam->excessDefer = DEFAULT_excessDefer; 201*0aeed3e9SJustin Hibbits p_DtsecDriverParam->maxRetransmission = DEFAULT_maxRetransmission; 202*0aeed3e9SJustin Hibbits p_DtsecDriverParam->collisionWindow = DEFAULT_collisionWindow; 203*0aeed3e9SJustin Hibbits 204*0aeed3e9SJustin Hibbits p_DtsecDriverParam->maxFrameLength = DEFAULT_maxFrameLength; 205*0aeed3e9SJustin Hibbits 206*0aeed3e9SJustin Hibbits p_DtsecDriverParam->fifoTxThr = DEFAULT_fifoTxThr; 207*0aeed3e9SJustin Hibbits p_DtsecDriverParam->fifoTxWatermarkH = DEFAULT_fifoTxWatermarkH; 208*0aeed3e9SJustin Hibbits 209*0aeed3e9SJustin Hibbits p_DtsecDriverParam->fifoRxWatermarkL = DEFAULT_fifoRxWatermarkL; 210*0aeed3e9SJustin Hibbits } 211*0aeed3e9SJustin Hibbits 212*0aeed3e9SJustin Hibbits static void DtsecException(t_Handle h_Dtsec) 213*0aeed3e9SJustin Hibbits { 214*0aeed3e9SJustin Hibbits t_Dtsec *p_Dtsec = (t_Dtsec *)h_Dtsec; 215*0aeed3e9SJustin Hibbits uint32_t event; 216*0aeed3e9SJustin Hibbits t_DtsecMemMap *p_DtsecMemMap; 217*0aeed3e9SJustin Hibbits 218*0aeed3e9SJustin Hibbits ASSERT_COND(p_Dtsec); 219*0aeed3e9SJustin Hibbits p_DtsecMemMap = p_Dtsec->p_MemMap; 220*0aeed3e9SJustin Hibbits ASSERT_COND(p_DtsecMemMap); 221*0aeed3e9SJustin Hibbits 222*0aeed3e9SJustin Hibbits event = GET_UINT32(p_DtsecMemMap->ievent); 223*0aeed3e9SJustin Hibbits /* handle only MDIO events */ 224*0aeed3e9SJustin Hibbits event &= (IMASK_MMRDEN | IMASK_MMWREN); 225*0aeed3e9SJustin Hibbits if(event) 226*0aeed3e9SJustin Hibbits { 227*0aeed3e9SJustin Hibbits event &= GET_UINT32(p_DtsecMemMap->imask); 228*0aeed3e9SJustin Hibbits 229*0aeed3e9SJustin Hibbits WRITE_UINT32(p_DtsecMemMap->ievent, event); 230*0aeed3e9SJustin Hibbits 231*0aeed3e9SJustin Hibbits if(event & IMASK_MMRDEN) 232*0aeed3e9SJustin Hibbits p_Dtsec->f_Event(p_Dtsec->h_App, e_FM_MAC_EX_1G_MII_MNG_RD_COMPLET); 233*0aeed3e9SJustin Hibbits if(event & IMASK_MMWREN) 234*0aeed3e9SJustin Hibbits p_Dtsec->f_Event(p_Dtsec->h_App, e_FM_MAC_EX_1G_MII_MNG_WR_COMPLET); 235*0aeed3e9SJustin Hibbits } 236*0aeed3e9SJustin Hibbits } 237*0aeed3e9SJustin Hibbits 238*0aeed3e9SJustin Hibbits static void UpdateStatistics(t_Dtsec *p_Dtsec) 239*0aeed3e9SJustin Hibbits { 240*0aeed3e9SJustin Hibbits t_DtsecMemMap *p_DtsecMemMap = p_Dtsec->p_MemMap; 241*0aeed3e9SJustin Hibbits uint32_t car1 = GET_UINT32(p_DtsecMemMap->car1); 242*0aeed3e9SJustin Hibbits uint32_t car2 = GET_UINT32(p_DtsecMemMap->car2); 243*0aeed3e9SJustin Hibbits 244*0aeed3e9SJustin Hibbits if(car1) 245*0aeed3e9SJustin Hibbits { 246*0aeed3e9SJustin Hibbits WRITE_UINT32(p_DtsecMemMap->car1, car1); 247*0aeed3e9SJustin Hibbits if(car1 & CAR1_TR64) 248*0aeed3e9SJustin Hibbits p_Dtsec->internalStatistics.tr64 += VAL22BIT; 249*0aeed3e9SJustin Hibbits if(car1 & CAR1_TR127) 250*0aeed3e9SJustin Hibbits p_Dtsec->internalStatistics.tr127 += VAL22BIT; 251*0aeed3e9SJustin Hibbits if(car1 & CAR1_TR255) 252*0aeed3e9SJustin Hibbits p_Dtsec->internalStatistics.tr255 += VAL22BIT; 253*0aeed3e9SJustin Hibbits if(car1 & CAR1_TR511) 254*0aeed3e9SJustin Hibbits p_Dtsec->internalStatistics.tr511 += VAL22BIT; 255*0aeed3e9SJustin Hibbits if(car1 & CAR1_TRK1) 256*0aeed3e9SJustin Hibbits p_Dtsec->internalStatistics.tr1k += VAL22BIT; 257*0aeed3e9SJustin Hibbits if(car1 & CAR1_TRMAX) 258*0aeed3e9SJustin Hibbits p_Dtsec->internalStatistics.trmax += VAL22BIT; 259*0aeed3e9SJustin Hibbits if(car1 & CAR1_TRMGV) 260*0aeed3e9SJustin Hibbits p_Dtsec->internalStatistics.trmgv += VAL22BIT; 261*0aeed3e9SJustin Hibbits if(car1 & CAR1_RBYT) 262*0aeed3e9SJustin Hibbits p_Dtsec->internalStatistics.rbyt += (uint64_t)VAL32BIT; 263*0aeed3e9SJustin Hibbits if(car1 & CAR1_RPKT) 264*0aeed3e9SJustin Hibbits p_Dtsec->internalStatistics.rpkt += VAL22BIT; 265*0aeed3e9SJustin Hibbits if(car1 & CAR1_RMCA) 266*0aeed3e9SJustin Hibbits p_Dtsec->internalStatistics.rmca += VAL22BIT; 267*0aeed3e9SJustin Hibbits if(car1 & CAR1_RBCA) 268*0aeed3e9SJustin Hibbits p_Dtsec->internalStatistics.rbca += VAL22BIT; 269*0aeed3e9SJustin Hibbits if(car1 & CAR1_RXPF) 270*0aeed3e9SJustin Hibbits p_Dtsec->internalStatistics.rxpf += VAL16BIT; 271*0aeed3e9SJustin Hibbits if(car1 & CAR1_RALN) 272*0aeed3e9SJustin Hibbits p_Dtsec->internalStatistics.raln += VAL16BIT; 273*0aeed3e9SJustin Hibbits if(car1 & CAR1_RFLR) 274*0aeed3e9SJustin Hibbits p_Dtsec->internalStatistics.rflr += VAL16BIT; 275*0aeed3e9SJustin Hibbits if(car1 & CAR1_RCDE) 276*0aeed3e9SJustin Hibbits p_Dtsec->internalStatistics.rcde += VAL16BIT; 277*0aeed3e9SJustin Hibbits if(car1 & CAR1_RCSE) 278*0aeed3e9SJustin Hibbits p_Dtsec->internalStatistics.rcse += VAL16BIT; 279*0aeed3e9SJustin Hibbits if(car1 & CAR1_RUND) 280*0aeed3e9SJustin Hibbits p_Dtsec->internalStatistics.rund += VAL16BIT; 281*0aeed3e9SJustin Hibbits if(car1 & CAR1_ROVR) 282*0aeed3e9SJustin Hibbits p_Dtsec->internalStatistics.rovr += VAL16BIT; 283*0aeed3e9SJustin Hibbits if(car1 & CAR1_RFRG) 284*0aeed3e9SJustin Hibbits p_Dtsec->internalStatistics.rfrg += VAL16BIT; 285*0aeed3e9SJustin Hibbits if(car1 & CAR1_RJBR) 286*0aeed3e9SJustin Hibbits p_Dtsec->internalStatistics.rjbr += VAL16BIT; 287*0aeed3e9SJustin Hibbits if(car1 & CAR1_RDRP) 288*0aeed3e9SJustin Hibbits p_Dtsec->internalStatistics.rdrp += VAL16BIT; 289*0aeed3e9SJustin Hibbits } 290*0aeed3e9SJustin Hibbits if(car2) 291*0aeed3e9SJustin Hibbits { 292*0aeed3e9SJustin Hibbits WRITE_UINT32(p_DtsecMemMap->car2, car2); 293*0aeed3e9SJustin Hibbits if(car2 & CAR2_TFCS) 294*0aeed3e9SJustin Hibbits p_Dtsec->internalStatistics.tfcs += VAL12BIT; 295*0aeed3e9SJustin Hibbits if(car2 & CAR2_TBYT) 296*0aeed3e9SJustin Hibbits p_Dtsec->internalStatistics.tbyt += (uint64_t)VAL32BIT; 297*0aeed3e9SJustin Hibbits if(car2 & CAR2_TPKT) 298*0aeed3e9SJustin Hibbits p_Dtsec->internalStatistics.tpkt += VAL22BIT; 299*0aeed3e9SJustin Hibbits if(car2 & CAR2_TMCA) 300*0aeed3e9SJustin Hibbits p_Dtsec->internalStatistics.tmca += VAL22BIT; 301*0aeed3e9SJustin Hibbits if(car2 & CAR2_TBCA) 302*0aeed3e9SJustin Hibbits p_Dtsec->internalStatistics.tbca += VAL22BIT; 303*0aeed3e9SJustin Hibbits if(car2 & CAR2_TXPF) 304*0aeed3e9SJustin Hibbits p_Dtsec->internalStatistics.txpf += VAL16BIT; 305*0aeed3e9SJustin Hibbits if(car2 & CAR2_TDRP) 306*0aeed3e9SJustin Hibbits p_Dtsec->internalStatistics.tdrp += VAL16BIT; 307*0aeed3e9SJustin Hibbits } 308*0aeed3e9SJustin Hibbits } 309*0aeed3e9SJustin Hibbits 310*0aeed3e9SJustin Hibbits /* .............................................................................. */ 311*0aeed3e9SJustin Hibbits 312*0aeed3e9SJustin Hibbits static uint16_t DtsecGetMaxFrameLength(t_Handle h_Dtsec) 313*0aeed3e9SJustin Hibbits { 314*0aeed3e9SJustin Hibbits t_Dtsec *p_Dtsec = (t_Dtsec *)h_Dtsec; 315*0aeed3e9SJustin Hibbits 316*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_VALUE(p_Dtsec, E_INVALID_HANDLE, 0); 317*0aeed3e9SJustin Hibbits 318*0aeed3e9SJustin Hibbits return (uint16_t)GET_UINT32(p_Dtsec->p_MemMap->maxfrm); 319*0aeed3e9SJustin Hibbits } 320*0aeed3e9SJustin Hibbits 321*0aeed3e9SJustin Hibbits static void DtsecErrException(t_Handle h_Dtsec) 322*0aeed3e9SJustin Hibbits { 323*0aeed3e9SJustin Hibbits t_Dtsec *p_Dtsec = (t_Dtsec *)h_Dtsec; 324*0aeed3e9SJustin Hibbits uint32_t event; 325*0aeed3e9SJustin Hibbits t_DtsecMemMap *p_DtsecMemMap = p_Dtsec->p_MemMap; 326*0aeed3e9SJustin Hibbits 327*0aeed3e9SJustin Hibbits event = GET_UINT32(p_DtsecMemMap->ievent); 328*0aeed3e9SJustin Hibbits /* do not handle MDIO events */ 329*0aeed3e9SJustin Hibbits event &= ~(IMASK_MMRDEN | IMASK_MMWREN); 330*0aeed3e9SJustin Hibbits 331*0aeed3e9SJustin Hibbits event &= GET_UINT32(p_DtsecMemMap->imask); 332*0aeed3e9SJustin Hibbits 333*0aeed3e9SJustin Hibbits WRITE_UINT32(p_DtsecMemMap->ievent, event); 334*0aeed3e9SJustin Hibbits 335*0aeed3e9SJustin Hibbits if(event & IMASK_BREN) 336*0aeed3e9SJustin Hibbits p_Dtsec->f_Exception(p_Dtsec->h_App, e_FM_MAC_EX_1G_BAB_RX); 337*0aeed3e9SJustin Hibbits if(event & IMASK_RXCEN) 338*0aeed3e9SJustin Hibbits p_Dtsec->f_Exception(p_Dtsec->h_App, e_FM_MAC_EX_1G_RX_CTL); 339*0aeed3e9SJustin Hibbits if(event & IMASK_MSROEN) 340*0aeed3e9SJustin Hibbits UpdateStatistics(p_Dtsec); 341*0aeed3e9SJustin Hibbits if(event & IMASK_GTSCEN) 342*0aeed3e9SJustin Hibbits p_Dtsec->f_Exception(p_Dtsec->h_App, e_FM_MAC_EX_1G_GRATEFUL_TX_STP_COMPLET); 343*0aeed3e9SJustin Hibbits if(event & IMASK_BTEN) 344*0aeed3e9SJustin Hibbits p_Dtsec->f_Exception(p_Dtsec->h_App, e_FM_MAC_EX_1G_BAB_TX); 345*0aeed3e9SJustin Hibbits if(event & IMASK_TXCEN) 346*0aeed3e9SJustin Hibbits p_Dtsec->f_Exception(p_Dtsec->h_App, e_FM_MAC_EX_1G_TX_CTL); 347*0aeed3e9SJustin Hibbits if(event & IMASK_TXEEN) 348*0aeed3e9SJustin Hibbits p_Dtsec->f_Exception(p_Dtsec->h_App, e_FM_MAC_EX_1G_TX_ERR); 349*0aeed3e9SJustin Hibbits if(event & IMASK_LCEN) 350*0aeed3e9SJustin Hibbits p_Dtsec->f_Exception(p_Dtsec->h_App, e_FM_MAC_EX_1G_LATE_COL); 351*0aeed3e9SJustin Hibbits if(event & IMASK_CRLEN) 352*0aeed3e9SJustin Hibbits p_Dtsec->f_Exception(p_Dtsec->h_App, e_FM_MAC_EX_1G_COL_RET_LMT); 353*0aeed3e9SJustin Hibbits if(event & IMASK_XFUNEN) 354*0aeed3e9SJustin Hibbits { 355*0aeed3e9SJustin Hibbits #ifdef FM_TX_LOCKUP_ERRATA_DTSEC6 356*0aeed3e9SJustin Hibbits uint32_t tpkt1, tmpReg1, tpkt2, tmpReg2, i; 357*0aeed3e9SJustin Hibbits /* a. Write 0x00E0_0C00 to DTSEC_ID */ 358*0aeed3e9SJustin Hibbits /* This is a read only regidter */ 359*0aeed3e9SJustin Hibbits 360*0aeed3e9SJustin Hibbits /* b. Read and save the value of TPKT */ 361*0aeed3e9SJustin Hibbits tpkt1 = GET_UINT32(p_DtsecMemMap->tpkt); 362*0aeed3e9SJustin Hibbits 363*0aeed3e9SJustin Hibbits /* c. Read the register at dTSEC address offset 0x32C */ 364*0aeed3e9SJustin Hibbits tmpReg1 = GET_UINT32(*(uint32_t*)((uint8_t*)p_DtsecMemMap + 0x32c)); 365*0aeed3e9SJustin Hibbits 366*0aeed3e9SJustin Hibbits /* d. Compare bits [9:15] to bits [25:31] of the register at address offset 0x32C. */ 367*0aeed3e9SJustin Hibbits if((tmpReg1 & 0x007F0000) != (tmpReg1 & 0x0000007F)) 368*0aeed3e9SJustin Hibbits { 369*0aeed3e9SJustin Hibbits /* If they are not equal, save the value of this register and wait for at least 370*0aeed3e9SJustin Hibbits * MAXFRM*16 ns */ 371*0aeed3e9SJustin Hibbits XX_UDelay((uint32_t)(NCSW_MIN(DtsecGetMaxFrameLength(p_Dtsec)*16/1000, 1))); 372*0aeed3e9SJustin Hibbits } 373*0aeed3e9SJustin Hibbits 374*0aeed3e9SJustin Hibbits /* e. Read and save TPKT again and read the register at dTSEC address offset 375*0aeed3e9SJustin Hibbits 0x32C again*/ 376*0aeed3e9SJustin Hibbits tpkt2 = GET_UINT32(p_DtsecMemMap->tpkt); 377*0aeed3e9SJustin Hibbits tmpReg2 = GET_UINT32(*(uint32_t*)((uint8_t*)p_DtsecMemMap + 0x32c)); 378*0aeed3e9SJustin Hibbits 379*0aeed3e9SJustin Hibbits /* f. Compare the value of TPKT saved in step b to value read in step e. Also 380*0aeed3e9SJustin Hibbits compare bits [9:15] of the register at offset 0x32C saved in step d to the value 381*0aeed3e9SJustin Hibbits of bits [9:15] saved in step e. If the two registers values are unchanged, then 382*0aeed3e9SJustin Hibbits the transmit portion of the dTSEC controller is locked up and the user should 383*0aeed3e9SJustin Hibbits proceed to the recover sequence. */ 384*0aeed3e9SJustin Hibbits if((tpkt1 == tpkt2) && ((tmpReg1 & 0x007F0000) == (tmpReg2 & 0x007F0000))) 385*0aeed3e9SJustin Hibbits { 386*0aeed3e9SJustin Hibbits /* recover sequence */ 387*0aeed3e9SJustin Hibbits 388*0aeed3e9SJustin Hibbits /* a.Write a 1 to RCTRL[GRS]*/ 389*0aeed3e9SJustin Hibbits 390*0aeed3e9SJustin Hibbits WRITE_UINT32(p_DtsecMemMap->rctrl, GET_UINT32(p_DtsecMemMap->rctrl) | RCTRL_GRS); 391*0aeed3e9SJustin Hibbits 392*0aeed3e9SJustin Hibbits /* b.Wait until IEVENT[GRSC]=1, or at least 100 us has elapsed. */ 393*0aeed3e9SJustin Hibbits for(i = 0 ; i < 100 ; i++ ) 394*0aeed3e9SJustin Hibbits { 395*0aeed3e9SJustin Hibbits if(GET_UINT32(p_DtsecMemMap->ievent) & IMASK_GRSCEN) 396*0aeed3e9SJustin Hibbits break; 397*0aeed3e9SJustin Hibbits XX_UDelay(1); 398*0aeed3e9SJustin Hibbits } 399*0aeed3e9SJustin Hibbits if(GET_UINT32(p_DtsecMemMap->ievent) & IMASK_GRSCEN) 400*0aeed3e9SJustin Hibbits WRITE_UINT32(p_DtsecMemMap->ievent, IMASK_GRSCEN); 401*0aeed3e9SJustin Hibbits else 402*0aeed3e9SJustin Hibbits DBG(INFO,("Rx lockup due to dTSEC Tx lockup")); 403*0aeed3e9SJustin Hibbits 404*0aeed3e9SJustin Hibbits 405*0aeed3e9SJustin Hibbits /* c.Write a 1 to bit n of FM_RSTC (offset 0x0CC of FPM)*/ 406*0aeed3e9SJustin Hibbits FmResetMac(p_Dtsec->fmMacControllerDriver.h_Fm, e_FM_MAC_1G, p_Dtsec->fmMacControllerDriver.macId); 407*0aeed3e9SJustin Hibbits 408*0aeed3e9SJustin Hibbits /* d.Wait 4 Tx clocks (32 ns) */ 409*0aeed3e9SJustin Hibbits XX_UDelay(1); 410*0aeed3e9SJustin Hibbits 411*0aeed3e9SJustin Hibbits /* e.Write a 0 to bit n of FM_RSTC. */ 412*0aeed3e9SJustin Hibbits /* cleared by FMAN */ 413*0aeed3e9SJustin Hibbits } 414*0aeed3e9SJustin Hibbits else 415*0aeed3e9SJustin Hibbits { 416*0aeed3e9SJustin Hibbits /* If either value has changed, the dTSEC controller is not locked up and the 417*0aeed3e9SJustin Hibbits controller should be allowed to proceed normally by writing the reset value 418*0aeed3e9SJustin Hibbits of 0x0824_0101 to DTSEC_ID. */ 419*0aeed3e9SJustin Hibbits /* Register is read only */ 420*0aeed3e9SJustin Hibbits } 421*0aeed3e9SJustin Hibbits #endif /* FM_TX_LOCKUP_ERRATA_DTSEC6 */ 422*0aeed3e9SJustin Hibbits 423*0aeed3e9SJustin Hibbits p_Dtsec->f_Exception(p_Dtsec->h_App, e_FM_MAC_EX_1G_TX_FIFO_UNDRN); 424*0aeed3e9SJustin Hibbits } 425*0aeed3e9SJustin Hibbits if(event & IMASK_MAGEN) 426*0aeed3e9SJustin Hibbits p_Dtsec->f_Exception(p_Dtsec->h_App, e_FM_MAC_EX_1G_MAG_PCKT); 427*0aeed3e9SJustin Hibbits if(event & IMASK_GRSCEN) 428*0aeed3e9SJustin Hibbits p_Dtsec->f_Exception(p_Dtsec->h_App, e_FM_MAC_EX_1G_GRATEFUL_RX_STP_COMPLET); 429*0aeed3e9SJustin Hibbits if(event & IMASK_TDPEEN) 430*0aeed3e9SJustin Hibbits p_Dtsec->f_Exception(p_Dtsec->h_App, e_FM_MAC_EX_1G_TX_DATA_ERR); 431*0aeed3e9SJustin Hibbits if(event & IMASK_RDPEEN) 432*0aeed3e9SJustin Hibbits p_Dtsec->f_Exception(p_Dtsec->h_App, e_FM_MAC_EX_1G_RX_DATA_ERR); 433*0aeed3e9SJustin Hibbits 434*0aeed3e9SJustin Hibbits /* - masked interrupts */ 435*0aeed3e9SJustin Hibbits ASSERT_COND(!(event & IMASK_ABRTEN)); 436*0aeed3e9SJustin Hibbits ASSERT_COND(!(event & IMASK_IFERREN)); 437*0aeed3e9SJustin Hibbits } 438*0aeed3e9SJustin Hibbits 439*0aeed3e9SJustin Hibbits static void Dtsec1588Exception(t_Handle h_Dtsec) 440*0aeed3e9SJustin Hibbits { 441*0aeed3e9SJustin Hibbits t_Dtsec *p_Dtsec = (t_Dtsec *)h_Dtsec; 442*0aeed3e9SJustin Hibbits uint32_t event; 443*0aeed3e9SJustin Hibbits t_DtsecMemMap *p_DtsecMemMap = p_Dtsec->p_MemMap; 444*0aeed3e9SJustin Hibbits 445*0aeed3e9SJustin Hibbits if (p_Dtsec->ptpTsuEnabled) 446*0aeed3e9SJustin Hibbits { 447*0aeed3e9SJustin Hibbits event = GET_UINT32(p_DtsecMemMap->tmr_pevent); 448*0aeed3e9SJustin Hibbits event &= GET_UINT32(p_DtsecMemMap->tmr_pemask); 449*0aeed3e9SJustin Hibbits if(event) 450*0aeed3e9SJustin Hibbits { 451*0aeed3e9SJustin Hibbits WRITE_UINT32(p_DtsecMemMap->tmr_pevent, event); 452*0aeed3e9SJustin Hibbits ASSERT_COND(event & PEMASK_TSRE); 453*0aeed3e9SJustin Hibbits p_Dtsec->f_Exception(p_Dtsec->h_App, e_FM_MAC_EX_1G_1588_TS_RX_ERR); 454*0aeed3e9SJustin Hibbits } 455*0aeed3e9SJustin Hibbits } 456*0aeed3e9SJustin Hibbits } 457*0aeed3e9SJustin Hibbits 458*0aeed3e9SJustin Hibbits /* ........................................................................... */ 459*0aeed3e9SJustin Hibbits 460*0aeed3e9SJustin Hibbits static void FreeInitResources(t_Dtsec *p_Dtsec) 461*0aeed3e9SJustin Hibbits { 462*0aeed3e9SJustin Hibbits /*TODO - need to ask why with mdioIrq != 0*/ 463*0aeed3e9SJustin Hibbits if ((p_Dtsec->mdioIrq != 0) && (p_Dtsec->mdioIrq != NO_IRQ)) 464*0aeed3e9SJustin Hibbits { 465*0aeed3e9SJustin Hibbits XX_DisableIntr(p_Dtsec->mdioIrq); 466*0aeed3e9SJustin Hibbits XX_FreeIntr(p_Dtsec->mdioIrq); 467*0aeed3e9SJustin Hibbits } 468*0aeed3e9SJustin Hibbits else if (p_Dtsec->mdioIrq == 0) 469*0aeed3e9SJustin Hibbits FmUnregisterIntr(p_Dtsec->fmMacControllerDriver.h_Fm, e_FM_MOD_1G_MAC, p_Dtsec->macId, e_FM_INTR_TYPE_NORMAL); 470*0aeed3e9SJustin Hibbits FmUnregisterIntr(p_Dtsec->fmMacControllerDriver.h_Fm, e_FM_MOD_1G_MAC, p_Dtsec->macId, e_FM_INTR_TYPE_ERR); 471*0aeed3e9SJustin Hibbits FmUnregisterIntr(p_Dtsec->fmMacControllerDriver.h_Fm, e_FM_MOD_1G_MAC_TMR, p_Dtsec->macId, e_FM_INTR_TYPE_NORMAL); 472*0aeed3e9SJustin Hibbits 473*0aeed3e9SJustin Hibbits /* release the driver's group hash table */ 474*0aeed3e9SJustin Hibbits FreeHashTable(p_Dtsec->p_MulticastAddrHash); 475*0aeed3e9SJustin Hibbits p_Dtsec->p_MulticastAddrHash = NULL; 476*0aeed3e9SJustin Hibbits 477*0aeed3e9SJustin Hibbits /* release the driver's individual hash table */ 478*0aeed3e9SJustin Hibbits FreeHashTable(p_Dtsec->p_UnicastAddrHash); 479*0aeed3e9SJustin Hibbits p_Dtsec->p_UnicastAddrHash = NULL; 480*0aeed3e9SJustin Hibbits } 481*0aeed3e9SJustin Hibbits 482*0aeed3e9SJustin Hibbits /* ........................................................................... */ 483*0aeed3e9SJustin Hibbits 484*0aeed3e9SJustin Hibbits static void HardwareClearAddrInPaddr(t_Dtsec *p_Dtsec, uint8_t paddrNum) 485*0aeed3e9SJustin Hibbits { 486*0aeed3e9SJustin Hibbits WRITE_UINT32(((t_DtsecMemMap*)p_Dtsec->p_MemMap)->macaddr[paddrNum].exact_match1, 0x0); 487*0aeed3e9SJustin Hibbits WRITE_UINT32(((t_DtsecMemMap*)p_Dtsec->p_MemMap)->macaddr[paddrNum].exact_match2, 0x0); 488*0aeed3e9SJustin Hibbits } 489*0aeed3e9SJustin Hibbits 490*0aeed3e9SJustin Hibbits /* ........................................................................... */ 491*0aeed3e9SJustin Hibbits 492*0aeed3e9SJustin Hibbits static void HardwareAddAddrInPaddr(t_Dtsec *p_Dtsec, uint64_t *p_Addr, uint8_t paddrNum) 493*0aeed3e9SJustin Hibbits { 494*0aeed3e9SJustin Hibbits uint32_t tmpReg32 = 0; 495*0aeed3e9SJustin Hibbits uint64_t addr = *p_Addr; 496*0aeed3e9SJustin Hibbits t_DtsecMemMap *p_DtsecMemMap = (t_DtsecMemMap*)p_Dtsec->p_MemMap; 497*0aeed3e9SJustin Hibbits 498*0aeed3e9SJustin Hibbits tmpReg32 = (uint32_t)(addr); 499*0aeed3e9SJustin Hibbits SwapUint32P(&tmpReg32); 500*0aeed3e9SJustin Hibbits WRITE_UINT32(p_DtsecMemMap->macaddr[paddrNum].exact_match1, tmpReg32); 501*0aeed3e9SJustin Hibbits 502*0aeed3e9SJustin Hibbits tmpReg32 = (uint32_t)(addr>>32); 503*0aeed3e9SJustin Hibbits SwapUint32P(&tmpReg32); 504*0aeed3e9SJustin Hibbits WRITE_UINT32(p_DtsecMemMap->macaddr[paddrNum].exact_match2, tmpReg32); 505*0aeed3e9SJustin Hibbits } 506*0aeed3e9SJustin Hibbits 507*0aeed3e9SJustin Hibbits /* ........................................................................... */ 508*0aeed3e9SJustin Hibbits 509*0aeed3e9SJustin Hibbits static t_Error GracefulStop(t_Dtsec *p_Dtsec, e_CommMode mode) 510*0aeed3e9SJustin Hibbits { 511*0aeed3e9SJustin Hibbits t_DtsecMemMap *p_MemMap; 512*0aeed3e9SJustin Hibbits 513*0aeed3e9SJustin Hibbits ASSERT_COND(p_Dtsec); 514*0aeed3e9SJustin Hibbits 515*0aeed3e9SJustin Hibbits p_MemMap= (t_DtsecMemMap*)(p_Dtsec->p_MemMap); 516*0aeed3e9SJustin Hibbits ASSERT_COND(p_MemMap); 517*0aeed3e9SJustin Hibbits 518*0aeed3e9SJustin Hibbits /* Assert the graceful transmit stop bit */ 519*0aeed3e9SJustin Hibbits if (mode & e_COMM_MODE_RX) 520*0aeed3e9SJustin Hibbits WRITE_UINT32(p_MemMap->rctrl, 521*0aeed3e9SJustin Hibbits GET_UINT32(p_MemMap->rctrl) | RCTRL_GRS); 522*0aeed3e9SJustin Hibbits 523*0aeed3e9SJustin Hibbits #ifdef FM_GRS_ERRATA_DTSEC_A002 524*0aeed3e9SJustin Hibbits XX_UDelay(100); 525*0aeed3e9SJustin Hibbits #endif /* FM_GRS_ERRATA_DTSEC_A002 */ 526*0aeed3e9SJustin Hibbits 527*0aeed3e9SJustin Hibbits #ifdef FM_GTS_ERRATA_DTSEC_A004 528*0aeed3e9SJustin Hibbits DBG(INFO, ("GTS not supported due to DTSEC_A004 errata.")); 529*0aeed3e9SJustin Hibbits #else /* not FM_GTS_ERRATA_DTSEC_A004 */ 530*0aeed3e9SJustin Hibbits if (mode & e_COMM_MODE_TX) 531*0aeed3e9SJustin Hibbits WRITE_UINT32(p_MemMap->tctrl, 532*0aeed3e9SJustin Hibbits GET_UINT32(p_MemMap->tctrl) | TCTRL_GTS); 533*0aeed3e9SJustin Hibbits #endif /* not FM_GTS_ERRATA_DTSEC_A004 */ 534*0aeed3e9SJustin Hibbits 535*0aeed3e9SJustin Hibbits return E_OK; 536*0aeed3e9SJustin Hibbits } 537*0aeed3e9SJustin Hibbits 538*0aeed3e9SJustin Hibbits /* .............................................................................. */ 539*0aeed3e9SJustin Hibbits 540*0aeed3e9SJustin Hibbits static t_Error GracefulRestart(t_Dtsec *p_Dtsec, e_CommMode mode) 541*0aeed3e9SJustin Hibbits { 542*0aeed3e9SJustin Hibbits t_DtsecMemMap *p_MemMap; 543*0aeed3e9SJustin Hibbits 544*0aeed3e9SJustin Hibbits ASSERT_COND(p_Dtsec); 545*0aeed3e9SJustin Hibbits 546*0aeed3e9SJustin Hibbits p_MemMap= (t_DtsecMemMap*)(p_Dtsec->p_MemMap); 547*0aeed3e9SJustin Hibbits ASSERT_COND(p_MemMap); 548*0aeed3e9SJustin Hibbits 549*0aeed3e9SJustin Hibbits /* clear the graceful receive stop bit */ 550*0aeed3e9SJustin Hibbits if(mode & e_COMM_MODE_TX) 551*0aeed3e9SJustin Hibbits WRITE_UINT32(p_MemMap->tctrl, 552*0aeed3e9SJustin Hibbits GET_UINT32(p_MemMap->tctrl) & ~TCTRL_GTS); 553*0aeed3e9SJustin Hibbits 554*0aeed3e9SJustin Hibbits if(mode & e_COMM_MODE_RX) 555*0aeed3e9SJustin Hibbits WRITE_UINT32(p_MemMap->rctrl, 556*0aeed3e9SJustin Hibbits GET_UINT32(p_MemMap->rctrl) & ~RCTRL_GRS); 557*0aeed3e9SJustin Hibbits 558*0aeed3e9SJustin Hibbits return E_OK; 559*0aeed3e9SJustin Hibbits } 560*0aeed3e9SJustin Hibbits 561*0aeed3e9SJustin Hibbits 562*0aeed3e9SJustin Hibbits /*****************************************************************************/ 563*0aeed3e9SJustin Hibbits /* dTSEC Configs modification functions */ 564*0aeed3e9SJustin Hibbits /*****************************************************************************/ 565*0aeed3e9SJustin Hibbits 566*0aeed3e9SJustin Hibbits 567*0aeed3e9SJustin Hibbits /* .............................................................................. */ 568*0aeed3e9SJustin Hibbits 569*0aeed3e9SJustin Hibbits static t_Error DtsecConfigLoopback(t_Handle h_Dtsec, bool newVal) 570*0aeed3e9SJustin Hibbits { 571*0aeed3e9SJustin Hibbits 572*0aeed3e9SJustin Hibbits t_Dtsec *p_Dtsec = (t_Dtsec *)h_Dtsec; 573*0aeed3e9SJustin Hibbits 574*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Dtsec, E_INVALID_HANDLE); 575*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Dtsec->p_DtsecDriverParam, E_INVALID_STATE); 576*0aeed3e9SJustin Hibbits 577*0aeed3e9SJustin Hibbits p_Dtsec->p_DtsecDriverParam->loopback = newVal; 578*0aeed3e9SJustin Hibbits 579*0aeed3e9SJustin Hibbits return E_OK; 580*0aeed3e9SJustin Hibbits } 581*0aeed3e9SJustin Hibbits 582*0aeed3e9SJustin Hibbits /* .............................................................................. */ 583*0aeed3e9SJustin Hibbits 584*0aeed3e9SJustin Hibbits static t_Error DtsecConfigMaxFrameLength(t_Handle h_Dtsec, uint16_t newVal) 585*0aeed3e9SJustin Hibbits { 586*0aeed3e9SJustin Hibbits t_Dtsec *p_Dtsec = (t_Dtsec *)h_Dtsec; 587*0aeed3e9SJustin Hibbits 588*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Dtsec, E_INVALID_HANDLE); 589*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Dtsec->p_DtsecDriverParam, E_INVALID_STATE); 590*0aeed3e9SJustin Hibbits 591*0aeed3e9SJustin Hibbits p_Dtsec->p_DtsecDriverParam->maxFrameLength = newVal; 592*0aeed3e9SJustin Hibbits 593*0aeed3e9SJustin Hibbits return E_OK; 594*0aeed3e9SJustin Hibbits } 595*0aeed3e9SJustin Hibbits 596*0aeed3e9SJustin Hibbits /* .............................................................................. */ 597*0aeed3e9SJustin Hibbits 598*0aeed3e9SJustin Hibbits static t_Error DtsecConfigPadAndCrc(t_Handle h_Dtsec, bool newVal) 599*0aeed3e9SJustin Hibbits { 600*0aeed3e9SJustin Hibbits t_Dtsec *p_Dtsec = (t_Dtsec *)h_Dtsec; 601*0aeed3e9SJustin Hibbits 602*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Dtsec, E_INVALID_HANDLE); 603*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Dtsec->p_DtsecDriverParam, E_INVALID_STATE); 604*0aeed3e9SJustin Hibbits 605*0aeed3e9SJustin Hibbits p_Dtsec->p_DtsecDriverParam->padAndCrcEnable = newVal; 606*0aeed3e9SJustin Hibbits 607*0aeed3e9SJustin Hibbits return E_OK; 608*0aeed3e9SJustin Hibbits } 609*0aeed3e9SJustin Hibbits 610*0aeed3e9SJustin Hibbits /* .............................................................................. */ 611*0aeed3e9SJustin Hibbits 612*0aeed3e9SJustin Hibbits static t_Error DtsecConfigHalfDuplex(t_Handle h_Dtsec, bool newVal) 613*0aeed3e9SJustin Hibbits { 614*0aeed3e9SJustin Hibbits t_Dtsec *p_Dtsec = (t_Dtsec *)h_Dtsec; 615*0aeed3e9SJustin Hibbits 616*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Dtsec, E_INVALID_HANDLE); 617*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Dtsec->p_DtsecDriverParam, E_INVALID_STATE); 618*0aeed3e9SJustin Hibbits 619*0aeed3e9SJustin Hibbits p_Dtsec->p_DtsecDriverParam->halfDuplex = newVal; 620*0aeed3e9SJustin Hibbits 621*0aeed3e9SJustin Hibbits return E_OK; 622*0aeed3e9SJustin Hibbits } 623*0aeed3e9SJustin Hibbits 624*0aeed3e9SJustin Hibbits /* .............................................................................. */ 625*0aeed3e9SJustin Hibbits 626*0aeed3e9SJustin Hibbits static t_Error DtsecConfigLengthCheck(t_Handle h_Dtsec, bool newVal) 627*0aeed3e9SJustin Hibbits { 628*0aeed3e9SJustin Hibbits #ifdef FM_LEN_CHECK_ERRATA_FMAN_SW002 629*0aeed3e9SJustin Hibbits UNUSED(h_Dtsec); 630*0aeed3e9SJustin Hibbits RETURN_ERROR(MINOR, E_NOT_SUPPORTED, ("LengthCheck!")); 631*0aeed3e9SJustin Hibbits 632*0aeed3e9SJustin Hibbits #else 633*0aeed3e9SJustin Hibbits t_Dtsec *p_Dtsec = (t_Dtsec *)h_Dtsec; 634*0aeed3e9SJustin Hibbits 635*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Dtsec, E_INVALID_HANDLE); 636*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Dtsec->p_DtsecDriverParam, E_INVALID_STATE); 637*0aeed3e9SJustin Hibbits 638*0aeed3e9SJustin Hibbits p_Dtsec->p_DtsecDriverParam->lengthCheckEnable = newVal; 639*0aeed3e9SJustin Hibbits 640*0aeed3e9SJustin Hibbits return E_OK; 641*0aeed3e9SJustin Hibbits #endif /* FM_LEN_CHECK_ERRATA_FMAN_SW002 */ 642*0aeed3e9SJustin Hibbits } 643*0aeed3e9SJustin Hibbits 644*0aeed3e9SJustin Hibbits static t_Error DtsecConfigException(t_Handle h_Dtsec, e_FmMacExceptions exception, bool enable) 645*0aeed3e9SJustin Hibbits { 646*0aeed3e9SJustin Hibbits t_Dtsec *p_Dtsec = (t_Dtsec *)h_Dtsec; 647*0aeed3e9SJustin Hibbits uint32_t bitMask = 0; 648*0aeed3e9SJustin Hibbits 649*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Dtsec, E_INVALID_HANDLE); 650*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Dtsec->p_DtsecDriverParam, E_INVALID_STATE); 651*0aeed3e9SJustin Hibbits 652*0aeed3e9SJustin Hibbits if(exception != e_FM_MAC_EX_1G_1588_TS_RX_ERR) 653*0aeed3e9SJustin Hibbits { 654*0aeed3e9SJustin Hibbits GET_EXCEPTION_FLAG(bitMask, exception); 655*0aeed3e9SJustin Hibbits if(bitMask) 656*0aeed3e9SJustin Hibbits { 657*0aeed3e9SJustin Hibbits if (enable) 658*0aeed3e9SJustin Hibbits p_Dtsec->exceptions |= bitMask; 659*0aeed3e9SJustin Hibbits else 660*0aeed3e9SJustin Hibbits p_Dtsec->exceptions &= ~bitMask; 661*0aeed3e9SJustin Hibbits } 662*0aeed3e9SJustin Hibbits else 663*0aeed3e9SJustin Hibbits RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("Undefined exception")); 664*0aeed3e9SJustin Hibbits } 665*0aeed3e9SJustin Hibbits else 666*0aeed3e9SJustin Hibbits { 667*0aeed3e9SJustin Hibbits if(!p_Dtsec->ptpTsuEnabled) 668*0aeed3e9SJustin Hibbits RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("Exception valid for 1588 only")); 669*0aeed3e9SJustin Hibbits switch(exception){ 670*0aeed3e9SJustin Hibbits case(e_FM_MAC_EX_1G_1588_TS_RX_ERR): 671*0aeed3e9SJustin Hibbits if(enable) 672*0aeed3e9SJustin Hibbits p_Dtsec->enTsuErrExeption = TRUE; 673*0aeed3e9SJustin Hibbits else 674*0aeed3e9SJustin Hibbits p_Dtsec->enTsuErrExeption = FALSE; 675*0aeed3e9SJustin Hibbits break; 676*0aeed3e9SJustin Hibbits default: 677*0aeed3e9SJustin Hibbits RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("Undefined exception")); 678*0aeed3e9SJustin Hibbits } 679*0aeed3e9SJustin Hibbits } 680*0aeed3e9SJustin Hibbits return E_OK; 681*0aeed3e9SJustin Hibbits } 682*0aeed3e9SJustin Hibbits /*****************************************************************************/ 683*0aeed3e9SJustin Hibbits /* dTSEC Run Time API functions */ 684*0aeed3e9SJustin Hibbits /*****************************************************************************/ 685*0aeed3e9SJustin Hibbits 686*0aeed3e9SJustin Hibbits /* .............................................................................. */ 687*0aeed3e9SJustin Hibbits 688*0aeed3e9SJustin Hibbits static t_Error DtsecEnable(t_Handle h_Dtsec, e_CommMode mode) 689*0aeed3e9SJustin Hibbits { 690*0aeed3e9SJustin Hibbits t_Dtsec *p_Dtsec = (t_Dtsec *)h_Dtsec; 691*0aeed3e9SJustin Hibbits t_DtsecMemMap *p_MemMap ; 692*0aeed3e9SJustin Hibbits uint32_t tmpReg32 = 0; 693*0aeed3e9SJustin Hibbits 694*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Dtsec, E_INVALID_HANDLE); 695*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Dtsec->p_MemMap, E_INVALID_HANDLE); 696*0aeed3e9SJustin Hibbits 697*0aeed3e9SJustin Hibbits p_MemMap= (t_DtsecMemMap*)(p_Dtsec->p_MemMap); 698*0aeed3e9SJustin Hibbits 699*0aeed3e9SJustin Hibbits tmpReg32 = GET_UINT32(p_MemMap->maccfg1); 700*0aeed3e9SJustin Hibbits if (mode & e_COMM_MODE_RX) 701*0aeed3e9SJustin Hibbits tmpReg32 |= MACCFG1_RX_EN; 702*0aeed3e9SJustin Hibbits if (mode & e_COMM_MODE_TX) 703*0aeed3e9SJustin Hibbits tmpReg32 |= MACCFG1_TX_EN; 704*0aeed3e9SJustin Hibbits WRITE_UINT32(p_MemMap->maccfg1, tmpReg32); 705*0aeed3e9SJustin Hibbits 706*0aeed3e9SJustin Hibbits GracefulRestart(p_Dtsec, mode); 707*0aeed3e9SJustin Hibbits 708*0aeed3e9SJustin Hibbits return E_OK; 709*0aeed3e9SJustin Hibbits } 710*0aeed3e9SJustin Hibbits 711*0aeed3e9SJustin Hibbits /* .............................................................................. */ 712*0aeed3e9SJustin Hibbits 713*0aeed3e9SJustin Hibbits static t_Error DtsecDisable (t_Handle h_Dtsec, e_CommMode mode) 714*0aeed3e9SJustin Hibbits { 715*0aeed3e9SJustin Hibbits t_Dtsec *p_Dtsec = (t_Dtsec *)h_Dtsec; 716*0aeed3e9SJustin Hibbits t_DtsecMemMap *p_MemMap ; 717*0aeed3e9SJustin Hibbits uint32_t tmpReg32 = 0; 718*0aeed3e9SJustin Hibbits 719*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Dtsec, E_INVALID_HANDLE); 720*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Dtsec->p_MemMap, E_INVALID_HANDLE); 721*0aeed3e9SJustin Hibbits 722*0aeed3e9SJustin Hibbits p_MemMap = (t_DtsecMemMap*)(p_Dtsec->p_MemMap); 723*0aeed3e9SJustin Hibbits 724*0aeed3e9SJustin Hibbits GracefulStop(p_Dtsec, mode); 725*0aeed3e9SJustin Hibbits 726*0aeed3e9SJustin Hibbits tmpReg32 = GET_UINT32(p_MemMap->maccfg1); 727*0aeed3e9SJustin Hibbits if (mode & e_COMM_MODE_RX) 728*0aeed3e9SJustin Hibbits tmpReg32 &= ~MACCFG1_RX_EN; 729*0aeed3e9SJustin Hibbits if (mode & e_COMM_MODE_TX) 730*0aeed3e9SJustin Hibbits tmpReg32 &= ~MACCFG1_TX_EN; 731*0aeed3e9SJustin Hibbits WRITE_UINT32(p_MemMap->maccfg1, tmpReg32); 732*0aeed3e9SJustin Hibbits 733*0aeed3e9SJustin Hibbits return E_OK; 734*0aeed3e9SJustin Hibbits } 735*0aeed3e9SJustin Hibbits 736*0aeed3e9SJustin Hibbits /* .............................................................................. */ 737*0aeed3e9SJustin Hibbits 738*0aeed3e9SJustin Hibbits static t_Error DtsecTxMacPause(t_Handle h_Dtsec, uint16_t pauseTime) 739*0aeed3e9SJustin Hibbits { 740*0aeed3e9SJustin Hibbits t_Dtsec *p_Dtsec = (t_Dtsec *)h_Dtsec; 741*0aeed3e9SJustin Hibbits uint32_t ptv = 0; 742*0aeed3e9SJustin Hibbits t_DtsecMemMap *p_MemMap; 743*0aeed3e9SJustin Hibbits 744*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Dtsec, E_INVALID_STATE); 745*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(!p_Dtsec->p_DtsecDriverParam, E_INVALID_STATE); 746*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Dtsec->p_MemMap, E_INVALID_STATE); 747*0aeed3e9SJustin Hibbits 748*0aeed3e9SJustin Hibbits p_MemMap = (t_DtsecMemMap*)(p_Dtsec->p_MemMap); 749*0aeed3e9SJustin Hibbits 750*0aeed3e9SJustin Hibbits if (pauseTime) 751*0aeed3e9SJustin Hibbits { 752*0aeed3e9SJustin Hibbits #ifdef FM_BAD_TX_TS_IN_B_2_B_ERRATA_DTSEC_A003 753*0aeed3e9SJustin Hibbits { 754*0aeed3e9SJustin Hibbits if (pauseTime <= 320) 755*0aeed3e9SJustin Hibbits RETURN_ERROR(MINOR, E_INVALID_VALUE, 756*0aeed3e9SJustin Hibbits ("This pause-time value of %d is illegal due to errata dTSEC-A003!" 757*0aeed3e9SJustin Hibbits " value should be greater than 320.")); 758*0aeed3e9SJustin Hibbits } 759*0aeed3e9SJustin Hibbits #endif /* FM_BAD_TX_TS_IN_B_2_B_ERRATA_DTSEC_A003 */ 760*0aeed3e9SJustin Hibbits 761*0aeed3e9SJustin Hibbits #ifdef FM_SHORT_PAUSE_TIME_ERRATA_DTSEC1 762*0aeed3e9SJustin Hibbits { 763*0aeed3e9SJustin Hibbits t_FmRevisionInfo revInfo; 764*0aeed3e9SJustin Hibbits FM_GetRevision(p_Dtsec->fmMacControllerDriver.h_Fm, &revInfo); 765*0aeed3e9SJustin Hibbits if ((revInfo.majorRev == 1) && (revInfo.minorRev == 0)) 766*0aeed3e9SJustin Hibbits pauseTime += 2; 767*0aeed3e9SJustin Hibbits } 768*0aeed3e9SJustin Hibbits #endif /* FM_SHORT_PAUSE_TIME_ERRATA_DTSEC1 */ 769*0aeed3e9SJustin Hibbits 770*0aeed3e9SJustin Hibbits ptv = GET_UINT32(p_MemMap->ptv); 771*0aeed3e9SJustin Hibbits ptv |= pauseTime; 772*0aeed3e9SJustin Hibbits WRITE_UINT32(p_MemMap->ptv, ptv); 773*0aeed3e9SJustin Hibbits 774*0aeed3e9SJustin Hibbits /* trigger the transmission of a flow-control pause frame */ 775*0aeed3e9SJustin Hibbits WRITE_UINT32(p_MemMap->maccfg1, 776*0aeed3e9SJustin Hibbits GET_UINT32(p_MemMap->maccfg1) | MACCFG1_TX_FLOW); 777*0aeed3e9SJustin Hibbits } 778*0aeed3e9SJustin Hibbits else 779*0aeed3e9SJustin Hibbits { 780*0aeed3e9SJustin Hibbits WRITE_UINT32(p_MemMap->maccfg1, 781*0aeed3e9SJustin Hibbits GET_UINT32(p_MemMap->maccfg1) & ~MACCFG1_TX_FLOW); 782*0aeed3e9SJustin Hibbits } 783*0aeed3e9SJustin Hibbits 784*0aeed3e9SJustin Hibbits return E_OK; 785*0aeed3e9SJustin Hibbits } 786*0aeed3e9SJustin Hibbits 787*0aeed3e9SJustin Hibbits /* .............................................................................. */ 788*0aeed3e9SJustin Hibbits 789*0aeed3e9SJustin Hibbits static t_Error DtsecRxIgnoreMacPause(t_Handle h_Dtsec, bool en) 790*0aeed3e9SJustin Hibbits { 791*0aeed3e9SJustin Hibbits t_Dtsec *p_Dtsec = (t_Dtsec *)h_Dtsec; 792*0aeed3e9SJustin Hibbits t_DtsecMemMap *p_MemMap; 793*0aeed3e9SJustin Hibbits uint32_t tmpReg32; 794*0aeed3e9SJustin Hibbits 795*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Dtsec, E_INVALID_STATE); 796*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(!p_Dtsec->p_DtsecDriverParam, E_INVALID_STATE); 797*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Dtsec->p_MemMap, E_INVALID_STATE); 798*0aeed3e9SJustin Hibbits 799*0aeed3e9SJustin Hibbits p_MemMap = (t_DtsecMemMap*)(p_Dtsec->p_MemMap); 800*0aeed3e9SJustin Hibbits 801*0aeed3e9SJustin Hibbits tmpReg32 = GET_UINT32(p_MemMap->maccfg1); 802*0aeed3e9SJustin Hibbits if (en) 803*0aeed3e9SJustin Hibbits tmpReg32 &= ~MACCFG1_RX_FLOW; 804*0aeed3e9SJustin Hibbits else 805*0aeed3e9SJustin Hibbits tmpReg32 |= MACCFG1_RX_FLOW; 806*0aeed3e9SJustin Hibbits WRITE_UINT32(p_MemMap->maccfg1, tmpReg32); 807*0aeed3e9SJustin Hibbits 808*0aeed3e9SJustin Hibbits return E_OK; 809*0aeed3e9SJustin Hibbits } 810*0aeed3e9SJustin Hibbits 811*0aeed3e9SJustin Hibbits 812*0aeed3e9SJustin Hibbits /* .............................................................................. */ 813*0aeed3e9SJustin Hibbits 814*0aeed3e9SJustin Hibbits static t_Error DtsecEnable1588TimeStamp(t_Handle h_Dtsec) 815*0aeed3e9SJustin Hibbits { 816*0aeed3e9SJustin Hibbits t_Dtsec *p_Dtsec = (t_Dtsec *)h_Dtsec; 817*0aeed3e9SJustin Hibbits 818*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Dtsec, E_INVALID_HANDLE); 819*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(!p_Dtsec->p_DtsecDriverParam, E_INVALID_STATE); 820*0aeed3e9SJustin Hibbits #ifdef FM_10_100_SGMII_NO_TS_ERRATA_DTSEC3 821*0aeed3e9SJustin Hibbits if((p_Dtsec->enetMode == e_ENET_MODE_SGMII_10) || (p_Dtsec->enetMode == e_ENET_MODE_SGMII_100)) 822*0aeed3e9SJustin Hibbits RETURN_ERROR(MINOR, E_NOT_SUPPORTED, ("1588TimeStamp in 10/100 SGMII")); 823*0aeed3e9SJustin Hibbits #endif /* FM_10_100_SGMII_NO_TS_ERRATA_DTSEC3 */ 824*0aeed3e9SJustin Hibbits p_Dtsec->ptpTsuEnabled = TRUE; 825*0aeed3e9SJustin Hibbits WRITE_UINT32(p_Dtsec->p_MemMap->rctrl, GET_UINT32(p_Dtsec->p_MemMap->rctrl) | RCTRL_RTSE); 826*0aeed3e9SJustin Hibbits WRITE_UINT32(p_Dtsec->p_MemMap->tctrl, GET_UINT32(p_Dtsec->p_MemMap->tctrl) | TCTRL_TTSE); 827*0aeed3e9SJustin Hibbits 828*0aeed3e9SJustin Hibbits return E_OK; 829*0aeed3e9SJustin Hibbits } 830*0aeed3e9SJustin Hibbits 831*0aeed3e9SJustin Hibbits static t_Error DtsecDisable1588TimeStamp(t_Handle h_Dtsec) 832*0aeed3e9SJustin Hibbits { 833*0aeed3e9SJustin Hibbits t_Dtsec *p_Dtsec = (t_Dtsec *)h_Dtsec; 834*0aeed3e9SJustin Hibbits 835*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Dtsec, E_INVALID_HANDLE); 836*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(!p_Dtsec->p_DtsecDriverParam, E_INVALID_STATE); 837*0aeed3e9SJustin Hibbits 838*0aeed3e9SJustin Hibbits p_Dtsec->ptpTsuEnabled = FALSE; 839*0aeed3e9SJustin Hibbits WRITE_UINT32(p_Dtsec->p_MemMap->rctrl, GET_UINT32(p_Dtsec->p_MemMap->rctrl) & ~RCTRL_RTSE); 840*0aeed3e9SJustin Hibbits WRITE_UINT32(p_Dtsec->p_MemMap->tctrl, GET_UINT32(p_Dtsec->p_MemMap->tctrl) & ~TCTRL_TTSE); 841*0aeed3e9SJustin Hibbits 842*0aeed3e9SJustin Hibbits return E_OK; 843*0aeed3e9SJustin Hibbits } 844*0aeed3e9SJustin Hibbits 845*0aeed3e9SJustin Hibbits /* .............................................................................. */ 846*0aeed3e9SJustin Hibbits 847*0aeed3e9SJustin Hibbits static t_Error DtsecGetStatistics(t_Handle h_Dtsec, t_FmMacStatistics *p_Statistics) 848*0aeed3e9SJustin Hibbits { 849*0aeed3e9SJustin Hibbits t_Dtsec *p_Dtsec = (t_Dtsec *)h_Dtsec; 850*0aeed3e9SJustin Hibbits t_DtsecMemMap *p_DtsecMemMap; 851*0aeed3e9SJustin Hibbits 852*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Dtsec, E_INVALID_HANDLE); 853*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Dtsec->p_MemMap, E_NULL_POINTER); 854*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Statistics, E_NULL_POINTER); 855*0aeed3e9SJustin Hibbits 856*0aeed3e9SJustin Hibbits if (p_Dtsec->statisticsLevel == e_FM_MAC_NONE_STATISTICS) 857*0aeed3e9SJustin Hibbits RETURN_ERROR(MINOR, E_INVALID_STATE, ("Statistics disabled")); 858*0aeed3e9SJustin Hibbits 859*0aeed3e9SJustin Hibbits p_DtsecMemMap = p_Dtsec->p_MemMap; 860*0aeed3e9SJustin Hibbits memset(p_Statistics, 0xff, sizeof(t_FmMacStatistics)); 861*0aeed3e9SJustin Hibbits 862*0aeed3e9SJustin Hibbits if (p_Dtsec->statisticsLevel == e_FM_MAC_FULL_STATISTICS) 863*0aeed3e9SJustin Hibbits { 864*0aeed3e9SJustin Hibbits p_Statistics->eStatPkts64 = (MASK22BIT & GET_UINT32(p_DtsecMemMap->tr64)) 865*0aeed3e9SJustin Hibbits + p_Dtsec->internalStatistics.tr64; /**< r-10G tr-DT 64 byte frame counter */ 866*0aeed3e9SJustin Hibbits p_Statistics->eStatPkts65to127 = (MASK22BIT & GET_UINT32(p_DtsecMemMap->tr127)) 867*0aeed3e9SJustin Hibbits + p_Dtsec->internalStatistics.tr127; /**< r-10G 65 to 127 byte frame counter */ 868*0aeed3e9SJustin Hibbits p_Statistics->eStatPkts128to255 = (MASK22BIT & GET_UINT32(p_DtsecMemMap->tr255)) 869*0aeed3e9SJustin Hibbits + p_Dtsec->internalStatistics.tr255; /**< r-10G 128 to 255 byte frame counter */ 870*0aeed3e9SJustin Hibbits p_Statistics->eStatPkts256to511 = (MASK22BIT & GET_UINT32(p_DtsecMemMap->tr511)) 871*0aeed3e9SJustin Hibbits + p_Dtsec->internalStatistics.tr511; /**< r-10G 256 to 511 byte frame counter */ 872*0aeed3e9SJustin Hibbits p_Statistics->eStatPkts512to1023 = (MASK22BIT & GET_UINT32(p_DtsecMemMap->tr1k)) 873*0aeed3e9SJustin Hibbits + p_Dtsec->internalStatistics.tr1k; /**< r-10G 512 to 1023 byte frame counter */ 874*0aeed3e9SJustin Hibbits p_Statistics->eStatPkts1024to1518 = (MASK22BIT & GET_UINT32(p_DtsecMemMap->trmax)) 875*0aeed3e9SJustin Hibbits + p_Dtsec->internalStatistics.trmax; /**< r-10G 1024 to 1518 byte frame counter */ 876*0aeed3e9SJustin Hibbits p_Statistics->eStatPkts1519to1522 = (MASK22BIT & GET_UINT32(p_DtsecMemMap->trmgv)) 877*0aeed3e9SJustin Hibbits + p_Dtsec->internalStatistics.trmgv; /**< r-10G 1519 to 1522 byte good frame count */ 878*0aeed3e9SJustin Hibbits /* MIB II */ 879*0aeed3e9SJustin Hibbits p_Statistics->ifInOctets = GET_UINT32(p_DtsecMemMap->rbyt) 880*0aeed3e9SJustin Hibbits + p_Dtsec->internalStatistics.rbyt; /**< Total number of byte received. */ 881*0aeed3e9SJustin Hibbits p_Statistics->ifInPkts = (MASK22BIT & GET_UINT32(p_DtsecMemMap->rpkt)) 882*0aeed3e9SJustin Hibbits + p_Dtsec->internalStatistics.rpkt; /**< Total number of packets received.*/ 883*0aeed3e9SJustin Hibbits p_Statistics->ifInMcastPkts = (MASK22BIT & GET_UINT32(p_DtsecMemMap->rmca)) 884*0aeed3e9SJustin Hibbits + p_Dtsec->internalStatistics.rmca; /**< Total number of multicast frame received*/ 885*0aeed3e9SJustin Hibbits p_Statistics->ifInBcastPkts = (MASK22BIT & GET_UINT32(p_DtsecMemMap->rbca)) 886*0aeed3e9SJustin Hibbits + p_Dtsec->internalStatistics.rbca; /**< Total number of broadcast frame received */ 887*0aeed3e9SJustin Hibbits p_Statistics->ifOutOctets = GET_UINT32(p_DtsecMemMap->tbyt) 888*0aeed3e9SJustin Hibbits + p_Dtsec->internalStatistics.tbyt; /**< Total number of byte sent. */ 889*0aeed3e9SJustin Hibbits p_Statistics->ifOutPkts = (MASK22BIT & GET_UINT32(p_DtsecMemMap->tpkt)) 890*0aeed3e9SJustin Hibbits + p_Dtsec->internalStatistics.tpkt; /**< Total number of packets sent .*/ 891*0aeed3e9SJustin Hibbits p_Statistics->ifOutMcastPkts = (MASK22BIT & GET_UINT32(p_DtsecMemMap->tmca)) 892*0aeed3e9SJustin Hibbits + p_Dtsec->internalStatistics.tmca; /**< Total number of multicast frame sent */ 893*0aeed3e9SJustin Hibbits p_Statistics->ifOutBcastPkts = (MASK22BIT & GET_UINT32(p_DtsecMemMap->tbca)) 894*0aeed3e9SJustin Hibbits + p_Dtsec->internalStatistics.tbca; /**< Total number of multicast frame sent */ 895*0aeed3e9SJustin Hibbits } 896*0aeed3e9SJustin Hibbits /* */ 897*0aeed3e9SJustin Hibbits p_Statistics->eStatFragments = (MASK16BIT & GET_UINT32(p_DtsecMemMap->rfrg)) 898*0aeed3e9SJustin Hibbits + p_Dtsec->internalStatistics.rfrg; /**< Total number of packets that were less than 64 octets long with a wrong CRC.*/ 899*0aeed3e9SJustin Hibbits p_Statistics->eStatJabbers = (MASK16BIT & GET_UINT32(p_DtsecMemMap->rjbr)) 900*0aeed3e9SJustin Hibbits + p_Dtsec->internalStatistics.rjbr; /**< Total number of packets longer than valid maximum length octets */ 901*0aeed3e9SJustin Hibbits 902*0aeed3e9SJustin Hibbits p_Statistics->eStatsDropEvents = (MASK16BIT & GET_UINT32(p_DtsecMemMap->rdrp)) 903*0aeed3e9SJustin Hibbits + p_Dtsec->internalStatistics.rdrp; /**< number of dropped packets due to internal errors of the MAC Client. */ 904*0aeed3e9SJustin Hibbits p_Statistics->eStatCRCAlignErrors = (MASK16BIT & GET_UINT32(p_DtsecMemMap->raln)) 905*0aeed3e9SJustin Hibbits + p_Dtsec->internalStatistics.raln; /**< Incremented when frames of correct length but with CRC error are received.*/ 906*0aeed3e9SJustin Hibbits 907*0aeed3e9SJustin Hibbits p_Statistics->eStatUndersizePkts = (MASK16BIT & GET_UINT32(p_DtsecMemMap->rund)) 908*0aeed3e9SJustin Hibbits + p_Dtsec->internalStatistics.rund; /**< Total number of packets that were less than 64 octets long with a good CRC.*/ 909*0aeed3e9SJustin Hibbits p_Statistics->eStatOversizePkts = (MASK16BIT & GET_UINT32(p_DtsecMemMap->rovr)) 910*0aeed3e9SJustin Hibbits + p_Dtsec->internalStatistics.rovr; /**< T,B.D*/ 911*0aeed3e9SJustin Hibbits /* Pause */ 912*0aeed3e9SJustin Hibbits p_Statistics->reStatPause = (MASK16BIT & GET_UINT32(p_DtsecMemMap->rxpf)) 913*0aeed3e9SJustin Hibbits + p_Dtsec->internalStatistics.rxpf; /**< Pause MAC Control received */ 914*0aeed3e9SJustin Hibbits p_Statistics->teStatPause = (MASK16BIT & GET_UINT32(p_DtsecMemMap->txpf)) 915*0aeed3e9SJustin Hibbits + p_Dtsec->internalStatistics.txpf; /**< Pause MAC Control sent */ 916*0aeed3e9SJustin Hibbits 917*0aeed3e9SJustin Hibbits p_Statistics->ifInDiscards = p_Statistics->eStatsDropEvents; /**< Frames received, but discarded due to problems within the MAC RX. */ 918*0aeed3e9SJustin Hibbits 919*0aeed3e9SJustin Hibbits p_Statistics->ifInErrors = p_Statistics->eStatsDropEvents 920*0aeed3e9SJustin Hibbits + p_Statistics->eStatCRCAlignErrors 921*0aeed3e9SJustin Hibbits + (MASK16BIT & GET_UINT32(p_DtsecMemMap->rflr)) 922*0aeed3e9SJustin Hibbits + p_Dtsec->internalStatistics.rflr 923*0aeed3e9SJustin Hibbits + (MASK16BIT & GET_UINT32(p_DtsecMemMap->rcde)) 924*0aeed3e9SJustin Hibbits + p_Dtsec->internalStatistics.rcde 925*0aeed3e9SJustin Hibbits + (MASK16BIT & GET_UINT32(p_DtsecMemMap->rcse)) 926*0aeed3e9SJustin Hibbits + p_Dtsec->internalStatistics.rcse; 927*0aeed3e9SJustin Hibbits 928*0aeed3e9SJustin Hibbits p_Statistics->ifOutDiscards = (MASK16BIT & GET_UINT32(p_DtsecMemMap->tdrp)) 929*0aeed3e9SJustin Hibbits + p_Dtsec->internalStatistics.tdrp; /**< Frames received, but discarded due to problems within the MAC TX N/A!.*/ 930*0aeed3e9SJustin Hibbits p_Statistics->ifOutErrors = p_Statistics->ifOutDiscards /**< Number of frames transmitted with error: */ 931*0aeed3e9SJustin Hibbits + (MASK12BIT & GET_UINT32(p_DtsecMemMap->tfcs)) 932*0aeed3e9SJustin Hibbits + p_Dtsec->internalStatistics.tfcs; 933*0aeed3e9SJustin Hibbits 934*0aeed3e9SJustin Hibbits return E_OK; 935*0aeed3e9SJustin Hibbits } 936*0aeed3e9SJustin Hibbits 937*0aeed3e9SJustin Hibbits /* .............................................................................. */ 938*0aeed3e9SJustin Hibbits 939*0aeed3e9SJustin Hibbits static t_Error DtsecModifyMacAddress (t_Handle h_Dtsec, t_EnetAddr *p_EnetAddr) 940*0aeed3e9SJustin Hibbits { 941*0aeed3e9SJustin Hibbits t_Dtsec *p_Dtsec = (t_Dtsec *)h_Dtsec; 942*0aeed3e9SJustin Hibbits t_DtsecMemMap *p_DtsecMemMap; 943*0aeed3e9SJustin Hibbits uint32_t tmpReg32 = 0; 944*0aeed3e9SJustin Hibbits uint64_t addr; 945*0aeed3e9SJustin Hibbits 946*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Dtsec, E_INVALID_HANDLE); 947*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Dtsec->p_MemMap, E_NULL_POINTER); 948*0aeed3e9SJustin Hibbits 949*0aeed3e9SJustin Hibbits p_DtsecMemMap = p_Dtsec->p_MemMap; 950*0aeed3e9SJustin Hibbits /* Initialize MAC Station Address registers (1 & 2) */ 951*0aeed3e9SJustin Hibbits /* Station address have to be swapped (big endian to little endian */ 952*0aeed3e9SJustin Hibbits addr = ((*(uint64_t *)p_EnetAddr) >> 16); 953*0aeed3e9SJustin Hibbits p_Dtsec->addr = addr; 954*0aeed3e9SJustin Hibbits 955*0aeed3e9SJustin Hibbits tmpReg32 = (uint32_t)(addr); 956*0aeed3e9SJustin Hibbits SwapUint32P(&tmpReg32); 957*0aeed3e9SJustin Hibbits WRITE_UINT32(p_DtsecMemMap->macstnaddr1, tmpReg32); 958*0aeed3e9SJustin Hibbits 959*0aeed3e9SJustin Hibbits tmpReg32 = (uint32_t)(addr>>32); 960*0aeed3e9SJustin Hibbits SwapUint32P(&tmpReg32); 961*0aeed3e9SJustin Hibbits WRITE_UINT32(p_DtsecMemMap->macstnaddr2, tmpReg32); 962*0aeed3e9SJustin Hibbits 963*0aeed3e9SJustin Hibbits return E_OK; 964*0aeed3e9SJustin Hibbits } 965*0aeed3e9SJustin Hibbits 966*0aeed3e9SJustin Hibbits /* .............................................................................. */ 967*0aeed3e9SJustin Hibbits 968*0aeed3e9SJustin Hibbits static t_Error DtsecResetCounters (t_Handle h_Dtsec) 969*0aeed3e9SJustin Hibbits { 970*0aeed3e9SJustin Hibbits t_Dtsec *p_Dtsec = (t_Dtsec *)h_Dtsec; 971*0aeed3e9SJustin Hibbits 972*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Dtsec, E_INVALID_HANDLE); 973*0aeed3e9SJustin Hibbits 974*0aeed3e9SJustin Hibbits /* clear HW counters */ 975*0aeed3e9SJustin Hibbits WRITE_UINT32(p_Dtsec->p_MemMap->ecntrl, GET_UINT32(p_Dtsec->p_MemMap->ecntrl) | ECNTRL_CLRCNT); 976*0aeed3e9SJustin Hibbits 977*0aeed3e9SJustin Hibbits /* clear SW counters holding carries */ 978*0aeed3e9SJustin Hibbits memset((char *)&p_Dtsec->internalStatistics, (char)0x0, sizeof(t_InternalStatistics)); 979*0aeed3e9SJustin Hibbits 980*0aeed3e9SJustin Hibbits return E_OK; 981*0aeed3e9SJustin Hibbits } 982*0aeed3e9SJustin Hibbits 983*0aeed3e9SJustin Hibbits /* .............................................................................. */ 984*0aeed3e9SJustin Hibbits 985*0aeed3e9SJustin Hibbits static t_Error DtsecAddExactMatchMacAddress(t_Handle h_Dtsec, t_EnetAddr *p_EthAddr) 986*0aeed3e9SJustin Hibbits { 987*0aeed3e9SJustin Hibbits t_Dtsec *p_Dtsec = (t_Dtsec *) h_Dtsec; 988*0aeed3e9SJustin Hibbits uint64_t ethAddr; 989*0aeed3e9SJustin Hibbits uint8_t paddrNum; 990*0aeed3e9SJustin Hibbits 991*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Dtsec, E_INVALID_HANDLE); 992*0aeed3e9SJustin Hibbits 993*0aeed3e9SJustin Hibbits ethAddr = ((*(uint64_t *)p_EthAddr) >> 16); 994*0aeed3e9SJustin Hibbits 995*0aeed3e9SJustin Hibbits if (ethAddr & GROUP_ADDRESS) 996*0aeed3e9SJustin Hibbits /* Multicast address has no effect in PADDR */ 997*0aeed3e9SJustin Hibbits RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("Multicast address")); 998*0aeed3e9SJustin Hibbits 999*0aeed3e9SJustin Hibbits /* Make sure no PADDR contains this address */ 1000*0aeed3e9SJustin Hibbits for (paddrNum = 0; paddrNum < DTSEC_NUM_OF_PADDRS; paddrNum++) 1001*0aeed3e9SJustin Hibbits if (p_Dtsec->indAddrRegUsed[paddrNum]) 1002*0aeed3e9SJustin Hibbits if (p_Dtsec->paddr[paddrNum] == ethAddr) 1003*0aeed3e9SJustin Hibbits RETURN_ERROR(MAJOR, E_ALREADY_EXISTS, NO_MSG); 1004*0aeed3e9SJustin Hibbits 1005*0aeed3e9SJustin Hibbits /* Find first unused PADDR */ 1006*0aeed3e9SJustin Hibbits for (paddrNum = 0; paddrNum < DTSEC_NUM_OF_PADDRS; paddrNum++) 1007*0aeed3e9SJustin Hibbits if (!(p_Dtsec->indAddrRegUsed[paddrNum])) 1008*0aeed3e9SJustin Hibbits { 1009*0aeed3e9SJustin Hibbits /* mark this PADDR as used */ 1010*0aeed3e9SJustin Hibbits p_Dtsec->indAddrRegUsed[paddrNum] = TRUE; 1011*0aeed3e9SJustin Hibbits /* store address */ 1012*0aeed3e9SJustin Hibbits p_Dtsec->paddr[paddrNum] = ethAddr; 1013*0aeed3e9SJustin Hibbits 1014*0aeed3e9SJustin Hibbits /* put in hardware */ 1015*0aeed3e9SJustin Hibbits HardwareAddAddrInPaddr(p_Dtsec, ðAddr, paddrNum); 1016*0aeed3e9SJustin Hibbits p_Dtsec->numOfIndAddrInRegs++; 1017*0aeed3e9SJustin Hibbits 1018*0aeed3e9SJustin Hibbits return E_OK; 1019*0aeed3e9SJustin Hibbits } 1020*0aeed3e9SJustin Hibbits 1021*0aeed3e9SJustin Hibbits /* No free PADDR */ 1022*0aeed3e9SJustin Hibbits RETURN_ERROR(MAJOR, E_FULL, NO_MSG); 1023*0aeed3e9SJustin Hibbits } 1024*0aeed3e9SJustin Hibbits 1025*0aeed3e9SJustin Hibbits /* .............................................................................. */ 1026*0aeed3e9SJustin Hibbits 1027*0aeed3e9SJustin Hibbits static t_Error DtsecDelExactMatchMacAddress(t_Handle h_Dtsec, t_EnetAddr *p_EthAddr) 1028*0aeed3e9SJustin Hibbits { 1029*0aeed3e9SJustin Hibbits t_Dtsec *p_Dtsec = (t_Dtsec *) h_Dtsec; 1030*0aeed3e9SJustin Hibbits uint64_t ethAddr; 1031*0aeed3e9SJustin Hibbits uint8_t paddrNum; 1032*0aeed3e9SJustin Hibbits 1033*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Dtsec, E_INVALID_HANDLE); 1034*0aeed3e9SJustin Hibbits 1035*0aeed3e9SJustin Hibbits ethAddr = ((*(uint64_t *)p_EthAddr) >> 16); 1036*0aeed3e9SJustin Hibbits 1037*0aeed3e9SJustin Hibbits /* Find used PADDR containing this address */ 1038*0aeed3e9SJustin Hibbits for (paddrNum = 0; paddrNum < DTSEC_NUM_OF_PADDRS; paddrNum++) 1039*0aeed3e9SJustin Hibbits { 1040*0aeed3e9SJustin Hibbits if ((p_Dtsec->indAddrRegUsed[paddrNum]) && 1041*0aeed3e9SJustin Hibbits (p_Dtsec->paddr[paddrNum] == ethAddr)) 1042*0aeed3e9SJustin Hibbits { 1043*0aeed3e9SJustin Hibbits /* mark this PADDR as not used */ 1044*0aeed3e9SJustin Hibbits p_Dtsec->indAddrRegUsed[paddrNum] = FALSE; 1045*0aeed3e9SJustin Hibbits /* clear in hardware */ 1046*0aeed3e9SJustin Hibbits HardwareClearAddrInPaddr(p_Dtsec, paddrNum); 1047*0aeed3e9SJustin Hibbits p_Dtsec->numOfIndAddrInRegs--; 1048*0aeed3e9SJustin Hibbits 1049*0aeed3e9SJustin Hibbits return E_OK; 1050*0aeed3e9SJustin Hibbits } 1051*0aeed3e9SJustin Hibbits } 1052*0aeed3e9SJustin Hibbits 1053*0aeed3e9SJustin Hibbits RETURN_ERROR(MAJOR, E_NOT_FOUND, NO_MSG); 1054*0aeed3e9SJustin Hibbits } 1055*0aeed3e9SJustin Hibbits 1056*0aeed3e9SJustin Hibbits /* .............................................................................. */ 1057*0aeed3e9SJustin Hibbits 1058*0aeed3e9SJustin Hibbits static t_Error DtsecAddHashMacAddress(t_Handle h_Dtsec, t_EnetAddr *p_EthAddr) 1059*0aeed3e9SJustin Hibbits { 1060*0aeed3e9SJustin Hibbits t_Dtsec *p_Dtsec = (t_Dtsec *)h_Dtsec; 1061*0aeed3e9SJustin Hibbits t_DtsecMemMap *p_DtsecMemMap; 1062*0aeed3e9SJustin Hibbits uint32_t crc; 1063*0aeed3e9SJustin Hibbits uint8_t crcMirror, reg; 1064*0aeed3e9SJustin Hibbits uint32_t bitMask; 1065*0aeed3e9SJustin Hibbits t_EthHashEntry *p_HashEntry; 1066*0aeed3e9SJustin Hibbits uint64_t ethAddr; 1067*0aeed3e9SJustin Hibbits 1068*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Dtsec, E_INVALID_HANDLE); 1069*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Dtsec->p_MemMap, E_NULL_POINTER); 1070*0aeed3e9SJustin Hibbits 1071*0aeed3e9SJustin Hibbits p_DtsecMemMap = p_Dtsec->p_MemMap; 1072*0aeed3e9SJustin Hibbits 1073*0aeed3e9SJustin Hibbits ethAddr = ((*(uint64_t *)p_EthAddr) >> 16); 1074*0aeed3e9SJustin Hibbits 1075*0aeed3e9SJustin Hibbits /* CRC calculation */ 1076*0aeed3e9SJustin Hibbits GET_MAC_ADDR_CRC(ethAddr, crc); 1077*0aeed3e9SJustin Hibbits 1078*0aeed3e9SJustin Hibbits /* calculate the "crc mirror" */ 1079*0aeed3e9SJustin Hibbits crcMirror = MIRROR((uint8_t)crc); 1080*0aeed3e9SJustin Hibbits 1081*0aeed3e9SJustin Hibbits /* 3 MSB bits define the register */ 1082*0aeed3e9SJustin Hibbits reg = (uint8_t)(crcMirror >> 5); 1083*0aeed3e9SJustin Hibbits /* 5 LSB bits define the bit within the register */ 1084*0aeed3e9SJustin Hibbits bitMask = 0x80000000 >> (crcMirror & 0x1f); 1085*0aeed3e9SJustin Hibbits 1086*0aeed3e9SJustin Hibbits /* Create element to be added to the driver hash table */ 1087*0aeed3e9SJustin Hibbits p_HashEntry = (t_EthHashEntry *)XX_Malloc(sizeof(t_EthHashEntry)); 1088*0aeed3e9SJustin Hibbits p_HashEntry->addr = ethAddr; 1089*0aeed3e9SJustin Hibbits INIT_LIST(&p_HashEntry->node); 1090*0aeed3e9SJustin Hibbits 1091*0aeed3e9SJustin Hibbits if (ethAddr & GROUP_ADDRESS) 1092*0aeed3e9SJustin Hibbits { 1093*0aeed3e9SJustin Hibbits /* Group Address */ 1094*0aeed3e9SJustin Hibbits LIST_AddToTail(&(p_HashEntry->node), &(p_Dtsec->p_MulticastAddrHash->p_Lsts[crcMirror])); 1095*0aeed3e9SJustin Hibbits /* Set the appropriate bit in GADDR0-7 */ 1096*0aeed3e9SJustin Hibbits WRITE_UINT32(p_DtsecMemMap->gaddr[reg], 1097*0aeed3e9SJustin Hibbits GET_UINT32(p_DtsecMemMap->gaddr[reg]) | bitMask); 1098*0aeed3e9SJustin Hibbits } 1099*0aeed3e9SJustin Hibbits else 1100*0aeed3e9SJustin Hibbits { 1101*0aeed3e9SJustin Hibbits LIST_AddToTail(&(p_HashEntry->node), &(p_Dtsec->p_UnicastAddrHash->p_Lsts[crcMirror])); 1102*0aeed3e9SJustin Hibbits /* Set the appropriate bit in IADDR0-7 */ 1103*0aeed3e9SJustin Hibbits WRITE_UINT32(p_DtsecMemMap->igaddr[reg], 1104*0aeed3e9SJustin Hibbits GET_UINT32(p_DtsecMemMap->igaddr[reg]) | bitMask); 1105*0aeed3e9SJustin Hibbits } 1106*0aeed3e9SJustin Hibbits 1107*0aeed3e9SJustin Hibbits return E_OK; 1108*0aeed3e9SJustin Hibbits } 1109*0aeed3e9SJustin Hibbits 1110*0aeed3e9SJustin Hibbits /* .............................................................................. */ 1111*0aeed3e9SJustin Hibbits 1112*0aeed3e9SJustin Hibbits static t_Error DtsecDelHashMacAddress(t_Handle h_Dtsec, t_EnetAddr *p_EthAddr) 1113*0aeed3e9SJustin Hibbits { 1114*0aeed3e9SJustin Hibbits t_Dtsec *p_Dtsec = (t_Dtsec *)h_Dtsec; 1115*0aeed3e9SJustin Hibbits t_DtsecMemMap *p_DtsecMemMap; 1116*0aeed3e9SJustin Hibbits t_List *p_Pos; 1117*0aeed3e9SJustin Hibbits uint32_t crc; 1118*0aeed3e9SJustin Hibbits uint8_t crcMirror, reg; 1119*0aeed3e9SJustin Hibbits uint32_t bitMask; 1120*0aeed3e9SJustin Hibbits t_EthHashEntry *p_HashEntry = NULL; 1121*0aeed3e9SJustin Hibbits uint64_t ethAddr; 1122*0aeed3e9SJustin Hibbits 1123*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Dtsec, E_INVALID_HANDLE); 1124*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Dtsec->p_MemMap, E_NULL_POINTER); 1125*0aeed3e9SJustin Hibbits 1126*0aeed3e9SJustin Hibbits p_DtsecMemMap = p_Dtsec->p_MemMap; 1127*0aeed3e9SJustin Hibbits 1128*0aeed3e9SJustin Hibbits ethAddr = ((*(uint64_t *)p_EthAddr) >> 16); 1129*0aeed3e9SJustin Hibbits 1130*0aeed3e9SJustin Hibbits /* CRC calculation */ 1131*0aeed3e9SJustin Hibbits GET_MAC_ADDR_CRC(ethAddr, crc); 1132*0aeed3e9SJustin Hibbits 1133*0aeed3e9SJustin Hibbits /* calculate the "crc mirror" */ 1134*0aeed3e9SJustin Hibbits crcMirror = MIRROR((uint8_t)crc); 1135*0aeed3e9SJustin Hibbits 1136*0aeed3e9SJustin Hibbits /* 3 MSB bits define the register */ 1137*0aeed3e9SJustin Hibbits reg =(uint8_t)( crcMirror >> 5); 1138*0aeed3e9SJustin Hibbits /* 5 LSB bits define the bit within the register */ 1139*0aeed3e9SJustin Hibbits bitMask = 0x80000000 >> (crcMirror & 0x1f); 1140*0aeed3e9SJustin Hibbits 1141*0aeed3e9SJustin Hibbits if (ethAddr & GROUP_ADDRESS) 1142*0aeed3e9SJustin Hibbits { 1143*0aeed3e9SJustin Hibbits /* Group Address */ 1144*0aeed3e9SJustin Hibbits LIST_FOR_EACH(p_Pos, &(p_Dtsec->p_MulticastAddrHash->p_Lsts[crcMirror])) 1145*0aeed3e9SJustin Hibbits { 1146*0aeed3e9SJustin Hibbits p_HashEntry = ETH_HASH_ENTRY_OBJ(p_Pos); 1147*0aeed3e9SJustin Hibbits if(p_HashEntry->addr == ethAddr) 1148*0aeed3e9SJustin Hibbits { 1149*0aeed3e9SJustin Hibbits LIST_DelAndInit(&p_HashEntry->node); 1150*0aeed3e9SJustin Hibbits XX_Free(p_HashEntry); 1151*0aeed3e9SJustin Hibbits break; 1152*0aeed3e9SJustin Hibbits } 1153*0aeed3e9SJustin Hibbits } 1154*0aeed3e9SJustin Hibbits if(LIST_IsEmpty(&p_Dtsec->p_MulticastAddrHash->p_Lsts[crcMirror])) 1155*0aeed3e9SJustin Hibbits WRITE_UINT32(p_DtsecMemMap->gaddr[reg], 1156*0aeed3e9SJustin Hibbits GET_UINT32(p_DtsecMemMap->gaddr[reg]) & ~bitMask); 1157*0aeed3e9SJustin Hibbits } 1158*0aeed3e9SJustin Hibbits else 1159*0aeed3e9SJustin Hibbits { 1160*0aeed3e9SJustin Hibbits /* Individual Address */ 1161*0aeed3e9SJustin Hibbits LIST_FOR_EACH(p_Pos, &(p_Dtsec->p_UnicastAddrHash->p_Lsts[crcMirror])) 1162*0aeed3e9SJustin Hibbits { 1163*0aeed3e9SJustin Hibbits p_HashEntry = ETH_HASH_ENTRY_OBJ(p_Pos); 1164*0aeed3e9SJustin Hibbits if(p_HashEntry->addr == ethAddr) 1165*0aeed3e9SJustin Hibbits { 1166*0aeed3e9SJustin Hibbits LIST_DelAndInit(&p_HashEntry->node); 1167*0aeed3e9SJustin Hibbits XX_Free(p_HashEntry); 1168*0aeed3e9SJustin Hibbits break; 1169*0aeed3e9SJustin Hibbits } 1170*0aeed3e9SJustin Hibbits } 1171*0aeed3e9SJustin Hibbits if(LIST_IsEmpty(&p_Dtsec->p_UnicastAddrHash->p_Lsts[crcMirror])) 1172*0aeed3e9SJustin Hibbits WRITE_UINT32(p_DtsecMemMap->igaddr[reg], 1173*0aeed3e9SJustin Hibbits GET_UINT32(p_DtsecMemMap->igaddr[reg]) & ~bitMask); 1174*0aeed3e9SJustin Hibbits } 1175*0aeed3e9SJustin Hibbits 1176*0aeed3e9SJustin Hibbits /* address does not exist */ 1177*0aeed3e9SJustin Hibbits ASSERT_COND(p_HashEntry != NULL); 1178*0aeed3e9SJustin Hibbits 1179*0aeed3e9SJustin Hibbits return E_OK; 1180*0aeed3e9SJustin Hibbits } 1181*0aeed3e9SJustin Hibbits 1182*0aeed3e9SJustin Hibbits 1183*0aeed3e9SJustin Hibbits /* .............................................................................. */ 1184*0aeed3e9SJustin Hibbits 1185*0aeed3e9SJustin Hibbits static t_Error DtsecSetPromiscuous(t_Handle h_Dtsec, bool newVal) 1186*0aeed3e9SJustin Hibbits { 1187*0aeed3e9SJustin Hibbits t_Dtsec *p_Dtsec = (t_Dtsec *)h_Dtsec; 1188*0aeed3e9SJustin Hibbits t_DtsecMemMap *p_DtsecMemMap; 1189*0aeed3e9SJustin Hibbits uint32_t tmpReg32; 1190*0aeed3e9SJustin Hibbits 1191*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Dtsec, E_INVALID_HANDLE); 1192*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(!p_Dtsec->p_DtsecDriverParam, E_INVALID_HANDLE); 1193*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Dtsec->p_MemMap, E_NULL_POINTER); 1194*0aeed3e9SJustin Hibbits 1195*0aeed3e9SJustin Hibbits p_DtsecMemMap = p_Dtsec->p_MemMap; 1196*0aeed3e9SJustin Hibbits 1197*0aeed3e9SJustin Hibbits tmpReg32 = GET_UINT32(p_DtsecMemMap->rctrl); 1198*0aeed3e9SJustin Hibbits 1199*0aeed3e9SJustin Hibbits if (newVal) 1200*0aeed3e9SJustin Hibbits tmpReg32 |= RCTRL_PROM; 1201*0aeed3e9SJustin Hibbits else 1202*0aeed3e9SJustin Hibbits tmpReg32 &= ~RCTRL_PROM; 1203*0aeed3e9SJustin Hibbits 1204*0aeed3e9SJustin Hibbits WRITE_UINT32(p_DtsecMemMap->rctrl, tmpReg32); 1205*0aeed3e9SJustin Hibbits 1206*0aeed3e9SJustin Hibbits return E_OK; 1207*0aeed3e9SJustin Hibbits } 1208*0aeed3e9SJustin Hibbits 1209*0aeed3e9SJustin Hibbits /* .............................................................................. */ 1210*0aeed3e9SJustin Hibbits 1211*0aeed3e9SJustin Hibbits static t_Error DtsecSetStatistics(t_Handle h_Dtsec, e_FmMacStatisticsLevel statisticsLevel) 1212*0aeed3e9SJustin Hibbits { 1213*0aeed3e9SJustin Hibbits t_Dtsec *p_Dtsec = (t_Dtsec *)h_Dtsec; 1214*0aeed3e9SJustin Hibbits t_DtsecMemMap *p_DtsecMemMap; 1215*0aeed3e9SJustin Hibbits 1216*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Dtsec, E_INVALID_HANDLE); 1217*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Dtsec->p_MemMap, E_NULL_POINTER); 1218*0aeed3e9SJustin Hibbits 1219*0aeed3e9SJustin Hibbits p_DtsecMemMap = p_Dtsec->p_MemMap; 1220*0aeed3e9SJustin Hibbits 1221*0aeed3e9SJustin Hibbits p_Dtsec->statisticsLevel = statisticsLevel; 1222*0aeed3e9SJustin Hibbits 1223*0aeed3e9SJustin Hibbits switch (p_Dtsec->statisticsLevel) 1224*0aeed3e9SJustin Hibbits { 1225*0aeed3e9SJustin Hibbits case(e_FM_MAC_NONE_STATISTICS): 1226*0aeed3e9SJustin Hibbits WRITE_UINT32(p_DtsecMemMap->cam1,0xffffffff); 1227*0aeed3e9SJustin Hibbits WRITE_UINT32(p_DtsecMemMap->cam2,0xffffffff); 1228*0aeed3e9SJustin Hibbits WRITE_UINT32(p_DtsecMemMap->ecntrl, GET_UINT32(p_DtsecMemMap->ecntrl) & ~ECNTRL_STEN); 1229*0aeed3e9SJustin Hibbits WRITE_UINT32(p_DtsecMemMap->imask, GET_UINT32(p_DtsecMemMap->imask) & ~IMASK_MSROEN); 1230*0aeed3e9SJustin Hibbits p_Dtsec->exceptions &= ~IMASK_MSROEN; 1231*0aeed3e9SJustin Hibbits break; 1232*0aeed3e9SJustin Hibbits case(e_FM_MAC_PARTIAL_STATISTICS): 1233*0aeed3e9SJustin Hibbits WRITE_UINT32(p_DtsecMemMap->cam1, CAM1_ERRORS_ONLY); 1234*0aeed3e9SJustin Hibbits WRITE_UINT32(p_DtsecMemMap->cam2, CAM2_ERRORS_ONLY); 1235*0aeed3e9SJustin Hibbits WRITE_UINT32(p_DtsecMemMap->ecntrl, GET_UINT32(p_DtsecMemMap->ecntrl) | ECNTRL_STEN); 1236*0aeed3e9SJustin Hibbits WRITE_UINT32(p_DtsecMemMap->imask, GET_UINT32(p_DtsecMemMap->imask) | IMASK_MSROEN); 1237*0aeed3e9SJustin Hibbits p_Dtsec->exceptions |= IMASK_MSROEN; 1238*0aeed3e9SJustin Hibbits break; 1239*0aeed3e9SJustin Hibbits case(e_FM_MAC_FULL_STATISTICS): 1240*0aeed3e9SJustin Hibbits WRITE_UINT32(p_DtsecMemMap->cam1,0); 1241*0aeed3e9SJustin Hibbits WRITE_UINT32(p_DtsecMemMap->cam2,0); 1242*0aeed3e9SJustin Hibbits WRITE_UINT32(p_DtsecMemMap->ecntrl, GET_UINT32(p_DtsecMemMap->ecntrl) | ECNTRL_STEN); 1243*0aeed3e9SJustin Hibbits WRITE_UINT32(p_DtsecMemMap->imask, GET_UINT32(p_DtsecMemMap->imask) | IMASK_MSROEN); 1244*0aeed3e9SJustin Hibbits p_Dtsec->exceptions |= IMASK_MSROEN; 1245*0aeed3e9SJustin Hibbits break; 1246*0aeed3e9SJustin Hibbits default: 1247*0aeed3e9SJustin Hibbits RETURN_ERROR(MINOR, E_INVALID_SELECTION, NO_MSG); 1248*0aeed3e9SJustin Hibbits } 1249*0aeed3e9SJustin Hibbits 1250*0aeed3e9SJustin Hibbits return E_OK; 1251*0aeed3e9SJustin Hibbits } 1252*0aeed3e9SJustin Hibbits 1253*0aeed3e9SJustin Hibbits /* .............................................................................. */ 1254*0aeed3e9SJustin Hibbits 1255*0aeed3e9SJustin Hibbits static t_Error DtsecAdjustLink(t_Handle h_Dtsec, e_EnetSpeed speed, bool fullDuplex) 1256*0aeed3e9SJustin Hibbits { 1257*0aeed3e9SJustin Hibbits t_Dtsec *p_Dtsec = (t_Dtsec *)h_Dtsec; 1258*0aeed3e9SJustin Hibbits t_DtsecMemMap *p_DtsecMemMap; 1259*0aeed3e9SJustin Hibbits uint32_t tmpReg32; 1260*0aeed3e9SJustin Hibbits 1261*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Dtsec, E_INVALID_HANDLE); 1262*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(!p_Dtsec->p_DtsecDriverParam, E_INVALID_HANDLE); 1263*0aeed3e9SJustin Hibbits p_DtsecMemMap = p_Dtsec->p_MemMap; 1264*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_DtsecMemMap, E_INVALID_HANDLE); 1265*0aeed3e9SJustin Hibbits 1266*0aeed3e9SJustin Hibbits if ((!fullDuplex) && (speed >= e_ENET_SPEED_1000)) 1267*0aeed3e9SJustin Hibbits RETURN_ERROR(MAJOR, E_CONFLICT, ("Ethernet interface does not support Half Duplex mode")); 1268*0aeed3e9SJustin Hibbits 1269*0aeed3e9SJustin Hibbits p_Dtsec->enetMode = MAKE_ENET_MODE(ENET_INTERFACE_FROM_MODE(p_Dtsec->enetMode), speed); 1270*0aeed3e9SJustin Hibbits p_Dtsec->halfDuplex = !fullDuplex; 1271*0aeed3e9SJustin Hibbits 1272*0aeed3e9SJustin Hibbits tmpReg32 = GET_UINT32(p_DtsecMemMap->maccfg2); 1273*0aeed3e9SJustin Hibbits if(p_Dtsec->halfDuplex) 1274*0aeed3e9SJustin Hibbits tmpReg32 &= ~MACCFG2_FULL_DUPLEX; 1275*0aeed3e9SJustin Hibbits else 1276*0aeed3e9SJustin Hibbits tmpReg32 |= MACCFG2_FULL_DUPLEX; 1277*0aeed3e9SJustin Hibbits 1278*0aeed3e9SJustin Hibbits tmpReg32 &= ~(MACCFG2_NIBBLE_MODE | MACCFG2_BYTE_MODE); 1279*0aeed3e9SJustin Hibbits if((p_Dtsec->enetMode == e_ENET_MODE_RGMII_10) || 1280*0aeed3e9SJustin Hibbits (p_Dtsec->enetMode == e_ENET_MODE_RGMII_100)|| 1281*0aeed3e9SJustin Hibbits (p_Dtsec->enetMode == e_ENET_MODE_SGMII_10) || 1282*0aeed3e9SJustin Hibbits (p_Dtsec->enetMode == e_ENET_MODE_SGMII_100)) 1283*0aeed3e9SJustin Hibbits tmpReg32 |= MACCFG2_NIBBLE_MODE; 1284*0aeed3e9SJustin Hibbits else if((p_Dtsec->enetMode == e_ENET_MODE_RGMII_1000) || 1285*0aeed3e9SJustin Hibbits (p_Dtsec->enetMode == e_ENET_MODE_SGMII_1000)|| 1286*0aeed3e9SJustin Hibbits (p_Dtsec->enetMode == e_ENET_MODE_GMII_1000)) 1287*0aeed3e9SJustin Hibbits tmpReg32 |= MACCFG2_BYTE_MODE; 1288*0aeed3e9SJustin Hibbits WRITE_UINT32(p_DtsecMemMap->maccfg2, tmpReg32); 1289*0aeed3e9SJustin Hibbits 1290*0aeed3e9SJustin Hibbits tmpReg32 = GET_UINT32(p_DtsecMemMap->ecntrl); 1291*0aeed3e9SJustin Hibbits if (!(tmpReg32 & ECNTRL_CFG_RO)) 1292*0aeed3e9SJustin Hibbits { 1293*0aeed3e9SJustin Hibbits if ((p_Dtsec->enetMode == e_ENET_MODE_RGMII_100) || 1294*0aeed3e9SJustin Hibbits (p_Dtsec->enetMode == e_ENET_MODE_SGMII_100)) 1295*0aeed3e9SJustin Hibbits tmpReg32 |= ECNTRL_R100M; 1296*0aeed3e9SJustin Hibbits else 1297*0aeed3e9SJustin Hibbits tmpReg32 &= ~ECNTRL_R100M; 1298*0aeed3e9SJustin Hibbits WRITE_UINT32(p_DtsecMemMap->ecntrl, tmpReg32); 1299*0aeed3e9SJustin Hibbits } 1300*0aeed3e9SJustin Hibbits 1301*0aeed3e9SJustin Hibbits return E_OK; 1302*0aeed3e9SJustin Hibbits } 1303*0aeed3e9SJustin Hibbits 1304*0aeed3e9SJustin Hibbits /* .............................................................................. */ 1305*0aeed3e9SJustin Hibbits 1306*0aeed3e9SJustin Hibbits static t_Error DtsecGetId(t_Handle h_Dtsec, uint32_t *macId) 1307*0aeed3e9SJustin Hibbits { 1308*0aeed3e9SJustin Hibbits t_Dtsec *p_Dtsec = (t_Dtsec *)h_Dtsec; 1309*0aeed3e9SJustin Hibbits 1310*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Dtsec, E_INVALID_HANDLE); 1311*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(!p_Dtsec->p_DtsecDriverParam, E_INVALID_HANDLE); 1312*0aeed3e9SJustin Hibbits 1313*0aeed3e9SJustin Hibbits *macId = p_Dtsec->macId; 1314*0aeed3e9SJustin Hibbits 1315*0aeed3e9SJustin Hibbits return E_OK; 1316*0aeed3e9SJustin Hibbits } 1317*0aeed3e9SJustin Hibbits 1318*0aeed3e9SJustin Hibbits /* .............................................................................. */ 1319*0aeed3e9SJustin Hibbits 1320*0aeed3e9SJustin Hibbits static t_Error DtsecGetVersion(t_Handle h_Dtsec, uint32_t *macVersion) 1321*0aeed3e9SJustin Hibbits { 1322*0aeed3e9SJustin Hibbits t_Dtsec *p_Dtsec = (t_Dtsec *)h_Dtsec; 1323*0aeed3e9SJustin Hibbits t_DtsecMemMap *p_DtsecMemMap; 1324*0aeed3e9SJustin Hibbits 1325*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Dtsec, E_INVALID_HANDLE); 1326*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(!p_Dtsec->p_DtsecDriverParam, E_INVALID_HANDLE); 1327*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Dtsec->p_MemMap, E_NULL_POINTER); 1328*0aeed3e9SJustin Hibbits 1329*0aeed3e9SJustin Hibbits p_DtsecMemMap = p_Dtsec->p_MemMap; 1330*0aeed3e9SJustin Hibbits *macVersion = GET_UINT32(p_DtsecMemMap->tsec_id1); 1331*0aeed3e9SJustin Hibbits 1332*0aeed3e9SJustin Hibbits return E_OK; 1333*0aeed3e9SJustin Hibbits } 1334*0aeed3e9SJustin Hibbits 1335*0aeed3e9SJustin Hibbits /* .............................................................................. */ 1336*0aeed3e9SJustin Hibbits 1337*0aeed3e9SJustin Hibbits static t_Error DtsecSetException(t_Handle h_Dtsec, e_FmMacExceptions exception, bool enable) 1338*0aeed3e9SJustin Hibbits { 1339*0aeed3e9SJustin Hibbits t_Dtsec *p_Dtsec = (t_Dtsec *)h_Dtsec; 1340*0aeed3e9SJustin Hibbits uint32_t tmpReg, bitMask = 0; 1341*0aeed3e9SJustin Hibbits t_DtsecMemMap *p_DtsecMemMap; 1342*0aeed3e9SJustin Hibbits 1343*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Dtsec, E_INVALID_HANDLE); 1344*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(!p_Dtsec->p_DtsecDriverParam, E_INVALID_HANDLE); 1345*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Dtsec->p_MemMap, E_NULL_POINTER); 1346*0aeed3e9SJustin Hibbits 1347*0aeed3e9SJustin Hibbits p_DtsecMemMap = p_Dtsec->p_MemMap; 1348*0aeed3e9SJustin Hibbits 1349*0aeed3e9SJustin Hibbits if(exception != e_FM_MAC_EX_1G_1588_TS_RX_ERR) 1350*0aeed3e9SJustin Hibbits { 1351*0aeed3e9SJustin Hibbits GET_EXCEPTION_FLAG(bitMask, exception); 1352*0aeed3e9SJustin Hibbits if(bitMask) 1353*0aeed3e9SJustin Hibbits { 1354*0aeed3e9SJustin Hibbits if (enable) 1355*0aeed3e9SJustin Hibbits p_Dtsec->exceptions |= bitMask; 1356*0aeed3e9SJustin Hibbits else 1357*0aeed3e9SJustin Hibbits p_Dtsec->exceptions &= ~bitMask; 1358*0aeed3e9SJustin Hibbits } 1359*0aeed3e9SJustin Hibbits else 1360*0aeed3e9SJustin Hibbits RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("Undefined exception")); 1361*0aeed3e9SJustin Hibbits 1362*0aeed3e9SJustin Hibbits tmpReg = GET_UINT32(p_DtsecMemMap->imask); 1363*0aeed3e9SJustin Hibbits if(enable) 1364*0aeed3e9SJustin Hibbits tmpReg |= bitMask; 1365*0aeed3e9SJustin Hibbits else 1366*0aeed3e9SJustin Hibbits tmpReg &= ~bitMask; 1367*0aeed3e9SJustin Hibbits WRITE_UINT32(p_DtsecMemMap->imask, tmpReg); 1368*0aeed3e9SJustin Hibbits 1369*0aeed3e9SJustin Hibbits /* warn if MIB OVFL is disabled and statistic gathering is enabled */ 1370*0aeed3e9SJustin Hibbits if((exception == e_FM_MAC_EX_1G_RX_MIB_CNT_OVFL) && 1371*0aeed3e9SJustin Hibbits !enable && 1372*0aeed3e9SJustin Hibbits (p_Dtsec->statisticsLevel != e_FM_MAC_NONE_STATISTICS)) 1373*0aeed3e9SJustin Hibbits DBG(WARNING, ("Disabled MIB counters overflow exceptions. Counters value may be inaccurate due to unregistered overflow")); 1374*0aeed3e9SJustin Hibbits 1375*0aeed3e9SJustin Hibbits } 1376*0aeed3e9SJustin Hibbits else 1377*0aeed3e9SJustin Hibbits { 1378*0aeed3e9SJustin Hibbits if(!p_Dtsec->ptpTsuEnabled) 1379*0aeed3e9SJustin Hibbits RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("Exception valid for 1588 only")); 1380*0aeed3e9SJustin Hibbits tmpReg = GET_UINT32(p_DtsecMemMap->tmr_pemask); 1381*0aeed3e9SJustin Hibbits switch(exception){ 1382*0aeed3e9SJustin Hibbits case(e_FM_MAC_EX_1G_1588_TS_RX_ERR): 1383*0aeed3e9SJustin Hibbits if(enable) 1384*0aeed3e9SJustin Hibbits { 1385*0aeed3e9SJustin Hibbits p_Dtsec->enTsuErrExeption = TRUE; 1386*0aeed3e9SJustin Hibbits WRITE_UINT32(p_DtsecMemMap->tmr_pemask, tmpReg | PEMASK_TSRE); 1387*0aeed3e9SJustin Hibbits } 1388*0aeed3e9SJustin Hibbits else 1389*0aeed3e9SJustin Hibbits { 1390*0aeed3e9SJustin Hibbits p_Dtsec->enTsuErrExeption = FALSE; 1391*0aeed3e9SJustin Hibbits WRITE_UINT32(p_DtsecMemMap->tmr_pemask, tmpReg & ~PEMASK_TSRE); 1392*0aeed3e9SJustin Hibbits } 1393*0aeed3e9SJustin Hibbits break; 1394*0aeed3e9SJustin Hibbits default: 1395*0aeed3e9SJustin Hibbits RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("Undefined exception")); 1396*0aeed3e9SJustin Hibbits } 1397*0aeed3e9SJustin Hibbits } 1398*0aeed3e9SJustin Hibbits 1399*0aeed3e9SJustin Hibbits return E_OK; 1400*0aeed3e9SJustin Hibbits } 1401*0aeed3e9SJustin Hibbits 1402*0aeed3e9SJustin Hibbits /* ........................................................................... */ 1403*0aeed3e9SJustin Hibbits 1404*0aeed3e9SJustin Hibbits #if (defined(DEBUG_ERRORS) && (DEBUG_ERRORS > 0)) 1405*0aeed3e9SJustin Hibbits static t_Error DtsecDumpRegs(t_Handle h_Dtsec) 1406*0aeed3e9SJustin Hibbits { 1407*0aeed3e9SJustin Hibbits t_Dtsec *p_Dtsec = (t_Dtsec *)h_Dtsec; 1408*0aeed3e9SJustin Hibbits int i = 0; 1409*0aeed3e9SJustin Hibbits 1410*0aeed3e9SJustin Hibbits DECLARE_DUMP; 1411*0aeed3e9SJustin Hibbits 1412*0aeed3e9SJustin Hibbits if (p_Dtsec->p_MemMap) 1413*0aeed3e9SJustin Hibbits { 1414*0aeed3e9SJustin Hibbits 1415*0aeed3e9SJustin Hibbits DUMP_TITLE(p_Dtsec->p_MemMap, ("MAC %d: ", p_Dtsec->macId)); 1416*0aeed3e9SJustin Hibbits DUMP_VAR(p_Dtsec->p_MemMap, tsec_id1); 1417*0aeed3e9SJustin Hibbits DUMP_VAR(p_Dtsec->p_MemMap, tsec_id2); 1418*0aeed3e9SJustin Hibbits DUMP_VAR(p_Dtsec->p_MemMap, ievent); 1419*0aeed3e9SJustin Hibbits DUMP_VAR(p_Dtsec->p_MemMap, imask); 1420*0aeed3e9SJustin Hibbits DUMP_VAR(p_Dtsec->p_MemMap, edis); 1421*0aeed3e9SJustin Hibbits DUMP_VAR(p_Dtsec->p_MemMap, ecntrl); 1422*0aeed3e9SJustin Hibbits DUMP_VAR(p_Dtsec->p_MemMap, ptv); 1423*0aeed3e9SJustin Hibbits DUMP_VAR(p_Dtsec->p_MemMap, tmr_ctrl); 1424*0aeed3e9SJustin Hibbits DUMP_VAR(p_Dtsec->p_MemMap, tmr_pevent); 1425*0aeed3e9SJustin Hibbits DUMP_VAR(p_Dtsec->p_MemMap, tmr_pemask); 1426*0aeed3e9SJustin Hibbits DUMP_VAR(p_Dtsec->p_MemMap, tctrl); 1427*0aeed3e9SJustin Hibbits DUMP_VAR(p_Dtsec->p_MemMap, rctrl); 1428*0aeed3e9SJustin Hibbits DUMP_VAR(p_Dtsec->p_MemMap, maccfg1); 1429*0aeed3e9SJustin Hibbits DUMP_VAR(p_Dtsec->p_MemMap, maccfg2); 1430*0aeed3e9SJustin Hibbits DUMP_VAR(p_Dtsec->p_MemMap, ipgifg); 1431*0aeed3e9SJustin Hibbits DUMP_VAR(p_Dtsec->p_MemMap, hafdup); 1432*0aeed3e9SJustin Hibbits DUMP_VAR(p_Dtsec->p_MemMap, maxfrm); 1433*0aeed3e9SJustin Hibbits 1434*0aeed3e9SJustin Hibbits DUMP_VAR(p_Dtsec->p_MemMap, macstnaddr1); 1435*0aeed3e9SJustin Hibbits DUMP_VAR(p_Dtsec->p_MemMap, macstnaddr2); 1436*0aeed3e9SJustin Hibbits 1437*0aeed3e9SJustin Hibbits DUMP_SUBSTRUCT_ARRAY(i, 8) 1438*0aeed3e9SJustin Hibbits { 1439*0aeed3e9SJustin Hibbits DUMP_VAR(p_Dtsec->p_MemMap, macaddr[i].exact_match1); 1440*0aeed3e9SJustin Hibbits DUMP_VAR(p_Dtsec->p_MemMap, macaddr[i].exact_match2); 1441*0aeed3e9SJustin Hibbits } 1442*0aeed3e9SJustin Hibbits } 1443*0aeed3e9SJustin Hibbits 1444*0aeed3e9SJustin Hibbits return E_OK; 1445*0aeed3e9SJustin Hibbits } 1446*0aeed3e9SJustin Hibbits #endif /* (defined(DEBUG_ERRORS) && ... */ 1447*0aeed3e9SJustin Hibbits 1448*0aeed3e9SJustin Hibbits 1449*0aeed3e9SJustin Hibbits /*****************************************************************************/ 1450*0aeed3e9SJustin Hibbits /* FM Init & Free API */ 1451*0aeed3e9SJustin Hibbits /*****************************************************************************/ 1452*0aeed3e9SJustin Hibbits 1453*0aeed3e9SJustin Hibbits /* .............................................................................. */ 1454*0aeed3e9SJustin Hibbits 1455*0aeed3e9SJustin Hibbits static t_Error DtsecInit(t_Handle h_Dtsec) 1456*0aeed3e9SJustin Hibbits { 1457*0aeed3e9SJustin Hibbits t_Dtsec *p_Dtsec = (t_Dtsec *)h_Dtsec; 1458*0aeed3e9SJustin Hibbits t_DtsecDriverParam *p_DtsecDriverParam; 1459*0aeed3e9SJustin Hibbits t_DtsecMemMap *p_DtsecMemMap; 1460*0aeed3e9SJustin Hibbits int i; 1461*0aeed3e9SJustin Hibbits uint32_t tmpReg32; 1462*0aeed3e9SJustin Hibbits uint64_t addr; 1463*0aeed3e9SJustin Hibbits t_Error err; 1464*0aeed3e9SJustin Hibbits 1465*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Dtsec, E_INVALID_HANDLE); 1466*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Dtsec->p_DtsecDriverParam, E_INVALID_STATE); 1467*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Dtsec->p_MemMap, E_INVALID_STATE); 1468*0aeed3e9SJustin Hibbits 1469*0aeed3e9SJustin Hibbits CHECK_INIT_PARAMETERS(p_Dtsec, CheckInitParameters); 1470*0aeed3e9SJustin Hibbits 1471*0aeed3e9SJustin Hibbits p_DtsecDriverParam = p_Dtsec->p_DtsecDriverParam; 1472*0aeed3e9SJustin Hibbits p_Dtsec->halfDuplex = p_DtsecDriverParam->halfDuplex; 1473*0aeed3e9SJustin Hibbits p_Dtsec->debugMode = p_DtsecDriverParam->debugMode; 1474*0aeed3e9SJustin Hibbits p_DtsecMemMap = p_Dtsec->p_MemMap; 1475*0aeed3e9SJustin Hibbits 1476*0aeed3e9SJustin Hibbits /*************dtsec_id2******************/ 1477*0aeed3e9SJustin Hibbits tmpReg32 = GET_UINT32(p_DtsecMemMap->tsec_id2); 1478*0aeed3e9SJustin Hibbits 1479*0aeed3e9SJustin Hibbits if ((p_Dtsec->enetMode == e_ENET_MODE_RGMII_10) || 1480*0aeed3e9SJustin Hibbits (p_Dtsec->enetMode == e_ENET_MODE_RGMII_100) || 1481*0aeed3e9SJustin Hibbits (p_Dtsec->enetMode == e_ENET_MODE_RGMII_1000) || 1482*0aeed3e9SJustin Hibbits (p_Dtsec->enetMode == e_ENET_MODE_RMII_10) || 1483*0aeed3e9SJustin Hibbits (p_Dtsec->enetMode == e_ENET_MODE_RMII_100)) 1484*0aeed3e9SJustin Hibbits if(tmpReg32 & ID2_INT_REDUCED_OFF) 1485*0aeed3e9SJustin Hibbits { 1486*0aeed3e9SJustin Hibbits RETURN_ERROR(MAJOR, E_NOT_SUPPORTED, ("no support for reduced interface in current DTSEC version")); 1487*0aeed3e9SJustin Hibbits } 1488*0aeed3e9SJustin Hibbits 1489*0aeed3e9SJustin Hibbits if ((p_Dtsec->enetMode == e_ENET_MODE_SGMII_10) || 1490*0aeed3e9SJustin Hibbits (p_Dtsec->enetMode == e_ENET_MODE_SGMII_100) || 1491*0aeed3e9SJustin Hibbits (p_Dtsec->enetMode == e_ENET_MODE_SGMII_1000)|| 1492*0aeed3e9SJustin Hibbits (p_Dtsec->enetMode == e_ENET_MODE_MII_10) || 1493*0aeed3e9SJustin Hibbits (p_Dtsec->enetMode == e_ENET_MODE_MII_100)) 1494*0aeed3e9SJustin Hibbits if(tmpReg32 & ID2_INT_NORMAL_OFF) 1495*0aeed3e9SJustin Hibbits { 1496*0aeed3e9SJustin Hibbits RETURN_ERROR(MAJOR, E_NOT_SUPPORTED, ("no support for normal interface in current DTSEC version")); 1497*0aeed3e9SJustin Hibbits } 1498*0aeed3e9SJustin Hibbits /*************dtsec_id2******************/ 1499*0aeed3e9SJustin Hibbits 1500*0aeed3e9SJustin Hibbits /***************EDIS************************/ 1501*0aeed3e9SJustin Hibbits WRITE_UINT32(p_DtsecMemMap->edis, p_DtsecDriverParam->errorDisabled); 1502*0aeed3e9SJustin Hibbits /***************EDIS************************/ 1503*0aeed3e9SJustin Hibbits 1504*0aeed3e9SJustin Hibbits /***************ECNTRL************************/ 1505*0aeed3e9SJustin Hibbits tmpReg32 = 0; 1506*0aeed3e9SJustin Hibbits if ((p_Dtsec->enetMode == e_ENET_MODE_RGMII_10) || 1507*0aeed3e9SJustin Hibbits (p_Dtsec->enetMode == e_ENET_MODE_RGMII_100) || 1508*0aeed3e9SJustin Hibbits (p_Dtsec->enetMode == e_ENET_MODE_RGMII_1000) || 1509*0aeed3e9SJustin Hibbits (p_Dtsec->enetMode == e_ENET_MODE_GMII_1000)) 1510*0aeed3e9SJustin Hibbits tmpReg32 |= ECNTRL_GMIIM; 1511*0aeed3e9SJustin Hibbits if ((p_Dtsec->enetMode == e_ENET_MODE_SGMII_10) || 1512*0aeed3e9SJustin Hibbits (p_Dtsec->enetMode == e_ENET_MODE_SGMII_100) || 1513*0aeed3e9SJustin Hibbits (p_Dtsec->enetMode == e_ENET_MODE_SGMII_1000)) 1514*0aeed3e9SJustin Hibbits tmpReg32 |= (ECNTRL_SGMIIM | ECNTRL_TBIM); 1515*0aeed3e9SJustin Hibbits if (p_Dtsec->enetMode == e_ENET_MODE_QSGMII_1000) 1516*0aeed3e9SJustin Hibbits tmpReg32 |= (ECNTRL_SGMIIM | ECNTRL_TBIM | ECNTRL_QSGMIIM); 1517*0aeed3e9SJustin Hibbits if ((p_Dtsec->enetMode == e_ENET_MODE_RGMII_1000) || 1518*0aeed3e9SJustin Hibbits (p_Dtsec->enetMode == e_ENET_MODE_RGMII_10)|| 1519*0aeed3e9SJustin Hibbits (p_Dtsec->enetMode == e_ENET_MODE_RGMII_100)) 1520*0aeed3e9SJustin Hibbits tmpReg32 |= ECNTRL_RPM; 1521*0aeed3e9SJustin Hibbits if ((p_Dtsec->enetMode == e_ENET_MODE_RGMII_100) || 1522*0aeed3e9SJustin Hibbits (p_Dtsec->enetMode == e_ENET_MODE_SGMII_100) || 1523*0aeed3e9SJustin Hibbits (p_Dtsec->enetMode == e_ENET_MODE_RMII_100)) 1524*0aeed3e9SJustin Hibbits tmpReg32 |= ECNTRL_R100M; 1525*0aeed3e9SJustin Hibbits if ((p_Dtsec->enetMode == e_ENET_MODE_RMII_10) || (p_Dtsec->enetMode == e_ENET_MODE_RMII_100)) 1526*0aeed3e9SJustin Hibbits tmpReg32 |= ECNTRL_RMM; 1527*0aeed3e9SJustin Hibbits WRITE_UINT32(p_DtsecMemMap->ecntrl, tmpReg32); 1528*0aeed3e9SJustin Hibbits /***************ECNTRL************************/ 1529*0aeed3e9SJustin Hibbits 1530*0aeed3e9SJustin Hibbits /***************PTV************************/ 1531*0aeed3e9SJustin Hibbits tmpReg32 = 0; 1532*0aeed3e9SJustin Hibbits #ifdef FM_SHORT_PAUSE_TIME_ERRATA_DTSEC1 1533*0aeed3e9SJustin Hibbits { 1534*0aeed3e9SJustin Hibbits t_FmRevisionInfo revInfo; 1535*0aeed3e9SJustin Hibbits FM_GetRevision(p_Dtsec->fmMacControllerDriver.h_Fm, &revInfo); 1536*0aeed3e9SJustin Hibbits if ((revInfo.majorRev == 1) && (revInfo.minorRev == 0)) 1537*0aeed3e9SJustin Hibbits p_DtsecDriverParam->pauseTime += 2; 1538*0aeed3e9SJustin Hibbits } 1539*0aeed3e9SJustin Hibbits #endif /* FM_SHORT_PAUSE_TIME_ERRATA_DTSEC1 */ 1540*0aeed3e9SJustin Hibbits if (p_DtsecDriverParam->pauseTime) 1541*0aeed3e9SJustin Hibbits tmpReg32 |= (uint32_t)p_DtsecDriverParam->pauseTime; 1542*0aeed3e9SJustin Hibbits 1543*0aeed3e9SJustin Hibbits if (p_DtsecDriverParam->pauseExtended) 1544*0aeed3e9SJustin Hibbits tmpReg32 |= ((uint32_t)p_DtsecDriverParam->pauseExtended) << PTV_PTE_OFST; 1545*0aeed3e9SJustin Hibbits WRITE_UINT32(p_DtsecMemMap->ptv, tmpReg32); 1546*0aeed3e9SJustin Hibbits /***************PTV************************/ 1547*0aeed3e9SJustin Hibbits 1548*0aeed3e9SJustin Hibbits /***************TCTRL************************/ 1549*0aeed3e9SJustin Hibbits tmpReg32 = 0; 1550*0aeed3e9SJustin Hibbits if(p_DtsecDriverParam->halfDuplex) 1551*0aeed3e9SJustin Hibbits { 1552*0aeed3e9SJustin Hibbits if(p_DtsecDriverParam->halfDulexFlowControlEn) 1553*0aeed3e9SJustin Hibbits tmpReg32 |= TCTRL_THDF; 1554*0aeed3e9SJustin Hibbits } 1555*0aeed3e9SJustin Hibbits else 1556*0aeed3e9SJustin Hibbits { 1557*0aeed3e9SJustin Hibbits if(p_DtsecDriverParam->txTimeStampEn) 1558*0aeed3e9SJustin Hibbits tmpReg32 |= TCTRL_TTSE; 1559*0aeed3e9SJustin Hibbits } 1560*0aeed3e9SJustin Hibbits WRITE_UINT32(p_DtsecMemMap->tctrl, tmpReg32); 1561*0aeed3e9SJustin Hibbits /***************TCTRL************************/ 1562*0aeed3e9SJustin Hibbits 1563*0aeed3e9SJustin Hibbits /***************RCTRL************************/ 1564*0aeed3e9SJustin Hibbits tmpReg32 = 0; 1565*0aeed3e9SJustin Hibbits if (p_DtsecDriverParam->packetAlignmentPadding) 1566*0aeed3e9SJustin Hibbits tmpReg32 |= ((uint32_t)(0x0000001f & p_DtsecDriverParam->packetAlignmentPadding)) << 16; 1567*0aeed3e9SJustin Hibbits if (p_DtsecDriverParam->controlFrameAccept) 1568*0aeed3e9SJustin Hibbits tmpReg32 |= RCTRL_CFA; 1569*0aeed3e9SJustin Hibbits if (p_DtsecDriverParam->groupHashExtend) 1570*0aeed3e9SJustin Hibbits tmpReg32 |= RCTRL_GHTX; 1571*0aeed3e9SJustin Hibbits if(p_DtsecDriverParam->rxTimeStampEn) 1572*0aeed3e9SJustin Hibbits tmpReg32 |= RCTRL_RTSE; 1573*0aeed3e9SJustin Hibbits if (p_DtsecDriverParam->broadcReject) 1574*0aeed3e9SJustin Hibbits tmpReg32 |= RCTRL_BC_REJ; 1575*0aeed3e9SJustin Hibbits if (p_DtsecDriverParam->rxShortFrame) 1576*0aeed3e9SJustin Hibbits tmpReg32 |= RCTRL_RSF; 1577*0aeed3e9SJustin Hibbits if (p_DtsecDriverParam->promiscuousEnable) 1578*0aeed3e9SJustin Hibbits tmpReg32 |= RCTRL_PROM; 1579*0aeed3e9SJustin Hibbits if (p_DtsecDriverParam->exactMatch) 1580*0aeed3e9SJustin Hibbits tmpReg32 |= RCTRL_EMEN; 1581*0aeed3e9SJustin Hibbits 1582*0aeed3e9SJustin Hibbits WRITE_UINT32(p_DtsecMemMap->rctrl, tmpReg32); 1583*0aeed3e9SJustin Hibbits /***************RCTRL************************/ 1584*0aeed3e9SJustin Hibbits 1585*0aeed3e9SJustin Hibbits /* Assign a Phy Address to the TBI (TBIPA). */ 1586*0aeed3e9SJustin Hibbits /* Done also in case that TBI is not selected to avoid */ 1587*0aeed3e9SJustin Hibbits /* conflict with the external PHY�s Physical address */ 1588*0aeed3e9SJustin Hibbits WRITE_UINT32(p_DtsecMemMap->tbipa, p_DtsecDriverParam->tbiPhyAddr); 1589*0aeed3e9SJustin Hibbits 1590*0aeed3e9SJustin Hibbits /* Reset the management interface */ 1591*0aeed3e9SJustin Hibbits WRITE_UINT32(p_Dtsec->p_MiiMemMap->miimcfg, MIIMCFG_RESET_MGMT); 1592*0aeed3e9SJustin Hibbits WRITE_UINT32(p_Dtsec->p_MiiMemMap->miimcfg, ~MIIMCFG_RESET_MGMT); 1593*0aeed3e9SJustin Hibbits /* Setup the MII Mgmt clock speed */ 1594*0aeed3e9SJustin Hibbits WRITE_UINT32(p_Dtsec->p_MiiMemMap->miimcfg, 1595*0aeed3e9SJustin Hibbits (uint32_t)GetMiiDiv((int32_t)(((p_Dtsec->fmMacControllerDriver.clkFreq*10)/2)/8))); 1596*0aeed3e9SJustin Hibbits 1597*0aeed3e9SJustin Hibbits if(p_Dtsec->enetMode == e_ENET_MODE_SGMII_1000) 1598*0aeed3e9SJustin Hibbits { 1599*0aeed3e9SJustin Hibbits uint16_t tmpReg16; 1600*0aeed3e9SJustin Hibbits 1601*0aeed3e9SJustin Hibbits /* Configure the TBI PHY Control Register */ 1602*0aeed3e9SJustin Hibbits tmpReg16 = PHY_TBICON_SPEED2 | PHY_TBICON_SRESET; 1603*0aeed3e9SJustin Hibbits 1604*0aeed3e9SJustin Hibbits DTSEC_MII_WritePhyReg(p_Dtsec, p_DtsecDriverParam->tbiPhyAddr, 17, tmpReg16); 1605*0aeed3e9SJustin Hibbits 1606*0aeed3e9SJustin Hibbits tmpReg16 = PHY_TBICON_SPEED2; 1607*0aeed3e9SJustin Hibbits 1608*0aeed3e9SJustin Hibbits DTSEC_MII_WritePhyReg(p_Dtsec, p_DtsecDriverParam->tbiPhyAddr, 17, tmpReg16); 1609*0aeed3e9SJustin Hibbits 1610*0aeed3e9SJustin Hibbits if(!p_DtsecDriverParam->halfDuplex) 1611*0aeed3e9SJustin Hibbits tmpReg16 |= PHY_CR_FULLDUPLEX | 0x8000 | PHY_CR_ANE; 1612*0aeed3e9SJustin Hibbits 1613*0aeed3e9SJustin Hibbits DTSEC_MII_WritePhyReg(p_Dtsec, p_DtsecDriverParam->tbiPhyAddr, 0, tmpReg16); 1614*0aeed3e9SJustin Hibbits 1615*0aeed3e9SJustin Hibbits tmpReg16 = 0x01a0; 1616*0aeed3e9SJustin Hibbits DTSEC_MII_WritePhyReg(p_Dtsec, p_DtsecDriverParam->tbiPhyAddr, 4, tmpReg16); 1617*0aeed3e9SJustin Hibbits 1618*0aeed3e9SJustin Hibbits tmpReg16 = 0x1340; 1619*0aeed3e9SJustin Hibbits DTSEC_MII_WritePhyReg(p_Dtsec, p_DtsecDriverParam->tbiPhyAddr, 0, tmpReg16); 1620*0aeed3e9SJustin Hibbits } 1621*0aeed3e9SJustin Hibbits 1622*0aeed3e9SJustin Hibbits /***************TMR_CTL************************/ 1623*0aeed3e9SJustin Hibbits WRITE_UINT32(p_DtsecMemMap->tmr_ctrl, 0); 1624*0aeed3e9SJustin Hibbits 1625*0aeed3e9SJustin Hibbits if(p_Dtsec->ptpTsuEnabled) 1626*0aeed3e9SJustin Hibbits { 1627*0aeed3e9SJustin Hibbits tmpReg32 = 0; 1628*0aeed3e9SJustin Hibbits if (p_Dtsec->enTsuErrExeption) 1629*0aeed3e9SJustin Hibbits tmpReg32 |= PEMASK_TSRE; 1630*0aeed3e9SJustin Hibbits WRITE_UINT32(p_DtsecMemMap->tmr_pemask, tmpReg32); 1631*0aeed3e9SJustin Hibbits WRITE_UINT32(p_DtsecMemMap->tmr_pevent, tmpReg32); 1632*0aeed3e9SJustin Hibbits } 1633*0aeed3e9SJustin Hibbits 1634*0aeed3e9SJustin Hibbits /***************DEBUG************************/ 1635*0aeed3e9SJustin Hibbits tmpReg32 = 0; 1636*0aeed3e9SJustin Hibbits if(p_DtsecDriverParam->debugMode) 1637*0aeed3e9SJustin Hibbits WRITE_UINT32(p_DtsecMemMap->tsec_id1, TSEC_ID1_DEBUG); 1638*0aeed3e9SJustin Hibbits /***************DEBUG************************/ 1639*0aeed3e9SJustin Hibbits 1640*0aeed3e9SJustin Hibbits /***************MACCFG1***********************/ 1641*0aeed3e9SJustin Hibbits WRITE_UINT32(p_DtsecMemMap->maccfg1, MACCFG1_SOFT_RESET); 1642*0aeed3e9SJustin Hibbits WRITE_UINT32(p_DtsecMemMap->maccfg1, 0); 1643*0aeed3e9SJustin Hibbits tmpReg32 = 0; 1644*0aeed3e9SJustin Hibbits if(p_DtsecDriverParam->loopback) 1645*0aeed3e9SJustin Hibbits tmpReg32 |= MACCFG1_LOOPBACK; 1646*0aeed3e9SJustin Hibbits if(p_DtsecDriverParam->actOnRxPauseFrame) 1647*0aeed3e9SJustin Hibbits tmpReg32 |= MACCFG1_RX_FLOW; 1648*0aeed3e9SJustin Hibbits if(p_DtsecDriverParam->actOnTxPauseFrame) 1649*0aeed3e9SJustin Hibbits tmpReg32 |= MACCFG1_TX_FLOW; 1650*0aeed3e9SJustin Hibbits WRITE_UINT32(p_DtsecMemMap->maccfg1, tmpReg32); 1651*0aeed3e9SJustin Hibbits /***************MACCFG1***********************/ 1652*0aeed3e9SJustin Hibbits 1653*0aeed3e9SJustin Hibbits /***************MACCFG2***********************/ 1654*0aeed3e9SJustin Hibbits tmpReg32 = 0; 1655*0aeed3e9SJustin Hibbits if( (p_Dtsec->enetMode == e_ENET_MODE_RMII_10) || 1656*0aeed3e9SJustin Hibbits (p_Dtsec->enetMode == e_ENET_MODE_RMII_100) || 1657*0aeed3e9SJustin Hibbits (p_Dtsec->enetMode == e_ENET_MODE_MII_10) || 1658*0aeed3e9SJustin Hibbits (p_Dtsec->enetMode == e_ENET_MODE_MII_100) || 1659*0aeed3e9SJustin Hibbits (p_Dtsec->enetMode == e_ENET_MODE_RGMII_10) || 1660*0aeed3e9SJustin Hibbits (p_Dtsec->enetMode == e_ENET_MODE_RGMII_100)|| 1661*0aeed3e9SJustin Hibbits (p_Dtsec->enetMode == e_ENET_MODE_SGMII_10) || 1662*0aeed3e9SJustin Hibbits (p_Dtsec->enetMode == e_ENET_MODE_SGMII_100)) 1663*0aeed3e9SJustin Hibbits tmpReg32 |= MACCFG2_NIBBLE_MODE; 1664*0aeed3e9SJustin Hibbits else if((p_Dtsec->enetMode == e_ENET_MODE_RGMII_1000) || 1665*0aeed3e9SJustin Hibbits (p_Dtsec->enetMode == e_ENET_MODE_SGMII_1000)|| 1666*0aeed3e9SJustin Hibbits (p_Dtsec->enetMode == e_ENET_MODE_GMII_1000)|| 1667*0aeed3e9SJustin Hibbits (p_Dtsec->enetMode == e_ENET_MODE_QSGMII_1000)) 1668*0aeed3e9SJustin Hibbits tmpReg32 |= MACCFG2_BYTE_MODE; 1669*0aeed3e9SJustin Hibbits 1670*0aeed3e9SJustin Hibbits tmpReg32 |= (((uint32_t)p_DtsecDriverParam->preambleLength) & 0x0000000f)<< PREAMBLE_LENGTH_SHIFT; 1671*0aeed3e9SJustin Hibbits 1672*0aeed3e9SJustin Hibbits if(p_DtsecDriverParam->preambleRxEn) 1673*0aeed3e9SJustin Hibbits tmpReg32 |= MACCFG2_PRE_AM_Rx_EN; 1674*0aeed3e9SJustin Hibbits if(p_DtsecDriverParam->preambleTxEn) 1675*0aeed3e9SJustin Hibbits tmpReg32 |= MACCFG2_PRE_AM_Tx_EN; 1676*0aeed3e9SJustin Hibbits if(p_DtsecDriverParam->lengthCheckEnable) 1677*0aeed3e9SJustin Hibbits tmpReg32 |= MACCFG2_LENGTH_CHECK; 1678*0aeed3e9SJustin Hibbits if(p_DtsecDriverParam->padAndCrcEnable) 1679*0aeed3e9SJustin Hibbits tmpReg32 |= MACCFG2_PAD_CRC_EN; 1680*0aeed3e9SJustin Hibbits if(p_DtsecDriverParam->crcEnable) 1681*0aeed3e9SJustin Hibbits tmpReg32 |= MACCFG2_CRC_EN; 1682*0aeed3e9SJustin Hibbits if(!p_DtsecDriverParam->halfDuplex) 1683*0aeed3e9SJustin Hibbits tmpReg32 |= MACCFG2_FULL_DUPLEX; 1684*0aeed3e9SJustin Hibbits WRITE_UINT32(p_DtsecMemMap->maccfg2, tmpReg32); 1685*0aeed3e9SJustin Hibbits /***************MACCFG2***********************/ 1686*0aeed3e9SJustin Hibbits 1687*0aeed3e9SJustin Hibbits /***************IPGIFG************************/ 1688*0aeed3e9SJustin Hibbits tmpReg32 = 0; 1689*0aeed3e9SJustin Hibbits ASSERT_COND(p_DtsecDriverParam->nonBackToBackIpg1 <= p_DtsecDriverParam->nonBackToBackIpg2); 1690*0aeed3e9SJustin Hibbits tmpReg32 = (uint32_t)((((uint32_t)p_DtsecDriverParam->nonBackToBackIpg1 << 1691*0aeed3e9SJustin Hibbits IPGIFG_NON_BACK_TO_BACK_IPG_1_SHIFT) & IPGIFG_NON_BACK_TO_BACK_IPG_1) | 1692*0aeed3e9SJustin Hibbits (((uint32_t)p_DtsecDriverParam->nonBackToBackIpg2 << 1693*0aeed3e9SJustin Hibbits IPGIFG_NON_BACK_TO_BACK_IPG_2_SHIFT) & IPGIFG_NON_BACK_TO_BACK_IPG_2) | 1694*0aeed3e9SJustin Hibbits (((uint32_t)p_DtsecDriverParam->minIfgEnforcement << 1695*0aeed3e9SJustin Hibbits IPGIFG_MIN_IFG_ENFORCEMENT_SHIFT) & IPGIFG_MIN_IFG_ENFORCEMENT) | 1696*0aeed3e9SJustin Hibbits ((uint32_t)p_DtsecDriverParam->backToBackIpg & IPGIFG_BACK_TO_BACK_IPG)); 1697*0aeed3e9SJustin Hibbits WRITE_UINT32(p_DtsecMemMap->ipgifg, tmpReg32); 1698*0aeed3e9SJustin Hibbits /***************IPGIFG************************/ 1699*0aeed3e9SJustin Hibbits 1700*0aeed3e9SJustin Hibbits /***************HAFDUP************************/ 1701*0aeed3e9SJustin Hibbits tmpReg32 = 0; 1702*0aeed3e9SJustin Hibbits if(p_DtsecDriverParam->alternateBackoffEnable) 1703*0aeed3e9SJustin Hibbits { 1704*0aeed3e9SJustin Hibbits tmpReg32 = (uint32_t) (HAFDUP_ALT_BEB | (((uint32_t)p_DtsecDriverParam->alternateBackoffVal & 0x0000000f) << 1705*0aeed3e9SJustin Hibbits HAFDUP_ALTERNATE_BEB_TRUNCATION_SHIFT)); 1706*0aeed3e9SJustin Hibbits } 1707*0aeed3e9SJustin Hibbits 1708*0aeed3e9SJustin Hibbits if(p_DtsecDriverParam->backPressureNoBackoff) 1709*0aeed3e9SJustin Hibbits tmpReg32 |= HAFDUP_BP_NO_BACKOFF; 1710*0aeed3e9SJustin Hibbits if(p_DtsecDriverParam->noBackoff) 1711*0aeed3e9SJustin Hibbits tmpReg32 |= HAFDUP_NO_BACKOFF; 1712*0aeed3e9SJustin Hibbits if(p_DtsecDriverParam->excessDefer) 1713*0aeed3e9SJustin Hibbits tmpReg32 |= HAFDUP_EXCESS_DEFER; 1714*0aeed3e9SJustin Hibbits tmpReg32 |= (((uint32_t)p_DtsecDriverParam->maxRetransmission << 1715*0aeed3e9SJustin Hibbits HAFDUP_RETRANSMISSION_MAX_SHIFT )& HAFDUP_RETRANSMISSION_MAX); 1716*0aeed3e9SJustin Hibbits tmpReg32|= ((uint32_t)p_DtsecDriverParam->collisionWindow & HAFDUP_COLLISION_WINDOW); 1717*0aeed3e9SJustin Hibbits 1718*0aeed3e9SJustin Hibbits WRITE_UINT32(p_DtsecMemMap->hafdup, tmpReg32); 1719*0aeed3e9SJustin Hibbits /***************HAFDUP************************/ 1720*0aeed3e9SJustin Hibbits 1721*0aeed3e9SJustin Hibbits /***************MAXFRM************************/ 1722*0aeed3e9SJustin Hibbits /* Initialize MAXFRM */ 1723*0aeed3e9SJustin Hibbits WRITE_UINT32(p_DtsecMemMap->maxfrm, 1724*0aeed3e9SJustin Hibbits p_DtsecDriverParam->maxFrameLength); 1725*0aeed3e9SJustin Hibbits err = FmSetMacMaxFrame(p_Dtsec->fmMacControllerDriver.h_Fm, 1726*0aeed3e9SJustin Hibbits e_FM_MAC_1G, 1727*0aeed3e9SJustin Hibbits p_Dtsec->fmMacControllerDriver.macId, 1728*0aeed3e9SJustin Hibbits p_DtsecDriverParam->maxFrameLength); 1729*0aeed3e9SJustin Hibbits if (err) 1730*0aeed3e9SJustin Hibbits RETURN_ERROR(MAJOR, err, NO_MSG); 1731*0aeed3e9SJustin Hibbits /***************MAXFRM************************/ 1732*0aeed3e9SJustin Hibbits 1733*0aeed3e9SJustin Hibbits /***************CAM1************************/ 1734*0aeed3e9SJustin Hibbits WRITE_UINT32(p_DtsecMemMap->cam1,0xffffffff); 1735*0aeed3e9SJustin Hibbits WRITE_UINT32(p_DtsecMemMap->cam2,0xffffffff); 1736*0aeed3e9SJustin Hibbits 1737*0aeed3e9SJustin Hibbits /***************IMASK************************/ 1738*0aeed3e9SJustin Hibbits WRITE_UINT32(p_DtsecMemMap->imask, p_Dtsec->exceptions); 1739*0aeed3e9SJustin Hibbits /***************IMASK************************/ 1740*0aeed3e9SJustin Hibbits 1741*0aeed3e9SJustin Hibbits /***************IEVENT************************/ 1742*0aeed3e9SJustin Hibbits WRITE_UINT32(p_DtsecMemMap->ievent, EVENTS_MASK); 1743*0aeed3e9SJustin Hibbits 1744*0aeed3e9SJustin Hibbits /***************MACSTNADDR1/2*****************/ 1745*0aeed3e9SJustin Hibbits /* Initialize MAC Station Address registers (1 & 2) */ 1746*0aeed3e9SJustin Hibbits /* Station address have to be swapped (big endian to little endian */ 1747*0aeed3e9SJustin Hibbits addr = p_Dtsec->addr; 1748*0aeed3e9SJustin Hibbits 1749*0aeed3e9SJustin Hibbits tmpReg32 = (uint32_t)(addr); 1750*0aeed3e9SJustin Hibbits SwapUint32P(&tmpReg32); 1751*0aeed3e9SJustin Hibbits WRITE_UINT32(p_DtsecMemMap->macstnaddr1, tmpReg32); 1752*0aeed3e9SJustin Hibbits 1753*0aeed3e9SJustin Hibbits tmpReg32 = (uint32_t)(addr>>32); 1754*0aeed3e9SJustin Hibbits SwapUint32P(&tmpReg32); 1755*0aeed3e9SJustin Hibbits WRITE_UINT32(p_DtsecMemMap->macstnaddr2, tmpReg32); 1756*0aeed3e9SJustin Hibbits /***************MACSTNADDR1/2*****************/ 1757*0aeed3e9SJustin Hibbits 1758*0aeed3e9SJustin Hibbits /***************DEBUG*****************/ 1759*0aeed3e9SJustin Hibbits WRITE_UINT32(p_DtsecMemMap->tx_threshold, (uint32_t)(p_DtsecDriverParam->fifoTxThr & 0x7f)); 1760*0aeed3e9SJustin Hibbits WRITE_UINT32(p_DtsecMemMap->tx_watermark_high, (uint32_t)(p_DtsecDriverParam->fifoTxWatermarkH & 0x7f)); 1761*0aeed3e9SJustin Hibbits WRITE_UINT32(p_DtsecMemMap->rx_watermark_low, (uint32_t)(p_DtsecDriverParam->fifoRxWatermarkL & 0x7f)); 1762*0aeed3e9SJustin Hibbits /***************DEBUG*****************/ 1763*0aeed3e9SJustin Hibbits 1764*0aeed3e9SJustin Hibbits /*****************HASH************************/ 1765*0aeed3e9SJustin Hibbits for(i=0 ; i<NUM_OF_HASH_REGS ; i++) 1766*0aeed3e9SJustin Hibbits { 1767*0aeed3e9SJustin Hibbits /* Initialize IADDRx */ 1768*0aeed3e9SJustin Hibbits WRITE_UINT32(p_DtsecMemMap->igaddr[i], 0); 1769*0aeed3e9SJustin Hibbits /* Initialize GADDRx */ 1770*0aeed3e9SJustin Hibbits WRITE_UINT32(p_DtsecMemMap->gaddr[i], 0); 1771*0aeed3e9SJustin Hibbits } 1772*0aeed3e9SJustin Hibbits 1773*0aeed3e9SJustin Hibbits p_Dtsec->p_MulticastAddrHash = AllocHashTable(HASH_TABLE_SIZE); 1774*0aeed3e9SJustin Hibbits if(!p_Dtsec->p_MulticastAddrHash) 1775*0aeed3e9SJustin Hibbits { 1776*0aeed3e9SJustin Hibbits FreeInitResources(p_Dtsec); 1777*0aeed3e9SJustin Hibbits RETURN_ERROR(MAJOR, E_NO_MEMORY, ("MC hash table is FAILED")); 1778*0aeed3e9SJustin Hibbits } 1779*0aeed3e9SJustin Hibbits 1780*0aeed3e9SJustin Hibbits p_Dtsec->p_UnicastAddrHash = AllocHashTable(HASH_TABLE_SIZE); 1781*0aeed3e9SJustin Hibbits if(!p_Dtsec->p_UnicastAddrHash) 1782*0aeed3e9SJustin Hibbits { 1783*0aeed3e9SJustin Hibbits FreeInitResources(p_Dtsec); 1784*0aeed3e9SJustin Hibbits RETURN_ERROR(MAJOR, E_NO_MEMORY, ("UC hash table is FAILED")); 1785*0aeed3e9SJustin Hibbits } 1786*0aeed3e9SJustin Hibbits 1787*0aeed3e9SJustin Hibbits /* register err intr handler for dtsec to FPM (err)*/ 1788*0aeed3e9SJustin Hibbits FmRegisterIntr(p_Dtsec->fmMacControllerDriver.h_Fm, e_FM_MOD_1G_MAC, p_Dtsec->macId, e_FM_INTR_TYPE_ERR, DtsecErrException , p_Dtsec); 1789*0aeed3e9SJustin Hibbits /* register 1588 intr handler for TMR to FPM (normal)*/ 1790*0aeed3e9SJustin Hibbits FmRegisterIntr(p_Dtsec->fmMacControllerDriver.h_Fm, e_FM_MOD_1G_MAC_TMR, p_Dtsec->macId, e_FM_INTR_TYPE_NORMAL, Dtsec1588Exception , p_Dtsec); 1791*0aeed3e9SJustin Hibbits /* register normal intr handler for dtsec to main interrupt controller. */ 1792*0aeed3e9SJustin Hibbits if (p_Dtsec->mdioIrq != NO_IRQ) 1793*0aeed3e9SJustin Hibbits { 1794*0aeed3e9SJustin Hibbits XX_SetIntr(p_Dtsec->mdioIrq, DtsecException, p_Dtsec); 1795*0aeed3e9SJustin Hibbits XX_EnableIntr(p_Dtsec->mdioIrq); 1796*0aeed3e9SJustin Hibbits } 1797*0aeed3e9SJustin Hibbits 1798*0aeed3e9SJustin Hibbits XX_Free(p_DtsecDriverParam); 1799*0aeed3e9SJustin Hibbits p_Dtsec->p_DtsecDriverParam = NULL; 1800*0aeed3e9SJustin Hibbits 1801*0aeed3e9SJustin Hibbits err = DtsecSetStatistics(p_Dtsec, e_FM_MAC_FULL_STATISTICS); 1802*0aeed3e9SJustin Hibbits if(err) 1803*0aeed3e9SJustin Hibbits { 1804*0aeed3e9SJustin Hibbits FreeInitResources(p_Dtsec); 1805*0aeed3e9SJustin Hibbits RETURN_ERROR(MAJOR, err, NO_MSG); 1806*0aeed3e9SJustin Hibbits } 1807*0aeed3e9SJustin Hibbits 1808*0aeed3e9SJustin Hibbits return E_OK; 1809*0aeed3e9SJustin Hibbits } 1810*0aeed3e9SJustin Hibbits 1811*0aeed3e9SJustin Hibbits /* ........................................................................... */ 1812*0aeed3e9SJustin Hibbits 1813*0aeed3e9SJustin Hibbits static t_Error DtsecFree(t_Handle h_Dtsec) 1814*0aeed3e9SJustin Hibbits { 1815*0aeed3e9SJustin Hibbits t_Dtsec *p_Dtsec = (t_Dtsec *)h_Dtsec; 1816*0aeed3e9SJustin Hibbits 1817*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Dtsec, E_INVALID_HANDLE); 1818*0aeed3e9SJustin Hibbits 1819*0aeed3e9SJustin Hibbits FreeInitResources(p_Dtsec); 1820*0aeed3e9SJustin Hibbits 1821*0aeed3e9SJustin Hibbits if (p_Dtsec->p_DtsecDriverParam) 1822*0aeed3e9SJustin Hibbits { 1823*0aeed3e9SJustin Hibbits XX_Free(p_Dtsec->p_DtsecDriverParam); 1824*0aeed3e9SJustin Hibbits p_Dtsec->p_DtsecDriverParam = NULL; 1825*0aeed3e9SJustin Hibbits } 1826*0aeed3e9SJustin Hibbits XX_Free (h_Dtsec); 1827*0aeed3e9SJustin Hibbits 1828*0aeed3e9SJustin Hibbits return E_OK; 1829*0aeed3e9SJustin Hibbits } 1830*0aeed3e9SJustin Hibbits 1831*0aeed3e9SJustin Hibbits /* .............................................................................. */ 1832*0aeed3e9SJustin Hibbits 1833*0aeed3e9SJustin Hibbits static void InitFmMacControllerDriver(t_FmMacControllerDriver *p_FmMacControllerDriver) 1834*0aeed3e9SJustin Hibbits { 1835*0aeed3e9SJustin Hibbits p_FmMacControllerDriver->f_FM_MAC_Init = DtsecInit; 1836*0aeed3e9SJustin Hibbits p_FmMacControllerDriver->f_FM_MAC_Free = DtsecFree; 1837*0aeed3e9SJustin Hibbits 1838*0aeed3e9SJustin Hibbits p_FmMacControllerDriver->f_FM_MAC_SetStatistics = DtsecSetStatistics; 1839*0aeed3e9SJustin Hibbits p_FmMacControllerDriver->f_FM_MAC_ConfigLoopback = DtsecConfigLoopback; 1840*0aeed3e9SJustin Hibbits p_FmMacControllerDriver->f_FM_MAC_ConfigMaxFrameLength = DtsecConfigMaxFrameLength; 1841*0aeed3e9SJustin Hibbits 1842*0aeed3e9SJustin Hibbits p_FmMacControllerDriver->f_FM_MAC_ConfigWan = NULL; /* Not supported on dTSEC */ 1843*0aeed3e9SJustin Hibbits 1844*0aeed3e9SJustin Hibbits p_FmMacControllerDriver->f_FM_MAC_ConfigPadAndCrc = DtsecConfigPadAndCrc; 1845*0aeed3e9SJustin Hibbits p_FmMacControllerDriver->f_FM_MAC_ConfigHalfDuplex = DtsecConfigHalfDuplex; 1846*0aeed3e9SJustin Hibbits p_FmMacControllerDriver->f_FM_MAC_ConfigLengthCheck = DtsecConfigLengthCheck; 1847*0aeed3e9SJustin Hibbits p_FmMacControllerDriver->f_FM_MAC_ConfigException = DtsecConfigException; 1848*0aeed3e9SJustin Hibbits 1849*0aeed3e9SJustin Hibbits p_FmMacControllerDriver->f_FM_MAC_Enable = DtsecEnable; 1850*0aeed3e9SJustin Hibbits p_FmMacControllerDriver->f_FM_MAC_Disable = DtsecDisable; 1851*0aeed3e9SJustin Hibbits 1852*0aeed3e9SJustin Hibbits p_FmMacControllerDriver->f_FM_MAC_SetException = DtsecSetException; 1853*0aeed3e9SJustin Hibbits 1854*0aeed3e9SJustin Hibbits p_FmMacControllerDriver->f_FM_MAC_SetPromiscuous = DtsecSetPromiscuous; 1855*0aeed3e9SJustin Hibbits p_FmMacControllerDriver->f_FM_MAC_AdjustLink = DtsecAdjustLink; 1856*0aeed3e9SJustin Hibbits 1857*0aeed3e9SJustin Hibbits p_FmMacControllerDriver->f_FM_MAC_Enable1588TimeStamp = DtsecEnable1588TimeStamp; 1858*0aeed3e9SJustin Hibbits p_FmMacControllerDriver->f_FM_MAC_Disable1588TimeStamp = DtsecDisable1588TimeStamp; 1859*0aeed3e9SJustin Hibbits 1860*0aeed3e9SJustin Hibbits p_FmMacControllerDriver->f_FM_MAC_SetTxAutoPauseFrames = DtsecTxMacPause; 1861*0aeed3e9SJustin Hibbits p_FmMacControllerDriver->f_FM_MAC_SetRxIgnorePauseFrames = DtsecRxIgnoreMacPause; 1862*0aeed3e9SJustin Hibbits 1863*0aeed3e9SJustin Hibbits p_FmMacControllerDriver->f_FM_MAC_ResetCounters = DtsecResetCounters; 1864*0aeed3e9SJustin Hibbits p_FmMacControllerDriver->f_FM_MAC_GetStatistics = DtsecGetStatistics; 1865*0aeed3e9SJustin Hibbits 1866*0aeed3e9SJustin Hibbits p_FmMacControllerDriver->f_FM_MAC_ModifyMacAddr = DtsecModifyMacAddress; 1867*0aeed3e9SJustin Hibbits p_FmMacControllerDriver->f_FM_MAC_AddHashMacAddr = DtsecAddHashMacAddress; 1868*0aeed3e9SJustin Hibbits p_FmMacControllerDriver->f_FM_MAC_RemoveHashMacAddr = DtsecDelHashMacAddress; 1869*0aeed3e9SJustin Hibbits p_FmMacControllerDriver->f_FM_MAC_AddExactMatchMacAddr = DtsecAddExactMatchMacAddress; 1870*0aeed3e9SJustin Hibbits p_FmMacControllerDriver->f_FM_MAC_RemovelExactMatchMacAddr = DtsecDelExactMatchMacAddress; 1871*0aeed3e9SJustin Hibbits p_FmMacControllerDriver->f_FM_MAC_GetId = DtsecGetId; 1872*0aeed3e9SJustin Hibbits p_FmMacControllerDriver->f_FM_MAC_GetVersion = DtsecGetVersion; 1873*0aeed3e9SJustin Hibbits p_FmMacControllerDriver->f_FM_MAC_GetMaxFrameLength = DtsecGetMaxFrameLength; 1874*0aeed3e9SJustin Hibbits 1875*0aeed3e9SJustin Hibbits p_FmMacControllerDriver->f_FM_MAC_MII_WritePhyReg = DTSEC_MII_WritePhyReg; 1876*0aeed3e9SJustin Hibbits p_FmMacControllerDriver->f_FM_MAC_MII_ReadPhyReg = DTSEC_MII_ReadPhyReg; 1877*0aeed3e9SJustin Hibbits 1878*0aeed3e9SJustin Hibbits #if (defined(DEBUG_ERRORS) && (DEBUG_ERRORS > 0)) 1879*0aeed3e9SJustin Hibbits p_FmMacControllerDriver->f_FM_MAC_DumpRegs = DtsecDumpRegs; 1880*0aeed3e9SJustin Hibbits #endif /* (defined(DEBUG_ERRORS) && ... */ 1881*0aeed3e9SJustin Hibbits } 1882*0aeed3e9SJustin Hibbits 1883*0aeed3e9SJustin Hibbits 1884*0aeed3e9SJustin Hibbits /*****************************************************************************/ 1885*0aeed3e9SJustin Hibbits /* dTSEC Config Main Entry */ 1886*0aeed3e9SJustin Hibbits /*****************************************************************************/ 1887*0aeed3e9SJustin Hibbits 1888*0aeed3e9SJustin Hibbits /* .............................................................................. */ 1889*0aeed3e9SJustin Hibbits 1890*0aeed3e9SJustin Hibbits t_Handle DTSEC_Config(t_FmMacParams *p_FmMacParam) 1891*0aeed3e9SJustin Hibbits { 1892*0aeed3e9SJustin Hibbits t_Dtsec *p_Dtsec; 1893*0aeed3e9SJustin Hibbits t_DtsecDriverParam *p_DtsecDriverParam; 1894*0aeed3e9SJustin Hibbits uintptr_t baseAddr; 1895*0aeed3e9SJustin Hibbits uint8_t i; 1896*0aeed3e9SJustin Hibbits 1897*0aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_VALUE(p_FmMacParam, E_NULL_POINTER, NULL); 1898*0aeed3e9SJustin Hibbits 1899*0aeed3e9SJustin Hibbits baseAddr = p_FmMacParam->baseAddr; 1900*0aeed3e9SJustin Hibbits /* allocate memory for the UCC GETH data structure. */ 1901*0aeed3e9SJustin Hibbits p_Dtsec = (t_Dtsec *) XX_Malloc(sizeof(t_Dtsec)); 1902*0aeed3e9SJustin Hibbits if (!p_Dtsec) 1903*0aeed3e9SJustin Hibbits { 1904*0aeed3e9SJustin Hibbits REPORT_ERROR(MAJOR, E_NO_MEMORY, ("dTSEC driver structure")); 1905*0aeed3e9SJustin Hibbits return NULL; 1906*0aeed3e9SJustin Hibbits } 1907*0aeed3e9SJustin Hibbits /* Zero out * p_Dtsec */ 1908*0aeed3e9SJustin Hibbits memset(p_Dtsec, 0, sizeof(t_Dtsec)); 1909*0aeed3e9SJustin Hibbits InitFmMacControllerDriver(&p_Dtsec->fmMacControllerDriver); 1910*0aeed3e9SJustin Hibbits 1911*0aeed3e9SJustin Hibbits /* allocate memory for the dTSEC driver parameters data structure. */ 1912*0aeed3e9SJustin Hibbits p_DtsecDriverParam = (t_DtsecDriverParam *) XX_Malloc(sizeof(t_DtsecDriverParam)); 1913*0aeed3e9SJustin Hibbits if (!p_DtsecDriverParam) 1914*0aeed3e9SJustin Hibbits { 1915*0aeed3e9SJustin Hibbits XX_Free(p_Dtsec); 1916*0aeed3e9SJustin Hibbits REPORT_ERROR(MAJOR, E_NO_MEMORY, ("dTSEC driver parameters")); 1917*0aeed3e9SJustin Hibbits return NULL; 1918*0aeed3e9SJustin Hibbits } 1919*0aeed3e9SJustin Hibbits /* Zero out */ 1920*0aeed3e9SJustin Hibbits memset(p_DtsecDriverParam, 0, sizeof(t_DtsecDriverParam)); 1921*0aeed3e9SJustin Hibbits 1922*0aeed3e9SJustin Hibbits /* Plant parameter structure pointer */ 1923*0aeed3e9SJustin Hibbits p_Dtsec->p_DtsecDriverParam = p_DtsecDriverParam; 1924*0aeed3e9SJustin Hibbits 1925*0aeed3e9SJustin Hibbits SetDefaultParam(p_DtsecDriverParam); 1926*0aeed3e9SJustin Hibbits 1927*0aeed3e9SJustin Hibbits for (i=0; i < sizeof(p_FmMacParam->addr); i++) 1928*0aeed3e9SJustin Hibbits p_Dtsec->addr |= ((uint64_t)p_FmMacParam->addr[i] << ((5-i) * 8)); 1929*0aeed3e9SJustin Hibbits 1930*0aeed3e9SJustin Hibbits p_Dtsec->p_MemMap = (t_DtsecMemMap *)UINT_TO_PTR(baseAddr); 1931*0aeed3e9SJustin Hibbits p_Dtsec->p_MiiMemMap = (t_MiiAccessMemMap *)UINT_TO_PTR(baseAddr + DTSEC_TO_MII_OFFSET); 1932*0aeed3e9SJustin Hibbits p_Dtsec->enetMode = p_FmMacParam->enetMode; 1933*0aeed3e9SJustin Hibbits p_Dtsec->macId = p_FmMacParam->macId; 1934*0aeed3e9SJustin Hibbits p_Dtsec->exceptions = DEFAULT_exceptions; 1935*0aeed3e9SJustin Hibbits p_Dtsec->mdioIrq = p_FmMacParam->mdioIrq; 1936*0aeed3e9SJustin Hibbits p_Dtsec->f_Exception = p_FmMacParam->f_Exception; 1937*0aeed3e9SJustin Hibbits p_Dtsec->f_Event = p_FmMacParam->f_Event; 1938*0aeed3e9SJustin Hibbits p_Dtsec->h_App = p_FmMacParam->h_App; 1939*0aeed3e9SJustin Hibbits 1940*0aeed3e9SJustin Hibbits return p_Dtsec; 1941*0aeed3e9SJustin Hibbits } 1942