2 Copyright (c) 2004 - 2007, Intel Corporation
3 All rights reserved. This program and the accompanying materials
4 are licensed and made available under the terms and conditions of the BSD License
5 which accompanies this distribution. The full text of the license may be found at
6 http://opensource.org/licenses/bsd-license.php
8 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
9 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 2000-Feb-09 M(f)J Genesis.
26 SnpWaitForPacketNotify (
33 this routine calls undi to initialize the interface.
35 @param snp pointer to snp driver structure
36 @param CableDetectFlag Do/don't detect the cable (depending on what undi
44 UINT16 CableDetectFlag
47 PXE_CPB_INITIALIZE
*cpb
;
52 if (snp
->tx_rx_bufsize
!= 0) {
53 Status
= snp
->IoFncs
->AllocateBuffer (
57 SNP_MEM_PAGES (snp
->tx_rx_bufsize
),
62 if (Status
!= EFI_SUCCESS
) {
65 "\nsnp->pxe_init() AllocateBuffer %xh (%r)\n",
75 snp
->tx_rx_buffer
= addr
;
78 cpb
->MemoryAddr
= (UINT64
)(UINTN
) snp
->tx_rx_buffer
;
80 cpb
->MemoryLength
= snp
->tx_rx_bufsize
;
83 // let UNDI decide/detect these values
91 cpb
->DuplexMode
= PXE_DUPLEX_DEFAULT
;
93 cpb
->LoopBackMode
= LOOPBACK_NORMAL
;
95 snp
->cdb
.OpCode
= PXE_OPCODE_INITIALIZE
;
96 snp
->cdb
.OpFlags
= CableDetectFlag
;
98 snp
->cdb
.CPBsize
= sizeof (PXE_CPB_INITIALIZE
);
99 snp
->cdb
.DBsize
= sizeof (PXE_DB_INITIALIZE
);
101 snp
->cdb
.CPBaddr
= (UINT64
)(UINTN
) snp
->cpb
;
102 snp
->cdb
.DBaddr
= (UINT64
)(UINTN
) snp
->db
;
104 snp
->cdb
.StatCode
= PXE_STATCODE_INITIALIZE
;
105 snp
->cdb
.StatFlags
= PXE_STATFLAGS_INITIALIZE
;
106 snp
->cdb
.IFnum
= snp
->if_num
;
107 snp
->cdb
.Control
= PXE_CONTROL_LAST_CDB_IN_LIST
;
109 DEBUG ((EFI_D_NET
, "\nsnp->undi.initialize() "));
111 (*snp
->issue_undi32_command
) ((UINT64
)(UINTN
) &snp
->cdb
);
113 if (snp
->cdb
.StatCode
== PXE_STATCODE_SUCCESS
) {
114 snp
->mode
.State
= EfiSimpleNetworkInitialized
;
116 Status
= EFI_SUCCESS
;
120 "\nsnp->undi.initialize() %xh:%xh\n",
125 if (snp
->tx_rx_buffer
!= NULL
) {
126 snp
->IoFncs
->FreeBuffer (
128 SNP_MEM_PAGES (snp
->tx_rx_bufsize
),
129 (VOID
*) snp
->tx_rx_buffer
133 snp
->tx_rx_buffer
= NULL
;
135 Status
= EFI_DEVICE_ERROR
;
143 This is the SNP interface routine for initializing the interface
144 This routine basically retrieves snp structure, checks the SNP state and
145 calls the pxe_initialize routine to actually do the undi initialization
147 @param this context pointer
148 @param extra_rx_buffer_size optional parameter, indicates extra space for
150 @param extra_tx_buffer_size optional parameter, indicates extra space for
157 snp_undi32_initialize (
158 IN EFI_SIMPLE_NETWORK_PROTOCOL
*this,
159 IN UINTN extra_rx_buffer_size OPTIONAL
,
160 IN UINTN extra_tx_buffer_size OPTIONAL
163 EFI_STATUS EfiStatus
;
171 return EFI_INVALID_PARAMETER
;
174 snp
= EFI_SIMPLE_NETWORK_DEV_FROM_THIS (this);
176 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
179 EfiStatus
= EFI_INVALID_PARAMETER
;
183 switch (snp
->mode
.State
) {
184 case EfiSimpleNetworkStarted
:
187 case EfiSimpleNetworkStopped
:
188 EfiStatus
= EFI_NOT_STARTED
;
192 EfiStatus
= EFI_DEVICE_ERROR
;
196 EfiStatus
= gBS
->CreateEvent (
199 &SnpWaitForPacketNotify
,
201 &snp
->snp
.WaitForPacket
204 if (EFI_ERROR (EfiStatus
)) {
205 snp
->snp
.WaitForPacket
= NULL
;
206 EfiStatus
= EFI_DEVICE_ERROR
;
212 snp
->mode
.MCastFilterCount
= 0;
213 snp
->mode
.ReceiveFilterSetting
= 0;
214 ZeroMem (snp
->mode
.MCastFilter
, sizeof snp
->mode
.MCastFilter
);
216 &snp
->mode
.CurrentAddress
,
217 &snp
->mode
.PermanentAddress
,
218 sizeof (EFI_MAC_ADDRESS
)
222 // Compute tx/rx buffer sizes based on UNDI init info and parameters.
224 snp
->tx_rx_bufsize
= (UINT32
) (snp
->init_info
.MemoryRequired
+ extra_rx_buffer_size
+ extra_tx_buffer_size
);
226 if (snp
->mode
.MediaPresentSupported
) {
227 if (pxe_init (snp
, PXE_OPFLAGS_INITIALIZE_DETECT_CABLE
) == EFI_SUCCESS
) {
228 snp
->mode
.MediaPresent
= TRUE
;
233 snp
->mode
.MediaPresent
= FALSE
;
235 EfiStatus
= pxe_init (snp
, PXE_OPFLAGS_INITIALIZE_DO_NOT_DETECT_CABLE
);
237 if (EFI_ERROR (EfiStatus
)) {
238 gBS
->CloseEvent (snp
->snp
.WaitForPacket
);
242 gBS
->RestoreTPL (OldTpl
);