1296177Sjhibbits/* Copyright (c) 2008-2011 Freescale Semiconductor, Inc.
2296177Sjhibbits * All rights reserved.
3296177Sjhibbits *
4296177Sjhibbits * Redistribution and use in source and binary forms, with or without
5296177Sjhibbits * modification, are permitted provided that the following conditions are met:
6296177Sjhibbits *     * Redistributions of source code must retain the above copyright
7296177Sjhibbits *       notice, this list of conditions and the following disclaimer.
8296177Sjhibbits *     * Redistributions in binary form must reproduce the above copyright
9296177Sjhibbits *       notice, this list of conditions and the following disclaimer in the
10296177Sjhibbits *       documentation and/or other materials provided with the distribution.
11296177Sjhibbits *     * Neither the name of Freescale Semiconductor nor the
12296177Sjhibbits *       names of its contributors may be used to endorse or promote products
13296177Sjhibbits *       derived from this software without specific prior written permission.
14296177Sjhibbits *
15296177Sjhibbits *
16296177Sjhibbits * ALTERNATIVELY, this software may be distributed under the terms of the
17296177Sjhibbits * GNU General Public License ("GPL") as published by the Free Software
18296177Sjhibbits * Foundation, either version 2 of that License or (at your option) any
19296177Sjhibbits * later version.
20296177Sjhibbits *
21296177Sjhibbits * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
22296177Sjhibbits * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23296177Sjhibbits * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24296177Sjhibbits * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
25296177Sjhibbits * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26296177Sjhibbits * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27296177Sjhibbits * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
28296177Sjhibbits * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29296177Sjhibbits * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30296177Sjhibbits * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31296177Sjhibbits */
32296177Sjhibbits
33296177Sjhibbits/******************************************************************************
34296177Sjhibbits @File          fm_mac.h
35296177Sjhibbits
36296177Sjhibbits @Description   FM MAC ...
37296177Sjhibbits*//***************************************************************************/
38296177Sjhibbits#ifndef __FM_MAC_H
39296177Sjhibbits#define __FM_MAC_H
40296177Sjhibbits
41296177Sjhibbits#include "std_ext.h"
42296177Sjhibbits#include "error_ext.h"
43296177Sjhibbits#include "list_ext.h"
44296177Sjhibbits#include "fm_mac_ext.h"
45296177Sjhibbits
46296177Sjhibbits
47296177Sjhibbits#define __ERR_MODULE__  MODULE_FM_MAC
48296177Sjhibbits
49296177Sjhibbits
50296177Sjhibbits#define DEFAULT_resetOnInit                 FALSE
51296177Sjhibbits
52296177Sjhibbits
53296177Sjhibbitstypedef struct {
54296177Sjhibbits    uint64_t addr;      /* Ethernet Address  */
55296177Sjhibbits    t_List   node;
56296177Sjhibbits} t_EthHashEntry;
57296177Sjhibbits#define ETH_HASH_ENTRY_OBJ(ptr) LIST_OBJECT(ptr, t_EthHashEntry, node)
58296177Sjhibbits
59296177Sjhibbitstypedef struct {
60296177Sjhibbits    uint16_t    size;
61296177Sjhibbits    t_List      *p_Lsts;
62296177Sjhibbits} t_EthHash;
63296177Sjhibbits
64296177Sjhibbitstypedef struct {
65296177Sjhibbits    t_Error (*f_FM_MAC_Init) (t_Handle h_FmMac);
66296177Sjhibbits    t_Error (*f_FM_MAC_Free) (t_Handle h_FmMac);
67296177Sjhibbits
68296177Sjhibbits    t_Error (*f_FM_MAC_SetStatistics) (t_Handle h_FmMac, e_FmMacStatisticsLevel statisticsLevel);
69296177Sjhibbits    t_Error (*f_FM_MAC_ConfigLoopback) (t_Handle h_FmMac, bool newVal);
70296177Sjhibbits    t_Error (*f_FM_MAC_ConfigMaxFrameLength) (t_Handle h_FmMac, uint16_t newVal);
71296177Sjhibbits    t_Error (*f_FM_MAC_ConfigWan) (t_Handle h_FmMac, bool flag);
72296177Sjhibbits    t_Error (*f_FM_MAC_ConfigPadAndCrc) (t_Handle h_FmMac, bool newVal);
73296177Sjhibbits    t_Error (*f_FM_MAC_ConfigHalfDuplex) (t_Handle h_FmMac, bool newVal);
74296177Sjhibbits    t_Error (*f_FM_MAC_ConfigLengthCheck) (t_Handle h_FmMac, bool newVal);
75296177Sjhibbits    t_Error (*f_FM_MAC_ConfigException) (t_Handle h_FmMac, e_FmMacExceptions, bool enable);
76296177Sjhibbits#ifdef FM_TX_ECC_FRMS_ERRATA_10GMAC_A004
77296177Sjhibbits    t_Error (*f_FM_MAC_ConfigSkipFman11Workaround) (t_Handle h_FmMac);
78296177Sjhibbits#endif /* FM_TX_ECC_FRMS_ERRATA_10GMAC_A004 */
79296177Sjhibbits
80296177Sjhibbits    t_Error (*f_FM_MAC_SetException) (t_Handle h_FmMac, e_FmMacExceptions ex, bool enable);
81296177Sjhibbits
82296177Sjhibbits    t_Error (*f_FM_MAC_Enable)  (t_Handle h_FmMac,  e_CommMode mode);
83296177Sjhibbits    t_Error (*f_FM_MAC_Disable) (t_Handle h_FmMac, e_CommMode mode);
84296177Sjhibbits    t_Error (*f_FM_MAC_Enable1588TimeStamp) (t_Handle h_FmMac);
85296177Sjhibbits    t_Error (*f_FM_MAC_Disable1588TimeStamp) (t_Handle h_FmMac);
86296177Sjhibbits    t_Error (*f_FM_MAC_Reset)   (t_Handle h_FmMac, bool wait);
87296177Sjhibbits
88296177Sjhibbits    t_Error (*f_FM_MAC_SetTxAutoPauseFrames)   (t_Handle h_FmMac, uint16_t pauseTime);
89296177Sjhibbits    t_Error (*f_FM_MAC_SetRxIgnorePauseFrames) (t_Handle h_FmMac, bool en);
90296177Sjhibbits
91296177Sjhibbits    t_Error (*f_FM_MAC_ResetCounters) (t_Handle h_FmMac);
92296177Sjhibbits    t_Error (*f_FM_MAC_GetStatistics) (t_Handle h_FmMac, t_FmMacStatistics *p_Statistics);
93296177Sjhibbits
94296177Sjhibbits    t_Error (*f_FM_MAC_ModifyMacAddr) (t_Handle h_FmMac, t_EnetAddr *p_EnetAddr);
95296177Sjhibbits    t_Error (*f_FM_MAC_AddHashMacAddr) (t_Handle h_FmMac, t_EnetAddr *p_EnetAddr);
96296177Sjhibbits    t_Error (*f_FM_MAC_RemoveHashMacAddr) (t_Handle h_FmMac, t_EnetAddr *p_EnetAddr);
97296177Sjhibbits    t_Error (*f_FM_MAC_AddExactMatchMacAddr) (t_Handle h_FmMac, t_EnetAddr *p_EnetAddr);
98296177Sjhibbits    t_Error (*f_FM_MAC_RemovelExactMatchMacAddr) (t_Handle h_FmMac, t_EnetAddr *p_EnetAddr);
99296177Sjhibbits
100296177Sjhibbits    t_Error (*f_FM_MAC_SetPromiscuous) (t_Handle h_FmMac, bool newVal);
101296177Sjhibbits    t_Error (*f_FM_MAC_AdjustLink)     (t_Handle h_FmMac, e_EnetSpeed speed, bool fullDuplex);
102296177Sjhibbits
103296177Sjhibbits    t_Error (*f_FM_MAC_GetId) (t_Handle h_FmMac, uint32_t *macId);
104296177Sjhibbits
105296177Sjhibbits    t_Error (*f_FM_MAC_GetVersion) (t_Handle h_FmMac, uint32_t *macVersion);
106296177Sjhibbits
107296177Sjhibbits    uint16_t (*f_FM_MAC_GetMaxFrameLength) (t_Handle h_FmMac);
108296177Sjhibbits
109296177Sjhibbits    t_Error (*f_FM_MAC_MII_WritePhyReg)(t_Handle h_FmMac, uint8_t phyAddr, uint8_t reg, uint16_t data);
110296177Sjhibbits    t_Error (*f_FM_MAC_MII_ReadPhyReg)(t_Handle h_FmMac,  uint8_t phyAddr, uint8_t reg, uint16_t *p_Data);
111296177Sjhibbits
112296177Sjhibbits#if (defined(DEBUG_ERRORS) && (DEBUG_ERRORS > 0))
113296177Sjhibbits    t_Error (*f_FM_MAC_DumpRegs) (t_Handle h_FmMac);
114296177Sjhibbits#endif /* (defined(DEBUG_ERRORS) && ... */
115296177Sjhibbits
116296177Sjhibbits    t_Handle        h_Fm;
117296177Sjhibbits    e_EnetMode      enetMode;
118296177Sjhibbits    uint8_t         macId;
119296177Sjhibbits    bool            resetOnInit;
120296177Sjhibbits    uint16_t        clkFreq;
121296177Sjhibbits} t_FmMacControllerDriver;
122296177Sjhibbits
123296177Sjhibbits
124296177Sjhibbitst_Handle    DTSEC_Config(t_FmMacParams *p_FmMacParam);
125296177Sjhibbitst_Handle    TGEC_Config(t_FmMacParams *p_FmMacParams);
126296177Sjhibbitsuint16_t    FM_MAC_GetMaxFrameLength(t_Handle FmMac);
127296177Sjhibbits
128296177Sjhibbits
129296177Sjhibbits/* ........................................................................... */
130296177Sjhibbits
131296177Sjhibbitsstatic __inline__ t_EthHashEntry *DequeueAddrFromHashEntry(t_List *p_AddrLst)
132296177Sjhibbits{
133296177Sjhibbits   t_EthHashEntry *p_HashEntry = NULL;
134296177Sjhibbits    if (!LIST_IsEmpty(p_AddrLst))
135296177Sjhibbits    {
136296177Sjhibbits        p_HashEntry = ETH_HASH_ENTRY_OBJ(p_AddrLst->p_Next);
137296177Sjhibbits        LIST_DelAndInit(&p_HashEntry->node);
138296177Sjhibbits    }
139296177Sjhibbits    return p_HashEntry;
140296177Sjhibbits}
141296177Sjhibbits
142296177Sjhibbits/* ........................................................................... */
143296177Sjhibbits
144296177Sjhibbitsstatic __inline__ void FreeHashTable(t_EthHash *p_Hash)
145296177Sjhibbits{
146296177Sjhibbits    t_EthHashEntry  *p_HashEntry;
147296177Sjhibbits    int             i = 0;
148296177Sjhibbits
149296177Sjhibbits    if (!p_Hash || !p_Hash->p_Lsts)
150296177Sjhibbits        return;
151296177Sjhibbits
152296177Sjhibbits    for(i=0; i<p_Hash->size; i++)
153296177Sjhibbits    {
154296177Sjhibbits        p_HashEntry = DequeueAddrFromHashEntry(&p_Hash->p_Lsts[i]);
155296177Sjhibbits        while (p_HashEntry)
156296177Sjhibbits        {
157296177Sjhibbits            XX_Free(p_HashEntry);
158296177Sjhibbits            p_HashEntry = DequeueAddrFromHashEntry(&p_Hash->p_Lsts[i]);
159296177Sjhibbits        }
160296177Sjhibbits    }
161296177Sjhibbits
162296177Sjhibbits    XX_Free(p_Hash->p_Lsts);
163296177Sjhibbits    XX_Free(p_Hash);
164296177Sjhibbits}
165296177Sjhibbits
166296177Sjhibbits/* ........................................................................... */
167296177Sjhibbits
168296177Sjhibbitsstatic __inline__ t_EthHash * AllocHashTable(uint16_t size)
169296177Sjhibbits{
170296177Sjhibbits    uint32_t    i;
171296177Sjhibbits    t_EthHash *p_Hash;
172296177Sjhibbits
173296177Sjhibbits    /* Allocate address hash table */
174296177Sjhibbits    p_Hash = (t_EthHash *)XX_Malloc(size*sizeof(t_EthHash *));
175296177Sjhibbits    if (!p_Hash)
176296177Sjhibbits    {
177296177Sjhibbits        REPORT_ERROR(MAJOR, E_NO_MEMORY, ("Address hash table"));
178296177Sjhibbits        return NULL;
179296177Sjhibbits    }
180296177Sjhibbits    p_Hash->size = size;
181296177Sjhibbits
182296177Sjhibbits    p_Hash->p_Lsts = (t_List *)XX_Malloc(p_Hash->size*sizeof(t_List));
183296177Sjhibbits    if (!p_Hash->p_Lsts)
184296177Sjhibbits    {
185296177Sjhibbits        REPORT_ERROR(MAJOR, E_NO_MEMORY, ("Address hash table"));
186296177Sjhibbits        XX_Free(p_Hash);
187296177Sjhibbits        return NULL;
188296177Sjhibbits    }
189296177Sjhibbits
190296177Sjhibbits    for(i=0 ; i<p_Hash->size; i++)
191296177Sjhibbits        INIT_LIST(&p_Hash->p_Lsts[i]);
192296177Sjhibbits
193296177Sjhibbits    return p_Hash;
194296177Sjhibbits}
195296177Sjhibbits
196296177Sjhibbits
197296177Sjhibbits#endif /* __FM_MAC_H */
198