2 Implementation of initializing a network adapter.
4 Copyright (c) 2004 - 2008, Intel Corporation. <BR>
5 All rights reserved. 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 this routine calls 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 undi supports)
24 @retval EFI_SUCCESS UNDI is initialized successfully
25 @retval EFI_DEVICE_ERROR UNDI could not be initialized
26 @retval Other other errors
32 UINT16 CableDetectFlag
35 PXE_CPB_INITIALIZE
*Cpb
;
40 if (Snp
->TxRxBufferSize
!= 0) {
41 Status
= Snp
->PciIo
->AllocateBuffer (
45 SNP_MEM_PAGES (Snp
->TxRxBufferSize
),
50 if (Status
!= EFI_SUCCESS
) {
53 "\nSnp->PxeInit() AllocateBuffer %xh (%r)\n",
63 Snp
->TxRxBuffer
= Addr
;
66 Cpb
->MemoryAddr
= (UINT64
)(UINTN
) Snp
->TxRxBuffer
;
68 Cpb
->MemoryLength
= Snp
->TxRxBufferSize
;
71 // let UNDI decide/detect these values
79 Cpb
->DuplexMode
= PXE_DUPLEX_DEFAULT
;
81 Cpb
->LoopBackMode
= LOOPBACK_NORMAL
;
83 Snp
->Cdb
.OpCode
= PXE_OPCODE_INITIALIZE
;
84 Snp
->Cdb
.OpFlags
= CableDetectFlag
;
86 Snp
->Cdb
.CPBsize
= sizeof (PXE_CPB_INITIALIZE
);
87 Snp
->Cdb
.DBsize
= sizeof (PXE_DB_INITIALIZE
);
89 Snp
->Cdb
.CPBaddr
= (UINT64
)(UINTN
) Snp
->Cpb
;
90 Snp
->Cdb
.DBaddr
= (UINT64
)(UINTN
) Snp
->Db
;
92 Snp
->Cdb
.StatCode
= PXE_STATCODE_INITIALIZE
;
93 Snp
->Cdb
.StatFlags
= PXE_STATFLAGS_INITIALIZE
;
94 Snp
->Cdb
.IFnum
= Snp
->IfNum
;
95 Snp
->Cdb
.Control
= PXE_CONTROL_LAST_CDB_IN_LIST
;
97 DEBUG ((EFI_D_NET
, "\nSnp->undi.initialize() "));
99 (*Snp
->IssueUndi32Command
) ((UINT64
)(UINTN
) &Snp
->Cdb
);
101 if (Snp
->Cdb
.StatCode
== PXE_STATCODE_SUCCESS
) {
102 Snp
->Mode
.State
= EfiSimpleNetworkInitialized
;
104 Status
= EFI_SUCCESS
;
108 "\nSnp->undi.initialize() %xh:%xh\n",
113 if (Snp
->TxRxBuffer
!= NULL
) {
114 Snp
->PciIo
->FreeBuffer (
116 SNP_MEM_PAGES (Snp
->TxRxBufferSize
),
117 (VOID
*) Snp
->TxRxBuffer
121 Snp
->TxRxBuffer
= NULL
;
123 Status
= EFI_DEVICE_ERROR
;
131 Resets a network adapter and allocates the transmit and receive buffers
132 required by the network interface; optionally, also requests allocation of
133 additional transmit and receive buffers.
135 This function allocates the transmit and receive buffers required by the network
136 interface. If this allocation fails, then EFI_OUT_OF_RESOURCES is returned.
137 If the allocation succeeds and the network interface is successfully initialized,
138 then EFI_SUCCESS will be returned.
140 @param This A pointer to the EFI_SIMPLE_NETWORK_PROTOCOL instance.
142 @param ExtraRxBufferSize The size, in bytes, of the extra receive buffer space
143 that the driver should allocate for the network interface.
144 Some network interfaces will not be able to use the
145 extra buffer, and the caller will not know if it is
147 @param ExtraTxBufferSize The size, in bytes, of the extra transmit buffer space
148 that the driver should allocate for the network interface.
149 Some network interfaces will not be able to use the
150 extra buffer, and the caller will not know if it is
153 @retval EFI_SUCCESS The network interface was initialized.
154 @retval EFI_NOT_STARTED The network interface has not been started.
155 @retval EFI_OUT_OF_RESOURCES There was not enough memory for the transmit and
157 @retval EFI_INVALID_PARAMETER This parameter was NULL or did not point to a valid
158 EFI_SIMPLE_NETWORK_PROTOCOL structure.
159 @retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
160 @retval EFI_UNSUPPORTED The increased buffer size feature is not supported.
165 SnpUndi32Initialize (
166 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
167 IN UINTN ExtraRxBufferSize OPTIONAL
,
168 IN UINTN ExtraTxBufferSize OPTIONAL
171 EFI_STATUS EfiStatus
;
176 return EFI_INVALID_PARAMETER
;
179 Snp
= EFI_SIMPLE_NETWORK_DEV_FROM_THIS (This
);
181 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
184 EfiStatus
= EFI_INVALID_PARAMETER
;
188 switch (Snp
->Mode
.State
) {
189 case EfiSimpleNetworkStarted
:
192 case EfiSimpleNetworkStopped
:
193 EfiStatus
= EFI_NOT_STARTED
;
197 EfiStatus
= EFI_DEVICE_ERROR
;
201 EfiStatus
= gBS
->CreateEvent (
204 &SnpWaitForPacketNotify
,
206 &Snp
->Snp
.WaitForPacket
209 if (EFI_ERROR (EfiStatus
)) {
210 Snp
->Snp
.WaitForPacket
= NULL
;
211 EfiStatus
= EFI_DEVICE_ERROR
;
217 Snp
->Mode
.MCastFilterCount
= 0;
218 Snp
->Mode
.ReceiveFilterSetting
= 0;
219 ZeroMem (Snp
->Mode
.MCastFilter
, sizeof Snp
->Mode
.MCastFilter
);
221 &Snp
->Mode
.CurrentAddress
,
222 &Snp
->Mode
.PermanentAddress
,
223 sizeof (EFI_MAC_ADDRESS
)
227 // Compute tx/rx buffer sizes based on UNDI init info and parameters.
229 Snp
->TxRxBufferSize
= (UINT32
) (Snp
->InitInfo
.MemoryRequired
+ ExtraRxBufferSize
+ ExtraTxBufferSize
);
231 if (Snp
->Mode
.MediaPresentSupported
) {
232 if (PxeInit (Snp
, PXE_OPFLAGS_INITIALIZE_DETECT_CABLE
) == EFI_SUCCESS
) {
233 Snp
->Mode
.MediaPresent
= TRUE
;
238 Snp
->Mode
.MediaPresent
= FALSE
;
240 EfiStatus
= PxeInit (Snp
, PXE_OPFLAGS_INITIALIZE_DO_NOT_DETECT_CABLE
);
242 if (EFI_ERROR (EfiStatus
)) {
243 gBS
->CloseEvent (Snp
->Snp
.WaitForPacket
);
247 gBS
->RestoreTPL (OldTpl
);