]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/Network/SnpDxe/Initialize.c
Roll back the DEBUG mask change which cause SerialIo read_conf test item failure.
[mirror_edk2.git] / MdeModulePkg / Universal / Network / SnpDxe / Initialize.c
CommitLineData
c74593cd 1/** @file\r
4cda7726 2 Implementation of initializing a network adapter.\r
3\r
4Copyright (c) 2004 - 2008, Intel Corporation. <BR> \r
5All rights reserved. This program and the accompanying materials are licensed \r
6and made available under the terms and conditions of the BSD License which \r
7accompanies this distribution. The full text of the license may be found at \r
8http://opensource.org/licenses/bsd-license.php \r
c74593cd 9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
c74593cd 13**/\r
14\r
15\r
16#include "Snp.h"\r
17\r
c74593cd 18/**\r
f3816027 19 Call UNDI to initialize the interface.\r
c74593cd 20\r
f3816027 21 @param Snp Pointer to snp driver structure.\r
22 @param CableDetectFlag Do/don't detect the cable (depending on what \r
23 undi supports).\r
4cda7726 24 \r
f3816027 25 @retval EFI_SUCCESS UNDI is initialized successfully.\r
26 @retval EFI_DEVICE_ERROR UNDI could not be initialized.\r
27 @retval Other Other errors as indicated.\r
c74593cd 28\r
29**/\r
30EFI_STATUS\r
4cda7726 31PxeInit (\r
32 SNP_DRIVER *Snp,\r
c74593cd 33 UINT16 CableDetectFlag\r
34 )\r
35{\r
4cda7726 36 PXE_CPB_INITIALIZE *Cpb;\r
37 VOID *Addr;\r
c74593cd 38 EFI_STATUS Status;\r
39\r
4cda7726 40 Cpb = Snp->Cpb;\r
41 if (Snp->TxRxBufferSize != 0) {\r
42 Status = Snp->PciIo->AllocateBuffer (\r
43 Snp->PciIo,\r
44 AllocateAnyPages,\r
45 EfiBootServicesData,\r
46 SNP_MEM_PAGES (Snp->TxRxBufferSize),\r
47 &Addr,\r
48 0\r
49 );\r
c74593cd 50\r
51 if (Status != EFI_SUCCESS) {\r
52 DEBUG (\r
53 (EFI_D_ERROR,\r
4cda7726 54 "\nSnp->PxeInit() AllocateBuffer %xh (%r)\n",\r
c74593cd 55 Status,\r
56 Status)\r
57 );\r
58\r
59 return Status;\r
60 }\r
61\r
4cda7726 62 ASSERT (Addr);\r
c74593cd 63\r
4cda7726 64 Snp->TxRxBuffer = Addr;\r
c74593cd 65 }\r
66\r
4cda7726 67 Cpb->MemoryAddr = (UINT64)(UINTN) Snp->TxRxBuffer;\r
c74593cd 68\r
4cda7726 69 Cpb->MemoryLength = Snp->TxRxBufferSize;\r
c74593cd 70\r
71 //\r
72 // let UNDI decide/detect these values\r
73 //\r
4cda7726 74 Cpb->LinkSpeed = 0;\r
75 Cpb->TxBufCnt = 0;\r
76 Cpb->TxBufSize = 0;\r
77 Cpb->RxBufCnt = 0;\r
78 Cpb->RxBufSize = 0;\r
c74593cd 79\r
4cda7726 80 Cpb->DuplexMode = PXE_DUPLEX_DEFAULT;\r
c74593cd 81\r
4cda7726 82 Cpb->LoopBackMode = LOOPBACK_NORMAL;\r
c74593cd 83\r
4cda7726 84 Snp->Cdb.OpCode = PXE_OPCODE_INITIALIZE;\r
85 Snp->Cdb.OpFlags = CableDetectFlag;\r
c74593cd 86\r
4cda7726 87 Snp->Cdb.CPBsize = sizeof (PXE_CPB_INITIALIZE);\r
88 Snp->Cdb.DBsize = sizeof (PXE_DB_INITIALIZE);\r
c74593cd 89\r
4cda7726 90 Snp->Cdb.CPBaddr = (UINT64)(UINTN) Snp->Cpb;\r
91 Snp->Cdb.DBaddr = (UINT64)(UINTN) Snp->Db;\r
c74593cd 92\r
4cda7726 93 Snp->Cdb.StatCode = PXE_STATCODE_INITIALIZE;\r
94 Snp->Cdb.StatFlags = PXE_STATFLAGS_INITIALIZE;\r
95 Snp->Cdb.IFnum = Snp->IfNum;\r
96 Snp->Cdb.Control = PXE_CONTROL_LAST_CDB_IN_LIST;\r
c74593cd 97\r
9cff2f8d 98 DEBUG ((EFI_D_NET, "\nSnp->undi.initialize() "));\r
c74593cd 99\r
4cda7726 100 (*Snp->IssueUndi32Command) ((UINT64)(UINTN) &Snp->Cdb);\r
c74593cd 101\r
4cda7726 102 if (Snp->Cdb.StatCode == PXE_STATCODE_SUCCESS) {\r
103 Snp->Mode.State = EfiSimpleNetworkInitialized;\r
c74593cd 104\r
105 Status = EFI_SUCCESS;\r
106 } else {\r
107 DEBUG (\r
9cff2f8d 108 (EFI_D_WARN,\r
4cda7726 109 "\nSnp->undi.initialize() %xh:%xh\n",\r
110 Snp->Cdb.StatFlags,\r
111 Snp->Cdb.StatCode)\r
c74593cd 112 );\r
113\r
4cda7726 114 if (Snp->TxRxBuffer != NULL) {\r
115 Snp->PciIo->FreeBuffer (\r
116 Snp->PciIo,\r
117 SNP_MEM_PAGES (Snp->TxRxBufferSize),\r
118 (VOID *) Snp->TxRxBuffer\r
c74593cd 119 );\r
120 }\r
121\r
4cda7726 122 Snp->TxRxBuffer = NULL;\r
c74593cd 123\r
4cda7726 124 Status = EFI_DEVICE_ERROR;\r
c74593cd 125 }\r
126\r
127 return Status;\r
128}\r
129\r
130\r
131/**\r
4cda7726 132 Resets a network adapter and allocates the transmit and receive buffers \r
133 required by the network interface; optionally, also requests allocation of \r
134 additional transmit and receive buffers.\r
135\r
136 This function allocates the transmit and receive buffers required by the network\r
137 interface. If this allocation fails, then EFI_OUT_OF_RESOURCES is returned.\r
138 If the allocation succeeds and the network interface is successfully initialized,\r
139 then EFI_SUCCESS will be returned.\r
140\r
141 @param This A pointer to the EFI_SIMPLE_NETWORK_PROTOCOL instance.\r
142\r
143 @param ExtraRxBufferSize The size, in bytes, of the extra receive buffer space\r
144 that the driver should allocate for the network interface.\r
145 Some network interfaces will not be able to use the \r
146 extra buffer, and the caller will not know if it is \r
147 actually being used.\r
148 @param ExtraTxBufferSize The size, in bytes, of the extra transmit buffer space\r
149 that the driver should allocate for the network interface.\r
150 Some network interfaces will not be able to use the\r
151 extra buffer, and the caller will not know if it is\r
152 actually being used.\r
153\r
154 @retval EFI_SUCCESS The network interface was initialized.\r
155 @retval EFI_NOT_STARTED The network interface has not been started.\r
156 @retval EFI_OUT_OF_RESOURCES There was not enough memory for the transmit and\r
157 receive buffers.\r
158 @retval EFI_INVALID_PARAMETER This parameter was NULL or did not point to a valid\r
159 EFI_SIMPLE_NETWORK_PROTOCOL structure.\r
160 @retval EFI_DEVICE_ERROR The command could not be sent to the network interface.\r
161 @retval EFI_UNSUPPORTED The increased buffer size feature is not supported.\r
c74593cd 162\r
163**/\r
164EFI_STATUS\r
165EFIAPI\r
4cda7726 166SnpUndi32Initialize (\r
167 IN EFI_SIMPLE_NETWORK_PROTOCOL *This,\r
168 IN UINTN ExtraRxBufferSize OPTIONAL,\r
169 IN UINTN ExtraTxBufferSize OPTIONAL\r
c74593cd 170 )\r
171{\r
172 EFI_STATUS EfiStatus;\r
4cda7726 173 SNP_DRIVER *Snp;\r
c74593cd 174 EFI_TPL OldTpl;\r
175\r
4cda7726 176 if (This == NULL) {\r
c74593cd 177 return EFI_INVALID_PARAMETER;\r
178 }\r
179\r
4cda7726 180 Snp = EFI_SIMPLE_NETWORK_DEV_FROM_THIS (This);\r
c74593cd 181\r
182 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
183\r
4cda7726 184 if (Snp == NULL) {\r
c74593cd 185 EfiStatus = EFI_INVALID_PARAMETER;\r
186 goto ON_EXIT;\r
187 }\r
188\r
4cda7726 189 switch (Snp->Mode.State) {\r
c74593cd 190 case EfiSimpleNetworkStarted:\r
191 break;\r
192\r
193 case EfiSimpleNetworkStopped:\r
194 EfiStatus = EFI_NOT_STARTED;\r
195 goto ON_EXIT;\r
196\r
197 default:\r
198 EfiStatus = EFI_DEVICE_ERROR;\r
199 goto ON_EXIT;\r
200 }\r
201\r
202 EfiStatus = gBS->CreateEvent (\r
203 EVT_NOTIFY_WAIT,\r
204 TPL_NOTIFY,\r
205 &SnpWaitForPacketNotify,\r
4cda7726 206 Snp,\r
207 &Snp->Snp.WaitForPacket\r
c74593cd 208 );\r
209\r
210 if (EFI_ERROR (EfiStatus)) {\r
4cda7726 211 Snp->Snp.WaitForPacket = NULL;\r
c74593cd 212 EfiStatus = EFI_DEVICE_ERROR;\r
213 goto ON_EXIT;\r
214 }\r
215 //\r
216 //\r
217 //\r
4cda7726 218 Snp->Mode.MCastFilterCount = 0;\r
219 Snp->Mode.ReceiveFilterSetting = 0;\r
220 ZeroMem (Snp->Mode.MCastFilter, sizeof Snp->Mode.MCastFilter);\r
c74593cd 221 CopyMem (\r
4cda7726 222 &Snp->Mode.CurrentAddress,\r
223 &Snp->Mode.PermanentAddress,\r
c74593cd 224 sizeof (EFI_MAC_ADDRESS)\r
225 );\r
226\r
227 //\r
228 // Compute tx/rx buffer sizes based on UNDI init info and parameters.\r
229 //\r
4cda7726 230 Snp->TxRxBufferSize = (UINT32) (Snp->InitInfo.MemoryRequired + ExtraRxBufferSize + ExtraTxBufferSize);\r
c74593cd 231\r
4cda7726 232 if (Snp->Mode.MediaPresentSupported) {\r
233 if (PxeInit (Snp, PXE_OPFLAGS_INITIALIZE_DETECT_CABLE) == EFI_SUCCESS) {\r
234 Snp->Mode.MediaPresent = TRUE;\r
c74593cd 235 goto ON_EXIT;\r
236 }\r
237 }\r
238\r
4cda7726 239 Snp->Mode.MediaPresent = FALSE;\r
c74593cd 240\r
4cda7726 241 EfiStatus = PxeInit (Snp, PXE_OPFLAGS_INITIALIZE_DO_NOT_DETECT_CABLE);\r
c74593cd 242\r
243 if (EFI_ERROR (EfiStatus)) {\r
4cda7726 244 gBS->CloseEvent (Snp->Snp.WaitForPacket);\r
c74593cd 245 }\r
246\r
247ON_EXIT:\r
248 gBS->RestoreTPL (OldTpl);\r
249\r
250 return EfiStatus;\r
251}\r