]> git.proxmox.com Git - mirror_edk2.git/blob - EdkModulePkg/Universal/Network/Snp32_64/Dxe/initialize.c
Add some definitions for efi event in Uefi/UefiSpec.h to follow spec.
[mirror_edk2.git] / EdkModulePkg / Universal / Network / Snp32_64 / Dxe / initialize.c
1 /*++
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
7
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.
10
11 Module name:
12 initialize.c
13
14 Abstract:
15
16 Revision history:
17 2000-Feb-09 M(f)J Genesis.
18 --*/
19
20
21 #include "Snp.h"
22
23 EFI_STATUS
24 pxe_init (
25 SNP_DRIVER *snp,
26 UINT16 CableDetectFlag
27 )
28 /*++
29
30 Routine Description:
31 this routine calls undi to initialize the interface.
32
33 Arguments:
34 snp - pointer to snp driver structure
35 CableDetectFlag - Do/don't detect the cable (depending on what undi supports)
36
37 Returns:
38
39 --*/
40 {
41 PXE_CPB_INITIALIZE *cpb;
42 VOID *addr;
43 EFI_STATUS Status;
44
45 cpb = snp->cpb;
46 if (snp->tx_rx_bufsize != 0) {
47 Status = snp->IoFncs->AllocateBuffer (
48 snp->IoFncs,
49 AllocateAnyPages,
50 EfiBootServicesData,
51 SNP_MEM_PAGES (snp->tx_rx_bufsize),
52 &addr,
53 0
54 );
55
56 if (Status != EFI_SUCCESS) {
57 DEBUG (
58 (EFI_D_ERROR,
59 "\nsnp->pxe_init() AllocateBuffer %xh (%r)\n",
60 Status,
61 Status)
62 );
63
64 return Status;
65 }
66
67 ASSERT (addr);
68
69 snp->tx_rx_buffer = addr;
70 }
71
72 cpb->MemoryAddr = (UINT64) (UINTN) snp->tx_rx_buffer;
73
74 cpb->MemoryLength = snp->tx_rx_bufsize;
75
76 //
77 // let UNDI decide/detect these values
78 //
79 cpb->LinkSpeed = 0;
80 cpb->TxBufCnt = 0;
81 cpb->TxBufSize = 0;
82 cpb->RxBufCnt = 0;
83 cpb->RxBufSize = 0;
84
85 cpb->DuplexMode = PXE_DUPLEX_DEFAULT;
86
87 cpb->LoopBackMode = LOOPBACK_NORMAL;
88
89 snp->cdb.OpCode = PXE_OPCODE_INITIALIZE;
90 snp->cdb.OpFlags = CableDetectFlag;
91
92 snp->cdb.CPBsize = sizeof (PXE_CPB_INITIALIZE);
93 snp->cdb.DBsize = sizeof (PXE_DB_INITIALIZE);
94
95 snp->cdb.CPBaddr = (UINT64) (UINTN) snp->cpb;
96 snp->cdb.DBaddr = (UINT64) (UINTN) snp->db;
97
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;
102
103 DEBUG ((EFI_D_NET, "\nsnp->undi.initialize() "));
104
105 (*snp->issue_undi32_command) ((UINT64) (UINTN) &snp->cdb);
106
107 if (snp->cdb.StatCode == PXE_STATCODE_SUCCESS) {
108 snp->mode.State = EfiSimpleNetworkInitialized;
109
110 Status = EFI_SUCCESS;
111 } else {
112 DEBUG (
113 (EFI_D_WARN,
114 "\nsnp->undi.initialize() %xh:%xh\n",
115 snp->cdb.StatFlags,
116 snp->cdb.StatCode)
117 );
118
119 if (snp->tx_rx_buffer != NULL) {
120 snp->IoFncs->FreeBuffer (
121 snp->IoFncs,
122 SNP_MEM_PAGES (snp->tx_rx_bufsize),
123 (VOID *) snp->tx_rx_buffer
124 );
125 }
126
127 snp->tx_rx_buffer = NULL;
128
129 Status = EFI_DEVICE_ERROR;
130 }
131
132 return Status;
133 }
134
135 EFI_STATUS
136 EFIAPI
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
141 )
142 /*++
143
144 Routine Description:
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
148
149 Arguments:
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
153
154 Returns:
155
156 --*/
157 {
158 EFI_STATUS EfiStatus;
159 SNP_DRIVER *snp;
160
161 //
162 //
163 //
164 if (this == NULL) {
165 return EFI_INVALID_PARAMETER;
166 }
167
168 snp = EFI_SIMPLE_NETWORK_DEV_FROM_THIS (this);
169
170 if (snp == NULL) {
171 return EFI_INVALID_PARAMETER;
172 }
173 //
174 //
175 //
176 switch (snp->mode.State) {
177 case EfiSimpleNetworkStarted:
178 break;
179
180 case EfiSimpleNetworkStopped:
181 return EFI_NOT_STARTED;
182
183 case EfiSimpleNetworkInitialized:
184 return EFI_DEVICE_ERROR;
185
186 default:
187 return EFI_DEVICE_ERROR;
188 }
189 //
190 //
191 //
192 EfiStatus = gBS->CreateEvent (
193 EVT_NOTIFY_WAIT,
194 TPL_NOTIFY,
195 &SnpWaitForPacketNotify,
196 snp,
197 &snp->snp.WaitForPacket
198 );
199
200 if (EFI_ERROR (EfiStatus)) {
201 snp->snp.WaitForPacket = NULL;
202 return EFI_DEVICE_ERROR;
203 }
204 //
205 //
206 //
207 snp->mode.MCastFilterCount = 0;
208 snp->mode.ReceiveFilterSetting = 0;
209 ZeroMem (snp->mode.MCastFilter, sizeof snp->mode.MCastFilter);
210 CopyMem (
211 &snp->mode.CurrentAddress,
212 &snp->mode.PermanentAddress,
213 sizeof (EFI_MAC_ADDRESS)
214 );
215
216 //
217 // Compute tx/rx buffer sizes based on UNDI init info and parameters.
218 //
219 snp->tx_rx_bufsize = (UINT32) (snp->init_info.MemoryRequired + extra_rx_buffer_size + extra_tx_buffer_size);
220
221 if (snp->mode.MediaPresentSupported) {
222 if (pxe_init (snp, PXE_OPFLAGS_INITIALIZE_DETECT_CABLE) == EFI_SUCCESS) {
223 snp->mode.MediaPresent = TRUE;
224 return EFI_SUCCESS;
225 }
226 }
227
228 snp->mode.MediaPresent = FALSE;
229
230 EfiStatus = pxe_init (snp, PXE_OPFLAGS_INITIALIZE_DO_NOT_DETECT_CABLE);
231
232 if (EFI_ERROR (EfiStatus)) {
233 gBS->CloseEvent (snp->snp.WaitForPacket);
234 }
235
236 return EfiStatus;
237 }