Save original PCI attributes in start() function and restore it in Stop() for those...
[mirror_edk2.git] / MdeModulePkg / Bus / Pci / UndiRuntimeDxe / Undi32.h
1
2 /*++
3
4 Copyright (c) 2006, Intel Corporation.
5 All rights reserved. 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 Module Name:
14
15 undi32.h
16
17 Abstract:
18
19 EFI internal structures for the EFI UNDI driver
20
21
22
23 Revision History
24
25 --*/
26
27 #ifndef _UNDI_32_H_
28 #define _UNDI_32_H_
29
30 #include <PiDxe.h>
31
32 #include <Guid/EventGroup.h>
33 #include <Protocol/PciIo.h>
34 #include <Protocol/NetworkInterfaceIdentifier.h>
35 #include <Protocol/DevicePath.h>
36
37 #include <Library/UefiDriverEntryPoint.h>
38 #include <Library/UefiRuntimeLib.h>
39 #include <Library/DebugLib.h>
40 #include <Library/BaseMemoryLib.h>
41 #include <Library/UefiBootServicesTableLib.h>
42 #include <Library/UefiLib.h>
43
44 #include <IndustryStandard/Pci.h>
45
46
47 #include "E100b.h"
48
49 #define MAX_NIC_INTERFACES 16
50
51 #define EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL_REVISION_31 0x00010001
52 #define PXE_ROMID_MINORVER_31 0x10
53 #define PXE_STATFLAGS_DB_WRITE_TRUNCATED 0x2000
54
55 //
56 // UNDI_CALL_TABLE.state can have the following values
57 //
58 #define DONT_CHECK -1
59 #define ANY_STATE -1
60 #define MUST_BE_STARTED 1
61 #define MUST_BE_INITIALIZED 2
62
63 #define UNDI_DEV_SIGNATURE EFI_SIGNATURE_32('u','n','d','i')
64 #define UNDI_DEV_FROM_THIS(a) CR(a, UNDI32_DEV, NIIProtocol, UNDI_DEV_SIGNATURE)
65 #define UNDI_DEV_FROM_NIC(a) CR(a, UNDI32_DEV, NicInfo, UNDI_DEV_SIGNATURE)
66
67 typedef struct {
68 UINTN Signature;
69 EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL NIIProtocol;
70 EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL NIIProtocol_31;
71 EFI_HANDLE DeviceHandle;
72 EFI_DEVICE_PATH_PROTOCOL *Undi32BaseDevPath;
73 EFI_DEVICE_PATH_PROTOCOL *Undi32DevPath;
74 NIC_DATA_INSTANCE NicInfo;
75 } UNDI32_DEV;
76
77 typedef struct {
78 UINT16 cpbsize;
79 UINT16 dbsize;
80 UINT16 opflags;
81 UINT16 state;
82 VOID (*api_ptr)();
83 } UNDI_CALL_TABLE;
84
85 typedef struct {
86 EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL *InterfacePointer;
87 EFI_DEVICE_PATH_PROTOCOL *DevicePathPointer;
88 } NII_ENTRY;
89
90 typedef struct NII_CONFIG_ENTRY {
91 UINT32 NumEntries;
92 UINT32 Reserved; // padding for alignment
93 struct NII_CONFIG_ENTRY *NextLink;
94 NII_ENTRY NiiEntry[1];
95 } NII_TABLE;
96
97 typedef VOID (*ptr)(VOID);
98 typedef VOID (*bsptr_30)(UINTN);
99 typedef VOID (*virtphys_30)(UINT64, UINT64);
100 typedef VOID (*block_30)(UINT32);
101 typedef VOID (*mem_io_30)(UINT8, UINT8, UINT64, UINT64);
102
103 typedef VOID (*bsptr)(UINT64, UINTN);
104 typedef VOID (*virtphys)(UINT64, UINT64, UINT64);
105 typedef VOID (*block)(UINT64, UINT32);
106 typedef VOID (*mem_io)(UINT64, UINT8, UINT8, UINT64, UINT64);
107
108 typedef VOID (*map_mem)(UINT64, UINT64, UINT32, UINT32, UINT64);
109 typedef VOID (*unmap_mem)(UINT64, UINT64, UINT32, UINT32, UINT64);
110 typedef VOID (*sync_mem)(UINT64, UINT64, UINT32, UINT32, UINT64);
111
112 extern UNDI_CALL_TABLE api_table[];
113 extern PXE_SW_UNDI *pxe; // !pxe structure
114 extern PXE_SW_UNDI *pxe_31; // !pxe structure for 3.1 drivers
115 extern UNDI32_DEV *UNDI32DeviceList[MAX_NIC_INTERFACES];
116
117 //
118 // functions defined in e100b.c
119 //
120 UINT8 InByte (NIC_DATA_INSTANCE *AdapterInfo, UINT32 Port);
121 UINT16 InWord (NIC_DATA_INSTANCE *AdapterInfo, UINT32 Port);
122 UINT32 InLong (NIC_DATA_INSTANCE *AdapterInfo, UINT32 Port);
123 VOID OutByte (NIC_DATA_INSTANCE *AdapterInfo, UINT8 Data, UINT32 Port);
124 VOID OutWord (NIC_DATA_INSTANCE *AdapterInfo, UINT16 Data, UINT32 Port);
125 VOID OutLong (NIC_DATA_INSTANCE *AdapterInfo, UINT32 Data, UINT32 Port);
126
127 UINTN E100bInit (NIC_DATA_INSTANCE *AdapterInfo);
128 UINTN E100bReset (NIC_DATA_INSTANCE *AdapterInfo, INT32 OpFlags);
129 UINTN E100bShutdown (NIC_DATA_INSTANCE *AdapterInfo);
130 UINTN E100bTransmit (NIC_DATA_INSTANCE *AdapterInfo, UINT64 cpb, UINT16 opflags);
131 UINTN E100bReceive (NIC_DATA_INSTANCE *AdapterInfo, UINT64 cpb, UINT64 db);
132 UINTN E100bSetfilter (NIC_DATA_INSTANCE *AdapterInfo, UINT16 New_filter,
133 UINT64 cpb, UINT32 cpbsize);
134 UINTN E100bStatistics(NIC_DATA_INSTANCE *AdapterInfo, UINT64 db, UINT16 dbsize);
135 UINT8 E100bSetupIAAddr (NIC_DATA_INSTANCE *AdapterInfo);
136 UINT8 E100bSetInterruptState (NIC_DATA_INSTANCE *AdapterInfo);
137
138 UINT8 E100bGetEepromAddrLen (NIC_DATA_INSTANCE *AdapterInfo);
139 UINT16 E100bReadEeprom (NIC_DATA_INSTANCE *AdapterInfo, INT32 Location, UINT8 address_len);
140 INT16 E100bReadEepromAndStationAddress (NIC_DATA_INSTANCE *AdapterInfo);
141
142 UINT16 next(UINT16);
143 UINT8 SetupCBlink (NIC_DATA_INSTANCE *AdapterInfo);
144 VOID SetFreeCB (NIC_DATA_INSTANCE *AdapterInfo,TxCB *);
145 TxCB *GetFreeCB (NIC_DATA_INSTANCE *AdapterInfo);
146 UINT16 CheckCBList (NIC_DATA_INSTANCE *AdapterInfo);
147
148 UINT8 SelectiveReset (NIC_DATA_INSTANCE *AdapterInfo);
149 UINT16 InitializeChip (NIC_DATA_INSTANCE *AdapterInfo);
150 UINT8 SetupReceiveQueues (NIC_DATA_INSTANCE *AdapterInfo);
151 VOID Recycle_RFD (NIC_DATA_INSTANCE *AdapterInfo, UINT16);
152 VOID XmitWaitForCompletion (NIC_DATA_INSTANCE *AdapterInfo);
153 INT8 CommandWaitForCompletion (TxCB *cmd_ptr, NIC_DATA_INSTANCE *AdapterInfo);
154
155 BOOLEAN PhyDetect (NIC_DATA_INSTANCE *AdapterInfo);
156 VOID PhyReset (NIC_DATA_INSTANCE *AdapterInfo);
157 VOID
158 MdiWrite (
159 IN NIC_DATA_INSTANCE *AdapterInfo,
160 IN UINT8 RegAddress,
161 IN UINT8 PhyAddress,
162 IN UINT16 DataValue
163 );
164
165 VOID
166 MdiRead(
167 IN NIC_DATA_INSTANCE *AdapterInfo,
168 IN UINT8 RegAddress,
169 IN UINT8 PhyAddress,
170 IN OUT UINT16 *DataValue
171 );
172
173 BOOLEAN SetupPhy (NIC_DATA_INSTANCE *AdapterInfo);
174 VOID FindPhySpeedAndDpx (NIC_DATA_INSTANCE *AdapterInfo, UINT32 PhyId);
175
176
177
178 //
179 // functions defined in init.c
180 //
181 EFI_STATUS
182 InstallConfigTable (
183 IN VOID
184 );
185
186 EFI_STATUS
187 EFIAPI
188 InitializeUNDIDriver (
189 IN EFI_HANDLE ImageHandle,
190 IN EFI_SYSTEM_TABLE *SystemTable
191 );
192
193 VOID
194 UNDI_notify_virtual (
195 EFI_EVENT event,
196 VOID *context
197 );
198
199 VOID
200 EFIAPI
201 UndiNotifyExitBs (
202 EFI_EVENT Event,
203 VOID *Context
204 );
205
206 EFI_STATUS
207 EFIAPI
208 UndiDriverSupported (
209 IN EFI_DRIVER_BINDING_PROTOCOL *This,
210 IN EFI_HANDLE Controller,
211 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
212 );
213
214 EFI_STATUS
215 EFIAPI
216 UndiDriverStart (
217 IN EFI_DRIVER_BINDING_PROTOCOL *This,
218 IN EFI_HANDLE Controller,
219 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
220 );
221
222 EFI_STATUS
223 EFIAPI
224 UndiDriverStop (
225 IN EFI_DRIVER_BINDING_PROTOCOL *This,
226 IN EFI_HANDLE Controller,
227 IN UINTN NumberOfChildren,
228 IN EFI_HANDLE *ChildHandleBuffer
229 );
230
231 EFI_STATUS
232 AppendMac2DevPath (
233 IN OUT EFI_DEVICE_PATH_PROTOCOL **DevPtr,
234 IN EFI_DEVICE_PATH_PROTOCOL *BaseDevPtr,
235 IN NIC_DATA_INSTANCE *AdapterInfo
236 );
237
238 VOID
239 TmpDelay (
240 IN UINT64 UnqId,
241 IN UINTN MicroSeconds
242 );
243
244 VOID
245 TmpMemIo (
246 IN UINT64 UnqId,
247 IN UINT8 ReadWrite,
248 IN UINT8 Len,
249 IN UINT64 Port,
250 IN UINT64 BufAddr
251 );
252
253 //
254 // functions defined in decode.c
255 //
256 VOID
257 UNDI_GetState (
258 IN PXE_CDB *CdbPtr,
259 IN NIC_DATA_INSTANCE *AdapterInfo
260 );
261
262 VOID
263 UNDI_Start (
264 IN PXE_CDB *CdbPtr,
265 IN NIC_DATA_INSTANCE *AdapterInfo
266 );
267
268 VOID
269 UNDI_Stop (
270 IN PXE_CDB *CdbPtr,
271 IN NIC_DATA_INSTANCE *AdapterInfo
272 );
273
274 VOID
275 UNDI_GetInitInfo (
276 IN PXE_CDB *CdbPtr,
277 IN NIC_DATA_INSTANCE *AdapterInfo
278 );
279
280 VOID
281 UNDI_GetConfigInfo (
282 IN PXE_CDB *CdbPtr,
283 IN NIC_DATA_INSTANCE *AdapterInfo
284 );
285
286 VOID
287 UNDI_Initialize (
288 IN PXE_CDB *CdbPtr,
289 NIC_DATA_INSTANCE *AdapterInfo
290 );
291
292 VOID
293 UNDI_Reset (
294 IN PXE_CDB *CdbPtr,
295 IN NIC_DATA_INSTANCE *AdapterInfo
296 );
297
298 VOID
299 UNDI_Shutdown (
300 IN PXE_CDB *CdbPtr,
301 IN NIC_DATA_INSTANCE *AdapterInfo
302 );
303
304 VOID
305 UNDI_Interrupt (
306 IN PXE_CDB *CdbPtr,
307 IN NIC_DATA_INSTANCE *AdapterInfo
308 );
309
310 VOID
311 UNDI_RecFilter (
312 IN PXE_CDB *CdbPtr,
313 IN NIC_DATA_INSTANCE *AdapterInfo
314 );
315
316 VOID
317 UNDI_StnAddr (
318 IN PXE_CDB *CdbPtr,
319 IN NIC_DATA_INSTANCE *AdapterInfo
320 );
321
322 VOID
323 UNDI_Statistics (
324 IN PXE_CDB *CdbPtr,
325 IN NIC_DATA_INSTANCE *AdapterInfo
326 );
327
328 VOID
329 UNDI_ip2mac (
330 IN PXE_CDB *CdbPtr,
331 IN NIC_DATA_INSTANCE *AdapterInfo
332 );
333
334 VOID
335 UNDI_NVData (
336 IN PXE_CDB *CdbPtr,
337 IN NIC_DATA_INSTANCE *AdapterInfo
338 );
339
340 VOID
341 UNDI_Status (
342 IN PXE_CDB *CdbPtr,
343 IN NIC_DATA_INSTANCE *AdapterInfo
344 );
345
346 VOID
347 UNDI_FillHeader (
348 IN PXE_CDB *CdbPtr,
349 IN NIC_DATA_INSTANCE *AdapterInfo
350 );
351
352 VOID
353 UNDI_Transmit (
354 IN PXE_CDB *CdbPtr,
355 IN NIC_DATA_INSTANCE *AdapterInfo
356 );
357
358 VOID
359 UNDI_Receive (
360 IN PXE_CDB *CdbPtr,
361 IN NIC_DATA_INSTANCE *AdapterInfo
362 );
363
364 VOID UNDI_APIEntry_new(UINT64);
365 VOID UNDI_APIEntry_old(UINT64);
366 VOID UNDI_APIEntry_Common(UINT64);
367
368 PXE_IPV4 convert_mcip(PXE_MAC_ADDR *);
369 INT32 validate_mcip (PXE_MAC_ADDR *MCastAddr);
370
371 VOID PxeStructInit (PXE_SW_UNDI *PxePtr, UINTN VersionFlag);
372 VOID PxeUpdate (NIC_DATA_INSTANCE *NicPtr, PXE_SW_UNDI *PxePtr);
373
374 #endif