2 Implementation of initializing a network adapter.
4 Copyright (c) 2004 - 2008, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials are licensed
6 and made available under the terms and conditions of the BSD License which
7 accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
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.
19 Call UNDI to initialize the interface.
21 @param Snp Pointer to snp driver structure.
22 @param CableDetectFlag Do/don't detect the cable (depending on what
25 @retval EFI_SUCCESS UNDI is initialized successfully.
26 @retval EFI_DEVICE_ERROR UNDI could not be initialized.
27 @retval Other Other errors as indicated.
33 UINT16 CableDetectFlag
36 PXE_CPB_INITIALIZE
*Cpb
;
41 if (Snp
->TxRxBufferSize
!= 0) {
42 Status
= Snp
->PciIo
->AllocateBuffer (
46 SNP_MEM_PAGES (Snp
->TxRxBufferSize
),
51 if (Status
!= EFI_SUCCESS
) {
54 "\nSnp->PxeInit() AllocateBuffer %xh (%r)\n",
64 Snp
->TxRxBuffer
= Addr
;
67 Cpb
->MemoryAddr
= (UINT64
)(UINTN
) Snp
->TxRxBuffer
;
69 Cpb
->MemoryLength
= Snp
->TxRxBufferSize
;
72 // let UNDI decide/detect these values
80 Cpb
->DuplexMode
= PXE_DUPLEX_DEFAULT
;
82 Cpb
->LoopBackMode
= LOOPBACK_NORMAL
;
84 Snp
->Cdb
.OpCode
= PXE_OPCODE_INITIALIZE
;
85 Snp
->Cdb
.OpFlags
= CableDetectFlag
;
87 Snp
->Cdb
.CPBsize
= (UINT16
) sizeof (PXE_CPB_INITIALIZE
);
88 Snp
->Cdb
.DBsize
= (UINT16
) sizeof (PXE_DB_INITIALIZE
);
90 Snp
->Cdb
.CPBaddr
= (UINT64
)(UINTN
) Snp
->Cpb
;
91 Snp
->Cdb
.DBaddr
= (UINT64
)(UINTN
) Snp
->Db
;
93 Snp
->Cdb
.StatCode
= PXE_STATCODE_INITIALIZE
;
94 Snp
->Cdb
.StatFlags
= PXE_STATFLAGS_INITIALIZE
;
95 Snp
->Cdb
.IFnum
= Snp
->IfNum
;
96 Snp
->Cdb
.Control
= PXE_CONTROL_LAST_CDB_IN_LIST
;
98 DEBUG ((EFI_D_NET
, "\nSnp->undi.initialize() "));
100 (*Snp
->IssueUndi32Command
) ((UINT64
)(UINTN
) &Snp
->Cdb
);
102 if (Snp
->Cdb
.StatCode
== PXE_STATCODE_SUCCESS
) {
103 Snp
->Mode
.State
= EfiSimpleNetworkInitialized
;
105 Status
= EFI_SUCCESS
;
109 "\nSnp->undi.initialize() %xh:%xh\n",
114 if (Snp
->TxRxBuffer
!= NULL
) {
115 Snp
->PciIo
->FreeBuffer (
117 SNP_MEM_PAGES (Snp
->TxRxBufferSize
),
118 (VOID
*) Snp
->TxRxBuffer
122 Snp
->TxRxBuffer
= NULL
;
124 Status
= EFI_DEVICE_ERROR
;
132 Resets a network adapter and allocates the transmit and receive buffers
133 required by the network interface; optionally, also requests allocation of
134 additional transmit and receive buffers.
136 This function allocates the transmit and receive buffers required by the network
137 interface. If this allocation fails, then EFI_OUT_OF_RESOURCES is returned.
138 If the allocation succeeds and the network interface is successfully initialized,
139 then EFI_SUCCESS will be returned.
141 @param This A pointer to the EFI_SIMPLE_NETWORK_PROTOCOL instance.
143 @param ExtraRxBufferSize The size, in bytes, of the extra receive buffer space
144 that the driver should allocate for the network interface.
145 Some network interfaces will not be able to use the
146 extra buffer, and the caller will not know if it is
148 @param ExtraTxBufferSize The size, in bytes, of the extra transmit buffer space
149 that the driver should allocate for the network interface.
150 Some network interfaces will not be able to use the
151 extra buffer, and the caller will not know if it is
154 @retval EFI_SUCCESS The network interface was initialized.
155 @retval EFI_NOT_STARTED The network interface has not been started.
156 @retval EFI_OUT_OF_RESOURCES There was not enough memory for the transmit and
158 @retval EFI_INVALID_PARAMETER This parameter was NULL or did not point to a valid
159 EFI_SIMPLE_NETWORK_PROTOCOL structure.
160 @retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
161 @retval EFI_UNSUPPORTED The increased buffer size feature is not supported.
166 SnpUndi32Initialize (
167 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
168 IN UINTN ExtraRxBufferSize OPTIONAL
,
169 IN UINTN ExtraTxBufferSize OPTIONAL
172 EFI_STATUS EfiStatus
;
177 return EFI_INVALID_PARAMETER
;
180 Snp
= EFI_SIMPLE_NETWORK_DEV_FROM_THIS (This
);
182 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
185 EfiStatus
= EFI_INVALID_PARAMETER
;
189 switch (Snp
->Mode
.State
) {
190 case EfiSimpleNetworkStarted
:
193 case EfiSimpleNetworkStopped
:
194 EfiStatus
= EFI_NOT_STARTED
;
198 EfiStatus
= EFI_DEVICE_ERROR
;
202 EfiStatus
= gBS
->CreateEvent (
205 &SnpWaitForPacketNotify
,
207 &Snp
->Snp
.WaitForPacket
210 if (EFI_ERROR (EfiStatus
)) {
211 Snp
->Snp
.WaitForPacket
= NULL
;
212 EfiStatus
= EFI_DEVICE_ERROR
;
218 Snp
->Mode
.MCastFilterCount
= 0;
219 Snp
->Mode
.ReceiveFilterSetting
= 0;
220 ZeroMem (Snp
->Mode
.MCastFilter
, sizeof Snp
->Mode
.MCastFilter
);
222 &Snp
->Mode
.CurrentAddress
,
223 &Snp
->Mode
.PermanentAddress
,
224 sizeof (EFI_MAC_ADDRESS
)
228 // Compute tx/rx buffer sizes based on UNDI init info and parameters.
230 Snp
->TxRxBufferSize
= (UINT32
) (Snp
->InitInfo
.MemoryRequired
+ ExtraRxBufferSize
+ ExtraTxBufferSize
);
232 if (Snp
->Mode
.MediaPresentSupported
) {
233 if (PxeInit (Snp
, PXE_OPFLAGS_INITIALIZE_DETECT_CABLE
) == EFI_SUCCESS
) {
234 Snp
->Mode
.MediaPresent
= TRUE
;
239 Snp
->Mode
.MediaPresent
= FALSE
;
241 EfiStatus
= PxeInit (Snp
, PXE_OPFLAGS_INITIALIZE_DO_NOT_DETECT_CABLE
);
243 if (EFI_ERROR (EfiStatus
)) {
244 gBS
->CloseEvent (Snp
->Snp
.WaitForPacket
);
248 gBS
->RestoreTPL (OldTpl
);