1 /* Copyright (c) 2008-2011 Freescale Semiconductor, Inc. 2 * All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions are met: 6 * * Redistributions of source code must retain the above copyright 7 * notice, this list of conditions and the following disclaimer. 8 * * Redistributions in binary form must reproduce the above copyright 9 * notice, this list of conditions and the following disclaimer in the 10 * documentation and/or other materials provided with the distribution. 11 * * Neither the name of Freescale Semiconductor nor the 12 * names of its contributors may be used to endorse or promote products 13 * derived from this software without specific prior written permission. 14 * 15 * 16 * ALTERNATIVELY, this software may be distributed under the terms of the 17 * GNU General Public License ("GPL") as published by the Free Software 18 * Foundation, either version 2 of that License or (at your option) any 19 * later version. 20 * 21 * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY 22 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY 25 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 26 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 27 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 28 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 */ 32 33 /****************************************************************************** 34 @File fm_mac.h 35 36 @Description FM MAC ... 37 *//***************************************************************************/ 38 #ifndef __FM_MAC_H 39 #define __FM_MAC_H 40 41 #include "std_ext.h" 42 #include "error_ext.h" 43 #include "list_ext.h" 44 #include "fm_mac_ext.h" 45 46 47 #define __ERR_MODULE__ MODULE_FM_MAC 48 49 50 #define DEFAULT_resetOnInit FALSE 51 52 53 typedef struct { 54 uint64_t addr; /* Ethernet Address */ 55 t_List node; 56 } t_EthHashEntry; 57 #define ETH_HASH_ENTRY_OBJ(ptr) LIST_OBJECT(ptr, t_EthHashEntry, node) 58 59 typedef struct { 60 uint16_t size; 61 t_List *p_Lsts; 62 } t_EthHash; 63 64 typedef struct { 65 t_Error (*f_FM_MAC_Init) (t_Handle h_FmMac); 66 t_Error (*f_FM_MAC_Free) (t_Handle h_FmMac); 67 68 t_Error (*f_FM_MAC_SetStatistics) (t_Handle h_FmMac, e_FmMacStatisticsLevel statisticsLevel); 69 t_Error (*f_FM_MAC_ConfigLoopback) (t_Handle h_FmMac, bool newVal); 70 t_Error (*f_FM_MAC_ConfigMaxFrameLength) (t_Handle h_FmMac, uint16_t newVal); 71 t_Error (*f_FM_MAC_ConfigWan) (t_Handle h_FmMac, bool flag); 72 t_Error (*f_FM_MAC_ConfigPadAndCrc) (t_Handle h_FmMac, bool newVal); 73 t_Error (*f_FM_MAC_ConfigHalfDuplex) (t_Handle h_FmMac, bool newVal); 74 t_Error (*f_FM_MAC_ConfigLengthCheck) (t_Handle h_FmMac, bool newVal); 75 t_Error (*f_FM_MAC_ConfigException) (t_Handle h_FmMac, e_FmMacExceptions, bool enable); 76 #ifdef FM_TX_ECC_FRMS_ERRATA_10GMAC_A004 77 t_Error (*f_FM_MAC_ConfigSkipFman11Workaround) (t_Handle h_FmMac); 78 #endif /* FM_TX_ECC_FRMS_ERRATA_10GMAC_A004 */ 79 80 t_Error (*f_FM_MAC_SetException) (t_Handle h_FmMac, e_FmMacExceptions ex, bool enable); 81 82 t_Error (*f_FM_MAC_Enable) (t_Handle h_FmMac, e_CommMode mode); 83 t_Error (*f_FM_MAC_Disable) (t_Handle h_FmMac, e_CommMode mode); 84 t_Error (*f_FM_MAC_Enable1588TimeStamp) (t_Handle h_FmMac); 85 t_Error (*f_FM_MAC_Disable1588TimeStamp) (t_Handle h_FmMac); 86 t_Error (*f_FM_MAC_Reset) (t_Handle h_FmMac, bool wait); 87 88 t_Error (*f_FM_MAC_SetTxAutoPauseFrames) (t_Handle h_FmMac, uint16_t pauseTime); 89 t_Error (*f_FM_MAC_SetRxIgnorePauseFrames) (t_Handle h_FmMac, bool en); 90 91 t_Error (*f_FM_MAC_ResetCounters) (t_Handle h_FmMac); 92 t_Error (*f_FM_MAC_GetStatistics) (t_Handle h_FmMac, t_FmMacStatistics *p_Statistics); 93 94 t_Error (*f_FM_MAC_ModifyMacAddr) (t_Handle h_FmMac, t_EnetAddr *p_EnetAddr); 95 t_Error (*f_FM_MAC_AddHashMacAddr) (t_Handle h_FmMac, t_EnetAddr *p_EnetAddr); 96 t_Error (*f_FM_MAC_RemoveHashMacAddr) (t_Handle h_FmMac, t_EnetAddr *p_EnetAddr); 97 t_Error (*f_FM_MAC_AddExactMatchMacAddr) (t_Handle h_FmMac, t_EnetAddr *p_EnetAddr); 98 t_Error (*f_FM_MAC_RemovelExactMatchMacAddr) (t_Handle h_FmMac, t_EnetAddr *p_EnetAddr); 99 100 t_Error (*f_FM_MAC_SetPromiscuous) (t_Handle h_FmMac, bool newVal); 101 t_Error (*f_FM_MAC_AdjustLink) (t_Handle h_FmMac, e_EnetSpeed speed, bool fullDuplex); 102 103 t_Error (*f_FM_MAC_GetId) (t_Handle h_FmMac, uint32_t *macId); 104 105 t_Error (*f_FM_MAC_GetVersion) (t_Handle h_FmMac, uint32_t *macVersion); 106 107 uint16_t (*f_FM_MAC_GetMaxFrameLength) (t_Handle h_FmMac); 108 109 t_Error (*f_FM_MAC_MII_WritePhyReg)(t_Handle h_FmMac, uint8_t phyAddr, uint8_t reg, uint16_t data); 110 t_Error (*f_FM_MAC_MII_ReadPhyReg)(t_Handle h_FmMac, uint8_t phyAddr, uint8_t reg, uint16_t *p_Data); 111 112 #if (defined(DEBUG_ERRORS) && (DEBUG_ERRORS > 0)) 113 t_Error (*f_FM_MAC_DumpRegs) (t_Handle h_FmMac); 114 #endif /* (defined(DEBUG_ERRORS) && ... */ 115 116 t_Handle h_Fm; 117 e_EnetMode enetMode; 118 uint8_t macId; 119 bool resetOnInit; 120 uint16_t clkFreq; 121 } t_FmMacControllerDriver; 122 123 124 t_Handle DTSEC_Config(t_FmMacParams *p_FmMacParam); 125 t_Handle TGEC_Config(t_FmMacParams *p_FmMacParams); 126 uint16_t FM_MAC_GetMaxFrameLength(t_Handle FmMac); 127 128 129 /* ........................................................................... */ 130 131 static __inline__ t_EthHashEntry *DequeueAddrFromHashEntry(t_List *p_AddrLst) 132 { 133 t_EthHashEntry *p_HashEntry = NULL; 134 if (!LIST_IsEmpty(p_AddrLst)) 135 { 136 p_HashEntry = ETH_HASH_ENTRY_OBJ(p_AddrLst->p_Next); 137 LIST_DelAndInit(&p_HashEntry->node); 138 } 139 return p_HashEntry; 140 } 141 142 /* ........................................................................... */ 143 144 static __inline__ void FreeHashTable(t_EthHash *p_Hash) 145 { 146 t_EthHashEntry *p_HashEntry; 147 int i = 0; 148 149 if (!p_Hash || !p_Hash->p_Lsts) 150 return; 151 152 for(i=0; i<p_Hash->size; i++) 153 { 154 p_HashEntry = DequeueAddrFromHashEntry(&p_Hash->p_Lsts[i]); 155 while (p_HashEntry) 156 { 157 XX_Free(p_HashEntry); 158 p_HashEntry = DequeueAddrFromHashEntry(&p_Hash->p_Lsts[i]); 159 } 160 } 161 162 XX_Free(p_Hash->p_Lsts); 163 XX_Free(p_Hash); 164 } 165 166 /* ........................................................................... */ 167 168 static __inline__ t_EthHash * AllocHashTable(uint16_t size) 169 { 170 uint32_t i; 171 t_EthHash *p_Hash; 172 173 /* Allocate address hash table */ 174 p_Hash = (t_EthHash *)XX_Malloc(size*sizeof(t_EthHash *)); 175 if (!p_Hash) 176 { 177 REPORT_ERROR(MAJOR, E_NO_MEMORY, ("Address hash table")); 178 return NULL; 179 } 180 p_Hash->size = size; 181 182 p_Hash->p_Lsts = (t_List *)XX_Malloc(p_Hash->size*sizeof(t_List)); 183 if (!p_Hash->p_Lsts) 184 { 185 REPORT_ERROR(MAJOR, E_NO_MEMORY, ("Address hash table")); 186 XX_Free(p_Hash); 187 return NULL; 188 } 189 190 for(i=0 ; i<p_Hash->size; i++) 191 INIT_LIST(&p_Hash->p_Lsts[i]); 192 193 return p_Hash; 194 } 195 196 197 #endif /* __FM_MAC_H */ 198