NetBurner 3.5.7
PDF Version
coldfire/cpu/MCF5441X/include/ethervars.h
1/*NB_REVISION*/
2
3/*NB_COPYRIGHT*/
4
5#ifndef _ETHER_VARS_H
6#define _EHTER_VARS_H
7
8// PHY ID Register #3 bits with the last 4 revision number bits being don't cares
9#define MICREL_ID (0x1610)
10#define MICREL8041_ID (0x1510)
11#define DAVICOM_ID (0xB880)
12#define AMD_ID (0x5610)
13#define NATIONAL_ID (0x5C90)
14#define NATIONAL_IEEE1588_ID (0x5CE0)
15#define MICREL8081_ID (0x1560)
16
17#if (defined MCF5272)
18#define CORE72
19#else
20#define CORE70
21#endif
22
23// PHY Register addresses
24#define PHY_REG_BASIC_CTL 0x00
25#define PHY_REG_BASIC_ST 0x01
26#define PHY_REG_ID_1 0x02
27#define PHY_REG_ID_2 0x03
28#define PHY_REG_A_NEG_ADVERT 0x04
29#define PHY_REG_A_NEG_LPA 0x05
30#define PHY_REG_A_NEG_EXP 0x06
31#define PHY_REG_A_NEG_NEXT_PG 0x07
32#define PHY_REG_LP_NEXT_PG_ABIL 0x08
33#define PHY_AFE_CTL_1 0x10
34#define PHY_REG_MILL_CTL 0x14
35#define PHY_RXER_CNTR 0x15
36#define PHY_MODE_STRAP_OVER 0x16
37#define PHY_MODE_STRAP_STATUS 0x17
38#define PHY_EXPANDED_CTL 0x18
39#define PHY_REG_IRQ_CTL_ST 0x1B
40#define PHY_REG_PHY_CTL_1 0x1E
41#define PHY_REG_PHY_CTL_2 0x1F
42
43// PHY Register masks
44#define PHY_LINK_STAT 0x0004
45#define PHY_A_NEG_COMP 0x0020
46#define PHY_IRQ_DOWN_EN 0x0400
47#define PHY_IRQ_UP_EN 0x0100
48
49#define IP_20uint8_t_ID (0x4500)
50#define ETHER_TYPE_IP (0x0800)
51#define ETHER_TYPE_ARP (0x0806)
52
53#define NUM_TX_BD (3)
54
55#ifdef _DEBUG
56/*******************WARNING ***********************/
57// This number must be a power of 2 and match the mask value
58// OK to mess with the non debug value, leave the debug value alone.
59#define NUM_RX_BD (8)
60#define NUM_DEBUG_RX_BUFF (8)
61#define DB_RX_MASK (0x07)
62/*******************WARNING ***********************/
63
64#else
65
66#define NUM_RX_BD (10)
67
68#endif
69
70#define FEC_RMII_10T_MODE (0x00000200)
71
72#include <netinterface.h>
73#include <sim5441x.h>
74
75typedef enum
76{
77 PORT1_WAITING = 0,
78 PORT1_INITED = 1,
79 PORT1_SWITCH = 2
80} Port1_State;
81
82class EthernetVars : public EtherLikeInterface
83{
84 public:
85 int fecn; // FEC(Freescale Ethernet Controller) number
86 bool inited;
87 uint8_t supMacInUse; // Bitmask indicating which Supplemental MACs are in use
88
89 OS_SEM SemSend;
90
91 int nTx; // TX and RX counters
92 int nRx;
93 uint32_t TxIsrCnt;
94 uint32_t RxIsrCnt;
95 uint32_t LrnIsrCnt;
96
97 // Place for all the buffers
98 volatile EtherBD TxBD[NUM_TX_BD] __attribute__((aligned(16)));
99 volatile EtherBD RxBD[NUM_RX_BD] __attribute__((aligned(16)));
100
101 volatile PoolPtr RxBDpp[NUM_RX_BD] __attribute__((aligned(4)));
102 volatile PoolPtr TxBDpp[NUM_TX_BD] __attribute__((aligned(4)));
103
104 volatile uint8_t RxBDFlag[NUM_RX_BD] __attribute__((aligned(4)));
105 volatile uint8_t TxBDFlag[NUM_RX_BD] __attribute__((aligned(4)));
106
107 int last_rxbd;
108
109 uint32_t LastIsrStatus;
110
111 volatile uint32_t RxPosts;
112 volatile uint32_t TxcPosts;
113 volatile uint32_t RxReject;
114
115 // Current link status
116 BOOL bEthLink; /* do we have link? */
117 BOOL bEthDuplex; /* Are we set-up for duplex? */
118 BOOL bEth100Mb; /* Are we 100Mb? */
119 BOOL bPromisc; /* Are we in Promiscuous Mode? */
120
121 // Discovered PHY data
122 BOOL RMII;
123 uint8_t PHY_addr;
124 uint16_t PHY_ID;
125
126 // Phy forcing modes
127 BOOL SetEthDuplex;
128 BOOL SetEth100Mb;
129 BOOL AutoNeg;
130
131 // Link status info
132 BOOL bNewLink;
133 BOOL bNewDuplex;
134 BOOL bEverHadLink; /*Have we ever had link */
135 bool bDescriptorsReadied; /* Have we readied the buffer descriptors? */
136
137 volatile uint32_t phy_data_pd;
138 volatile uint32_t phy_data;
139
140 uint32_t last_phy_read;
141
142 uint32_t AutoTimeOut; // Link but no Auto Negotiation counter
143
144 // Real public interface
145 EthernetVars(int fec, const char *name);
146
147 void ManualEthernetConfig(BOOL Speed100, BOOL FullDuplex, BOOL AutoNegotiate);
148
149 void SetPromiscuous(BOOL promisc);
150 inline void EnablePromiscuous() { SetPromiscuous(TRUE); }
151 inline void DisablePromiscuous() { SetPromiscuous(FALSE); }
152 void EnablePHY();
153 void DisablePHY();
154
155 virtual void send_func(PoolPtr poolPtr);
156 virtual void kill_if();
157 virtual void EnableMulticast(MACADR macAddress, BOOL addAddress);
158 virtual bool LinkActive();
159 virtual bool LinkDuplex();
160 virtual int LinkSpeed();
161 virtual const char *GetInterfaceName();
162
163 void InitializeEthernet(bool bRegisterInterface);
164
165 uint32_t GetMII(uint8_t addr);
166 uint32_t GetMII(uint8_t mii_dev, uint8_t addr);
167 uint32_t SetMII(uint8_t addr, uint16_t value);
168 uint32_t SetMII(uint8_t mii_dev, uint8_t addr, uint16_t value);
169
170 // Internal processing functions
171 void DoRX(PoolPtr pp, uint16_t length);
172 int ProcessRxBuffer(PoolPtr pp);
173 void ResetEnet();
174 void ResetEnetPart2();
175 void ReadyDescriptors();
176 void WarmEnetReset();
177 void ProcessDuplexStatus(uint16_t phyStat);
178 void RxIsrProc(volatile uint32_t &isr, uint32_t frameMask, uint32_t bufferMask);
179 void TxIsrProc(volatile uint32_t &isr, uint32_t frameMask, uint32_t bufferMask);
180
181 // Info display functions
182 void ShowLinkStatus();
183 void ShowMII(uint8_t mii_dev, uint8_t addr, PCSTR name, uint16_t mask);
184 void ShowFECRegisters();
185 void ShowPhyterMII();
186#ifdef _DEBUG
187 void DebugEthernetTx(PoolPtr pb); // Transmits a buffer and frees it afterword.
188 void NMIEthernetYield(volatile uint32_t &isr, uint32_t frameMask, uint32_t bufferMask);
189 void NMI_Eth_Transmit(PoolPtr pb);
190#endif
191};
192
193void SetPromiscuous(BOOL promisc);
194inline void EnablePromiscuous()
195{
196 SetPromiscuous(TRUE);
197}
198inline void DisablePromiscuous()
199{
200 SetPromiscuous(FALSE);
201}
202void ShowESWRegisters();
203
204extern "C"
205{
206 void DoDumpEnet();
207}
208
209extern EthernetVars enet0;
210extern EthernetVars enet1;
211
212// Set to true save config and reboot to enter switch mode.
213extern config_bool DoEtherSwitch;
214
215#ifdef _DEBUG
216#define DEBUG_INTERFACE_MAGIC_IFNUM (0x80)
217#endif
218
219#endif
Used to store and manipulate MAC addresses.
Definition nettypes.h:69
Boolean Configuration Variable.
Definition config_obj.h:998
Counting semaphore for task synchronization and resource management.
Definition nbrtos.h:550
Main buffer structure for network and serial communication.
Definition buffers.h:90