1 /** @file
2   EFI internal structures for the EFI UNDI driver.
3 
4 Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>
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 _UNDI_32_H_
16 #define _UNDI_32_H_
17 
18 #include <Uefi.h>
19 
20 #include <Guid/EventGroup.h>
21 #include <Protocol/PciIo.h>
22 #include <Protocol/NetworkInterfaceIdentifier.h>
23 #include <Protocol/DevicePath.h>
24 #include <Protocol/AdapterInformation.h>
25 
26 #include <Library/UefiDriverEntryPoint.h>
27 #include <Library/UefiRuntimeLib.h>
28 #include <Library/DebugLib.h>
29 #include <Library/BaseMemoryLib.h>
30 #include <Library/UefiBootServicesTableLib.h>
31 #include <Library/UefiLib.h>
32 #include <Library/BaseLib.h>
33 #include <Library/DevicePathLib.h>
34 #include <Library/MemoryAllocationLib.h>
35 
36 #include <IndustryStandard/Pci.h>
37 
38 
39 #include "E100b.h"
40 
41 extern EFI_DRIVER_BINDING_PROTOCOL  gUndiDriverBinding;
42 extern EFI_COMPONENT_NAME_PROTOCOL  gUndiComponentName;
43 extern EFI_COMPONENT_NAME2_PROTOCOL gUndiComponentName2;
44 
45 #define MAX_NIC_INTERFACES 16
46 
47 #define EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL_REVISION_31 0x00010001
48 #define PXE_ROMID_MINORVER_31 0x10
49 #define PXE_STATFLAGS_DB_WRITE_TRUNCATED  0x2000
50 
51 //
52 // UNDI_CALL_TABLE.state can have the following values
53 //
54 #define DONT_CHECK -1
55 #define ANY_STATE -1
56 #define MUST_BE_STARTED 1
57 #define MUST_BE_INITIALIZED 2
58 
59 #define UNDI_DEV_SIGNATURE   SIGNATURE_32('u','n','d','i')
60 #define UNDI_DEV_FROM_THIS(a) CR(a, UNDI32_DEV, NIIProtocol_31, UNDI_DEV_SIGNATURE)
61 #define UNDI_DEV_FROM_NIC(a) CR(a, UNDI32_DEV, NicInfo, UNDI_DEV_SIGNATURE)
62 #define UNDI_DEV_FROM_AIP(a) CR(a, UNDI32_DEV, Aip, UNDI_DEV_SIGNATURE)
63 
64 typedef struct {
65   UINTN                                     Signature;
66   EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL NIIProtocol_31;
67   EFI_ADAPTER_INFORMATION_PROTOCOL          Aip;
68   EFI_HANDLE                                DeviceHandle;
69   EFI_DEVICE_PATH_PROTOCOL                  *Undi32BaseDevPath;
70   EFI_DEVICE_PATH_PROTOCOL                  *Undi32DevPath;
71   NIC_DATA_INSTANCE                         NicInfo;
72 } UNDI32_DEV;
73 
74 typedef struct {
75   UINT16 cpbsize;
76   UINT16 dbsize;
77   UINT16 opflags;
78   UINT16 state;
79   VOID (*api_ptr)();
80 } UNDI_CALL_TABLE;
81 
82 typedef VOID (*ptr)(VOID);
83 typedef VOID (*bsptr_30)(UINTN);
84 typedef VOID (*virtphys_30)(UINT64, UINT64);
85 typedef VOID (*block_30)(UINT32);
86 typedef VOID (*mem_io_30)(UINT8, UINT8, UINT64, UINT64);
87 
88 typedef VOID (*bsptr)(UINT64, UINTN);
89 typedef VOID (*virtphys)(UINT64, UINT64, UINT64);
90 typedef VOID (*block)(UINT64, UINT32);
91 typedef VOID (*mem_io)(UINT64, UINT8, UINT8, UINT64, UINT64);
92 
93 typedef VOID (*map_mem)(UINT64, UINT64, UINT32, UINT32, UINT64);
94 typedef VOID (*unmap_mem)(UINT64, UINT64, UINT32, UINT32, UINT64);
95 typedef VOID (*sync_mem)(UINT64, UINT64, UINT32, UINT32, UINT64);
96 
97 extern UNDI_CALL_TABLE  api_table[];
98 extern PXE_SW_UNDI      *pxe_31;  // !pxe structure for 3.1 drivers
99 extern UNDI32_DEV       *UNDI32DeviceList[MAX_NIC_INTERFACES];
100 
101 //
102 // functions defined in e100b.c
103 //
104 UINT8 InByte (NIC_DATA_INSTANCE *AdapterInfo, UINT32 Port);
105 UINT16 InWord (NIC_DATA_INSTANCE *AdapterInfo, UINT32 Port);
106 UINT32 InLong (NIC_DATA_INSTANCE *AdapterInfo, UINT32 Port);
107 VOID  OutByte (NIC_DATA_INSTANCE *AdapterInfo, UINT8 Data, UINT32 Port);
108 VOID  OutWord (NIC_DATA_INSTANCE *AdapterInfo, UINT16 Data, UINT32 Port);
109 VOID  OutLong (NIC_DATA_INSTANCE *AdapterInfo, UINT32 Data, UINT32 Port);
110 
111 UINTN E100bInit (NIC_DATA_INSTANCE *AdapterInfo);
112 UINTN E100bReset (NIC_DATA_INSTANCE *AdapterInfo, INT32 OpFlags);
113 UINTN E100bShutdown (NIC_DATA_INSTANCE *AdapterInfo);
114 UINTN E100bTransmit (NIC_DATA_INSTANCE *AdapterInfo, UINT64 cpb, UINT16 opflags);
115 UINTN E100bReceive (NIC_DATA_INSTANCE *AdapterInfo, UINT64 cpb, UINT64 db);
116 UINTN E100bSetfilter (NIC_DATA_INSTANCE *AdapterInfo, UINT16 New_filter,
117                       UINT64 cpb, UINT32 cpbsize);
118 UINTN E100bStatistics(NIC_DATA_INSTANCE *AdapterInfo, UINT64 db, UINT16 dbsize);
119 UINT8 E100bSetupIAAddr (NIC_DATA_INSTANCE *AdapterInfo);
120 UINT8 E100bSetInterruptState (NIC_DATA_INSTANCE *AdapterInfo);
121 
122 UINT8 E100bGetEepromAddrLen (NIC_DATA_INSTANCE *AdapterInfo);
123 UINT16 E100bReadEeprom (NIC_DATA_INSTANCE *AdapterInfo, INT32 Location, UINT8 address_len);
124 INT16 E100bReadEepromAndStationAddress (NIC_DATA_INSTANCE *AdapterInfo);
125 
126 UINT16 next(UINT16);
127 UINT8 SetupCBlink (NIC_DATA_INSTANCE *AdapterInfo);
128 VOID SetFreeCB (NIC_DATA_INSTANCE *AdapterInfo,TxCB *);
129 TxCB *GetFreeCB (NIC_DATA_INSTANCE *AdapterInfo);
130 UINT16 CheckCBList (NIC_DATA_INSTANCE *AdapterInfo);
131 
132 UINT8 SelectiveReset (NIC_DATA_INSTANCE *AdapterInfo);
133 UINT16 InitializeChip (NIC_DATA_INSTANCE *AdapterInfo);
134 UINT8 SetupReceiveQueues (NIC_DATA_INSTANCE *AdapterInfo);
135 VOID  Recycle_RFD (NIC_DATA_INSTANCE *AdapterInfo, UINT16);
136 VOID XmitWaitForCompletion (NIC_DATA_INSTANCE *AdapterInfo);
137 INT8 CommandWaitForCompletion (TxCB *cmd_ptr, NIC_DATA_INSTANCE *AdapterInfo);
138 
139 BOOLEAN PhyDetect (NIC_DATA_INSTANCE *AdapterInfo);
140 VOID PhyReset (NIC_DATA_INSTANCE *AdapterInfo);
141 VOID
142 MdiWrite (
143   IN NIC_DATA_INSTANCE *AdapterInfo,
144   IN UINT8 RegAddress,
145   IN UINT8 PhyAddress,
146   IN UINT16 DataValue
147   );
148 
149 VOID
150 MdiRead(
151   IN NIC_DATA_INSTANCE *AdapterInfo,
152   IN UINT8 RegAddress,
153   IN UINT8 PhyAddress,
154   IN OUT UINT16 *DataValue
155   );
156 
157 BOOLEAN SetupPhy (NIC_DATA_INSTANCE *AdapterInfo);
158 VOID FindPhySpeedAndDpx (NIC_DATA_INSTANCE *AdapterInfo, UINT32 PhyId);
159 
160 
161 
162 //
163 // functions defined in init.c
164 //
165 EFI_STATUS
166 InstallConfigTable (
167   IN VOID
168   );
169 
170 EFI_STATUS
171 EFIAPI
172 InitializeUNDIDriver (
173   IN EFI_HANDLE           ImageHandle,
174   IN EFI_SYSTEM_TABLE     *SystemTable
175   );
176 
177 VOID
178 UNDI_notify_virtual (
179   EFI_EVENT event,
180   VOID      *context
181   );
182 
183 EFI_STATUS
184 EFIAPI
185 UndiDriverSupported (
186   IN EFI_DRIVER_BINDING_PROTOCOL    *This,
187   IN EFI_HANDLE                     Controller,
188   IN EFI_DEVICE_PATH_PROTOCOL       *RemainingDevicePath
189   );
190 
191 EFI_STATUS
192 EFIAPI
193 UndiDriverStart (
194   IN EFI_DRIVER_BINDING_PROTOCOL    *This,
195   IN EFI_HANDLE                     Controller,
196   IN EFI_DEVICE_PATH_PROTOCOL       *RemainingDevicePath
197   );
198 
199 EFI_STATUS
200 EFIAPI
201 UndiDriverStop (
202   IN  EFI_DRIVER_BINDING_PROTOCOL    *This,
203   IN  EFI_HANDLE                     Controller,
204   IN  UINTN                          NumberOfChildren,
205   IN  EFI_HANDLE                     *ChildHandleBuffer
206   );
207 
208 EFI_STATUS
209 AppendMac2DevPath (
210   IN OUT  EFI_DEVICE_PATH_PROTOCOL **DevPtr,
211   IN      EFI_DEVICE_PATH_PROTOCOL *BaseDevPtr,
212   IN      NIC_DATA_INSTANCE        *AdapterInfo
213   );
214 
215 VOID
216 TmpDelay (
217   IN UINT64 UnqId,
218   IN UINTN MicroSeconds
219   );
220 
221 VOID
222 TmpMemIo (
223   IN UINT64 UnqId,
224   IN UINT8 ReadWrite,
225   IN UINT8 Len,
226   IN UINT64 Port,
227   IN UINT64 BufAddr
228   );
229 
230 //
231 // functions defined in decode.c
232 //
233 VOID
234 UNDI_GetState (
235   IN  PXE_CDB           *CdbPtr,
236   IN  NIC_DATA_INSTANCE *AdapterInfo
237   );
238 
239 VOID
240 UNDI_Start (
241   IN  PXE_CDB           *CdbPtr,
242   IN  NIC_DATA_INSTANCE *AdapterInfo
243   );
244 
245 VOID
246 UNDI_Stop (
247   IN  PXE_CDB           *CdbPtr,
248   IN  NIC_DATA_INSTANCE *AdapterInfo
249   );
250 
251 VOID
252 UNDI_GetInitInfo (
253   IN  PXE_CDB           *CdbPtr,
254   IN  NIC_DATA_INSTANCE *AdapterInfo
255   );
256 
257 VOID
258 UNDI_GetConfigInfo (
259   IN  PXE_CDB           *CdbPtr,
260   IN  NIC_DATA_INSTANCE *AdapterInfo
261   );
262 
263 VOID
264 UNDI_Initialize (
265   IN  PXE_CDB       *CdbPtr,
266   NIC_DATA_INSTANCE *AdapterInfo
267   );
268 
269 VOID
270 UNDI_Reset (
271   IN  PXE_CDB           *CdbPtr,
272   IN  NIC_DATA_INSTANCE *AdapterInfo
273   );
274 
275 VOID
276 UNDI_Shutdown (
277   IN  PXE_CDB           *CdbPtr,
278   IN  NIC_DATA_INSTANCE *AdapterInfo
279   );
280 
281 VOID
282 UNDI_Interrupt (
283   IN  PXE_CDB           *CdbPtr,
284   IN  NIC_DATA_INSTANCE *AdapterInfo
285   );
286 
287 VOID
288 UNDI_RecFilter (
289   IN  PXE_CDB           *CdbPtr,
290   IN  NIC_DATA_INSTANCE *AdapterInfo
291   );
292 
293 VOID
294 UNDI_StnAddr (
295   IN  PXE_CDB           *CdbPtr,
296   IN  NIC_DATA_INSTANCE *AdapterInfo
297   );
298 
299 VOID
300 UNDI_Statistics (
301   IN  PXE_CDB           *CdbPtr,
302   IN  NIC_DATA_INSTANCE *AdapterInfo
303   );
304 
305 VOID
306 UNDI_ip2mac (
307   IN  PXE_CDB           *CdbPtr,
308   IN  NIC_DATA_INSTANCE *AdapterInfo
309   );
310 
311 VOID
312 UNDI_NVData (
313   IN  PXE_CDB           *CdbPtr,
314   IN  NIC_DATA_INSTANCE *AdapterInfo
315   );
316 
317 VOID
318 UNDI_Status (
319   IN  PXE_CDB           *CdbPtr,
320   IN  NIC_DATA_INSTANCE *AdapterInfo
321   );
322 
323 VOID
324 UNDI_FillHeader (
325   IN  PXE_CDB           *CdbPtr,
326   IN  NIC_DATA_INSTANCE *AdapterInfo
327   );
328 
329 VOID
330 UNDI_Transmit (
331   IN  PXE_CDB           *CdbPtr,
332   IN  NIC_DATA_INSTANCE *AdapterInfo
333   );
334 
335 VOID
336 UNDI_Receive (
337   IN  PXE_CDB           *CdbPtr,
338   IN  NIC_DATA_INSTANCE *AdapterInfo
339   );
340 
341 VOID UNDI_APIEntry_new(UINT64);
342 VOID UNDI_APIEntry_Common(UINT64);
343 
344 PXE_IPV4 convert_mcip(PXE_MAC_ADDR *);
345 INT32 validate_mcip (PXE_MAC_ADDR *MCastAddr);
346 
347 VOID PxeStructInit (PXE_SW_UNDI *PxePtr);
348 VOID PxeUpdate (NIC_DATA_INSTANCE *NicPtr, PXE_SW_UNDI *PxePtr);
349 
350 //
351 // functions defined in UndiAipImpl.c
352 //
353 
354 /**
355   Returns the current state information for the adapter.
356 
357   This function returns information of type InformationType from the adapter.
358   If an adapter does not support the requested informational type, then
359   EFI_UNSUPPORTED is returned.
360 
361   @param[in]  This                   A pointer to the EFI_ADAPTER_INFORMATION_PROTOCOL instance.
362   @param[in]  InformationType        A pointer to an EFI_GUID that defines the contents of InformationBlock.
363   @param[out] InforamtionBlock       The service returns a pointer to the buffer with the InformationBlock
364                                      structure which contains details about the data specific to InformationType.
365   @param[out] InforamtionBlockSize   The driver returns the size of the InformationBlock in bytes.
366 
367   @retval EFI_SUCCESS                The InformationType information was retrieved.
368   @retval EFI_UNSUPPORTED            The InformationType is not known.
369   @retval EFI_DEVICE_ERROR           The device reported an error.
370   @retval EFI_OUT_OF_RESOURCES       The request could not be completed due to a lack of resources.
371   @retval EFI_INVALID_PARAMETER      This is NULL.
372   @retval EFI_INVALID_PARAMETER      InformationBlock is NULL.
373   @retval EFI_INVALID_PARAMETER      InformationBlockSize is NULL.
374 
375 **/
376 EFI_STATUS
377 EFIAPI
378 UndiAipGetInfo (
379   IN   EFI_ADAPTER_INFORMATION_PROTOCOL *This,
380   IN   EFI_GUID                         *InformationType,
381   OUT  VOID                             **InformationBlock,
382   OUT  UINTN                            *InformationBlockSize
383   );
384 
385 /**
386   Sets state information for an adapter.
387 
388   This function sends information of type InformationType for an adapter.
389   If an adapter does not support the requested information type, then EFI_UNSUPPORTED
390   is returned.
391 
392   @param[in]  This                   A pointer to the EFI_ADAPTER_INFORMATION_PROTOCOL instance.
393   @param[in]  InformationType        A pointer to an EFI_GUID that defines the contents of InformationBlock.
394   @param[in]  InforamtionBlock       A pointer to the InformationBlock structure which contains details
395                                      about the data specific to InformationType.
396   @param[in]  InforamtionBlockSize   The size of the InformationBlock in bytes.
397 
398   @retval EFI_SUCCESS                The information was received and interpreted successfully.
399   @retval EFI_UNSUPPORTED            The InformationType is not known.
400   @retval EFI_DEVICE_ERROR           The device reported an error.
401   @retval EFI_INVALID_PARAMETER      This is NULL.
402   @retval EFI_INVALID_PARAMETER      InformationBlock is NULL.
403   @retval EFI_WRITE_PROTECTED        The InformationType cannot be modified using EFI_ADAPTER_INFO_SET_INFO().
404 
405 **/
406 EFI_STATUS
407 EFIAPI
408 UndiAipSetInfo (
409   IN   EFI_ADAPTER_INFORMATION_PROTOCOL *This,
410   IN   EFI_GUID                         *InformationType,
411   IN   VOID                             *InformationBlock,
412   IN   UINTN                            InformationBlockSize
413   );
414 
415 /**
416   Get a list of supported information types for this instance of the protocol.
417 
418   This function returns a list of InformationType GUIDs that are supported on an
419   adapter with this instance of EFI_ADAPTER_INFORMATION_PROTOCOL. The list is returned
420   in InfoTypesBuffer, and the number of GUID pointers in InfoTypesBuffer is returned in
421   InfoTypesBufferCount.
422 
423   @param[in]  This                  A pointer to the EFI_ADAPTER_INFORMATION_PROTOCOL instance.
424   @param[out] InfoTypesBuffer       A pointer to the list of InformationType GUID pointers that are supported
425                                     by This.
426   @param[out] InfoTypesBufferCount  A pointer to the number of GUID pointers present in InfoTypesBuffer.
427 
428   @retval EFI_SUCCESS               The list of information type GUIDs that are supported on this adapter was
429                                     returned in InfoTypesBuffer. The number of information type GUIDs was
430                                     returned in InfoTypesBufferCount.
431   @retval EFI_INVALID_PARAMETER     This is NULL.
432   @retval EFI_INVALID_PARAMETER     InfoTypesBuffer is NULL.
433   @retval EFI_INVALID_PARAMETER     InfoTypesBufferCount is NULL.
434   @retval EFI_OUT_OF_RESOURCES      There is not enough pool memory to store the results.
435 
436 **/
437 EFI_STATUS
438 EFIAPI
439 UndiAipGetSupportedTypes (
440   IN    EFI_ADAPTER_INFORMATION_PROTOCOL *This,
441   OUT   EFI_GUID                         **InfoTypesBuffer,
442   OUT   UINTN                            *InfoTypesBufferCount
443   );
444 
445 #endif
446