• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /** @file
2 *
3 *  Copyright (c) 2012-2014, ARM Limited. All rights reserved.
4 *
5 *  This program and the accompanying materials
6 *  are licensed and made available under the terms and conditions of the BSD License
7 *  which accompanies this distribution.  The full text of the license may be found at
8 *  http://opensource.org/licenses/bsd-license.php
9 *
10 *  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 *  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12 *
13 **/
14 
15 #ifndef __LAN9118_DXE_UTIL_H__
16 #define __LAN9118_DXE_UTIL_H__
17 
18 // Most common CRC32 Polynomial for little endian machines
19 #define CRC_POLYNOMIAL               0xEDB88320
20 
21 /**
22   This internal function reverses bits for 32bit data.
23 
24   @param  Value                 The data to be reversed.
25 
26   @return                       Data reversed.
27 
28 **/
29 UINT32
30 ReverseBits (
31   UINT32  Value
32   );
33 
34 // Create an Ethernet CRC
35 UINT32
36 GenEtherCrc32 (
37   IN    EFI_MAC_ADDRESS *Mac,
38   IN    UINT32 AddrLen
39   );
40 
41 UINT32
42 Lan9118RawMmioRead32(
43   UINTN Address,
44   UINTN Delay
45   );
46 #define Lan9118MmioRead32(a) \
47 	Lan9118RawMmioRead32(a, a ## _RD_DELAY)
48 
49 UINT32
50 Lan9118RawMmioWrite32(
51   UINTN Address,
52   UINT32 Value,
53   UINTN Delay
54   );
55 #define Lan9118MmioWrite32(a, v) \
56 	Lan9118RawMmioWrite32(a, v, a ## _WR_DELAY)
57 
58 /* ------------------ MAC CSR Access ------------------- */
59 
60 // Read from MAC indirect registers
61 UINT32
62 IndirectMACRead32 (
63   UINT32 Index
64   );
65 
66 
67 // Write to indirect registers
68 UINT32
69 IndirectMACWrite32 (
70   UINT32 Index,
71   UINT32 Value
72   );
73 
74 
75 /* --------------- PHY Registers Access ---------------- */
76 
77 // Read from MII register (PHY Access)
78 UINT32
79 IndirectPHYRead32(
80   UINT32 Index
81   );
82 
83 
84 // Write to the MII register (PHY Access)
85 UINT32
86 IndirectPHYWrite32(
87   UINT32 Index,
88   UINT32 Value
89   );
90 
91 /* ---------------- EEPROM Operations ------------------ */
92 
93 // Read from EEPROM memory
94 UINT32
95 IndirectEEPROMRead32 (
96   UINT32 Index
97   );
98 
99 // Write to EEPROM memory
100 UINT32
101 IndirectEEPROMWrite32 (
102   UINT32 Index,
103   UINT32 Value
104   );
105 
106 /* ---------------- General Operations ----------------- */
107 
108 VOID
109 Lan9118SetMacAddress (
110   EFI_MAC_ADDRESS             *Mac,
111   EFI_SIMPLE_NETWORK_PROTOCOL *Snp
112   );
113 
114 // Initialise the LAN9118
115 EFI_STATUS
116 Lan9118Initialize (
117   IN  EFI_SIMPLE_NETWORK_PROTOCOL *Snp
118   );
119 
120 // Flags for software reset
121 #define SOFT_RESET_CHECK_MAC_ADDR_LOAD                  BIT0
122 #define SOFT_RESET_CLEAR_INT                            BIT1
123 #define SOFT_RESET_SELF_TEST                            BIT2
124 
125 // Perform software reset on the LAN9118
126 EFI_STATUS
127 SoftReset (
128   UINT32 Flags,
129   EFI_SIMPLE_NETWORK_PROTOCOL *Snp
130   );
131 
132 // Flags for PHY reset
133 #define PHY_RESET_PMT                                   BIT0
134 #define PHY_RESET_BCR                                   BIT1
135 #define PHY_SOFT_RESET_CLEAR_INT                        BIT2
136 
137 // Perform PHY software reset
138 EFI_STATUS
139 PhySoftReset (
140   UINT32 Flags,
141   EFI_SIMPLE_NETWORK_PROTOCOL *Snp
142   );
143 
144 // Flags for Hardware configuration
145 #define HW_CONF_USE_LEDS                                BIT0
146 
147 // Configure hardware for LAN9118
148 EFI_STATUS
149 ConfigureHardware (
150   UINT32 Flags,
151   EFI_SIMPLE_NETWORK_PROTOCOL *Snp
152   );
153 
154 // Configure flow control
155 EFI_STATUS
156 ConfigureFlow (
157   UINT32 Flags,
158   UINT32 HighTrig,
159   UINT32 LowTrig,
160   UINT32 BPDuration,
161   EFI_SIMPLE_NETWORK_PROTOCOL *Snp
162   );
163 
164 // Flags for auto negotiation
165 #define AUTO_NEGOTIATE_COLLISION_TEST         BIT0
166 #define AUTO_NEGOTIATE_ADVERTISE_ALL          BIT1
167 
168 // Do auto-negotiation
169 EFI_STATUS
170 AutoNegotiate (
171   UINT32 Flags,
172   EFI_SIMPLE_NETWORK_PROTOCOL *Snp
173   );
174 
175 // Check the Link Status and take appropriate action
176 EFI_STATUS
177 CheckLinkStatus (
178   UINT32 Flags,
179   EFI_SIMPLE_NETWORK_PROTOCOL *Snp
180   );
181 
182 // Stop transmitter flags
183 #define STOP_TX_MAC                       BIT0
184 #define STOP_TX_CFG                       BIT1
185 #define STOP_TX_CLEAR                     BIT2
186 
187 // Stop the transmitter
188 EFI_STATUS
189 StopTx (
190   UINT32 Flags,
191   EFI_SIMPLE_NETWORK_PROTOCOL *Snp
192   );
193 
194 // Stop receiver flags
195 #define STOP_RX_CLEAR                     BIT0
196 
197 // Stop the receiver
198 EFI_STATUS
199 StopRx (
200   UINT32 Flags,
201   EFI_SIMPLE_NETWORK_PROTOCOL *Snp
202   );
203 
204 // Start transmitter flags
205 #define START_TX_MAC                      BIT0
206 #define START_TX_CFG                      BIT1
207 #define START_TX_CLEAR                    BIT2
208 
209 // Start the transmitter
210 EFI_STATUS
211 StartTx (
212   UINT32 Flags,
213   EFI_SIMPLE_NETWORK_PROTOCOL *Snp
214   );
215 
216 // Stop receiver flags
217 #define START_RX_CLEAR                     BIT0
218 
219 // Start the receiver
220 EFI_STATUS
221 StartRx (
222   UINT32 Flags,
223   EFI_SIMPLE_NETWORK_PROTOCOL *Snp
224   );
225 
226 // Check Tx Data available space
227 UINT32
228 TxDataFreeSpace (
229   UINT32 Flags,
230   EFI_SIMPLE_NETWORK_PROTOCOL *Snp
231   );
232 
233 // Check Tx Status used space
234 UINT32
235 TxStatusUsedSpace (
236   UINT32 Flags,
237   EFI_SIMPLE_NETWORK_PROTOCOL *Snp
238   );
239 
240 // Check Rx Data used space
241 UINT32
242 RxDataUsedSpace (
243   UINT32 Flags,
244   EFI_SIMPLE_NETWORK_PROTOCOL *Snp
245   );
246 
247 // Check Rx Status used space
248 UINT32
249 RxStatusUsedSpace (
250   UINT32 Flags,
251   EFI_SIMPLE_NETWORK_PROTOCOL *Snp
252   );
253 
254 
255 // Flags for FIFO allocation
256 #define ALLOC_USE_DEFAULT                 BIT0
257 #define ALLOC_USE_FIFOS                   BIT1
258 #define ALLOC_USE_DMA                     BIT2
259 
260 // FIFO min and max sizes
261 #define TX_FIFO_MIN_SIZE            0x00000600
262 #define TX_FIFO_MAX_SIZE            0x00003600
263 //#define RX_FIFO_MIN_SIZE
264 //#define RX_FIFO_MAX_SIZE
265 
266 // Change the allocation of FIFOs
267 EFI_STATUS
268 ChangeFifoAllocation (
269   IN      UINT32 Flags,
270   IN  OUT UINTN  *TxDataSize    OPTIONAL,
271   IN  OUT UINTN  *RxDataSize    OPTIONAL,
272   IN  OUT UINT32 *TxStatusSize  OPTIONAL,
273   IN  OUT UINT32 *RxStatusSize  OPTIONAL,
274   IN  OUT EFI_SIMPLE_NETWORK_PROTOCOL *Snp
275   );
276 
277 VOID
278 Lan9118ReadMacAddress (
279   OUT EFI_MAC_ADDRESS *Mac
280   );
281 
282 #endif // __LAN9118_DXE_UTIL_H__
283