blob: 424bdc5a85ca06f84437aae2aa4ec4bb4ace60f9 [file] [log] [blame]
Vishal Bhoj82c80712015-12-15 21:13:33 +05301/** @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**/
29UINT32
30ReverseBits (
31 UINT32 Value
32 );
33
34// Create an Ethernet CRC
35UINT32
36GenEtherCrc32 (
37 IN EFI_MAC_ADDRESS *Mac,
38 IN UINT32 AddrLen
39 );
40
41/* ------------------ MAC CSR Access ------------------- */
42
43// Read from MAC indirect registers
44UINT32
45IndirectMACRead32 (
46 UINT32 Index
47 );
48
49
50// Write to indirect registers
51UINT32
52IndirectMACWrite32 (
53 UINT32 Index,
54 UINT32 Value
55 );
56
57
58/* --------------- PHY Registers Access ---------------- */
59
60// Read from MII register (PHY Access)
61UINT32
62IndirectPHYRead32(
63 UINT32 Index
64 );
65
66
67// Write to the MII register (PHY Access)
68UINT32
69IndirectPHYWrite32(
70 UINT32 Index,
71 UINT32 Value
72 );
73
74/* ---------------- EEPROM Operations ------------------ */
75
76// Read from EEPROM memory
77UINT32
78IndirectEEPROMRead32 (
79 UINT32 Index
80 );
81
82// Write to EEPROM memory
83UINT32
84IndirectEEPROMWrite32 (
85 UINT32 Index,
86 UINT32 Value
87 );
88
89/* ---------------- General Operations ----------------- */
90
91VOID
92Lan9118SetMacAddress (
93 EFI_MAC_ADDRESS *Mac,
94 EFI_SIMPLE_NETWORK_PROTOCOL *Snp
95 );
96
97// Initialise the LAN9118
98EFI_STATUS
99Lan9118Initialize (
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
109EFI_STATUS
110SoftReset (
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
121EFI_STATUS
122PhySoftReset (
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
131EFI_STATUS
132ConfigureHardware (
133 UINT32 Flags,
134 EFI_SIMPLE_NETWORK_PROTOCOL *Snp
135 );
136
137// Configure flow control
138EFI_STATUS
139ConfigureFlow (
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
152EFI_STATUS
153AutoNegotiate (
154 UINT32 Flags,
155 EFI_SIMPLE_NETWORK_PROTOCOL *Snp
156 );
157
158// Check the Link Status and take appropriate action
159EFI_STATUS
160CheckLinkStatus (
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
171EFI_STATUS
172StopTx (
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
181EFI_STATUS
182StopRx (
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
193EFI_STATUS
194StartTx (
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
203EFI_STATUS
204StartRx (
205 UINT32 Flags,
206 EFI_SIMPLE_NETWORK_PROTOCOL *Snp
207 );
208
209// Check Tx Data available space
210UINT32
211TxDataFreeSpace (
212 UINT32 Flags,
213 EFI_SIMPLE_NETWORK_PROTOCOL *Snp
214 );
215
216// Check Tx Status used space
217UINT32
218TxStatusUsedSpace (
219 UINT32 Flags,
220 EFI_SIMPLE_NETWORK_PROTOCOL *Snp
221 );
222
223// Check Rx Data used space
224UINT32
225RxDataUsedSpace (
226 UINT32 Flags,
227 EFI_SIMPLE_NETWORK_PROTOCOL *Snp
228 );
229
230// Check Rx Status used space
231UINT32
232RxStatusUsedSpace (
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
250EFI_STATUS
251ChangeFifoAllocation (
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
260VOID
261Lan9118ReadMacAddress (
262 OUT EFI_MAC_ADDRESS *Mac
263 );
264
265#endif // __LAN9118_DXE_UTIL_H__