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.
26 UINT16 CableDetectFlag
31 this routine calls undi to initialize the interface.
34 snp - pointer to snp driver structure
35 CableDetectFlag - Do/don't detect the cable (depending on what undi supports)
41 PXE_CPB_INITIALIZE
*cpb
;
46 if (snp
->tx_rx_bufsize
!= 0) {
47 Status
= snp
->IoFncs
->AllocateBuffer (
51 SNP_MEM_PAGES (snp
->tx_rx_bufsize
),
56 if (Status
!= EFI_SUCCESS
) {
59 "\nsnp->pxe_init() AllocateBuffer %xh (%r)\n",
69 snp
->tx_rx_buffer
= addr
;
72 cpb
->MemoryAddr
= (UINT64
) (UINTN
) snp
->tx_rx_buffer
;
74 cpb
->MemoryLength
= snp
->tx_rx_bufsize
;
77 // let UNDI decide/detect these values
85 cpb
->DuplexMode
= PXE_DUPLEX_DEFAULT
;
87 cpb
->LoopBackMode
= LOOPBACK_NORMAL
;
89 snp
->cdb
.OpCode
= PXE_OPCODE_INITIALIZE
;
90 snp
->cdb
.OpFlags
= CableDetectFlag
;
92 snp
->cdb
.CPBsize
= sizeof (PXE_CPB_INITIALIZE
);
93 snp
->cdb
.DBsize
= sizeof (PXE_DB_INITIALIZE
);
95 snp
->cdb
.CPBaddr
= (UINT64
) (UINTN
) snp
->cpb
;
96 snp
->cdb
.DBaddr
= (UINT64
) (UINTN
) snp
->db
;
98 snp
->cdb
.StatCode
= PXE_STATCODE_INITIALIZE
;
99 snp
->cdb
.StatFlags
= PXE_STATFLAGS_INITIALIZE
;
100 snp
->cdb
.IFnum
= snp
->if_num
;
101 snp
->cdb
.Control
= PXE_CONTROL_LAST_CDB_IN_LIST
;
103 DEBUG ((EFI_D_NET
, "\nsnp->undi.initialize() "));
105 (*snp
->issue_undi32_command
) ((UINT64
) (UINTN
) &snp
->cdb
);
107 if (snp
->cdb
.StatCode
== PXE_STATCODE_SUCCESS
) {
108 snp
->mode
.State
= EfiSimpleNetworkInitialized
;
110 Status
= EFI_SUCCESS
;
114 "\nsnp->undi.initialize() %xh:%xh\n",
119 if (snp
->tx_rx_buffer
!= NULL
) {
120 snp
->IoFncs
->FreeBuffer (
122 SNP_MEM_PAGES (snp
->tx_rx_bufsize
),
123 (VOID
*) snp
->tx_rx_buffer
127 snp
->tx_rx_buffer
= NULL
;
129 Status
= EFI_DEVICE_ERROR
;
137 snp_undi32_initialize (
138 IN EFI_SIMPLE_NETWORK_PROTOCOL
*this,
139 IN UINTN extra_rx_buffer_size OPTIONAL
,
140 IN UINTN extra_tx_buffer_size OPTIONAL
145 This is the SNP interface routine for initializing the interface
146 This routine basically retrieves snp structure, checks the SNP state and
147 calls the pxe_initialize routine to actually do the undi initialization
150 this - context pointer
151 extra_rx_buffer_size - optional parameter, indicates extra space for rx_buffers
152 extra_tx_buffer_size - optional parameter, indicates extra space for tx_buffers
158 EFI_STATUS EfiStatus
;
165 return EFI_INVALID_PARAMETER
;
168 snp
= EFI_SIMPLE_NETWORK_DEV_FROM_THIS (this);
171 return EFI_INVALID_PARAMETER
;
176 switch (snp
->mode
.State
) {
177 case EfiSimpleNetworkStarted
:
180 case EfiSimpleNetworkStopped
:
181 return EFI_NOT_STARTED
;
183 case EfiSimpleNetworkInitialized
:
184 return EFI_DEVICE_ERROR
;
187 return EFI_DEVICE_ERROR
;
192 EfiStatus
= gBS
->CreateEvent (
195 &SnpWaitForPacketNotify
,
197 &snp
->snp
.WaitForPacket
200 if (EFI_ERROR (EfiStatus
)) {
201 snp
->snp
.WaitForPacket
= NULL
;
202 return EFI_DEVICE_ERROR
;
207 snp
->mode
.MCastFilterCount
= 0;
208 snp
->mode
.ReceiveFilterSetting
= 0;
209 ZeroMem (snp
->mode
.MCastFilter
, sizeof snp
->mode
.MCastFilter
);
211 &snp
->mode
.CurrentAddress
,
212 &snp
->mode
.PermanentAddress
,
213 sizeof (EFI_MAC_ADDRESS
)
217 // Compute tx/rx buffer sizes based on UNDI init info and parameters.
219 snp
->tx_rx_bufsize
= (UINT32
) (snp
->init_info
.MemoryRequired
+ extra_rx_buffer_size
+ extra_tx_buffer_size
);
221 if (snp
->mode
.MediaPresentSupported
) {
222 if (pxe_init (snp
, PXE_OPFLAGS_INITIALIZE_DETECT_CABLE
) == EFI_SUCCESS
) {
223 snp
->mode
.MediaPresent
= TRUE
;
228 snp
->mode
.MediaPresent
= FALSE
;
230 EfiStatus
= pxe_init (snp
, PXE_OPFLAGS_INITIALIZE_DO_NOT_DETECT_CABLE
);
232 if (EFI_ERROR (EfiStatus
)) {
233 gBS
->CloseEvent (snp
->snp
.WaitForPacket
);