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 /* ------------------ MAC CSR Access ------------------- */
42 
43 // Read from MAC indirect registers
44 UINT32
45 IndirectMACRead32 (
46   UINT32 Index
47   );
48 
49 
50 // Write to indirect registers
51 UINT32
52 IndirectMACWrite32 (
53   UINT32 Index,
54   UINT32 Value
55   );
56 
57 
58 /* --------------- PHY Registers Access ---------------- */
59 
60 // Read from MII register (PHY Access)
61 UINT32
62 IndirectPHYRead32(
63   UINT32 Index
64   );
65 
66 
67 // Write to the MII register (PHY Access)
68 UINT32
69 IndirectPHYWrite32(
70   UINT32 Index,
71   UINT32 Value
72   );
73 
74 /* ---------------- EEPROM Operations ------------------ */
75 
76 // Read from EEPROM memory
77 UINT32
78 IndirectEEPROMRead32 (
79   UINT32 Index
80   );
81 
82 // Write to EEPROM memory
83 UINT32
84 IndirectEEPROMWrite32 (
85   UINT32 Index,
86   UINT32 Value
87   );
88 
89 /* ---------------- General Operations ----------------- */
90 
91 VOID
92 Lan9118SetMacAddress (
93   EFI_MAC_ADDRESS             *Mac,
94   EFI_SIMPLE_NETWORK_PROTOCOL *Snp
95   );
96 
97 // Initialise the LAN9118
98 EFI_STATUS
99 Lan9118Initialize (
100   IN  EFI_SIMPLE_NETWORK_PROTOCOL *Snp
101   );
102 
103 // Flags for software reset
104 #define SOFT_RESET_CHECK_MAC_ADDR_LOAD                  BIT0
105 #define SOFT_RESET_CLEAR_INT                            BIT1
106 #define SOFT_RESET_SELF_TEST                            BIT2
107 
108 // Perform software reset on the LAN9118
109 EFI_STATUS
110 SoftReset (
111   UINT32 Flags,
112   EFI_SIMPLE_NETWORK_PROTOCOL *Snp
113   );
114 
115 // Flags for PHY reset
116 #define PHY_RESET_PMT                                   BIT0
117 #define PHY_RESET_BCR                                   BIT1
118 #define PHY_SOFT_RESET_CLEAR_INT                        BIT2
119 
120 // Perform PHY software reset
121 EFI_STATUS
122 PhySoftReset (
123   UINT32 Flags,
124   EFI_SIMPLE_NETWORK_PROTOCOL *Snp
125   );
126 
127 // Flags for Hardware configuration
128 #define HW_CONF_USE_LEDS                                BIT0
129 
130 // Configure hardware for LAN9118
131 EFI_STATUS
132 ConfigureHardware (
133   UINT32 Flags,
134   EFI_SIMPLE_NETWORK_PROTOCOL *Snp
135   );
136 
137 // Configure flow control
138 EFI_STATUS
139 ConfigureFlow (
140   UINT32 Flags,
141   UINT32 HighTrig,
142   UINT32 LowTrig,
143   UINT32 BPDuration,
144   EFI_SIMPLE_NETWORK_PROTOCOL *Snp
145   );
146 
147 // Flags for auto negotiation
148 #define AUTO_NEGOTIATE_COLLISION_TEST         BIT0
149 #define AUTO_NEGOTIATE_ADVERTISE_ALL          BIT1
150 
151 // Do auto-negotiation
152 EFI_STATUS
153 AutoNegotiate (
154   UINT32 Flags,
155   EFI_SIMPLE_NETWORK_PROTOCOL *Snp
156   );
157 
158 // Check the Link Status and take appropriate action
159 EFI_STATUS
160 CheckLinkStatus (
161   UINT32 Flags,
162   EFI_SIMPLE_NETWORK_PROTOCOL *Snp
163   );
164 
165 // Stop transmitter flags
166 #define STOP_TX_MAC                       BIT0
167 #define STOP_TX_CFG                       BIT1
168 #define STOP_TX_CLEAR                     BIT2
169 
170 // Stop the transmitter
171 EFI_STATUS
172 StopTx (
173   UINT32 Flags,
174   EFI_SIMPLE_NETWORK_PROTOCOL *Snp
175   );
176 
177 // Stop receiver flags
178 #define STOP_RX_CLEAR                     BIT0
179 
180 // Stop the receiver
181 EFI_STATUS
182 StopRx (
183   UINT32 Flags,
184   EFI_SIMPLE_NETWORK_PROTOCOL *Snp
185   );
186 
187 // Start transmitter flags
188 #define START_TX_MAC                      BIT0
189 #define START_TX_CFG                      BIT1
190 #define START_TX_CLEAR                    BIT2
191 
192 // Start the transmitter
193 EFI_STATUS
194 StartTx (
195   UINT32 Flags,
196   EFI_SIMPLE_NETWORK_PROTOCOL *Snp
197   );
198 
199 // Stop receiver flags
200 #define START_RX_CLEAR                     BIT0
201 
202 // Start the receiver
203 EFI_STATUS
204 StartRx (
205   UINT32 Flags,
206   EFI_SIMPLE_NETWORK_PROTOCOL *Snp
207   );
208 
209 // Check Tx Data available space
210 UINT32
211 TxDataFreeSpace (
212   UINT32 Flags,
213   EFI_SIMPLE_NETWORK_PROTOCOL *Snp
214   );
215 
216 // Check Tx Status used space
217 UINT32
218 TxStatusUsedSpace (
219   UINT32 Flags,
220   EFI_SIMPLE_NETWORK_PROTOCOL *Snp
221   );
222 
223 // Check Rx Data used space
224 UINT32
225 RxDataUsedSpace (
226   UINT32 Flags,
227   EFI_SIMPLE_NETWORK_PROTOCOL *Snp
228   );
229 
230 // Check Rx Status used space
231 UINT32
232 RxStatusUsedSpace (
233   UINT32 Flags,
234   EFI_SIMPLE_NETWORK_PROTOCOL *Snp
235   );
236 
237 
238 // Flags for FIFO allocation
239 #define ALLOC_USE_DEFAULT                 BIT0
240 #define ALLOC_USE_FIFOS                   BIT1
241 #define ALLOC_USE_DMA                     BIT2
242 
243 // FIFO min and max sizes
244 #define TX_FIFO_MIN_SIZE            0x00000600
245 #define TX_FIFO_MAX_SIZE            0x00003600
246 //#define RX_FIFO_MIN_SIZE
247 //#define RX_FIFO_MAX_SIZE
248 
249 // Change the allocation of FIFOs
250 EFI_STATUS
251 ChangeFifoAllocation (
252   IN      UINT32 Flags,
253   IN  OUT UINTN  *TxDataSize    OPTIONAL,
254   IN  OUT UINTN  *RxDataSize    OPTIONAL,
255   IN  OUT UINT32 *TxStatusSize  OPTIONAL,
256   IN  OUT UINT32 *RxStatusSize  OPTIONAL,
257   IN  OUT EFI_SIMPLE_NETWORK_PROTOCOL *Snp
258   );
259 
260 VOID
261 Lan9118ReadMacAddress (
262   OUT EFI_MAC_ADDRESS *Mac
263   );
264 
265 #endif // __LAN9118_DXE_UTIL_H__
266