1*852ba100SJustin Hibbits /*
2*852ba100SJustin Hibbits * Copyright 2008-2013 Freescale Semiconductor Inc.
30aeed3e9SJustin Hibbits *
40aeed3e9SJustin Hibbits * Redistribution and use in source and binary forms, with or without
50aeed3e9SJustin Hibbits * modification, are permitted provided that the following conditions are met:
60aeed3e9SJustin Hibbits * * Redistributions of source code must retain the above copyright
70aeed3e9SJustin Hibbits * notice, this list of conditions and the following disclaimer.
80aeed3e9SJustin Hibbits * * Redistributions in binary form must reproduce the above copyright
90aeed3e9SJustin Hibbits * notice, this list of conditions and the following disclaimer in the
100aeed3e9SJustin Hibbits * documentation and/or other materials provided with the distribution.
110aeed3e9SJustin Hibbits * * Neither the name of Freescale Semiconductor nor the
120aeed3e9SJustin Hibbits * names of its contributors may be used to endorse or promote products
130aeed3e9SJustin Hibbits * derived from this software without specific prior written permission.
140aeed3e9SJustin Hibbits *
150aeed3e9SJustin Hibbits *
160aeed3e9SJustin Hibbits * ALTERNATIVELY, this software may be distributed under the terms of the
170aeed3e9SJustin Hibbits * GNU General Public License ("GPL") as published by the Free Software
180aeed3e9SJustin Hibbits * Foundation, either version 2 of that License or (at your option) any
190aeed3e9SJustin Hibbits * later version.
200aeed3e9SJustin Hibbits *
210aeed3e9SJustin Hibbits * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
220aeed3e9SJustin Hibbits * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
230aeed3e9SJustin Hibbits * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
240aeed3e9SJustin Hibbits * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
250aeed3e9SJustin Hibbits * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
260aeed3e9SJustin Hibbits * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
270aeed3e9SJustin Hibbits * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
280aeed3e9SJustin Hibbits * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
290aeed3e9SJustin Hibbits * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
300aeed3e9SJustin Hibbits * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
310aeed3e9SJustin Hibbits */
320aeed3e9SJustin Hibbits
330aeed3e9SJustin Hibbits /******************************************************************************
340aeed3e9SJustin Hibbits @File dtsec.c
350aeed3e9SJustin Hibbits
36*852ba100SJustin Hibbits @Description FMan dTSEC driver
370aeed3e9SJustin Hibbits *//***************************************************************************/
380aeed3e9SJustin Hibbits
390aeed3e9SJustin Hibbits #include "std_ext.h"
400aeed3e9SJustin Hibbits #include "error_ext.h"
410aeed3e9SJustin Hibbits #include "string_ext.h"
420aeed3e9SJustin Hibbits #include "xx_ext.h"
430aeed3e9SJustin Hibbits #include "endian_ext.h"
440aeed3e9SJustin Hibbits #include "debug_ext.h"
45*852ba100SJustin Hibbits #include "crc_mac_addr_ext.h"
460aeed3e9SJustin Hibbits
470aeed3e9SJustin Hibbits #include "fm_common.h"
480aeed3e9SJustin Hibbits #include "dtsec.h"
49*852ba100SJustin Hibbits #include "fsl_fman_dtsec.h"
50*852ba100SJustin Hibbits #include "fsl_fman_dtsec_mii_acc.h"
510aeed3e9SJustin Hibbits
520aeed3e9SJustin Hibbits /*****************************************************************************/
530aeed3e9SJustin Hibbits /* Internal routines */
540aeed3e9SJustin Hibbits /*****************************************************************************/
550aeed3e9SJustin Hibbits
CheckInitParameters(t_Dtsec * p_Dtsec)560aeed3e9SJustin Hibbits static t_Error CheckInitParameters(t_Dtsec *p_Dtsec)
570aeed3e9SJustin Hibbits {
580aeed3e9SJustin Hibbits if (ENET_SPEED_FROM_MODE(p_Dtsec->enetMode) >= e_ENET_SPEED_10000)
590aeed3e9SJustin Hibbits RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("Ethernet 1G MAC driver only supports 1G or lower speeds"));
600aeed3e9SJustin Hibbits if (p_Dtsec->macId >= FM_MAX_NUM_OF_1G_MACS)
610aeed3e9SJustin Hibbits RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("macId can not be greater than the number of 1G MACs"));
620aeed3e9SJustin Hibbits if (p_Dtsec->addr == 0)
630aeed3e9SJustin Hibbits RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("Ethernet MAC Must have a valid MAC Address"));
64*852ba100SJustin Hibbits if ((ENET_SPEED_FROM_MODE(p_Dtsec->enetMode) >= e_ENET_SPEED_1000) &&
65*852ba100SJustin Hibbits p_Dtsec->p_DtsecDriverParam->halfdup_on)
660aeed3e9SJustin Hibbits RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("Ethernet MAC 1G can't work in half duplex"));
67*852ba100SJustin Hibbits if (p_Dtsec->p_DtsecDriverParam->halfdup_on && (p_Dtsec->p_DtsecDriverParam)->loopback)
680aeed3e9SJustin Hibbits RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("LoopBack is not supported in halfDuplex mode"));
69*852ba100SJustin Hibbits #ifdef FM_RX_PREAM_4_ERRATA_DTSEC_A001
70*852ba100SJustin Hibbits if (p_Dtsec->fmMacControllerDriver.fmRevInfo.majorRev <= 6) /* fixed for rev3 */
71*852ba100SJustin Hibbits if (p_Dtsec->p_DtsecDriverParam->rx_preamble)
720aeed3e9SJustin Hibbits RETURN_ERROR(MAJOR, E_NOT_SUPPORTED, ("preambleRxEn"));
73*852ba100SJustin Hibbits #endif /* FM_RX_PREAM_4_ERRATA_DTSEC_A001 */
74*852ba100SJustin Hibbits if (((p_Dtsec->p_DtsecDriverParam)->tx_preamble || (p_Dtsec->p_DtsecDriverParam)->rx_preamble) &&( (p_Dtsec->p_DtsecDriverParam)->preamble_len != 0x7))
750aeed3e9SJustin Hibbits RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("Preamble length should be 0x7 bytes"));
76*852ba100SJustin Hibbits if ((p_Dtsec->p_DtsecDriverParam)->halfdup_on &&
77*852ba100SJustin Hibbits (p_Dtsec->p_DtsecDriverParam->tx_time_stamp_en || p_Dtsec->p_DtsecDriverParam->rx_time_stamp_en))
780aeed3e9SJustin Hibbits RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("dTSEC in half duplex mode has to be with 1588 timeStamping diable"));
79*852ba100SJustin Hibbits if ((p_Dtsec->p_DtsecDriverParam)->rx_flow && (p_Dtsec->p_DtsecDriverParam)->rx_ctrl_acc )
800aeed3e9SJustin Hibbits RETURN_ERROR(MAJOR, E_INVALID_STATE, ("Receive control frame are not passed to the system memory so it can not be accept "));
81*852ba100SJustin Hibbits if ((p_Dtsec->p_DtsecDriverParam)->rx_prepend > MAX_PACKET_ALIGNMENT)
820aeed3e9SJustin Hibbits RETURN_ERROR(MAJOR, E_INVALID_STATE, ("packetAlignmentPadding can't be greater than %d ",MAX_PACKET_ALIGNMENT ));
83*852ba100SJustin Hibbits if (((p_Dtsec->p_DtsecDriverParam)->non_back_to_back_ipg1 > MAX_INTER_PACKET_GAP) ||
84*852ba100SJustin Hibbits ((p_Dtsec->p_DtsecDriverParam)->non_back_to_back_ipg2 > MAX_INTER_PACKET_GAP) ||
85*852ba100SJustin Hibbits ((p_Dtsec->p_DtsecDriverParam)->back_to_back_ipg > MAX_INTER_PACKET_GAP))
860aeed3e9SJustin Hibbits RETURN_ERROR(MAJOR, E_INVALID_STATE, ("Inter packet gap can't be greater than %d ",MAX_INTER_PACKET_GAP ));
87*852ba100SJustin Hibbits if ((p_Dtsec->p_DtsecDriverParam)->halfdup_alt_backoff_val > MAX_INTER_PALTERNATE_BEB)
880aeed3e9SJustin Hibbits RETURN_ERROR(MAJOR, E_INVALID_STATE, ("alternateBackoffVal can't be greater than %d ",MAX_INTER_PALTERNATE_BEB ));
89*852ba100SJustin Hibbits if ((p_Dtsec->p_DtsecDriverParam)->halfdup_retransmit > MAX_RETRANSMISSION)
900aeed3e9SJustin Hibbits RETURN_ERROR(MAJOR, E_INVALID_STATE, ("maxRetransmission can't be greater than %d ",MAX_RETRANSMISSION ));
91*852ba100SJustin Hibbits if ((p_Dtsec->p_DtsecDriverParam)->halfdup_coll_window > MAX_COLLISION_WINDOW)
920aeed3e9SJustin Hibbits RETURN_ERROR(MAJOR, E_INVALID_STATE, ("collisionWindow can't be greater than %d ",MAX_COLLISION_WINDOW ));
930aeed3e9SJustin Hibbits
940aeed3e9SJustin Hibbits /* If Auto negotiation process is disabled, need to */
950aeed3e9SJustin Hibbits /* Set up the PHY using the MII Management Interface */
96*852ba100SJustin Hibbits if (p_Dtsec->p_DtsecDriverParam->tbipa > MAX_PHYS)
970aeed3e9SJustin Hibbits RETURN_ERROR(MAJOR, E_NOT_IN_RANGE, ("PHY address (should be 0-%d)", MAX_PHYS));
980aeed3e9SJustin Hibbits if (!p_Dtsec->f_Exception)
990aeed3e9SJustin Hibbits RETURN_ERROR(MAJOR, E_INVALID_HANDLE, ("uninitialized f_Exception"));
1000aeed3e9SJustin Hibbits if (!p_Dtsec->f_Event)
1010aeed3e9SJustin Hibbits RETURN_ERROR(MAJOR, E_INVALID_HANDLE, ("uninitialized f_Event"));
102*852ba100SJustin Hibbits
103*852ba100SJustin Hibbits #ifdef FM_LEN_CHECK_ERRATA_FMAN_SW002
104*852ba100SJustin Hibbits if (p_Dtsec->p_DtsecDriverParam->rx_len_check)
105*852ba100SJustin Hibbits RETURN_ERROR(MINOR, E_NOT_SUPPORTED, ("LengthCheck!"));
106*852ba100SJustin Hibbits #endif /* FM_LEN_CHECK_ERRATA_FMAN_SW002 */
107*852ba100SJustin Hibbits
1080aeed3e9SJustin Hibbits return E_OK;
1090aeed3e9SJustin Hibbits }
1100aeed3e9SJustin Hibbits
111*852ba100SJustin Hibbits /* ......................................................................... */
1120aeed3e9SJustin Hibbits
GetMacAddrHashCode(uint64_t ethAddr)113*852ba100SJustin Hibbits static uint32_t GetMacAddrHashCode(uint64_t ethAddr)
114*852ba100SJustin Hibbits {
115*852ba100SJustin Hibbits uint32_t crc;
1160aeed3e9SJustin Hibbits
117*852ba100SJustin Hibbits /* CRC calculation */
118*852ba100SJustin Hibbits GET_MAC_ADDR_CRC(ethAddr, crc);
119*852ba100SJustin Hibbits
120*852ba100SJustin Hibbits crc = GetMirror32(crc);
121*852ba100SJustin Hibbits
122*852ba100SJustin Hibbits return crc;
1230aeed3e9SJustin Hibbits }
1240aeed3e9SJustin Hibbits
125*852ba100SJustin Hibbits /* ......................................................................... */
1260aeed3e9SJustin Hibbits
UpdateStatistics(t_Dtsec * p_Dtsec)1270aeed3e9SJustin Hibbits static void UpdateStatistics(t_Dtsec *p_Dtsec)
1280aeed3e9SJustin Hibbits {
129*852ba100SJustin Hibbits uint32_t car1, car2;
130*852ba100SJustin Hibbits
131*852ba100SJustin Hibbits fman_dtsec_get_clear_carry_regs(p_Dtsec->p_MemMap, &car1, &car2);
1320aeed3e9SJustin Hibbits
1330aeed3e9SJustin Hibbits if (car1)
1340aeed3e9SJustin Hibbits {
1350aeed3e9SJustin Hibbits if (car1 & CAR1_TR64)
1360aeed3e9SJustin Hibbits p_Dtsec->internalStatistics.tr64 += VAL22BIT;
1370aeed3e9SJustin Hibbits if (car1 & CAR1_TR127)
1380aeed3e9SJustin Hibbits p_Dtsec->internalStatistics.tr127 += VAL22BIT;
1390aeed3e9SJustin Hibbits if (car1 & CAR1_TR255)
1400aeed3e9SJustin Hibbits p_Dtsec->internalStatistics.tr255 += VAL22BIT;
1410aeed3e9SJustin Hibbits if (car1 & CAR1_TR511)
1420aeed3e9SJustin Hibbits p_Dtsec->internalStatistics.tr511 += VAL22BIT;
1430aeed3e9SJustin Hibbits if (car1 & CAR1_TRK1)
1440aeed3e9SJustin Hibbits p_Dtsec->internalStatistics.tr1k += VAL22BIT;
1450aeed3e9SJustin Hibbits if (car1 & CAR1_TRMAX)
1460aeed3e9SJustin Hibbits p_Dtsec->internalStatistics.trmax += VAL22BIT;
1470aeed3e9SJustin Hibbits if (car1 & CAR1_TRMGV)
1480aeed3e9SJustin Hibbits p_Dtsec->internalStatistics.trmgv += VAL22BIT;
1490aeed3e9SJustin Hibbits if (car1 & CAR1_RBYT)
1500aeed3e9SJustin Hibbits p_Dtsec->internalStatistics.rbyt += (uint64_t)VAL32BIT;
1510aeed3e9SJustin Hibbits if (car1 & CAR1_RPKT)
1520aeed3e9SJustin Hibbits p_Dtsec->internalStatistics.rpkt += VAL22BIT;
1530aeed3e9SJustin Hibbits if (car1 & CAR1_RMCA)
1540aeed3e9SJustin Hibbits p_Dtsec->internalStatistics.rmca += VAL22BIT;
1550aeed3e9SJustin Hibbits if (car1 & CAR1_RBCA)
1560aeed3e9SJustin Hibbits p_Dtsec->internalStatistics.rbca += VAL22BIT;
1570aeed3e9SJustin Hibbits if (car1 & CAR1_RXPF)
1580aeed3e9SJustin Hibbits p_Dtsec->internalStatistics.rxpf += VAL16BIT;
1590aeed3e9SJustin Hibbits if (car1 & CAR1_RALN)
1600aeed3e9SJustin Hibbits p_Dtsec->internalStatistics.raln += VAL16BIT;
1610aeed3e9SJustin Hibbits if (car1 & CAR1_RFLR)
1620aeed3e9SJustin Hibbits p_Dtsec->internalStatistics.rflr += VAL16BIT;
1630aeed3e9SJustin Hibbits if (car1 & CAR1_RCDE)
1640aeed3e9SJustin Hibbits p_Dtsec->internalStatistics.rcde += VAL16BIT;
1650aeed3e9SJustin Hibbits if (car1 & CAR1_RCSE)
1660aeed3e9SJustin Hibbits p_Dtsec->internalStatistics.rcse += VAL16BIT;
1670aeed3e9SJustin Hibbits if (car1 & CAR1_RUND)
1680aeed3e9SJustin Hibbits p_Dtsec->internalStatistics.rund += VAL16BIT;
1690aeed3e9SJustin Hibbits if (car1 & CAR1_ROVR)
1700aeed3e9SJustin Hibbits p_Dtsec->internalStatistics.rovr += VAL16BIT;
1710aeed3e9SJustin Hibbits if (car1 & CAR1_RFRG)
1720aeed3e9SJustin Hibbits p_Dtsec->internalStatistics.rfrg += VAL16BIT;
1730aeed3e9SJustin Hibbits if (car1 & CAR1_RJBR)
1740aeed3e9SJustin Hibbits p_Dtsec->internalStatistics.rjbr += VAL16BIT;
1750aeed3e9SJustin Hibbits if (car1 & CAR1_RDRP)
1760aeed3e9SJustin Hibbits p_Dtsec->internalStatistics.rdrp += VAL16BIT;
1770aeed3e9SJustin Hibbits }
1780aeed3e9SJustin Hibbits if (car2)
1790aeed3e9SJustin Hibbits {
1800aeed3e9SJustin Hibbits if (car2 & CAR2_TFCS)
1810aeed3e9SJustin Hibbits p_Dtsec->internalStatistics.tfcs += VAL12BIT;
1820aeed3e9SJustin Hibbits if (car2 & CAR2_TBYT)
1830aeed3e9SJustin Hibbits p_Dtsec->internalStatistics.tbyt += (uint64_t)VAL32BIT;
1840aeed3e9SJustin Hibbits if (car2 & CAR2_TPKT)
1850aeed3e9SJustin Hibbits p_Dtsec->internalStatistics.tpkt += VAL22BIT;
1860aeed3e9SJustin Hibbits if (car2 & CAR2_TMCA)
1870aeed3e9SJustin Hibbits p_Dtsec->internalStatistics.tmca += VAL22BIT;
1880aeed3e9SJustin Hibbits if (car2 & CAR2_TBCA)
1890aeed3e9SJustin Hibbits p_Dtsec->internalStatistics.tbca += VAL22BIT;
1900aeed3e9SJustin Hibbits if (car2 & CAR2_TXPF)
1910aeed3e9SJustin Hibbits p_Dtsec->internalStatistics.txpf += VAL16BIT;
1920aeed3e9SJustin Hibbits if (car2 & CAR2_TDRP)
1930aeed3e9SJustin Hibbits p_Dtsec->internalStatistics.tdrp += VAL16BIT;
1940aeed3e9SJustin Hibbits }
1950aeed3e9SJustin Hibbits }
1960aeed3e9SJustin Hibbits
1970aeed3e9SJustin Hibbits /* .............................................................................. */
1980aeed3e9SJustin Hibbits
DtsecGetMaxFrameLength(t_Handle h_Dtsec)1990aeed3e9SJustin Hibbits static uint16_t DtsecGetMaxFrameLength(t_Handle h_Dtsec)
2000aeed3e9SJustin Hibbits {
2010aeed3e9SJustin Hibbits t_Dtsec *p_Dtsec = (t_Dtsec *)h_Dtsec;
2020aeed3e9SJustin Hibbits
2030aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_VALUE(p_Dtsec, E_INVALID_HANDLE, 0);
204*852ba100SJustin Hibbits SANITY_CHECK_RETURN_VALUE(!p_Dtsec->p_DtsecDriverParam, E_INVALID_STATE, 0);
2050aeed3e9SJustin Hibbits
206*852ba100SJustin Hibbits return fman_dtsec_get_max_frame_len(p_Dtsec->p_MemMap);
2070aeed3e9SJustin Hibbits }
2080aeed3e9SJustin Hibbits
209*852ba100SJustin Hibbits /* .............................................................................. */
210*852ba100SJustin Hibbits
DtsecIsr(t_Handle h_Dtsec)211*852ba100SJustin Hibbits static void DtsecIsr(t_Handle h_Dtsec)
2120aeed3e9SJustin Hibbits {
2130aeed3e9SJustin Hibbits t_Dtsec *p_Dtsec = (t_Dtsec *)h_Dtsec;
2140aeed3e9SJustin Hibbits uint32_t event;
215*852ba100SJustin Hibbits struct dtsec_regs *p_DtsecMemMap = p_Dtsec->p_MemMap;
2160aeed3e9SJustin Hibbits
2170aeed3e9SJustin Hibbits /* do not handle MDIO events */
218*852ba100SJustin Hibbits event = fman_dtsec_get_event(p_DtsecMemMap, (uint32_t)(~(DTSEC_IMASK_MMRDEN | DTSEC_IMASK_MMWREN)));
2190aeed3e9SJustin Hibbits
220*852ba100SJustin Hibbits event &= fman_dtsec_get_interrupt_mask(p_DtsecMemMap);
2210aeed3e9SJustin Hibbits
222*852ba100SJustin Hibbits fman_dtsec_ack_event(p_DtsecMemMap, event);
2230aeed3e9SJustin Hibbits
224*852ba100SJustin Hibbits if (event & DTSEC_IMASK_BREN)
2250aeed3e9SJustin Hibbits p_Dtsec->f_Exception(p_Dtsec->h_App, e_FM_MAC_EX_1G_BAB_RX);
226*852ba100SJustin Hibbits if (event & DTSEC_IMASK_RXCEN)
2270aeed3e9SJustin Hibbits p_Dtsec->f_Exception(p_Dtsec->h_App, e_FM_MAC_EX_1G_RX_CTL);
228*852ba100SJustin Hibbits if (event & DTSEC_IMASK_MSROEN)
2290aeed3e9SJustin Hibbits UpdateStatistics(p_Dtsec);
230*852ba100SJustin Hibbits if (event & DTSEC_IMASK_GTSCEN)
2310aeed3e9SJustin Hibbits p_Dtsec->f_Exception(p_Dtsec->h_App, e_FM_MAC_EX_1G_GRATEFUL_TX_STP_COMPLET);
232*852ba100SJustin Hibbits if (event & DTSEC_IMASK_BTEN)
2330aeed3e9SJustin Hibbits p_Dtsec->f_Exception(p_Dtsec->h_App, e_FM_MAC_EX_1G_BAB_TX);
234*852ba100SJustin Hibbits if (event & DTSEC_IMASK_TXCEN)
2350aeed3e9SJustin Hibbits p_Dtsec->f_Exception(p_Dtsec->h_App, e_FM_MAC_EX_1G_TX_CTL);
236*852ba100SJustin Hibbits if (event & DTSEC_IMASK_TXEEN)
2370aeed3e9SJustin Hibbits p_Dtsec->f_Exception(p_Dtsec->h_App, e_FM_MAC_EX_1G_TX_ERR);
238*852ba100SJustin Hibbits if (event & DTSEC_IMASK_LCEN)
2390aeed3e9SJustin Hibbits p_Dtsec->f_Exception(p_Dtsec->h_App, e_FM_MAC_EX_1G_LATE_COL);
240*852ba100SJustin Hibbits if (event & DTSEC_IMASK_CRLEN)
2410aeed3e9SJustin Hibbits p_Dtsec->f_Exception(p_Dtsec->h_App, e_FM_MAC_EX_1G_COL_RET_LMT);
242*852ba100SJustin Hibbits if (event & DTSEC_IMASK_XFUNEN)
2430aeed3e9SJustin Hibbits {
2440aeed3e9SJustin Hibbits #ifdef FM_TX_LOCKUP_ERRATA_DTSEC6
245*852ba100SJustin Hibbits if (p_Dtsec->fmMacControllerDriver.fmRevInfo.majorRev == 2)
246*852ba100SJustin Hibbits {
2470aeed3e9SJustin Hibbits uint32_t tpkt1, tmpReg1, tpkt2, tmpReg2, i;
2480aeed3e9SJustin Hibbits /* a. Write 0x00E0_0C00 to DTSEC_ID */
2490aeed3e9SJustin Hibbits /* This is a read only regidter */
2500aeed3e9SJustin Hibbits
2510aeed3e9SJustin Hibbits /* b. Read and save the value of TPKT */
2520aeed3e9SJustin Hibbits tpkt1 = GET_UINT32(p_DtsecMemMap->tpkt);
2530aeed3e9SJustin Hibbits
2540aeed3e9SJustin Hibbits /* c. Read the register at dTSEC address offset 0x32C */
2550aeed3e9SJustin Hibbits tmpReg1 = GET_UINT32(*(uint32_t*)((uint8_t*)p_DtsecMemMap + 0x32c));
2560aeed3e9SJustin Hibbits
2570aeed3e9SJustin Hibbits /* d. Compare bits [9:15] to bits [25:31] of the register at address offset 0x32C. */
2580aeed3e9SJustin Hibbits if ((tmpReg1 & 0x007F0000) != (tmpReg1 & 0x0000007F))
2590aeed3e9SJustin Hibbits {
2600aeed3e9SJustin Hibbits /* If they are not equal, save the value of this register and wait for at least
2610aeed3e9SJustin Hibbits * MAXFRM*16 ns */
262*852ba100SJustin Hibbits XX_UDelay((uint32_t)(MIN(DtsecGetMaxFrameLength(p_Dtsec)*16/1000, 1)));
2630aeed3e9SJustin Hibbits }
2640aeed3e9SJustin Hibbits
2650aeed3e9SJustin Hibbits /* e. Read and save TPKT again and read the register at dTSEC address offset
2660aeed3e9SJustin Hibbits 0x32C again*/
2670aeed3e9SJustin Hibbits tpkt2 = GET_UINT32(p_DtsecMemMap->tpkt);
2680aeed3e9SJustin Hibbits tmpReg2 = GET_UINT32(*(uint32_t*)((uint8_t*)p_DtsecMemMap + 0x32c));
2690aeed3e9SJustin Hibbits
2700aeed3e9SJustin Hibbits /* f. Compare the value of TPKT saved in step b to value read in step e. Also
2710aeed3e9SJustin Hibbits compare bits [9:15] of the register at offset 0x32C saved in step d to the value
2720aeed3e9SJustin Hibbits of bits [9:15] saved in step e. If the two registers values are unchanged, then
2730aeed3e9SJustin Hibbits the transmit portion of the dTSEC controller is locked up and the user should
2740aeed3e9SJustin Hibbits proceed to the recover sequence. */
2750aeed3e9SJustin Hibbits if ((tpkt1 == tpkt2) && ((tmpReg1 & 0x007F0000) == (tmpReg2 & 0x007F0000)))
2760aeed3e9SJustin Hibbits {
2770aeed3e9SJustin Hibbits /* recover sequence */
2780aeed3e9SJustin Hibbits
2790aeed3e9SJustin Hibbits /* a.Write a 1 to RCTRL[GRS]*/
2800aeed3e9SJustin Hibbits
2810aeed3e9SJustin Hibbits WRITE_UINT32(p_DtsecMemMap->rctrl, GET_UINT32(p_DtsecMemMap->rctrl) | RCTRL_GRS);
2820aeed3e9SJustin Hibbits
2830aeed3e9SJustin Hibbits /* b.Wait until IEVENT[GRSC]=1, or at least 100 us has elapsed. */
2840aeed3e9SJustin Hibbits for (i = 0 ; i < 100 ; i++ )
2850aeed3e9SJustin Hibbits {
286*852ba100SJustin Hibbits if (GET_UINT32(p_DtsecMemMap->ievent) & DTSEC_IMASK_GRSCEN)
2870aeed3e9SJustin Hibbits break;
2880aeed3e9SJustin Hibbits XX_UDelay(1);
2890aeed3e9SJustin Hibbits }
290*852ba100SJustin Hibbits if (GET_UINT32(p_DtsecMemMap->ievent) & DTSEC_IMASK_GRSCEN)
291*852ba100SJustin Hibbits WRITE_UINT32(p_DtsecMemMap->ievent, DTSEC_IMASK_GRSCEN);
2920aeed3e9SJustin Hibbits else
2930aeed3e9SJustin Hibbits DBG(INFO,("Rx lockup due to dTSEC Tx lockup"));
2940aeed3e9SJustin Hibbits
2950aeed3e9SJustin Hibbits /* c.Write a 1 to bit n of FM_RSTC (offset 0x0CC of FPM)*/
2960aeed3e9SJustin Hibbits FmResetMac(p_Dtsec->fmMacControllerDriver.h_Fm, e_FM_MAC_1G, p_Dtsec->fmMacControllerDriver.macId);
2970aeed3e9SJustin Hibbits
2980aeed3e9SJustin Hibbits /* d.Wait 4 Tx clocks (32 ns) */
2990aeed3e9SJustin Hibbits XX_UDelay(1);
3000aeed3e9SJustin Hibbits
3010aeed3e9SJustin Hibbits /* e.Write a 0 to bit n of FM_RSTC. */
3020aeed3e9SJustin Hibbits /* cleared by FMAN */
3030aeed3e9SJustin Hibbits }
3040aeed3e9SJustin Hibbits }
3050aeed3e9SJustin Hibbits #endif /* FM_TX_LOCKUP_ERRATA_DTSEC6 */
3060aeed3e9SJustin Hibbits
3070aeed3e9SJustin Hibbits p_Dtsec->f_Exception(p_Dtsec->h_App, e_FM_MAC_EX_1G_TX_FIFO_UNDRN);
3080aeed3e9SJustin Hibbits }
309*852ba100SJustin Hibbits if (event & DTSEC_IMASK_MAGEN)
3100aeed3e9SJustin Hibbits p_Dtsec->f_Exception(p_Dtsec->h_App, e_FM_MAC_EX_1G_MAG_PCKT);
311*852ba100SJustin Hibbits if (event & DTSEC_IMASK_GRSCEN)
3120aeed3e9SJustin Hibbits p_Dtsec->f_Exception(p_Dtsec->h_App, e_FM_MAC_EX_1G_GRATEFUL_RX_STP_COMPLET);
313*852ba100SJustin Hibbits if (event & DTSEC_IMASK_TDPEEN)
3140aeed3e9SJustin Hibbits p_Dtsec->f_Exception(p_Dtsec->h_App, e_FM_MAC_EX_1G_TX_DATA_ERR);
315*852ba100SJustin Hibbits if (event & DTSEC_IMASK_RDPEEN)
3160aeed3e9SJustin Hibbits p_Dtsec->f_Exception(p_Dtsec->h_App, e_FM_MAC_EX_1G_RX_DATA_ERR);
3170aeed3e9SJustin Hibbits
3180aeed3e9SJustin Hibbits /* - masked interrupts */
319*852ba100SJustin Hibbits ASSERT_COND(!(event & DTSEC_IMASK_ABRTEN));
320*852ba100SJustin Hibbits ASSERT_COND(!(event & DTSEC_IMASK_IFERREN));
3210aeed3e9SJustin Hibbits }
3220aeed3e9SJustin Hibbits
DtsecMdioIsr(t_Handle h_Dtsec)323*852ba100SJustin Hibbits static void DtsecMdioIsr(t_Handle h_Dtsec)
3240aeed3e9SJustin Hibbits {
3250aeed3e9SJustin Hibbits t_Dtsec *p_Dtsec = (t_Dtsec *)h_Dtsec;
3260aeed3e9SJustin Hibbits uint32_t event;
327*852ba100SJustin Hibbits struct dtsec_regs *p_DtsecMemMap = p_Dtsec->p_MemMap;
328*852ba100SJustin Hibbits
329*852ba100SJustin Hibbits event = GET_UINT32(p_DtsecMemMap->ievent);
330*852ba100SJustin Hibbits /* handle only MDIO events */
331*852ba100SJustin Hibbits event &= (DTSEC_IMASK_MMRDEN | DTSEC_IMASK_MMWREN);
332*852ba100SJustin Hibbits if (event)
333*852ba100SJustin Hibbits {
334*852ba100SJustin Hibbits event &= GET_UINT32(p_DtsecMemMap->imask);
335*852ba100SJustin Hibbits
336*852ba100SJustin Hibbits WRITE_UINT32(p_DtsecMemMap->ievent, event);
337*852ba100SJustin Hibbits
338*852ba100SJustin Hibbits if (event & DTSEC_IMASK_MMRDEN)
339*852ba100SJustin Hibbits p_Dtsec->f_Event(p_Dtsec->h_App, e_FM_MAC_EX_1G_MII_MNG_RD_COMPLET);
340*852ba100SJustin Hibbits if (event & DTSEC_IMASK_MMWREN)
341*852ba100SJustin Hibbits p_Dtsec->f_Event(p_Dtsec->h_App, e_FM_MAC_EX_1G_MII_MNG_WR_COMPLET);
342*852ba100SJustin Hibbits }
343*852ba100SJustin Hibbits }
344*852ba100SJustin Hibbits
Dtsec1588Isr(t_Handle h_Dtsec)345*852ba100SJustin Hibbits static void Dtsec1588Isr(t_Handle h_Dtsec)
346*852ba100SJustin Hibbits {
347*852ba100SJustin Hibbits t_Dtsec *p_Dtsec = (t_Dtsec *)h_Dtsec;
348*852ba100SJustin Hibbits uint32_t event;
349*852ba100SJustin Hibbits struct dtsec_regs *p_DtsecMemMap = p_Dtsec->p_MemMap;
3500aeed3e9SJustin Hibbits
3510aeed3e9SJustin Hibbits if (p_Dtsec->ptpTsuEnabled)
3520aeed3e9SJustin Hibbits {
353*852ba100SJustin Hibbits event = fman_dtsec_check_and_clear_tmr_event(p_DtsecMemMap);
354*852ba100SJustin Hibbits
3550aeed3e9SJustin Hibbits if (event)
3560aeed3e9SJustin Hibbits {
357*852ba100SJustin Hibbits ASSERT_COND(event & TMR_PEVENT_TSRE);
3580aeed3e9SJustin Hibbits p_Dtsec->f_Exception(p_Dtsec->h_App, e_FM_MAC_EX_1G_1588_TS_RX_ERR);
3590aeed3e9SJustin Hibbits }
3600aeed3e9SJustin Hibbits }
3610aeed3e9SJustin Hibbits }
3620aeed3e9SJustin Hibbits
3630aeed3e9SJustin Hibbits /* ........................................................................... */
3640aeed3e9SJustin Hibbits
FreeInitResources(t_Dtsec * p_Dtsec)3650aeed3e9SJustin Hibbits static void FreeInitResources(t_Dtsec *p_Dtsec)
3660aeed3e9SJustin Hibbits {
367*852ba100SJustin Hibbits if (p_Dtsec->mdioIrq != NO_IRQ)
3680aeed3e9SJustin Hibbits {
3690aeed3e9SJustin Hibbits XX_DisableIntr(p_Dtsec->mdioIrq);
3700aeed3e9SJustin Hibbits XX_FreeIntr(p_Dtsec->mdioIrq);
3710aeed3e9SJustin Hibbits }
3720aeed3e9SJustin Hibbits FmUnregisterIntr(p_Dtsec->fmMacControllerDriver.h_Fm, e_FM_MOD_1G_MAC, p_Dtsec->macId, e_FM_INTR_TYPE_ERR);
373*852ba100SJustin Hibbits FmUnregisterIntr(p_Dtsec->fmMacControllerDriver.h_Fm, e_FM_MOD_1G_MAC, p_Dtsec->macId, e_FM_INTR_TYPE_NORMAL);
3740aeed3e9SJustin Hibbits
3750aeed3e9SJustin Hibbits /* release the driver's group hash table */
3760aeed3e9SJustin Hibbits FreeHashTable(p_Dtsec->p_MulticastAddrHash);
3770aeed3e9SJustin Hibbits p_Dtsec->p_MulticastAddrHash = NULL;
3780aeed3e9SJustin Hibbits
3790aeed3e9SJustin Hibbits /* release the driver's individual hash table */
3800aeed3e9SJustin Hibbits FreeHashTable(p_Dtsec->p_UnicastAddrHash);
3810aeed3e9SJustin Hibbits p_Dtsec->p_UnicastAddrHash = NULL;
3820aeed3e9SJustin Hibbits }
3830aeed3e9SJustin Hibbits
3840aeed3e9SJustin Hibbits /* ........................................................................... */
3850aeed3e9SJustin Hibbits
GracefulStop(t_Dtsec * p_Dtsec,e_CommMode mode)3860aeed3e9SJustin Hibbits static t_Error GracefulStop(t_Dtsec *p_Dtsec, e_CommMode mode)
3870aeed3e9SJustin Hibbits {
388*852ba100SJustin Hibbits struct dtsec_regs *p_MemMap;
3890aeed3e9SJustin Hibbits
3900aeed3e9SJustin Hibbits ASSERT_COND(p_Dtsec);
3910aeed3e9SJustin Hibbits
392*852ba100SJustin Hibbits p_MemMap = p_Dtsec->p_MemMap;
3930aeed3e9SJustin Hibbits ASSERT_COND(p_MemMap);
3940aeed3e9SJustin Hibbits
3950aeed3e9SJustin Hibbits /* Assert the graceful transmit stop bit */
3960aeed3e9SJustin Hibbits if (mode & e_COMM_MODE_RX)
397*852ba100SJustin Hibbits {
398*852ba100SJustin Hibbits fman_dtsec_stop_rx(p_MemMap);
3990aeed3e9SJustin Hibbits
4000aeed3e9SJustin Hibbits #ifdef FM_GRS_ERRATA_DTSEC_A002
401*852ba100SJustin Hibbits if (p_Dtsec->fmMacControllerDriver.fmRevInfo.majorRev == 2)
4020aeed3e9SJustin Hibbits XX_UDelay(100);
403*852ba100SJustin Hibbits #else /* FM_GRS_ERRATA_DTSEC_A002 */
404*852ba100SJustin Hibbits #ifdef FM_GTS_AFTER_DROPPED_FRAME_ERRATA_DTSEC_A004839
405*852ba100SJustin Hibbits XX_UDelay(10);
406*852ba100SJustin Hibbits #endif /* FM_GTS_AFTER_DROPPED_FRAME_ERRATA_DTSEC_A004839 */
4070aeed3e9SJustin Hibbits #endif /* FM_GRS_ERRATA_DTSEC_A002 */
408*852ba100SJustin Hibbits }
4090aeed3e9SJustin Hibbits
4100aeed3e9SJustin Hibbits if (mode & e_COMM_MODE_TX)
411*852ba100SJustin Hibbits #if defined(FM_GTS_ERRATA_DTSEC_A004) || defined(FM_GTS_AFTER_MAC_ABORTED_FRAME_ERRATA_DTSEC_A0012)
412*852ba100SJustin Hibbits if (p_Dtsec->fmMacControllerDriver.fmRevInfo.majorRev == 2)
413*852ba100SJustin Hibbits DBG(INFO, ("GTS not supported due to DTSEC_A004 errata."));
414*852ba100SJustin Hibbits #else /* not defined(FM_GTS_ERRATA_DTSEC_A004) ||... */
415*852ba100SJustin Hibbits #ifdef FM_GTS_UNDERRUN_ERRATA_DTSEC_A0014
416*852ba100SJustin Hibbits DBG(INFO, ("GTS not supported due to DTSEC_A0014 errata."));
417*852ba100SJustin Hibbits #else /* FM_GTS_UNDERRUN_ERRATA_DTSEC_A0014 */
418*852ba100SJustin Hibbits fman_dtsec_stop_tx(p_MemMap);
419*852ba100SJustin Hibbits #endif /* FM_GTS_UNDERRUN_ERRATA_DTSEC_A0014 */
420*852ba100SJustin Hibbits #endif /* defined(FM_GTS_ERRATA_DTSEC_A004) ||... */
4210aeed3e9SJustin Hibbits
4220aeed3e9SJustin Hibbits return E_OK;
4230aeed3e9SJustin Hibbits }
4240aeed3e9SJustin Hibbits
4250aeed3e9SJustin Hibbits /* .............................................................................. */
4260aeed3e9SJustin Hibbits
GracefulRestart(t_Dtsec * p_Dtsec,e_CommMode mode)4270aeed3e9SJustin Hibbits static t_Error GracefulRestart(t_Dtsec *p_Dtsec, e_CommMode mode)
4280aeed3e9SJustin Hibbits {
429*852ba100SJustin Hibbits struct dtsec_regs *p_MemMap;
4300aeed3e9SJustin Hibbits
4310aeed3e9SJustin Hibbits ASSERT_COND(p_Dtsec);
432*852ba100SJustin Hibbits p_MemMap = p_Dtsec->p_MemMap;
4330aeed3e9SJustin Hibbits ASSERT_COND(p_MemMap);
4340aeed3e9SJustin Hibbits
4350aeed3e9SJustin Hibbits /* clear the graceful receive stop bit */
4360aeed3e9SJustin Hibbits if (mode & e_COMM_MODE_TX)
437*852ba100SJustin Hibbits fman_dtsec_start_tx(p_MemMap);
4380aeed3e9SJustin Hibbits
4390aeed3e9SJustin Hibbits if (mode & e_COMM_MODE_RX)
440*852ba100SJustin Hibbits fman_dtsec_start_rx(p_MemMap);
4410aeed3e9SJustin Hibbits
4420aeed3e9SJustin Hibbits return E_OK;
4430aeed3e9SJustin Hibbits }
4440aeed3e9SJustin Hibbits
4450aeed3e9SJustin Hibbits
4460aeed3e9SJustin Hibbits /*****************************************************************************/
4470aeed3e9SJustin Hibbits /* dTSEC Configs modification functions */
4480aeed3e9SJustin Hibbits /*****************************************************************************/
4490aeed3e9SJustin Hibbits
4500aeed3e9SJustin Hibbits /* .............................................................................. */
4510aeed3e9SJustin Hibbits
DtsecConfigLoopback(t_Handle h_Dtsec,bool newVal)4520aeed3e9SJustin Hibbits static t_Error DtsecConfigLoopback(t_Handle h_Dtsec, bool newVal)
4530aeed3e9SJustin Hibbits {
4540aeed3e9SJustin Hibbits
4550aeed3e9SJustin Hibbits t_Dtsec *p_Dtsec = (t_Dtsec *)h_Dtsec;
4560aeed3e9SJustin Hibbits
4570aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Dtsec, E_INVALID_HANDLE);
4580aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Dtsec->p_DtsecDriverParam, E_INVALID_STATE);
4590aeed3e9SJustin Hibbits
4600aeed3e9SJustin Hibbits p_Dtsec->p_DtsecDriverParam->loopback = newVal;
4610aeed3e9SJustin Hibbits
4620aeed3e9SJustin Hibbits return E_OK;
4630aeed3e9SJustin Hibbits }
4640aeed3e9SJustin Hibbits
4650aeed3e9SJustin Hibbits /* .............................................................................. */
4660aeed3e9SJustin Hibbits
DtsecConfigMaxFrameLength(t_Handle h_Dtsec,uint16_t newVal)4670aeed3e9SJustin Hibbits static t_Error DtsecConfigMaxFrameLength(t_Handle h_Dtsec, uint16_t newVal)
4680aeed3e9SJustin Hibbits {
4690aeed3e9SJustin Hibbits t_Dtsec *p_Dtsec = (t_Dtsec *)h_Dtsec;
4700aeed3e9SJustin Hibbits
4710aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Dtsec, E_INVALID_HANDLE);
4720aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Dtsec->p_DtsecDriverParam, E_INVALID_STATE);
4730aeed3e9SJustin Hibbits
474*852ba100SJustin Hibbits p_Dtsec->p_DtsecDriverParam->maximum_frame = newVal;
4750aeed3e9SJustin Hibbits
4760aeed3e9SJustin Hibbits return E_OK;
4770aeed3e9SJustin Hibbits }
4780aeed3e9SJustin Hibbits
4790aeed3e9SJustin Hibbits /* .............................................................................. */
4800aeed3e9SJustin Hibbits
DtsecConfigPadAndCrc(t_Handle h_Dtsec,bool newVal)4810aeed3e9SJustin Hibbits static t_Error DtsecConfigPadAndCrc(t_Handle h_Dtsec, bool newVal)
4820aeed3e9SJustin Hibbits {
4830aeed3e9SJustin Hibbits t_Dtsec *p_Dtsec = (t_Dtsec *)h_Dtsec;
4840aeed3e9SJustin Hibbits
4850aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Dtsec, E_INVALID_HANDLE);
4860aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Dtsec->p_DtsecDriverParam, E_INVALID_STATE);
4870aeed3e9SJustin Hibbits
488*852ba100SJustin Hibbits p_Dtsec->p_DtsecDriverParam->tx_pad_crc = newVal;
4890aeed3e9SJustin Hibbits
4900aeed3e9SJustin Hibbits return E_OK;
4910aeed3e9SJustin Hibbits }
4920aeed3e9SJustin Hibbits
4930aeed3e9SJustin Hibbits /* .............................................................................. */
4940aeed3e9SJustin Hibbits
DtsecConfigHalfDuplex(t_Handle h_Dtsec,bool newVal)4950aeed3e9SJustin Hibbits static t_Error DtsecConfigHalfDuplex(t_Handle h_Dtsec, bool newVal)
4960aeed3e9SJustin Hibbits {
4970aeed3e9SJustin Hibbits t_Dtsec *p_Dtsec = (t_Dtsec *)h_Dtsec;
4980aeed3e9SJustin Hibbits
4990aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Dtsec, E_INVALID_HANDLE);
5000aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Dtsec->p_DtsecDriverParam, E_INVALID_STATE);
5010aeed3e9SJustin Hibbits
502*852ba100SJustin Hibbits p_Dtsec->p_DtsecDriverParam->halfdup_on = newVal;
503*852ba100SJustin Hibbits
504*852ba100SJustin Hibbits return E_OK;
505*852ba100SJustin Hibbits }
506*852ba100SJustin Hibbits
507*852ba100SJustin Hibbits /* .............................................................................. */
508*852ba100SJustin Hibbits
DtsecConfigTbiPhyAddr(t_Handle h_Dtsec,uint8_t newVal)509*852ba100SJustin Hibbits static t_Error DtsecConfigTbiPhyAddr(t_Handle h_Dtsec, uint8_t newVal)
510*852ba100SJustin Hibbits {
511*852ba100SJustin Hibbits t_Dtsec *p_Dtsec = (t_Dtsec *)h_Dtsec;
512*852ba100SJustin Hibbits
513*852ba100SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Dtsec, E_INVALID_HANDLE);
514*852ba100SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Dtsec->p_DtsecDriverParam, E_INVALID_STATE);
515*852ba100SJustin Hibbits
516*852ba100SJustin Hibbits p_Dtsec->p_DtsecDriverParam->tbi_phy_addr = newVal;
5170aeed3e9SJustin Hibbits
5180aeed3e9SJustin Hibbits return E_OK;
5190aeed3e9SJustin Hibbits }
5200aeed3e9SJustin Hibbits
5210aeed3e9SJustin Hibbits /* .............................................................................. */
5220aeed3e9SJustin Hibbits
DtsecConfigLengthCheck(t_Handle h_Dtsec,bool newVal)5230aeed3e9SJustin Hibbits static t_Error DtsecConfigLengthCheck(t_Handle h_Dtsec, bool newVal)
5240aeed3e9SJustin Hibbits {
5250aeed3e9SJustin Hibbits t_Dtsec *p_Dtsec = (t_Dtsec *)h_Dtsec;
5260aeed3e9SJustin Hibbits
5270aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Dtsec, E_INVALID_HANDLE);
5280aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Dtsec->p_DtsecDriverParam, E_INVALID_STATE);
5290aeed3e9SJustin Hibbits
530*852ba100SJustin Hibbits p_Dtsec->p_DtsecDriverParam->rx_len_check = newVal;
5310aeed3e9SJustin Hibbits
5320aeed3e9SJustin Hibbits return E_OK;
5330aeed3e9SJustin Hibbits }
5340aeed3e9SJustin Hibbits
535*852ba100SJustin Hibbits /* .............................................................................. */
536*852ba100SJustin Hibbits
DtsecConfigException(t_Handle h_Dtsec,e_FmMacExceptions exception,bool enable)5370aeed3e9SJustin Hibbits static t_Error DtsecConfigException(t_Handle h_Dtsec, e_FmMacExceptions exception, bool enable)
5380aeed3e9SJustin Hibbits {
5390aeed3e9SJustin Hibbits t_Dtsec *p_Dtsec = (t_Dtsec *)h_Dtsec;
5400aeed3e9SJustin Hibbits uint32_t bitMask = 0;
5410aeed3e9SJustin Hibbits
5420aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Dtsec, E_INVALID_HANDLE);
5430aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Dtsec->p_DtsecDriverParam, E_INVALID_STATE);
5440aeed3e9SJustin Hibbits
5450aeed3e9SJustin Hibbits if (exception != e_FM_MAC_EX_1G_1588_TS_RX_ERR)
5460aeed3e9SJustin Hibbits {
5470aeed3e9SJustin Hibbits GET_EXCEPTION_FLAG(bitMask, exception);
5480aeed3e9SJustin Hibbits if (bitMask)
5490aeed3e9SJustin Hibbits {
5500aeed3e9SJustin Hibbits if (enable)
5510aeed3e9SJustin Hibbits p_Dtsec->exceptions |= bitMask;
5520aeed3e9SJustin Hibbits else
5530aeed3e9SJustin Hibbits p_Dtsec->exceptions &= ~bitMask;
5540aeed3e9SJustin Hibbits }
5550aeed3e9SJustin Hibbits else
5560aeed3e9SJustin Hibbits RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("Undefined exception"));
5570aeed3e9SJustin Hibbits }
5580aeed3e9SJustin Hibbits else
5590aeed3e9SJustin Hibbits {
5600aeed3e9SJustin Hibbits if (!p_Dtsec->ptpTsuEnabled)
5610aeed3e9SJustin Hibbits RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("Exception valid for 1588 only"));
562*852ba100SJustin Hibbits
5630aeed3e9SJustin Hibbits if (enable)
5640aeed3e9SJustin Hibbits p_Dtsec->enTsuErrExeption = TRUE;
5650aeed3e9SJustin Hibbits else
5660aeed3e9SJustin Hibbits p_Dtsec->enTsuErrExeption = FALSE;
5670aeed3e9SJustin Hibbits }
568*852ba100SJustin Hibbits
5690aeed3e9SJustin Hibbits return E_OK;
5700aeed3e9SJustin Hibbits }
571*852ba100SJustin Hibbits
572*852ba100SJustin Hibbits
5730aeed3e9SJustin Hibbits /*****************************************************************************/
5740aeed3e9SJustin Hibbits /* dTSEC Run Time API functions */
5750aeed3e9SJustin Hibbits /*****************************************************************************/
5760aeed3e9SJustin Hibbits
5770aeed3e9SJustin Hibbits /* .............................................................................. */
5780aeed3e9SJustin Hibbits
DtsecEnable(t_Handle h_Dtsec,e_CommMode mode)5790aeed3e9SJustin Hibbits static t_Error DtsecEnable(t_Handle h_Dtsec, e_CommMode mode)
5800aeed3e9SJustin Hibbits {
5810aeed3e9SJustin Hibbits t_Dtsec *p_Dtsec = (t_Dtsec *)h_Dtsec;
5820aeed3e9SJustin Hibbits
5830aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Dtsec, E_INVALID_HANDLE);
584*852ba100SJustin Hibbits SANITY_CHECK_RETURN_ERROR(!p_Dtsec->p_DtsecDriverParam, E_INVALID_STATE);
5850aeed3e9SJustin Hibbits
586*852ba100SJustin Hibbits fman_dtsec_enable(p_Dtsec->p_MemMap,
587*852ba100SJustin Hibbits (bool)!!(mode & e_COMM_MODE_RX),
588*852ba100SJustin Hibbits (bool)!!(mode & e_COMM_MODE_TX));
5890aeed3e9SJustin Hibbits
5900aeed3e9SJustin Hibbits GracefulRestart(p_Dtsec, mode);
5910aeed3e9SJustin Hibbits
5920aeed3e9SJustin Hibbits return E_OK;
5930aeed3e9SJustin Hibbits }
5940aeed3e9SJustin Hibbits
5950aeed3e9SJustin Hibbits /* .............................................................................. */
5960aeed3e9SJustin Hibbits
DtsecDisable(t_Handle h_Dtsec,e_CommMode mode)5970aeed3e9SJustin Hibbits static t_Error DtsecDisable (t_Handle h_Dtsec, e_CommMode mode)
5980aeed3e9SJustin Hibbits {
5990aeed3e9SJustin Hibbits t_Dtsec *p_Dtsec = (t_Dtsec *)h_Dtsec;
6000aeed3e9SJustin Hibbits
6010aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Dtsec, E_INVALID_HANDLE);
602*852ba100SJustin Hibbits SANITY_CHECK_RETURN_ERROR(!p_Dtsec->p_DtsecDriverParam, E_INVALID_STATE);
6030aeed3e9SJustin Hibbits
6040aeed3e9SJustin Hibbits GracefulStop(p_Dtsec, mode);
6050aeed3e9SJustin Hibbits
606*852ba100SJustin Hibbits fman_dtsec_disable(p_Dtsec->p_MemMap,
607*852ba100SJustin Hibbits (bool)!!(mode & e_COMM_MODE_RX),
608*852ba100SJustin Hibbits (bool)!!(mode & e_COMM_MODE_TX));
6090aeed3e9SJustin Hibbits
6100aeed3e9SJustin Hibbits return E_OK;
6110aeed3e9SJustin Hibbits }
6120aeed3e9SJustin Hibbits
6130aeed3e9SJustin Hibbits /* .............................................................................. */
6140aeed3e9SJustin Hibbits
DtsecSetTxPauseFrames(t_Handle h_Dtsec,uint8_t priority,uint16_t pauseTime,uint16_t threshTime)615*852ba100SJustin Hibbits static t_Error DtsecSetTxPauseFrames(t_Handle h_Dtsec,
616*852ba100SJustin Hibbits uint8_t priority,
617*852ba100SJustin Hibbits uint16_t pauseTime,
618*852ba100SJustin Hibbits uint16_t threshTime)
6190aeed3e9SJustin Hibbits {
6200aeed3e9SJustin Hibbits t_Dtsec *p_Dtsec = (t_Dtsec *)h_Dtsec;
621*852ba100SJustin Hibbits
622*852ba100SJustin Hibbits UNUSED(priority);UNUSED(threshTime);
6230aeed3e9SJustin Hibbits
6240aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Dtsec, E_INVALID_STATE);
6250aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(!p_Dtsec->p_DtsecDriverParam, E_INVALID_STATE);
6260aeed3e9SJustin Hibbits
6270aeed3e9SJustin Hibbits #ifdef FM_BAD_TX_TS_IN_B_2_B_ERRATA_DTSEC_A003
628*852ba100SJustin Hibbits if (p_Dtsec->fmMacControllerDriver.fmRevInfo.majorRev == 2)
629*852ba100SJustin Hibbits if (0 < pauseTime && pauseTime <= 320)
6300aeed3e9SJustin Hibbits RETURN_ERROR(MINOR, E_INVALID_VALUE,
6310aeed3e9SJustin Hibbits ("This pause-time value of %d is illegal due to errata dTSEC-A003!"
6320aeed3e9SJustin Hibbits " value should be greater than 320."));
6330aeed3e9SJustin Hibbits #endif /* FM_BAD_TX_TS_IN_B_2_B_ERRATA_DTSEC_A003 */
6340aeed3e9SJustin Hibbits
635*852ba100SJustin Hibbits fman_dtsec_set_tx_pause_frames(p_Dtsec->p_MemMap, pauseTime);
6360aeed3e9SJustin Hibbits return E_OK;
6370aeed3e9SJustin Hibbits }
6380aeed3e9SJustin Hibbits
6390aeed3e9SJustin Hibbits /* .............................................................................. */
640*852ba100SJustin Hibbits /* backward compatibility. will be removed in the future. */
DtsecTxMacPause(t_Handle h_Dtsec,uint16_t pauseTime)641*852ba100SJustin Hibbits static t_Error DtsecTxMacPause(t_Handle h_Dtsec, uint16_t pauseTime)
642*852ba100SJustin Hibbits {
643*852ba100SJustin Hibbits return DtsecSetTxPauseFrames(h_Dtsec, 0, pauseTime, 0);
644*852ba100SJustin Hibbits }
645*852ba100SJustin Hibbits
646*852ba100SJustin Hibbits /* .............................................................................. */
6470aeed3e9SJustin Hibbits
DtsecRxIgnoreMacPause(t_Handle h_Dtsec,bool en)6480aeed3e9SJustin Hibbits static t_Error DtsecRxIgnoreMacPause(t_Handle h_Dtsec, bool en)
6490aeed3e9SJustin Hibbits {
6500aeed3e9SJustin Hibbits t_Dtsec *p_Dtsec = (t_Dtsec *)h_Dtsec;
651*852ba100SJustin Hibbits bool accept_pause = !en;
6520aeed3e9SJustin Hibbits
6530aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Dtsec, E_INVALID_STATE);
6540aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(!p_Dtsec->p_DtsecDriverParam, E_INVALID_STATE);
6550aeed3e9SJustin Hibbits
656*852ba100SJustin Hibbits fman_dtsec_handle_rx_pause(p_Dtsec->p_MemMap, accept_pause);
6570aeed3e9SJustin Hibbits
6580aeed3e9SJustin Hibbits return E_OK;
6590aeed3e9SJustin Hibbits }
6600aeed3e9SJustin Hibbits
6610aeed3e9SJustin Hibbits /* .............................................................................. */
6620aeed3e9SJustin Hibbits
DtsecEnable1588TimeStamp(t_Handle h_Dtsec)6630aeed3e9SJustin Hibbits static t_Error DtsecEnable1588TimeStamp(t_Handle h_Dtsec)
6640aeed3e9SJustin Hibbits {
6650aeed3e9SJustin Hibbits t_Dtsec *p_Dtsec = (t_Dtsec *)h_Dtsec;
6660aeed3e9SJustin Hibbits
6670aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Dtsec, E_INVALID_HANDLE);
6680aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(!p_Dtsec->p_DtsecDriverParam, E_INVALID_STATE);
669*852ba100SJustin Hibbits
6700aeed3e9SJustin Hibbits p_Dtsec->ptpTsuEnabled = TRUE;
671*852ba100SJustin Hibbits fman_dtsec_set_ts(p_Dtsec->p_MemMap, TRUE);
6720aeed3e9SJustin Hibbits
6730aeed3e9SJustin Hibbits return E_OK;
6740aeed3e9SJustin Hibbits }
6750aeed3e9SJustin Hibbits
676*852ba100SJustin Hibbits /* .............................................................................. */
677*852ba100SJustin Hibbits
DtsecDisable1588TimeStamp(t_Handle h_Dtsec)6780aeed3e9SJustin Hibbits static t_Error DtsecDisable1588TimeStamp(t_Handle h_Dtsec)
6790aeed3e9SJustin Hibbits {
6800aeed3e9SJustin Hibbits t_Dtsec *p_Dtsec = (t_Dtsec *)h_Dtsec;
6810aeed3e9SJustin Hibbits
6820aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Dtsec, E_INVALID_HANDLE);
6830aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(!p_Dtsec->p_DtsecDriverParam, E_INVALID_STATE);
6840aeed3e9SJustin Hibbits
6850aeed3e9SJustin Hibbits p_Dtsec->ptpTsuEnabled = FALSE;
686*852ba100SJustin Hibbits fman_dtsec_set_ts(p_Dtsec->p_MemMap, FALSE);
6870aeed3e9SJustin Hibbits
6880aeed3e9SJustin Hibbits return E_OK;
6890aeed3e9SJustin Hibbits }
6900aeed3e9SJustin Hibbits
6910aeed3e9SJustin Hibbits /* .............................................................................. */
6920aeed3e9SJustin Hibbits
DtsecGetStatistics(t_Handle h_Dtsec,t_FmMacStatistics * p_Statistics)6930aeed3e9SJustin Hibbits static t_Error DtsecGetStatistics(t_Handle h_Dtsec, t_FmMacStatistics *p_Statistics)
6940aeed3e9SJustin Hibbits {
6950aeed3e9SJustin Hibbits t_Dtsec *p_Dtsec = (t_Dtsec *)h_Dtsec;
696*852ba100SJustin Hibbits struct dtsec_regs *p_DtsecMemMap;
6970aeed3e9SJustin Hibbits
6980aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Dtsec, E_INVALID_HANDLE);
699*852ba100SJustin Hibbits SANITY_CHECK_RETURN_ERROR(!p_Dtsec->p_DtsecDriverParam, E_INVALID_STATE);
7000aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Statistics, E_NULL_POINTER);
7010aeed3e9SJustin Hibbits
702*852ba100SJustin Hibbits p_DtsecMemMap = p_Dtsec->p_MemMap;
703*852ba100SJustin Hibbits
7040aeed3e9SJustin Hibbits if (p_Dtsec->statisticsLevel == e_FM_MAC_NONE_STATISTICS)
7050aeed3e9SJustin Hibbits RETURN_ERROR(MINOR, E_INVALID_STATE, ("Statistics disabled"));
7060aeed3e9SJustin Hibbits
7070aeed3e9SJustin Hibbits memset(p_Statistics, 0xff, sizeof(t_FmMacStatistics));
7080aeed3e9SJustin Hibbits
7090aeed3e9SJustin Hibbits if (p_Dtsec->statisticsLevel == e_FM_MAC_FULL_STATISTICS)
7100aeed3e9SJustin Hibbits {
711*852ba100SJustin Hibbits p_Statistics->eStatPkts64 = fman_dtsec_get_stat_counter(p_DtsecMemMap, E_DTSEC_STAT_TR64)
712*852ba100SJustin Hibbits + p_Dtsec->internalStatistics.tr64;
713*852ba100SJustin Hibbits p_Statistics->eStatPkts65to127 = fman_dtsec_get_stat_counter(p_DtsecMemMap, E_DTSEC_STAT_TR127)
714*852ba100SJustin Hibbits + p_Dtsec->internalStatistics.tr127;
715*852ba100SJustin Hibbits p_Statistics->eStatPkts128to255 = fman_dtsec_get_stat_counter(p_DtsecMemMap, E_DTSEC_STAT_TR255)
716*852ba100SJustin Hibbits + p_Dtsec->internalStatistics.tr255;
717*852ba100SJustin Hibbits p_Statistics->eStatPkts256to511 = fman_dtsec_get_stat_counter(p_DtsecMemMap, E_DTSEC_STAT_TR511)
718*852ba100SJustin Hibbits + p_Dtsec->internalStatistics.tr511;
719*852ba100SJustin Hibbits p_Statistics->eStatPkts512to1023 = fman_dtsec_get_stat_counter(p_DtsecMemMap, E_DTSEC_STAT_TR1K)
720*852ba100SJustin Hibbits + p_Dtsec->internalStatistics.tr1k;
721*852ba100SJustin Hibbits p_Statistics->eStatPkts1024to1518 = fman_dtsec_get_stat_counter(p_DtsecMemMap, E_DTSEC_STAT_TRMAX)
722*852ba100SJustin Hibbits + p_Dtsec->internalStatistics.trmax;
723*852ba100SJustin Hibbits p_Statistics->eStatPkts1519to1522 = fman_dtsec_get_stat_counter(p_DtsecMemMap, E_DTSEC_STAT_TRMGV)
724*852ba100SJustin Hibbits + p_Dtsec->internalStatistics.trmgv;
725*852ba100SJustin Hibbits
7260aeed3e9SJustin Hibbits /* MIB II */
727*852ba100SJustin Hibbits p_Statistics->ifInOctets = fman_dtsec_get_stat_counter(p_DtsecMemMap, E_DTSEC_STAT_RBYT)
728*852ba100SJustin Hibbits + p_Dtsec->internalStatistics.rbyt;
729*852ba100SJustin Hibbits p_Statistics->ifInPkts = fman_dtsec_get_stat_counter(p_DtsecMemMap, E_DTSEC_STAT_RPKT)
730*852ba100SJustin Hibbits + p_Dtsec->internalStatistics.rpkt;
731*852ba100SJustin Hibbits p_Statistics->ifInUcastPkts = 0;
732*852ba100SJustin Hibbits p_Statistics->ifInMcastPkts = fman_dtsec_get_stat_counter(p_DtsecMemMap, E_DTSEC_STAT_RMCA)
733*852ba100SJustin Hibbits + p_Dtsec->internalStatistics.rmca;
734*852ba100SJustin Hibbits p_Statistics->ifInBcastPkts = fman_dtsec_get_stat_counter(p_DtsecMemMap, E_DTSEC_STAT_RBCA)
735*852ba100SJustin Hibbits + p_Dtsec->internalStatistics.rbca;
736*852ba100SJustin Hibbits p_Statistics->ifOutOctets = fman_dtsec_get_stat_counter(p_DtsecMemMap, E_DTSEC_STAT_TBYT)
737*852ba100SJustin Hibbits + p_Dtsec->internalStatistics.tbyt;
738*852ba100SJustin Hibbits p_Statistics->ifOutPkts = fman_dtsec_get_stat_counter(p_DtsecMemMap, E_DTSEC_STAT_TPKT)
739*852ba100SJustin Hibbits + p_Dtsec->internalStatistics.tpkt;
740*852ba100SJustin Hibbits p_Statistics->ifOutUcastPkts = 0;
741*852ba100SJustin Hibbits p_Statistics->ifOutMcastPkts = fman_dtsec_get_stat_counter(p_DtsecMemMap, E_DTSEC_STAT_TMCA)
742*852ba100SJustin Hibbits + p_Dtsec->internalStatistics.tmca;
743*852ba100SJustin Hibbits p_Statistics->ifOutBcastPkts = fman_dtsec_get_stat_counter(p_DtsecMemMap, E_DTSEC_STAT_TBCA)
744*852ba100SJustin Hibbits + p_Dtsec->internalStatistics.tbca;
7450aeed3e9SJustin Hibbits }
7460aeed3e9SJustin Hibbits
747*852ba100SJustin Hibbits p_Statistics->eStatFragments = fman_dtsec_get_stat_counter(p_DtsecMemMap, E_DTSEC_STAT_RFRG)
748*852ba100SJustin Hibbits + p_Dtsec->internalStatistics.rfrg;
749*852ba100SJustin Hibbits p_Statistics->eStatJabbers = fman_dtsec_get_stat_counter(p_DtsecMemMap, E_DTSEC_STAT_RJBR)
750*852ba100SJustin Hibbits + p_Dtsec->internalStatistics.rjbr;
751*852ba100SJustin Hibbits p_Statistics->eStatsDropEvents = fman_dtsec_get_stat_counter(p_DtsecMemMap, E_DTSEC_STAT_RDRP)
752*852ba100SJustin Hibbits + p_Dtsec->internalStatistics.rdrp;
753*852ba100SJustin Hibbits p_Statistics->eStatCRCAlignErrors = fman_dtsec_get_stat_counter(p_DtsecMemMap, E_DTSEC_STAT_RALN)
754*852ba100SJustin Hibbits + p_Dtsec->internalStatistics.raln;
755*852ba100SJustin Hibbits p_Statistics->eStatUndersizePkts = fman_dtsec_get_stat_counter(p_DtsecMemMap, E_DTSEC_STAT_RUND)
756*852ba100SJustin Hibbits + p_Dtsec->internalStatistics.rund;
757*852ba100SJustin Hibbits p_Statistics->eStatOversizePkts = fman_dtsec_get_stat_counter(p_DtsecMemMap, E_DTSEC_STAT_ROVR)
758*852ba100SJustin Hibbits + p_Dtsec->internalStatistics.rovr;
759*852ba100SJustin Hibbits p_Statistics->reStatPause = fman_dtsec_get_stat_counter(p_DtsecMemMap, E_DTSEC_STAT_RXPF)
760*852ba100SJustin Hibbits + p_Dtsec->internalStatistics.rxpf;
761*852ba100SJustin Hibbits p_Statistics->teStatPause = fman_dtsec_get_stat_counter(p_DtsecMemMap, E_DTSEC_STAT_TXPF)
762*852ba100SJustin Hibbits + p_Dtsec->internalStatistics.txpf;
763*852ba100SJustin Hibbits p_Statistics->ifInDiscards = p_Statistics->eStatsDropEvents;
764*852ba100SJustin Hibbits p_Statistics->ifInErrors = p_Statistics->eStatsDropEvents + p_Statistics->eStatCRCAlignErrors
765*852ba100SJustin Hibbits + fman_dtsec_get_stat_counter(p_DtsecMemMap,E_DTSEC_STAT_RFLR) + p_Dtsec->internalStatistics.rflr
766*852ba100SJustin Hibbits + fman_dtsec_get_stat_counter(p_DtsecMemMap,E_DTSEC_STAT_RCDE) + p_Dtsec->internalStatistics.rcde
767*852ba100SJustin Hibbits + fman_dtsec_get_stat_counter(p_DtsecMemMap,E_DTSEC_STAT_RCSE) + p_Dtsec->internalStatistics.rcse;
7680aeed3e9SJustin Hibbits
769*852ba100SJustin Hibbits p_Statistics->ifOutDiscards = fman_dtsec_get_stat_counter(p_DtsecMemMap, E_DTSEC_STAT_TDRP)
770*852ba100SJustin Hibbits + p_Dtsec->internalStatistics.tdrp;
7710aeed3e9SJustin Hibbits p_Statistics->ifOutErrors = p_Statistics->ifOutDiscards /**< Number of frames transmitted with error: */
772*852ba100SJustin Hibbits + fman_dtsec_get_stat_counter(p_DtsecMemMap,E_DTSEC_STAT_TFCS)
7730aeed3e9SJustin Hibbits + p_Dtsec->internalStatistics.tfcs;
7740aeed3e9SJustin Hibbits
7750aeed3e9SJustin Hibbits return E_OK;
7760aeed3e9SJustin Hibbits }
7770aeed3e9SJustin Hibbits
7780aeed3e9SJustin Hibbits /* .............................................................................. */
7790aeed3e9SJustin Hibbits
DtsecModifyMacAddress(t_Handle h_Dtsec,t_EnetAddr * p_EnetAddr)7800aeed3e9SJustin Hibbits static t_Error DtsecModifyMacAddress (t_Handle h_Dtsec, t_EnetAddr *p_EnetAddr)
7810aeed3e9SJustin Hibbits {
7820aeed3e9SJustin Hibbits t_Dtsec *p_Dtsec = (t_Dtsec *)h_Dtsec;
7830aeed3e9SJustin Hibbits
7840aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Dtsec, E_INVALID_HANDLE);
785*852ba100SJustin Hibbits SANITY_CHECK_RETURN_ERROR(!p_Dtsec->p_DtsecDriverParam, E_INVALID_STATE);
7860aeed3e9SJustin Hibbits
7870aeed3e9SJustin Hibbits /* Initialize MAC Station Address registers (1 & 2) */
7880aeed3e9SJustin Hibbits /* Station address have to be swapped (big endian to little endian */
789*852ba100SJustin Hibbits p_Dtsec->addr = ENET_ADDR_TO_UINT64(*p_EnetAddr);
790*852ba100SJustin Hibbits fman_dtsec_set_mac_address(p_Dtsec->p_MemMap, (uint8_t *)(*p_EnetAddr));
7910aeed3e9SJustin Hibbits
7920aeed3e9SJustin Hibbits return E_OK;
7930aeed3e9SJustin Hibbits }
7940aeed3e9SJustin Hibbits
7950aeed3e9SJustin Hibbits /* .............................................................................. */
7960aeed3e9SJustin Hibbits
DtsecResetCounters(t_Handle h_Dtsec)7970aeed3e9SJustin Hibbits static t_Error DtsecResetCounters (t_Handle h_Dtsec)
7980aeed3e9SJustin Hibbits {
7990aeed3e9SJustin Hibbits t_Dtsec *p_Dtsec = (t_Dtsec *)h_Dtsec;
8000aeed3e9SJustin Hibbits
8010aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Dtsec, E_INVALID_HANDLE);
802*852ba100SJustin Hibbits SANITY_CHECK_RETURN_ERROR(!p_Dtsec->p_DtsecDriverParam, E_INVALID_STATE);
8030aeed3e9SJustin Hibbits
8040aeed3e9SJustin Hibbits /* clear HW counters */
805*852ba100SJustin Hibbits fman_dtsec_reset_stat(p_Dtsec->p_MemMap);
8060aeed3e9SJustin Hibbits
8070aeed3e9SJustin Hibbits /* clear SW counters holding carries */
808*852ba100SJustin Hibbits memset(&p_Dtsec->internalStatistics, 0, sizeof(t_InternalStatistics));
8090aeed3e9SJustin Hibbits
8100aeed3e9SJustin Hibbits return E_OK;
8110aeed3e9SJustin Hibbits }
8120aeed3e9SJustin Hibbits
8130aeed3e9SJustin Hibbits /* .............................................................................. */
8140aeed3e9SJustin Hibbits
DtsecAddExactMatchMacAddress(t_Handle h_Dtsec,t_EnetAddr * p_EthAddr)8150aeed3e9SJustin Hibbits static t_Error DtsecAddExactMatchMacAddress(t_Handle h_Dtsec, t_EnetAddr *p_EthAddr)
8160aeed3e9SJustin Hibbits {
8170aeed3e9SJustin Hibbits t_Dtsec *p_Dtsec = (t_Dtsec *) h_Dtsec;
8180aeed3e9SJustin Hibbits uint64_t ethAddr;
8190aeed3e9SJustin Hibbits uint8_t paddrNum;
8200aeed3e9SJustin Hibbits
8210aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Dtsec, E_INVALID_HANDLE);
822*852ba100SJustin Hibbits SANITY_CHECK_RETURN_ERROR(!p_Dtsec->p_DtsecDriverParam, E_INVALID_STATE);
8230aeed3e9SJustin Hibbits
824*852ba100SJustin Hibbits ethAddr = ENET_ADDR_TO_UINT64(*p_EthAddr);
8250aeed3e9SJustin Hibbits
8260aeed3e9SJustin Hibbits if (ethAddr & GROUP_ADDRESS)
8270aeed3e9SJustin Hibbits /* Multicast address has no effect in PADDR */
8280aeed3e9SJustin Hibbits RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("Multicast address"));
8290aeed3e9SJustin Hibbits
8300aeed3e9SJustin Hibbits /* Make sure no PADDR contains this address */
8310aeed3e9SJustin Hibbits for (paddrNum = 0; paddrNum < DTSEC_NUM_OF_PADDRS; paddrNum++)
8320aeed3e9SJustin Hibbits if (p_Dtsec->indAddrRegUsed[paddrNum])
8330aeed3e9SJustin Hibbits if (p_Dtsec->paddr[paddrNum] == ethAddr)
8340aeed3e9SJustin Hibbits RETURN_ERROR(MAJOR, E_ALREADY_EXISTS, NO_MSG);
8350aeed3e9SJustin Hibbits
8360aeed3e9SJustin Hibbits /* Find first unused PADDR */
8370aeed3e9SJustin Hibbits for (paddrNum = 0; paddrNum < DTSEC_NUM_OF_PADDRS; paddrNum++)
8380aeed3e9SJustin Hibbits if (!(p_Dtsec->indAddrRegUsed[paddrNum]))
8390aeed3e9SJustin Hibbits {
8400aeed3e9SJustin Hibbits /* mark this PADDR as used */
8410aeed3e9SJustin Hibbits p_Dtsec->indAddrRegUsed[paddrNum] = TRUE;
8420aeed3e9SJustin Hibbits /* store address */
8430aeed3e9SJustin Hibbits p_Dtsec->paddr[paddrNum] = ethAddr;
8440aeed3e9SJustin Hibbits
8450aeed3e9SJustin Hibbits /* put in hardware */
846*852ba100SJustin Hibbits fman_dtsec_add_addr_in_paddr(p_Dtsec->p_MemMap, (uint64_t)PTR_TO_UINT(ðAddr), paddrNum);
8470aeed3e9SJustin Hibbits p_Dtsec->numOfIndAddrInRegs++;
8480aeed3e9SJustin Hibbits
8490aeed3e9SJustin Hibbits return E_OK;
8500aeed3e9SJustin Hibbits }
8510aeed3e9SJustin Hibbits
8520aeed3e9SJustin Hibbits /* No free PADDR */
8530aeed3e9SJustin Hibbits RETURN_ERROR(MAJOR, E_FULL, NO_MSG);
8540aeed3e9SJustin Hibbits }
8550aeed3e9SJustin Hibbits
8560aeed3e9SJustin Hibbits /* .............................................................................. */
8570aeed3e9SJustin Hibbits
DtsecDelExactMatchMacAddress(t_Handle h_Dtsec,t_EnetAddr * p_EthAddr)8580aeed3e9SJustin Hibbits static t_Error DtsecDelExactMatchMacAddress(t_Handle h_Dtsec, t_EnetAddr *p_EthAddr)
8590aeed3e9SJustin Hibbits {
8600aeed3e9SJustin Hibbits t_Dtsec *p_Dtsec = (t_Dtsec *) h_Dtsec;
8610aeed3e9SJustin Hibbits uint64_t ethAddr;
8620aeed3e9SJustin Hibbits uint8_t paddrNum;
8630aeed3e9SJustin Hibbits
8640aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Dtsec, E_INVALID_HANDLE);
865*852ba100SJustin Hibbits SANITY_CHECK_RETURN_ERROR(!p_Dtsec->p_DtsecDriverParam, E_INVALID_STATE);
8660aeed3e9SJustin Hibbits
867*852ba100SJustin Hibbits ethAddr = ENET_ADDR_TO_UINT64(*p_EthAddr);
8680aeed3e9SJustin Hibbits
8690aeed3e9SJustin Hibbits /* Find used PADDR containing this address */
8700aeed3e9SJustin Hibbits for (paddrNum = 0; paddrNum < DTSEC_NUM_OF_PADDRS; paddrNum++)
8710aeed3e9SJustin Hibbits {
8720aeed3e9SJustin Hibbits if ((p_Dtsec->indAddrRegUsed[paddrNum]) &&
8730aeed3e9SJustin Hibbits (p_Dtsec->paddr[paddrNum] == ethAddr))
8740aeed3e9SJustin Hibbits {
8750aeed3e9SJustin Hibbits /* mark this PADDR as not used */
8760aeed3e9SJustin Hibbits p_Dtsec->indAddrRegUsed[paddrNum] = FALSE;
8770aeed3e9SJustin Hibbits /* clear in hardware */
878*852ba100SJustin Hibbits fman_dtsec_clear_addr_in_paddr(p_Dtsec->p_MemMap, paddrNum);
8790aeed3e9SJustin Hibbits p_Dtsec->numOfIndAddrInRegs--;
8800aeed3e9SJustin Hibbits
8810aeed3e9SJustin Hibbits return E_OK;
8820aeed3e9SJustin Hibbits }
8830aeed3e9SJustin Hibbits }
8840aeed3e9SJustin Hibbits
8850aeed3e9SJustin Hibbits RETURN_ERROR(MAJOR, E_NOT_FOUND, NO_MSG);
8860aeed3e9SJustin Hibbits }
8870aeed3e9SJustin Hibbits
8880aeed3e9SJustin Hibbits /* .............................................................................. */
8890aeed3e9SJustin Hibbits
DtsecAddHashMacAddress(t_Handle h_Dtsec,t_EnetAddr * p_EthAddr)8900aeed3e9SJustin Hibbits static t_Error DtsecAddHashMacAddress(t_Handle h_Dtsec, t_EnetAddr *p_EthAddr)
8910aeed3e9SJustin Hibbits {
8920aeed3e9SJustin Hibbits t_Dtsec *p_Dtsec = (t_Dtsec *)h_Dtsec;
8930aeed3e9SJustin Hibbits t_EthHashEntry *p_HashEntry;
8940aeed3e9SJustin Hibbits uint64_t ethAddr;
895*852ba100SJustin Hibbits int32_t bucket;
896*852ba100SJustin Hibbits uint32_t crc;
897*852ba100SJustin Hibbits bool mcast, ghtx;
8980aeed3e9SJustin Hibbits
8990aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Dtsec, E_INVALID_HANDLE);
900*852ba100SJustin Hibbits SANITY_CHECK_RETURN_ERROR(!p_Dtsec->p_DtsecDriverParam, E_INVALID_STATE);
9010aeed3e9SJustin Hibbits
902*852ba100SJustin Hibbits ethAddr = ENET_ADDR_TO_UINT64(*p_EthAddr);
9030aeed3e9SJustin Hibbits
904*852ba100SJustin Hibbits ghtx = (bool)((fman_dtsec_get_rctrl(p_Dtsec->p_MemMap) & RCTRL_GHTX) ? TRUE : FALSE);
905*852ba100SJustin Hibbits mcast = (bool)((ethAddr & MAC_GROUP_ADDRESS) ? TRUE : FALSE);
9060aeed3e9SJustin Hibbits
907*852ba100SJustin Hibbits if (ghtx && !mcast) /* Cannot handle unicast mac addr when GHTX is on */
908*852ba100SJustin Hibbits RETURN_ERROR(MAJOR, E_INVALID_STATE, ("Could not compute hash bucket"));
9090aeed3e9SJustin Hibbits
910*852ba100SJustin Hibbits crc = GetMacAddrHashCode(ethAddr);
9110aeed3e9SJustin Hibbits
912*852ba100SJustin Hibbits /* considering the 9 highest order bits in crc H[8:0]:
913*852ba100SJustin Hibbits * if ghtx = 0 H[8:6] (highest order 3 bits) identify the hash register
914*852ba100SJustin Hibbits * and H[5:1] (next 5 bits) identify the hash bit
915*852ba100SJustin Hibbits * if ghts = 1 H[8:5] (highest order 4 bits) identify the hash register
916*852ba100SJustin Hibbits * and H[4:0] (next 5 bits) identify the hash bit.
917*852ba100SJustin Hibbits *
918*852ba100SJustin Hibbits * In bucket index output the low 5 bits identify the hash register bit,
919*852ba100SJustin Hibbits * while the higher 4 bits identify the hash register
920*852ba100SJustin Hibbits */
921*852ba100SJustin Hibbits
922*852ba100SJustin Hibbits if (ghtx)
923*852ba100SJustin Hibbits bucket = (int32_t)((crc >> 23) & 0x1ff);
924*852ba100SJustin Hibbits else {
925*852ba100SJustin Hibbits bucket = (int32_t)((crc >> 24) & 0xff);
926*852ba100SJustin Hibbits /* if !ghtx and mcast the bit must be set in gaddr instead of igaddr. */
927*852ba100SJustin Hibbits if (mcast)
928*852ba100SJustin Hibbits bucket += 0x100;
929*852ba100SJustin Hibbits }
930*852ba100SJustin Hibbits
931*852ba100SJustin Hibbits fman_dtsec_set_bucket(p_Dtsec->p_MemMap, bucket, TRUE);
9320aeed3e9SJustin Hibbits
9330aeed3e9SJustin Hibbits /* Create element to be added to the driver hash table */
9340aeed3e9SJustin Hibbits p_HashEntry = (t_EthHashEntry *)XX_Malloc(sizeof(t_EthHashEntry));
9350aeed3e9SJustin Hibbits p_HashEntry->addr = ethAddr;
9360aeed3e9SJustin Hibbits INIT_LIST(&p_HashEntry->node);
9370aeed3e9SJustin Hibbits
938*852ba100SJustin Hibbits if (ethAddr & MAC_GROUP_ADDRESS)
9390aeed3e9SJustin Hibbits /* Group Address */
940*852ba100SJustin Hibbits NCSW_LIST_AddToTail(&(p_HashEntry->node), &(p_Dtsec->p_MulticastAddrHash->p_Lsts[bucket]));
9410aeed3e9SJustin Hibbits else
942*852ba100SJustin Hibbits NCSW_LIST_AddToTail(&(p_HashEntry->node), &(p_Dtsec->p_UnicastAddrHash->p_Lsts[bucket]));
9430aeed3e9SJustin Hibbits
9440aeed3e9SJustin Hibbits return E_OK;
9450aeed3e9SJustin Hibbits }
9460aeed3e9SJustin Hibbits
9470aeed3e9SJustin Hibbits /* .............................................................................. */
9480aeed3e9SJustin Hibbits
DtsecDelHashMacAddress(t_Handle h_Dtsec,t_EnetAddr * p_EthAddr)9490aeed3e9SJustin Hibbits static t_Error DtsecDelHashMacAddress(t_Handle h_Dtsec, t_EnetAddr *p_EthAddr)
9500aeed3e9SJustin Hibbits {
9510aeed3e9SJustin Hibbits t_Dtsec *p_Dtsec = (t_Dtsec *)h_Dtsec;
9520aeed3e9SJustin Hibbits t_List *p_Pos;
9530aeed3e9SJustin Hibbits t_EthHashEntry *p_HashEntry = NULL;
9540aeed3e9SJustin Hibbits uint64_t ethAddr;
955*852ba100SJustin Hibbits int32_t bucket;
956*852ba100SJustin Hibbits uint32_t crc;
957*852ba100SJustin Hibbits bool mcast, ghtx;
9580aeed3e9SJustin Hibbits
9590aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Dtsec, E_INVALID_HANDLE);
960*852ba100SJustin Hibbits SANITY_CHECK_RETURN_ERROR(!p_Dtsec->p_DtsecDriverParam, E_INVALID_STATE);
9610aeed3e9SJustin Hibbits
962*852ba100SJustin Hibbits ethAddr = ENET_ADDR_TO_UINT64(*p_EthAddr);
9630aeed3e9SJustin Hibbits
964*852ba100SJustin Hibbits ghtx = (bool)((fman_dtsec_get_rctrl(p_Dtsec->p_MemMap) & RCTRL_GHTX) ? TRUE : FALSE);
965*852ba100SJustin Hibbits mcast = (bool)((ethAddr & MAC_GROUP_ADDRESS) ? TRUE : FALSE);
9660aeed3e9SJustin Hibbits
967*852ba100SJustin Hibbits if (ghtx && !mcast) /* Cannot handle unicast mac addr when GHTX is on */
968*852ba100SJustin Hibbits RETURN_ERROR(MAJOR, E_INVALID_STATE, ("Could not compute hash bucket"));
9690aeed3e9SJustin Hibbits
970*852ba100SJustin Hibbits crc = GetMacAddrHashCode(ethAddr);
9710aeed3e9SJustin Hibbits
972*852ba100SJustin Hibbits if (ghtx)
973*852ba100SJustin Hibbits bucket = (int32_t)((crc >> 23) & 0x1ff);
974*852ba100SJustin Hibbits else {
975*852ba100SJustin Hibbits bucket = (int32_t)((crc >> 24) & 0xff);
976*852ba100SJustin Hibbits /* if !ghtx and mcast the bit must be set in gaddr instead of igaddr. */
977*852ba100SJustin Hibbits if (mcast)
978*852ba100SJustin Hibbits bucket += 0x100;
979*852ba100SJustin Hibbits }
9800aeed3e9SJustin Hibbits
981*852ba100SJustin Hibbits if (ethAddr & MAC_GROUP_ADDRESS)
9820aeed3e9SJustin Hibbits {
9830aeed3e9SJustin Hibbits /* Group Address */
984*852ba100SJustin Hibbits NCSW_LIST_FOR_EACH(p_Pos, &(p_Dtsec->p_MulticastAddrHash->p_Lsts[bucket]))
9850aeed3e9SJustin Hibbits {
9860aeed3e9SJustin Hibbits p_HashEntry = ETH_HASH_ENTRY_OBJ(p_Pos);
9870aeed3e9SJustin Hibbits if (p_HashEntry->addr == ethAddr)
9880aeed3e9SJustin Hibbits {
989*852ba100SJustin Hibbits NCSW_LIST_DelAndInit(&p_HashEntry->node);
9900aeed3e9SJustin Hibbits XX_Free(p_HashEntry);
9910aeed3e9SJustin Hibbits break;
9920aeed3e9SJustin Hibbits }
9930aeed3e9SJustin Hibbits }
994*852ba100SJustin Hibbits if (NCSW_LIST_IsEmpty(&p_Dtsec->p_MulticastAddrHash->p_Lsts[bucket]))
995*852ba100SJustin Hibbits fman_dtsec_set_bucket(p_Dtsec->p_MemMap, bucket, FALSE);
9960aeed3e9SJustin Hibbits }
9970aeed3e9SJustin Hibbits else
9980aeed3e9SJustin Hibbits {
9990aeed3e9SJustin Hibbits /* Individual Address */
1000*852ba100SJustin Hibbits NCSW_LIST_FOR_EACH(p_Pos, &(p_Dtsec->p_UnicastAddrHash->p_Lsts[bucket]))
10010aeed3e9SJustin Hibbits {
10020aeed3e9SJustin Hibbits p_HashEntry = ETH_HASH_ENTRY_OBJ(p_Pos);
10030aeed3e9SJustin Hibbits if (p_HashEntry->addr == ethAddr)
10040aeed3e9SJustin Hibbits {
1005*852ba100SJustin Hibbits NCSW_LIST_DelAndInit(&p_HashEntry->node);
10060aeed3e9SJustin Hibbits XX_Free(p_HashEntry);
10070aeed3e9SJustin Hibbits break;
10080aeed3e9SJustin Hibbits }
10090aeed3e9SJustin Hibbits }
1010*852ba100SJustin Hibbits if (NCSW_LIST_IsEmpty(&p_Dtsec->p_UnicastAddrHash->p_Lsts[bucket]))
1011*852ba100SJustin Hibbits fman_dtsec_set_bucket(p_Dtsec->p_MemMap, bucket, FALSE);
10120aeed3e9SJustin Hibbits }
10130aeed3e9SJustin Hibbits
10140aeed3e9SJustin Hibbits /* address does not exist */
10150aeed3e9SJustin Hibbits ASSERT_COND(p_HashEntry != NULL);
10160aeed3e9SJustin Hibbits
10170aeed3e9SJustin Hibbits return E_OK;
10180aeed3e9SJustin Hibbits }
10190aeed3e9SJustin Hibbits
10200aeed3e9SJustin Hibbits /* .............................................................................. */
10210aeed3e9SJustin Hibbits
DtsecSetPromiscuous(t_Handle h_Dtsec,bool newVal)10220aeed3e9SJustin Hibbits static t_Error DtsecSetPromiscuous(t_Handle h_Dtsec, bool newVal)
10230aeed3e9SJustin Hibbits {
10240aeed3e9SJustin Hibbits t_Dtsec *p_Dtsec = (t_Dtsec *)h_Dtsec;
10250aeed3e9SJustin Hibbits
10260aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Dtsec, E_INVALID_HANDLE);
1027*852ba100SJustin Hibbits SANITY_CHECK_RETURN_ERROR(!p_Dtsec->p_DtsecDriverParam, E_INVALID_STATE);
10280aeed3e9SJustin Hibbits
1029*852ba100SJustin Hibbits fman_dtsec_set_uc_promisc(p_Dtsec->p_MemMap, newVal);
1030*852ba100SJustin Hibbits fman_dtsec_set_mc_promisc(p_Dtsec->p_MemMap, newVal);
10310aeed3e9SJustin Hibbits
10320aeed3e9SJustin Hibbits return E_OK;
10330aeed3e9SJustin Hibbits }
10340aeed3e9SJustin Hibbits
10350aeed3e9SJustin Hibbits /* .............................................................................. */
10360aeed3e9SJustin Hibbits
DtsecSetStatistics(t_Handle h_Dtsec,e_FmMacStatisticsLevel statisticsLevel)10370aeed3e9SJustin Hibbits static t_Error DtsecSetStatistics(t_Handle h_Dtsec, e_FmMacStatisticsLevel statisticsLevel)
10380aeed3e9SJustin Hibbits {
10390aeed3e9SJustin Hibbits t_Dtsec *p_Dtsec = (t_Dtsec *)h_Dtsec;
1040*852ba100SJustin Hibbits t_Error err;
10410aeed3e9SJustin Hibbits
10420aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Dtsec, E_INVALID_HANDLE);
1043*852ba100SJustin Hibbits SANITY_CHECK_RETURN_ERROR(!p_Dtsec->p_DtsecDriverParam, E_INVALID_STATE);
10440aeed3e9SJustin Hibbits
10450aeed3e9SJustin Hibbits p_Dtsec->statisticsLevel = statisticsLevel;
10460aeed3e9SJustin Hibbits
1047*852ba100SJustin Hibbits err = (t_Error)fman_dtsec_set_stat_level(p_Dtsec->p_MemMap,
1048*852ba100SJustin Hibbits (enum dtsec_stat_level)statisticsLevel);
1049*852ba100SJustin Hibbits if (err != E_OK)
1050*852ba100SJustin Hibbits return err;
1051*852ba100SJustin Hibbits
1052*852ba100SJustin Hibbits switch (statisticsLevel)
10530aeed3e9SJustin Hibbits {
10540aeed3e9SJustin Hibbits case (e_FM_MAC_NONE_STATISTICS):
1055*852ba100SJustin Hibbits p_Dtsec->exceptions &= ~DTSEC_IMASK_MSROEN;
10560aeed3e9SJustin Hibbits break;
10570aeed3e9SJustin Hibbits case (e_FM_MAC_PARTIAL_STATISTICS):
1058*852ba100SJustin Hibbits p_Dtsec->exceptions |= DTSEC_IMASK_MSROEN;
10590aeed3e9SJustin Hibbits break;
10600aeed3e9SJustin Hibbits case (e_FM_MAC_FULL_STATISTICS):
1061*852ba100SJustin Hibbits p_Dtsec->exceptions |= DTSEC_IMASK_MSROEN;
10620aeed3e9SJustin Hibbits break;
10630aeed3e9SJustin Hibbits default:
10640aeed3e9SJustin Hibbits RETURN_ERROR(MINOR, E_INVALID_SELECTION, NO_MSG);
10650aeed3e9SJustin Hibbits }
10660aeed3e9SJustin Hibbits
10670aeed3e9SJustin Hibbits return E_OK;
10680aeed3e9SJustin Hibbits }
10690aeed3e9SJustin Hibbits
10700aeed3e9SJustin Hibbits /* .............................................................................. */
10710aeed3e9SJustin Hibbits
DtsecSetWakeOnLan(t_Handle h_Dtsec,bool en)1072*852ba100SJustin Hibbits static t_Error DtsecSetWakeOnLan(t_Handle h_Dtsec, bool en)
1073*852ba100SJustin Hibbits {
1074*852ba100SJustin Hibbits t_Dtsec *p_Dtsec = (t_Dtsec *)h_Dtsec;
1075*852ba100SJustin Hibbits
1076*852ba100SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Dtsec, E_INVALID_STATE);
1077*852ba100SJustin Hibbits SANITY_CHECK_RETURN_ERROR(!p_Dtsec->p_DtsecDriverParam, E_INVALID_STATE);
1078*852ba100SJustin Hibbits
1079*852ba100SJustin Hibbits fman_dtsec_set_wol(p_Dtsec->p_MemMap, en);
1080*852ba100SJustin Hibbits
1081*852ba100SJustin Hibbits return E_OK;
1082*852ba100SJustin Hibbits }
1083*852ba100SJustin Hibbits
1084*852ba100SJustin Hibbits /* .............................................................................. */
1085*852ba100SJustin Hibbits
DtsecAdjustLink(t_Handle h_Dtsec,e_EnetSpeed speed,bool fullDuplex)10860aeed3e9SJustin Hibbits static t_Error DtsecAdjustLink(t_Handle h_Dtsec, e_EnetSpeed speed, bool fullDuplex)
10870aeed3e9SJustin Hibbits {
10880aeed3e9SJustin Hibbits t_Dtsec *p_Dtsec = (t_Dtsec *)h_Dtsec;
1089*852ba100SJustin Hibbits int err;
1090*852ba100SJustin Hibbits enum enet_interface enet_interface;
1091*852ba100SJustin Hibbits enum enet_speed enet_speed;
10920aeed3e9SJustin Hibbits
10930aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Dtsec, E_INVALID_HANDLE);
1094*852ba100SJustin Hibbits SANITY_CHECK_RETURN_ERROR(!p_Dtsec->p_DtsecDriverParam, E_INVALID_STATE);
10950aeed3e9SJustin Hibbits
10960aeed3e9SJustin Hibbits p_Dtsec->enetMode = MAKE_ENET_MODE(ENET_INTERFACE_FROM_MODE(p_Dtsec->enetMode), speed);
1097*852ba100SJustin Hibbits enet_interface = (enum enet_interface) ENET_INTERFACE_FROM_MODE(p_Dtsec->enetMode);
1098*852ba100SJustin Hibbits enet_speed = (enum enet_speed) ENET_SPEED_FROM_MODE(p_Dtsec->enetMode);
10990aeed3e9SJustin Hibbits p_Dtsec->halfDuplex = !fullDuplex;
11000aeed3e9SJustin Hibbits
1101*852ba100SJustin Hibbits err = fman_dtsec_adjust_link(p_Dtsec->p_MemMap, enet_interface, enet_speed, fullDuplex);
11020aeed3e9SJustin Hibbits
1103*852ba100SJustin Hibbits if (err == -EINVAL)
1104*852ba100SJustin Hibbits RETURN_ERROR(MAJOR, E_CONFLICT, ("Ethernet interface does not support Half Duplex mode"));
11050aeed3e9SJustin Hibbits
1106*852ba100SJustin Hibbits return (t_Error)err;
11070aeed3e9SJustin Hibbits }
11080aeed3e9SJustin Hibbits
1109*852ba100SJustin Hibbits /* .............................................................................. */
1110*852ba100SJustin Hibbits
DtsecRestartAutoneg(t_Handle h_Dtsec)1111*852ba100SJustin Hibbits static t_Error DtsecRestartAutoneg(t_Handle h_Dtsec)
1112*852ba100SJustin Hibbits {
1113*852ba100SJustin Hibbits t_Dtsec *p_Dtsec = (t_Dtsec *)h_Dtsec;
1114*852ba100SJustin Hibbits uint16_t tmpReg16;
1115*852ba100SJustin Hibbits
1116*852ba100SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Dtsec, E_INVALID_HANDLE);
1117*852ba100SJustin Hibbits SANITY_CHECK_RETURN_ERROR(!p_Dtsec->p_DtsecDriverParam, E_INVALID_STATE);
1118*852ba100SJustin Hibbits
1119*852ba100SJustin Hibbits DTSEC_MII_ReadPhyReg(p_Dtsec, p_Dtsec->tbi_phy_addr, 0, &tmpReg16);
1120*852ba100SJustin Hibbits
1121*852ba100SJustin Hibbits tmpReg16 &= ~( PHY_CR_SPEED0 | PHY_CR_SPEED1 );
1122*852ba100SJustin Hibbits tmpReg16 |= (PHY_CR_ANE | PHY_CR_RESET_AN | PHY_CR_FULLDUPLEX | PHY_CR_SPEED1);
1123*852ba100SJustin Hibbits
1124*852ba100SJustin Hibbits DTSEC_MII_WritePhyReg(p_Dtsec, p_Dtsec->tbi_phy_addr, 0, tmpReg16);
1125*852ba100SJustin Hibbits
11260aeed3e9SJustin Hibbits return E_OK;
11270aeed3e9SJustin Hibbits }
11280aeed3e9SJustin Hibbits
11290aeed3e9SJustin Hibbits /* .............................................................................. */
11300aeed3e9SJustin Hibbits
DtsecGetId(t_Handle h_Dtsec,uint32_t * macId)11310aeed3e9SJustin Hibbits static t_Error DtsecGetId(t_Handle h_Dtsec, uint32_t *macId)
11320aeed3e9SJustin Hibbits {
11330aeed3e9SJustin Hibbits t_Dtsec *p_Dtsec = (t_Dtsec *)h_Dtsec;
11340aeed3e9SJustin Hibbits
11350aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Dtsec, E_INVALID_HANDLE);
1136*852ba100SJustin Hibbits SANITY_CHECK_RETURN_ERROR(!p_Dtsec->p_DtsecDriverParam, E_INVALID_STATE);
11370aeed3e9SJustin Hibbits
11380aeed3e9SJustin Hibbits *macId = p_Dtsec->macId;
11390aeed3e9SJustin Hibbits
11400aeed3e9SJustin Hibbits return E_OK;
11410aeed3e9SJustin Hibbits }
11420aeed3e9SJustin Hibbits
11430aeed3e9SJustin Hibbits /* .............................................................................. */
11440aeed3e9SJustin Hibbits
DtsecGetVersion(t_Handle h_Dtsec,uint32_t * macVersion)11450aeed3e9SJustin Hibbits static t_Error DtsecGetVersion(t_Handle h_Dtsec, uint32_t *macVersion)
11460aeed3e9SJustin Hibbits {
11470aeed3e9SJustin Hibbits t_Dtsec *p_Dtsec = (t_Dtsec *)h_Dtsec;
11480aeed3e9SJustin Hibbits
11490aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Dtsec, E_INVALID_HANDLE);
1150*852ba100SJustin Hibbits SANITY_CHECK_RETURN_ERROR(!p_Dtsec->p_DtsecDriverParam, E_INVALID_STATE);
11510aeed3e9SJustin Hibbits
1152*852ba100SJustin Hibbits *macVersion = fman_dtsec_get_revision(p_Dtsec->p_MemMap);
11530aeed3e9SJustin Hibbits
11540aeed3e9SJustin Hibbits return E_OK;
11550aeed3e9SJustin Hibbits }
11560aeed3e9SJustin Hibbits
11570aeed3e9SJustin Hibbits /* .............................................................................. */
11580aeed3e9SJustin Hibbits
DtsecSetException(t_Handle h_Dtsec,e_FmMacExceptions exception,bool enable)11590aeed3e9SJustin Hibbits static t_Error DtsecSetException(t_Handle h_Dtsec, e_FmMacExceptions exception, bool enable)
11600aeed3e9SJustin Hibbits {
11610aeed3e9SJustin Hibbits t_Dtsec *p_Dtsec = (t_Dtsec *)h_Dtsec;
1162*852ba100SJustin Hibbits uint32_t bitMask = 0;
11630aeed3e9SJustin Hibbits
11640aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Dtsec, E_INVALID_HANDLE);
1165*852ba100SJustin Hibbits SANITY_CHECK_RETURN_ERROR(!p_Dtsec->p_DtsecDriverParam, E_INVALID_STATE);
11660aeed3e9SJustin Hibbits
11670aeed3e9SJustin Hibbits if (exception != e_FM_MAC_EX_1G_1588_TS_RX_ERR)
11680aeed3e9SJustin Hibbits {
11690aeed3e9SJustin Hibbits GET_EXCEPTION_FLAG(bitMask, exception);
11700aeed3e9SJustin Hibbits if (bitMask)
11710aeed3e9SJustin Hibbits {
11720aeed3e9SJustin Hibbits if (enable)
11730aeed3e9SJustin Hibbits p_Dtsec->exceptions |= bitMask;
11740aeed3e9SJustin Hibbits else
11750aeed3e9SJustin Hibbits p_Dtsec->exceptions &= ~bitMask;
11760aeed3e9SJustin Hibbits }
11770aeed3e9SJustin Hibbits else
11780aeed3e9SJustin Hibbits RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("Undefined exception"));
11790aeed3e9SJustin Hibbits
11800aeed3e9SJustin Hibbits if (enable)
1181*852ba100SJustin Hibbits fman_dtsec_enable_interrupt(p_Dtsec->p_MemMap, bitMask);
11820aeed3e9SJustin Hibbits else
1183*852ba100SJustin Hibbits fman_dtsec_disable_interrupt(p_Dtsec->p_MemMap, bitMask);
11840aeed3e9SJustin Hibbits }
11850aeed3e9SJustin Hibbits else
11860aeed3e9SJustin Hibbits {
11870aeed3e9SJustin Hibbits if (!p_Dtsec->ptpTsuEnabled)
11880aeed3e9SJustin Hibbits RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("Exception valid for 1588 only"));
1189*852ba100SJustin Hibbits
11900aeed3e9SJustin Hibbits if (enable)
11910aeed3e9SJustin Hibbits {
11920aeed3e9SJustin Hibbits p_Dtsec->enTsuErrExeption = TRUE;
1193*852ba100SJustin Hibbits fman_dtsec_enable_tmr_interrupt(p_Dtsec->p_MemMap);
11940aeed3e9SJustin Hibbits }
11950aeed3e9SJustin Hibbits else
11960aeed3e9SJustin Hibbits {
11970aeed3e9SJustin Hibbits p_Dtsec->enTsuErrExeption = FALSE;
1198*852ba100SJustin Hibbits fman_dtsec_disable_tmr_interrupt(p_Dtsec->p_MemMap);
11990aeed3e9SJustin Hibbits }
12000aeed3e9SJustin Hibbits }
12010aeed3e9SJustin Hibbits
12020aeed3e9SJustin Hibbits return E_OK;
12030aeed3e9SJustin Hibbits }
12040aeed3e9SJustin Hibbits
12050aeed3e9SJustin Hibbits
12060aeed3e9SJustin Hibbits /*****************************************************************************/
1207*852ba100SJustin Hibbits /* dTSEC Init & Free API */
12080aeed3e9SJustin Hibbits /*****************************************************************************/
12090aeed3e9SJustin Hibbits
12100aeed3e9SJustin Hibbits /* .............................................................................. */
12110aeed3e9SJustin Hibbits
DtsecInit(t_Handle h_Dtsec)12120aeed3e9SJustin Hibbits static t_Error DtsecInit(t_Handle h_Dtsec)
12130aeed3e9SJustin Hibbits {
12140aeed3e9SJustin Hibbits t_Dtsec *p_Dtsec = (t_Dtsec *)h_Dtsec;
1215*852ba100SJustin Hibbits struct dtsec_cfg *p_DtsecDriverParam;
12160aeed3e9SJustin Hibbits t_Error err;
1217*852ba100SJustin Hibbits uint16_t maxFrmLn;
1218*852ba100SJustin Hibbits enum enet_interface enet_interface;
1219*852ba100SJustin Hibbits enum enet_speed enet_speed;
1220*852ba100SJustin Hibbits t_EnetAddr ethAddr;
12210aeed3e9SJustin Hibbits
12220aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Dtsec, E_INVALID_HANDLE);
12230aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Dtsec->p_DtsecDriverParam, E_INVALID_STATE);
1224*852ba100SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Dtsec->fmMacControllerDriver.h_Fm, E_INVALID_HANDLE);
12250aeed3e9SJustin Hibbits
1226*852ba100SJustin Hibbits FM_GetRevision(p_Dtsec->fmMacControllerDriver.h_Fm, &p_Dtsec->fmMacControllerDriver.fmRevInfo);
12270aeed3e9SJustin Hibbits CHECK_INIT_PARAMETERS(p_Dtsec, CheckInitParameters);
12280aeed3e9SJustin Hibbits
12290aeed3e9SJustin Hibbits p_DtsecDriverParam = p_Dtsec->p_DtsecDriverParam;
1230*852ba100SJustin Hibbits p_Dtsec->halfDuplex = p_DtsecDriverParam->halfdup_on;
12310aeed3e9SJustin Hibbits
1232*852ba100SJustin Hibbits enet_interface = (enum enet_interface)ENET_INTERFACE_FROM_MODE(p_Dtsec->enetMode);
1233*852ba100SJustin Hibbits enet_speed = (enum enet_speed)ENET_SPEED_FROM_MODE(p_Dtsec->enetMode);
1234*852ba100SJustin Hibbits MAKE_ENET_ADDR_FROM_UINT64(p_Dtsec->addr, ethAddr);
12350aeed3e9SJustin Hibbits
1236*852ba100SJustin Hibbits err = (t_Error)fman_dtsec_init(p_Dtsec->p_MemMap,
1237*852ba100SJustin Hibbits p_DtsecDriverParam,
1238*852ba100SJustin Hibbits enet_interface,
1239*852ba100SJustin Hibbits enet_speed,
1240*852ba100SJustin Hibbits (uint8_t*)ethAddr,
1241*852ba100SJustin Hibbits p_Dtsec->fmMacControllerDriver.fmRevInfo.majorRev,
1242*852ba100SJustin Hibbits p_Dtsec->fmMacControllerDriver.fmRevInfo.minorRev,
1243*852ba100SJustin Hibbits p_Dtsec->exceptions);
1244*852ba100SJustin Hibbits if (err)
12450aeed3e9SJustin Hibbits {
1246*852ba100SJustin Hibbits FreeInitResources(p_Dtsec);
1247*852ba100SJustin Hibbits RETURN_ERROR(MAJOR, err, ("This DTSEC version does not support the required i/f mode"));
12480aeed3e9SJustin Hibbits }
12490aeed3e9SJustin Hibbits
1250*852ba100SJustin Hibbits if (ENET_INTERFACE_FROM_MODE(p_Dtsec->enetMode) == e_ENET_IF_SGMII)
12510aeed3e9SJustin Hibbits {
12520aeed3e9SJustin Hibbits uint16_t tmpReg16;
12530aeed3e9SJustin Hibbits
12540aeed3e9SJustin Hibbits /* Configure the TBI PHY Control Register */
1255*852ba100SJustin Hibbits tmpReg16 = PHY_TBICON_CLK_SEL | PHY_TBICON_SRESET;
1256*852ba100SJustin Hibbits DTSEC_MII_WritePhyReg(p_Dtsec, (uint8_t)p_DtsecDriverParam->tbipa, 17, tmpReg16);
12570aeed3e9SJustin Hibbits
1258*852ba100SJustin Hibbits tmpReg16 = PHY_TBICON_CLK_SEL;
1259*852ba100SJustin Hibbits DTSEC_MII_WritePhyReg(p_Dtsec, (uint8_t)p_DtsecDriverParam->tbipa, 17, tmpReg16);
12600aeed3e9SJustin Hibbits
1261*852ba100SJustin Hibbits tmpReg16 = (PHY_CR_PHY_RESET | PHY_CR_ANE | PHY_CR_FULLDUPLEX | PHY_CR_SPEED1);
1262*852ba100SJustin Hibbits DTSEC_MII_WritePhyReg(p_Dtsec, (uint8_t)p_DtsecDriverParam->tbipa, 0, tmpReg16);
12630aeed3e9SJustin Hibbits
1264*852ba100SJustin Hibbits if (p_Dtsec->enetMode & ENET_IF_SGMII_BASEX)
1265*852ba100SJustin Hibbits tmpReg16 = PHY_TBIANA_1000X;
1266*852ba100SJustin Hibbits else
1267*852ba100SJustin Hibbits tmpReg16 = PHY_TBIANA_SGMII;
1268*852ba100SJustin Hibbits DTSEC_MII_WritePhyReg(p_Dtsec, (uint8_t)p_DtsecDriverParam->tbipa, 4, tmpReg16);
12690aeed3e9SJustin Hibbits
1270*852ba100SJustin Hibbits tmpReg16 = (PHY_CR_ANE | PHY_CR_RESET_AN | PHY_CR_FULLDUPLEX | PHY_CR_SPEED1);
12710aeed3e9SJustin Hibbits
1272*852ba100SJustin Hibbits DTSEC_MII_WritePhyReg(p_Dtsec, (uint8_t)p_DtsecDriverParam->tbipa, 0, tmpReg16);
12730aeed3e9SJustin Hibbits }
12740aeed3e9SJustin Hibbits
1275*852ba100SJustin Hibbits /* Max Frame Length */
1276*852ba100SJustin Hibbits maxFrmLn = fman_dtsec_get_max_frame_len(p_Dtsec->p_MemMap);
1277*852ba100SJustin Hibbits err = FmSetMacMaxFrame(p_Dtsec->fmMacControllerDriver.h_Fm, e_FM_MAC_1G,
1278*852ba100SJustin Hibbits p_Dtsec->fmMacControllerDriver.macId, maxFrmLn);
12790aeed3e9SJustin Hibbits if (err)
1280*852ba100SJustin Hibbits RETURN_ERROR(MINOR,err, NO_MSG);
12810aeed3e9SJustin Hibbits
1282*852ba100SJustin Hibbits p_Dtsec->p_MulticastAddrHash = AllocHashTable(EXTENDED_HASH_TABLE_SIZE);
1283*852ba100SJustin Hibbits if (!p_Dtsec->p_MulticastAddrHash) {
12840aeed3e9SJustin Hibbits FreeInitResources(p_Dtsec);
12850aeed3e9SJustin Hibbits RETURN_ERROR(MAJOR, E_NO_MEMORY, ("MC hash table is FAILED"));
12860aeed3e9SJustin Hibbits }
12870aeed3e9SJustin Hibbits
12880aeed3e9SJustin Hibbits p_Dtsec->p_UnicastAddrHash = AllocHashTable(HASH_TABLE_SIZE);
12890aeed3e9SJustin Hibbits if (!p_Dtsec->p_UnicastAddrHash)
12900aeed3e9SJustin Hibbits {
12910aeed3e9SJustin Hibbits FreeInitResources(p_Dtsec);
12920aeed3e9SJustin Hibbits RETURN_ERROR(MAJOR, E_NO_MEMORY, ("UC hash table is FAILED"));
12930aeed3e9SJustin Hibbits }
12940aeed3e9SJustin Hibbits
12950aeed3e9SJustin Hibbits /* register err intr handler for dtsec to FPM (err)*/
1296*852ba100SJustin Hibbits FmRegisterIntr(p_Dtsec->fmMacControllerDriver.h_Fm,
1297*852ba100SJustin Hibbits e_FM_MOD_1G_MAC,
1298*852ba100SJustin Hibbits p_Dtsec->macId,
1299*852ba100SJustin Hibbits e_FM_INTR_TYPE_ERR,
1300*852ba100SJustin Hibbits DtsecIsr,
1301*852ba100SJustin Hibbits p_Dtsec);
13020aeed3e9SJustin Hibbits /* register 1588 intr handler for TMR to FPM (normal)*/
1303*852ba100SJustin Hibbits FmRegisterIntr(p_Dtsec->fmMacControllerDriver.h_Fm,
1304*852ba100SJustin Hibbits e_FM_MOD_1G_MAC,
1305*852ba100SJustin Hibbits p_Dtsec->macId,
1306*852ba100SJustin Hibbits e_FM_INTR_TYPE_NORMAL,
1307*852ba100SJustin Hibbits Dtsec1588Isr,
1308*852ba100SJustin Hibbits p_Dtsec);
13090aeed3e9SJustin Hibbits /* register normal intr handler for dtsec to main interrupt controller. */
13100aeed3e9SJustin Hibbits if (p_Dtsec->mdioIrq != NO_IRQ)
13110aeed3e9SJustin Hibbits {
1312*852ba100SJustin Hibbits XX_SetIntr(p_Dtsec->mdioIrq, DtsecMdioIsr, p_Dtsec);
13130aeed3e9SJustin Hibbits XX_EnableIntr(p_Dtsec->mdioIrq);
13140aeed3e9SJustin Hibbits }
13150aeed3e9SJustin Hibbits
13160aeed3e9SJustin Hibbits XX_Free(p_DtsecDriverParam);
13170aeed3e9SJustin Hibbits p_Dtsec->p_DtsecDriverParam = NULL;
13180aeed3e9SJustin Hibbits
1319*852ba100SJustin Hibbits err = DtsecSetStatistics(h_Dtsec, e_FM_MAC_FULL_STATISTICS);
13200aeed3e9SJustin Hibbits if (err)
13210aeed3e9SJustin Hibbits {
13220aeed3e9SJustin Hibbits FreeInitResources(p_Dtsec);
1323*852ba100SJustin Hibbits RETURN_ERROR(MAJOR, err, ("Undefined statistics level"));
13240aeed3e9SJustin Hibbits }
13250aeed3e9SJustin Hibbits
13260aeed3e9SJustin Hibbits return E_OK;
13270aeed3e9SJustin Hibbits }
13280aeed3e9SJustin Hibbits
13290aeed3e9SJustin Hibbits /* ........................................................................... */
13300aeed3e9SJustin Hibbits
DtsecFree(t_Handle h_Dtsec)13310aeed3e9SJustin Hibbits static t_Error DtsecFree(t_Handle h_Dtsec)
13320aeed3e9SJustin Hibbits {
13330aeed3e9SJustin Hibbits t_Dtsec *p_Dtsec = (t_Dtsec *)h_Dtsec;
13340aeed3e9SJustin Hibbits
13350aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_ERROR(p_Dtsec, E_INVALID_HANDLE);
13360aeed3e9SJustin Hibbits
13370aeed3e9SJustin Hibbits if (p_Dtsec->p_DtsecDriverParam)
13380aeed3e9SJustin Hibbits {
1339*852ba100SJustin Hibbits /* Called after config */
13400aeed3e9SJustin Hibbits XX_Free(p_Dtsec->p_DtsecDriverParam);
13410aeed3e9SJustin Hibbits p_Dtsec->p_DtsecDriverParam = NULL;
13420aeed3e9SJustin Hibbits }
1343*852ba100SJustin Hibbits else
1344*852ba100SJustin Hibbits /* Called after init */
1345*852ba100SJustin Hibbits FreeInitResources(p_Dtsec);
1346*852ba100SJustin Hibbits
1347*852ba100SJustin Hibbits XX_Free(p_Dtsec);
13480aeed3e9SJustin Hibbits
13490aeed3e9SJustin Hibbits return E_OK;
13500aeed3e9SJustin Hibbits }
13510aeed3e9SJustin Hibbits
13520aeed3e9SJustin Hibbits /* .............................................................................. */
13530aeed3e9SJustin Hibbits
InitFmMacControllerDriver(t_FmMacControllerDriver * p_FmMacControllerDriver)13540aeed3e9SJustin Hibbits static void InitFmMacControllerDriver(t_FmMacControllerDriver *p_FmMacControllerDriver)
13550aeed3e9SJustin Hibbits {
13560aeed3e9SJustin Hibbits p_FmMacControllerDriver->f_FM_MAC_Init = DtsecInit;
13570aeed3e9SJustin Hibbits p_FmMacControllerDriver->f_FM_MAC_Free = DtsecFree;
13580aeed3e9SJustin Hibbits
13590aeed3e9SJustin Hibbits p_FmMacControllerDriver->f_FM_MAC_SetStatistics = DtsecSetStatistics;
13600aeed3e9SJustin Hibbits p_FmMacControllerDriver->f_FM_MAC_ConfigLoopback = DtsecConfigLoopback;
13610aeed3e9SJustin Hibbits p_FmMacControllerDriver->f_FM_MAC_ConfigMaxFrameLength = DtsecConfigMaxFrameLength;
13620aeed3e9SJustin Hibbits
13630aeed3e9SJustin Hibbits p_FmMacControllerDriver->f_FM_MAC_ConfigWan = NULL; /* Not supported on dTSEC */
13640aeed3e9SJustin Hibbits
13650aeed3e9SJustin Hibbits p_FmMacControllerDriver->f_FM_MAC_ConfigPadAndCrc = DtsecConfigPadAndCrc;
13660aeed3e9SJustin Hibbits p_FmMacControllerDriver->f_FM_MAC_ConfigHalfDuplex = DtsecConfigHalfDuplex;
13670aeed3e9SJustin Hibbits p_FmMacControllerDriver->f_FM_MAC_ConfigLengthCheck = DtsecConfigLengthCheck;
1368*852ba100SJustin Hibbits p_FmMacControllerDriver->f_FM_MAC_ConfigTbiPhyAddr = DtsecConfigTbiPhyAddr;
13690aeed3e9SJustin Hibbits p_FmMacControllerDriver->f_FM_MAC_ConfigException = DtsecConfigException;
1370*852ba100SJustin Hibbits p_FmMacControllerDriver->f_FM_MAC_ConfigResetOnInit = NULL;
13710aeed3e9SJustin Hibbits
13720aeed3e9SJustin Hibbits p_FmMacControllerDriver->f_FM_MAC_Enable = DtsecEnable;
13730aeed3e9SJustin Hibbits p_FmMacControllerDriver->f_FM_MAC_Disable = DtsecDisable;
1374*852ba100SJustin Hibbits p_FmMacControllerDriver->f_FM_MAC_Resume = NULL;
13750aeed3e9SJustin Hibbits
13760aeed3e9SJustin Hibbits p_FmMacControllerDriver->f_FM_MAC_SetException = DtsecSetException;
13770aeed3e9SJustin Hibbits
13780aeed3e9SJustin Hibbits p_FmMacControllerDriver->f_FM_MAC_SetPromiscuous = DtsecSetPromiscuous;
13790aeed3e9SJustin Hibbits p_FmMacControllerDriver->f_FM_MAC_AdjustLink = DtsecAdjustLink;
1380*852ba100SJustin Hibbits p_FmMacControllerDriver->f_FM_MAC_SetWakeOnLan = DtsecSetWakeOnLan;
1381*852ba100SJustin Hibbits p_FmMacControllerDriver->f_FM_MAC_RestartAutoneg = DtsecRestartAutoneg;
13820aeed3e9SJustin Hibbits
13830aeed3e9SJustin Hibbits p_FmMacControllerDriver->f_FM_MAC_Enable1588TimeStamp = DtsecEnable1588TimeStamp;
13840aeed3e9SJustin Hibbits p_FmMacControllerDriver->f_FM_MAC_Disable1588TimeStamp = DtsecDisable1588TimeStamp;
13850aeed3e9SJustin Hibbits
13860aeed3e9SJustin Hibbits p_FmMacControllerDriver->f_FM_MAC_SetTxAutoPauseFrames = DtsecTxMacPause;
1387*852ba100SJustin Hibbits p_FmMacControllerDriver->f_FM_MAC_SetTxPauseFrames = DtsecSetTxPauseFrames;
13880aeed3e9SJustin Hibbits p_FmMacControllerDriver->f_FM_MAC_SetRxIgnorePauseFrames = DtsecRxIgnoreMacPause;
13890aeed3e9SJustin Hibbits
13900aeed3e9SJustin Hibbits p_FmMacControllerDriver->f_FM_MAC_ResetCounters = DtsecResetCounters;
13910aeed3e9SJustin Hibbits p_FmMacControllerDriver->f_FM_MAC_GetStatistics = DtsecGetStatistics;
13920aeed3e9SJustin Hibbits
13930aeed3e9SJustin Hibbits p_FmMacControllerDriver->f_FM_MAC_ModifyMacAddr = DtsecModifyMacAddress;
13940aeed3e9SJustin Hibbits p_FmMacControllerDriver->f_FM_MAC_AddHashMacAddr = DtsecAddHashMacAddress;
13950aeed3e9SJustin Hibbits p_FmMacControllerDriver->f_FM_MAC_RemoveHashMacAddr = DtsecDelHashMacAddress;
13960aeed3e9SJustin Hibbits p_FmMacControllerDriver->f_FM_MAC_AddExactMatchMacAddr = DtsecAddExactMatchMacAddress;
13970aeed3e9SJustin Hibbits p_FmMacControllerDriver->f_FM_MAC_RemovelExactMatchMacAddr = DtsecDelExactMatchMacAddress;
13980aeed3e9SJustin Hibbits p_FmMacControllerDriver->f_FM_MAC_GetId = DtsecGetId;
13990aeed3e9SJustin Hibbits p_FmMacControllerDriver->f_FM_MAC_GetVersion = DtsecGetVersion;
14000aeed3e9SJustin Hibbits p_FmMacControllerDriver->f_FM_MAC_GetMaxFrameLength = DtsecGetMaxFrameLength;
14010aeed3e9SJustin Hibbits
14020aeed3e9SJustin Hibbits p_FmMacControllerDriver->f_FM_MAC_MII_WritePhyReg = DTSEC_MII_WritePhyReg;
14030aeed3e9SJustin Hibbits p_FmMacControllerDriver->f_FM_MAC_MII_ReadPhyReg = DTSEC_MII_ReadPhyReg;
14040aeed3e9SJustin Hibbits
14050aeed3e9SJustin Hibbits }
14060aeed3e9SJustin Hibbits
14070aeed3e9SJustin Hibbits
14080aeed3e9SJustin Hibbits /*****************************************************************************/
14090aeed3e9SJustin Hibbits /* dTSEC Config Main Entry */
14100aeed3e9SJustin Hibbits /*****************************************************************************/
14110aeed3e9SJustin Hibbits
14120aeed3e9SJustin Hibbits /* .............................................................................. */
14130aeed3e9SJustin Hibbits
DTSEC_Config(t_FmMacParams * p_FmMacParam)14140aeed3e9SJustin Hibbits t_Handle DTSEC_Config(t_FmMacParams *p_FmMacParam)
14150aeed3e9SJustin Hibbits {
14160aeed3e9SJustin Hibbits t_Dtsec *p_Dtsec;
1417*852ba100SJustin Hibbits struct dtsec_cfg *p_DtsecDriverParam;
14180aeed3e9SJustin Hibbits uintptr_t baseAddr;
14190aeed3e9SJustin Hibbits
14200aeed3e9SJustin Hibbits SANITY_CHECK_RETURN_VALUE(p_FmMacParam, E_NULL_POINTER, NULL);
14210aeed3e9SJustin Hibbits
14220aeed3e9SJustin Hibbits baseAddr = p_FmMacParam->baseAddr;
1423*852ba100SJustin Hibbits
14240aeed3e9SJustin Hibbits /* allocate memory for the UCC GETH data structure. */
14250aeed3e9SJustin Hibbits p_Dtsec = (t_Dtsec *)XX_Malloc(sizeof(t_Dtsec));
14260aeed3e9SJustin Hibbits if (!p_Dtsec)
14270aeed3e9SJustin Hibbits {
14280aeed3e9SJustin Hibbits REPORT_ERROR(MAJOR, E_NO_MEMORY, ("dTSEC driver structure"));
14290aeed3e9SJustin Hibbits return NULL;
14300aeed3e9SJustin Hibbits }
14310aeed3e9SJustin Hibbits memset(p_Dtsec, 0, sizeof(t_Dtsec));
14320aeed3e9SJustin Hibbits InitFmMacControllerDriver(&p_Dtsec->fmMacControllerDriver);
14330aeed3e9SJustin Hibbits
14340aeed3e9SJustin Hibbits /* allocate memory for the dTSEC driver parameters data structure. */
1435*852ba100SJustin Hibbits p_DtsecDriverParam = (struct dtsec_cfg *) XX_Malloc(sizeof(struct dtsec_cfg));
14360aeed3e9SJustin Hibbits if (!p_DtsecDriverParam)
14370aeed3e9SJustin Hibbits {
14380aeed3e9SJustin Hibbits XX_Free(p_Dtsec);
14390aeed3e9SJustin Hibbits REPORT_ERROR(MAJOR, E_NO_MEMORY, ("dTSEC driver parameters"));
14400aeed3e9SJustin Hibbits return NULL;
14410aeed3e9SJustin Hibbits }
1442*852ba100SJustin Hibbits memset(p_DtsecDriverParam, 0, sizeof(struct dtsec_cfg));
14430aeed3e9SJustin Hibbits
14440aeed3e9SJustin Hibbits /* Plant parameter structure pointer */
14450aeed3e9SJustin Hibbits p_Dtsec->p_DtsecDriverParam = p_DtsecDriverParam;
14460aeed3e9SJustin Hibbits
1447*852ba100SJustin Hibbits fman_dtsec_defconfig(p_DtsecDriverParam);
14480aeed3e9SJustin Hibbits
1449*852ba100SJustin Hibbits p_Dtsec->p_MemMap = (struct dtsec_regs *)UINT_TO_PTR(baseAddr);
1450*852ba100SJustin Hibbits p_Dtsec->p_MiiMemMap = (struct dtsec_mii_reg *)UINT_TO_PTR(baseAddr + DTSEC_TO_MII_OFFSET);
1451*852ba100SJustin Hibbits p_Dtsec->addr = ENET_ADDR_TO_UINT64(p_FmMacParam->addr);
14520aeed3e9SJustin Hibbits p_Dtsec->enetMode = p_FmMacParam->enetMode;
14530aeed3e9SJustin Hibbits p_Dtsec->macId = p_FmMacParam->macId;
14540aeed3e9SJustin Hibbits p_Dtsec->exceptions = DEFAULT_exceptions;
14550aeed3e9SJustin Hibbits p_Dtsec->mdioIrq = p_FmMacParam->mdioIrq;
14560aeed3e9SJustin Hibbits p_Dtsec->f_Exception = p_FmMacParam->f_Exception;
14570aeed3e9SJustin Hibbits p_Dtsec->f_Event = p_FmMacParam->f_Event;
14580aeed3e9SJustin Hibbits p_Dtsec->h_App = p_FmMacParam->h_App;
1459*852ba100SJustin Hibbits p_Dtsec->ptpTsuEnabled = p_Dtsec->p_DtsecDriverParam->ptp_tsu_en;
1460*852ba100SJustin Hibbits p_Dtsec->enTsuErrExeption = p_Dtsec->p_DtsecDriverParam->ptp_exception_en;
1461*852ba100SJustin Hibbits p_Dtsec->tbi_phy_addr = p_Dtsec->p_DtsecDriverParam->tbi_phy_addr;
14620aeed3e9SJustin Hibbits
14630aeed3e9SJustin Hibbits return p_Dtsec;
14640aeed3e9SJustin Hibbits }
1465