2 Copyright (c) 2006, 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.
25 SnpWaitForPacketNotify (
33 UINT16 CableDetectFlag
38 this routine calls undi to initialize the interface.
41 snp - pointer to snp driver structure
42 CableDetectFlag - Do/don't detect the cable (depending on what undi supports)
48 PXE_CPB_INITIALIZE
*cpb
;
53 if (snp
->tx_rx_bufsize
!= 0) {
54 Status
= snp
->IoFncs
->AllocateBuffer (
58 SNP_MEM_PAGES (snp
->tx_rx_bufsize
),
63 if (Status
!= EFI_SUCCESS
) {
66 "\nsnp->pxe_init() AllocateBuffer %xh (%r)\n",
76 snp
->tx_rx_buffer
= addr
;
79 cpb
->MemoryAddr
= (UINT64
) (UINTN
) snp
->tx_rx_buffer
;
81 cpb
->MemoryLength
= snp
->tx_rx_bufsize
;
84 // let UNDI decide/detect these values
92 cpb
->DuplexMode
= PXE_DUPLEX_DEFAULT
;
94 cpb
->LoopBackMode
= LOOPBACK_NORMAL
;
96 snp
->cdb
.OpCode
= PXE_OPCODE_INITIALIZE
;
97 snp
->cdb
.OpFlags
= CableDetectFlag
;
99 snp
->cdb
.CPBsize
= sizeof (PXE_CPB_INITIALIZE
);
100 snp
->cdb
.DBsize
= sizeof (PXE_DB_INITIALIZE
);
102 snp
->cdb
.CPBaddr
= (UINT64
) (UINTN
) snp
->cpb
;
103 snp
->cdb
.DBaddr
= (UINT64
) (UINTN
) snp
->db
;
105 snp
->cdb
.StatCode
= PXE_STATCODE_INITIALIZE
;
106 snp
->cdb
.StatFlags
= PXE_STATFLAGS_INITIALIZE
;
107 snp
->cdb
.IFnum
= snp
->if_num
;
108 snp
->cdb
.Control
= PXE_CONTROL_LAST_CDB_IN_LIST
;
110 DEBUG ((EFI_D_NET
, "\nsnp->undi.initialize() "));
112 (*snp
->issue_undi32_command
) ((UINT64
) (UINTN
) &snp
->cdb
);
114 if (snp
->cdb
.StatCode
== PXE_STATCODE_SUCCESS
) {
115 snp
->mode
.State
= EfiSimpleNetworkInitialized
;
117 Status
= EFI_SUCCESS
;
121 "\nsnp->undi.initialize() %xh:%xh\n",
126 if (snp
->tx_rx_buffer
!= NULL
) {
127 snp
->IoFncs
->FreeBuffer (
129 SNP_MEM_PAGES (snp
->tx_rx_bufsize
),
130 (VOID
*) snp
->tx_rx_buffer
134 snp
->tx_rx_buffer
= NULL
;
136 Status
= EFI_DEVICE_ERROR
;
144 snp_undi32_initialize (
145 IN EFI_SIMPLE_NETWORK_PROTOCOL
*this,
146 IN UINTN extra_rx_buffer_size OPTIONAL
,
147 IN UINTN extra_tx_buffer_size OPTIONAL
152 This is the SNP interface routine for initializing the interface
153 This routine basically retrieves snp structure, checks the SNP state and
154 calls the pxe_initialize routine to actually do the undi initialization
157 this - context pointer
158 extra_rx_buffer_size - optional parameter, indicates extra space for rx_buffers
159 extra_tx_buffer_size - optional parameter, indicates extra space for tx_buffers
165 EFI_STATUS EfiStatus
;
172 return EFI_INVALID_PARAMETER
;
175 snp
= EFI_SIMPLE_NETWORK_DEV_FROM_THIS (this);
178 return EFI_INVALID_PARAMETER
;
183 switch (snp
->mode
.State
) {
184 case EfiSimpleNetworkStarted
:
187 case EfiSimpleNetworkStopped
:
188 return EFI_NOT_STARTED
;
190 case EfiSimpleNetworkInitialized
:
191 return EFI_DEVICE_ERROR
;
194 return EFI_DEVICE_ERROR
;
199 EfiStatus
= gBS
->CreateEvent (
200 EFI_EVENT_NOTIFY_WAIT
,
202 &SnpWaitForPacketNotify
,
204 &snp
->snp
.WaitForPacket
207 if (EFI_ERROR (EfiStatus
)) {
208 snp
->snp
.WaitForPacket
= NULL
;
209 return EFI_DEVICE_ERROR
;
214 snp
->mode
.MCastFilterCount
= 0;
215 snp
->mode
.ReceiveFilterSetting
= 0;
216 ZeroMem (snp
->mode
.MCastFilter
, sizeof snp
->mode
.MCastFilter
);
218 &snp
->mode
.CurrentAddress
,
219 &snp
->mode
.PermanentAddress
,
220 sizeof (EFI_MAC_ADDRESS
)
224 // Compute tx/rx buffer sizes based on UNDI init info and parameters.
226 snp
->tx_rx_bufsize
= (UINT32
) (snp
->init_info
.MemoryRequired
+ extra_rx_buffer_size
+ extra_tx_buffer_size
);
228 if (snp
->mode
.MediaPresentSupported
) {
229 if (pxe_init (snp
, PXE_OPFLAGS_INITIALIZE_DETECT_CABLE
) == EFI_SUCCESS
) {
230 snp
->mode
.MediaPresent
= TRUE
;
235 snp
->mode
.MediaPresent
= FALSE
;
237 EfiStatus
= pxe_init (snp
, PXE_OPFLAGS_INITIALIZE_DO_NOT_DETECT_CABLE
);
239 if (EFI_ERROR (EfiStatus
)) {
240 gBS
->CloseEvent (snp
->snp
.WaitForPacket
);