]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/Network/MnpDxe/MnpDriver.c
Update the copyright notice format
[mirror_edk2.git] / MdeModulePkg / Universal / Network / MnpDxe / MnpDriver.c
CommitLineData
8a67d61d 1/** @file\r
6e4bac4d 2 Implementation of driver entry point and driver binding protocol.\r
8a67d61d 3\r
e5eed7d3
HT
4Copyright (c) 2005 - 2010, Intel Corporation. All rights reserved.<BR>\r
5This program and the accompanying materials\r
779ae357 6are licensed and made available under the terms and conditions\r
7of the BSD License which accompanies this distribution. The full\r
8text of the license may be found at<BR>\r
9http://opensource.org/licenses/bsd-license.php\r
8a67d61d 10\r
11THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13\r
8a67d61d 14**/\r
15\r
16#include "MnpDriver.h"\r
8a67d61d 17#include "MnpImpl.h"\r
779ae357 18#include "MnpVlan.h"\r
8a67d61d 19\r
20EFI_DRIVER_BINDING_PROTOCOL gMnpDriverBinding = {\r
21 MnpDriverBindingSupported,\r
22 MnpDriverBindingStart,\r
23 MnpDriverBindingStop,\r
24 0xa,\r
25 NULL,\r
26 NULL\r
27};\r
28\r
8a67d61d 29/**\r
b6c4ecad 30 Test to see if this driver supports ControllerHandle. This service\r
31 is called by the EFI boot service ConnectController(). In\r
32 order to make drivers as small as possible, there are a few calling\r
33 restrictions for this service. ConnectController() must\r
34 follow these calling restrictions. If any other agent wishes to call\r
35 Supported() it must also follow these calling restrictions.\r
36\r
6e4bac4d 37 @param[in] This Protocol instance pointer.\r
38 @param[in] ControllerHandle Handle of device to test.\r
779ae357 39 @param[in] RemainingDevicePath Optional parameter use to pick a specific\r
6e4bac4d 40 child device to start.\r
b6c4ecad 41\r
6e4bac4d 42 @retval EFI_SUCCESS This driver supports this device.\r
43 @retval EFI_ALREADY_STARTED This driver is already running on this device.\r
44 @retval Others This driver does not support this device.\r
8a67d61d 45\r
46**/\r
47EFI_STATUS\r
48EFIAPI\r
49MnpDriverBindingSupported (\r
779ae357 50 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
51 IN EFI_HANDLE ControllerHandle,\r
52 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL\r
8a67d61d 53 )\r
54{\r
b58baf6b 55 EFI_STATUS Status;\r
56 EFI_SIMPLE_NETWORK_PROTOCOL *Snp;\r
8a67d61d 57\r
8a67d61d 58 //\r
b58baf6b 59 // Test to open the Simple Network protocol BY_DRIVER.\r
8a67d61d 60 //\r
61 Status = gBS->OpenProtocol (\r
62 ControllerHandle,\r
63 &gEfiSimpleNetworkProtocolGuid,\r
b58baf6b 64 (VOID **) &Snp,\r
8a67d61d 65 This->DriverBindingHandle,\r
66 ControllerHandle,\r
b58baf6b 67 EFI_OPEN_PROTOCOL_BY_DRIVER\r
8a67d61d 68 );\r
b58baf6b 69 if (EFI_ERROR (Status)) {\r
70 return Status;\r
71 }\r
72\r
73 //\r
74 // Close the openned SNP protocol.\r
75 //\r
76 gBS->CloseProtocol (\r
77 ControllerHandle,\r
78 &gEfiSimpleNetworkProtocolGuid,\r
79 This->DriverBindingHandle,\r
80 ControllerHandle\r
81 );\r
82\r
83 return EFI_SUCCESS;\r
8a67d61d 84}\r
85\r
86\r
87/**\r
b6c4ecad 88 Start this driver on ControllerHandle. This service is called by the\r
779ae357 89 EFI boot service ConnectController(). In order to make drivers as small\r
6e4bac4d 90 as possible, there are a few calling restrictions for this service.\r
91 ConnectController() must follow these calling restrictions. If any other\r
92 agent wishes to call Start() it must also follow these calling restrictions.\r
93\r
94 @param[in] This Protocol instance pointer.\r
95 @param[in] ControllerHandle Handle of device to bind driver to.\r
779ae357 96 @param[in] RemainingDevicePath Optional parameter use to pick a specific\r
6e4bac4d 97 child device to start.\r
98\r
99 @retval EFI_SUCCESS This driver is added to ControllerHandle.\r
100 @retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle.\r
101 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory for Mnp Service Data.\r
102 @retval Others This driver does not support this device.\r
779ae357 103\r
8a67d61d 104**/\r
105EFI_STATUS\r
106EFIAPI\r
107MnpDriverBindingStart (\r
779ae357 108 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
109 IN EFI_HANDLE ControllerHandle,\r
110 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL\r
8a67d61d 111 )\r
112{\r
113 EFI_STATUS Status;\r
114 MNP_SERVICE_DATA *MnpServiceData;\r
779ae357 115 MNP_DEVICE_DATA *MnpDeviceData;\r
116 LIST_ENTRY *Entry;\r
117 VLAN_TCI *VlanVariable;\r
118 UINTN NumberOfVlan;\r
119 UINTN Index;\r
8a67d61d 120\r
779ae357 121 VlanVariable = NULL;\r
8a67d61d 122\r
779ae357 123 //\r
124 // Initialize the Mnp Device Data\r
125 //\r
126 MnpDeviceData = AllocateZeroPool (sizeof (MNP_DEVICE_DATA));\r
127 if (MnpDeviceData == NULL) {\r
128 DEBUG ((EFI_D_ERROR, "MnpDriverBindingStart(): Failed to allocate the Mnp Device Data.\n"));\r
8a67d61d 129\r
130 return EFI_OUT_OF_RESOURCES;\r
131 }\r
132\r
779ae357 133 Status = MnpInitializeDeviceData (MnpDeviceData, This->DriverBindingHandle, ControllerHandle);\r
8a67d61d 134 if (EFI_ERROR (Status)) {\r
779ae357 135 DEBUG ((EFI_D_ERROR, "MnpDriverBindingStart: MnpInitializeDeviceData failed, %r.\n", Status));\r
8a67d61d 136\r
779ae357 137 FreePool (MnpDeviceData);\r
138 return Status;\r
8a67d61d 139 }\r
140\r
779ae357 141 //\r
142 // Check whether NIC driver has already produced VlanConfig protocol\r
143 //\r
144 Status = gBS->OpenProtocol (\r
145 ControllerHandle,\r
146 &gEfiVlanConfigProtocolGuid,\r
147 NULL,\r
148 This->DriverBindingHandle,\r
149 ControllerHandle,\r
150 EFI_OPEN_PROTOCOL_TEST_PROTOCOL\r
151 );\r
152 if (!EFI_ERROR (Status)) {\r
153 //\r
154 // NIC hardware already implement VLAN,\r
155 // no need to provide software VLAN implementation in MNP driver\r
156 //\r
157 MnpDeviceData->NumberOfVlan = 0;\r
158 ZeroMem (&MnpDeviceData->VlanConfig, sizeof (EFI_VLAN_CONFIG_PROTOCOL));\r
159 MnpServiceData = MnpCreateServiceData (MnpDeviceData, 0, 0);\r
160 Status = (MnpServiceData != NULL) ? EFI_SUCCESS : EFI_OUT_OF_RESOURCES;\r
161 goto Exit;\r
162 }\r
8a67d61d 163\r
164 //\r
779ae357 165 // Install VLAN Config Protocol\r
8a67d61d 166 //\r
167 Status = gBS->InstallMultipleProtocolInterfaces (\r
168 &ControllerHandle,\r
779ae357 169 &gEfiVlanConfigProtocolGuid,\r
170 &MnpDeviceData->VlanConfig,\r
8a67d61d 171 NULL\r
172 );\r
779ae357 173 if (EFI_ERROR (Status)) {\r
174 goto Exit;\r
175 }\r
8a67d61d 176\r
779ae357 177 //\r
178 // Get current VLAN configuration from EFI Variable\r
179 //\r
180 NumberOfVlan = 0;\r
181 Status = MnpGetVlanVariable (MnpDeviceData, &NumberOfVlan, &VlanVariable);\r
182 if (EFI_ERROR (Status)) {\r
183 //\r
184 // No VLAN is set, create a default MNP service data for untagged frame\r
185 //\r
186 MnpDeviceData->NumberOfVlan = 0;\r
187 MnpServiceData = MnpCreateServiceData (MnpDeviceData, 0, 0);\r
188 Status = (MnpServiceData != NULL) ? EFI_SUCCESS : EFI_OUT_OF_RESOURCES;\r
189 goto Exit;\r
190 }\r
191\r
192 //\r
193 // Create MNP service data for each VLAN\r
194 //\r
195 MnpDeviceData->NumberOfVlan = NumberOfVlan;\r
196 for (Index = 0; Index < NumberOfVlan; Index++) {\r
197 MnpServiceData = MnpCreateServiceData (\r
198 MnpDeviceData,\r
199 VlanVariable[Index].Bits.Vid,\r
200 (UINT8) VlanVariable[Index].Bits.Priority\r
201 );\r
202\r
203 if (MnpServiceData == NULL) {\r
204 Status = EFI_OUT_OF_RESOURCES;\r
205\r
206 goto Exit;\r
207 }\r
208 }\r
209\r
210Exit:\r
211 if (VlanVariable != NULL) {\r
212 FreePool (VlanVariable);\r
213 }\r
8a67d61d 214\r
215 if (EFI_ERROR (Status)) {\r
779ae357 216 //\r
217 // Destroy all MNP service data\r
218 //\r
219 while (!IsListEmpty (&MnpDeviceData->ServiceList)) {\r
220 Entry = GetFirstNode (&MnpDeviceData->ServiceList);\r
221 MnpServiceData = MNP_SERVICE_DATA_FROM_LINK (Entry);\r
222 MnpDestroyServiceData (MnpServiceData);\r
223 }\r
8a67d61d 224\r
779ae357 225 //\r
226 // Uninstall the VLAN Config Protocol if any\r
227 //\r
228 if (MnpDeviceData->VlanConfig.Set != NULL) {\r
229 gBS->UninstallMultipleProtocolInterfaces (\r
230 MnpDeviceData->ControllerHandle,\r
231 &gEfiVlanConfigProtocolGuid,\r
232 &MnpDeviceData->VlanConfig,\r
233 NULL\r
234 );\r
8a67d61d 235 }\r
236\r
779ae357 237 //\r
238 // Destroy Mnp Device Data\r
239 //\r
240 MnpDestroyDeviceData (MnpDeviceData, This->DriverBindingHandle);\r
241 FreePool (MnpDeviceData);\r
8a67d61d 242 }\r
243\r
244 return Status;\r
245}\r
246\r
8a67d61d 247/**\r
b6c4ecad 248 Stop this driver on ControllerHandle. This service is called by the\r
779ae357 249 EFI boot service DisconnectController(). In order to make drivers as\r
250 small as possible, there are a few calling restrictions for this service.\r
251 DisconnectController() must follow these calling restrictions. If any other\r
6e4bac4d 252 agent wishes to call Stop() it must also follow these calling restrictions.\r
779ae357 253\r
6e4bac4d 254 @param[in] This Protocol instance pointer.\r
255 @param[in] ControllerHandle Handle of device to stop driver on.\r
779ae357 256 @param[in] NumberOfChildren Number of Handles in ChildHandleBuffer. If\r
257 number of children is zero stop the entire\r
258 bus driver.\r
6e4bac4d 259 @param[in] ChildHandleBuffer List of Child Handles to Stop.\r
b6c4ecad 260\r
6e4bac4d 261 @retval EFI_SUCCESS This driver is removed ControllerHandle.\r
262 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.\r
8a67d61d 263\r
264**/\r
265EFI_STATUS\r
266EFIAPI\r
267MnpDriverBindingStop (\r
779ae357 268 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
269 IN EFI_HANDLE ControllerHandle,\r
270 IN UINTN NumberOfChildren,\r
271 IN EFI_HANDLE *ChildHandleBuffer OPTIONAL\r
8a67d61d 272 )\r
273{\r
274 EFI_STATUS Status;\r
275 EFI_SERVICE_BINDING_PROTOCOL *ServiceBinding;\r
779ae357 276 EFI_VLAN_CONFIG_PROTOCOL *VlanConfig;\r
277 MNP_DEVICE_DATA *MnpDeviceData;\r
8a67d61d 278 MNP_SERVICE_DATA *MnpServiceData;\r
779ae357 279 BOOLEAN AllChildrenStopped;\r
280 LIST_ENTRY *Entry;\r
8a67d61d 281\r
282 //\r
779ae357 283 // Try to retrieve MNP service binding protocol from the ControllerHandle\r
8a67d61d 284 //\r
285 Status = gBS->OpenProtocol (\r
286 ControllerHandle,\r
287 &gEfiManagedNetworkServiceBindingProtocolGuid,\r
288 (VOID **) &ServiceBinding,\r
289 This->DriverBindingHandle,\r
290 ControllerHandle,\r
291 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
292 );\r
293 if (EFI_ERROR (Status)) {\r
779ae357 294 //\r
295 // Retrieve VLAN Config Protocol from the ControllerHandle\r
296 //\r
297 Status = gBS->OpenProtocol (\r
298 ControllerHandle,\r
299 &gEfiVlanConfigProtocolGuid,\r
300 (VOID **) &VlanConfig,\r
301 This->DriverBindingHandle,\r
302 ControllerHandle,\r
303 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
304 );\r
305 if (EFI_ERROR (Status)) {\r
306 DEBUG ((EFI_D_ERROR, "MnpDriverBindingStop: try to stop unknown Controller.\n"));\r
307 return EFI_DEVICE_ERROR;\r
308 }\r
8a67d61d 309\r
779ae357 310 MnpDeviceData = MNP_DEVICE_DATA_FROM_THIS (VlanConfig);\r
311 } else {\r
312 MnpServiceData = MNP_SERVICE_DATA_FROM_THIS (ServiceBinding);\r
313 MnpDeviceData = MnpServiceData->MnpDeviceData;\r
8a67d61d 314 }\r
315\r
c4a62a12 316 if (NumberOfChildren == 0) {\r
8a67d61d 317 //\r
779ae357 318 // Destroy all MNP service data\r
8a67d61d 319 //\r
779ae357 320 while (!IsListEmpty (&MnpDeviceData->ServiceList)) {\r
321 Entry = GetFirstNode (&MnpDeviceData->ServiceList);\r
322 MnpServiceData = MNP_SERVICE_DATA_FROM_LINK (Entry);\r
323 MnpDestroyServiceData (MnpServiceData);\r
324 }\r
8a67d61d 325\r
c4a62a12 326 //\r
779ae357 327 // Uninstall the VLAN Config Protocol if any\r
c4a62a12 328 //\r
779ae357 329 if (MnpDeviceData->VlanConfig.Set != NULL) {\r
330 gBS->UninstallMultipleProtocolInterfaces (\r
331 MnpDeviceData->ControllerHandle,\r
332 &gEfiVlanConfigProtocolGuid,\r
333 &MnpDeviceData->VlanConfig,\r
334 NULL\r
335 );\r
336 }\r
8a67d61d 337\r
779ae357 338 //\r
dd29f3ed 339 // Destroy Mnp Device Data\r
779ae357 340 //\r
341 MnpDestroyDeviceData (MnpDeviceData, This->DriverBindingHandle);\r
342 FreePool (MnpDeviceData);\r
343\r
344 return EFI_SUCCESS;\r
345 }\r
346\r
347 //\r
348 // Stop all MNP child\r
349 //\r
350 AllChildrenStopped = TRUE;\r
351 NET_LIST_FOR_EACH (Entry, &MnpDeviceData->ServiceList) {\r
352 MnpServiceData = MNP_SERVICE_DATA_FROM_LINK (Entry);\r
353\r
354 Status = MnpDestroyServiceChild (MnpServiceData);\r
355 if (EFI_ERROR (Status)) {\r
356 AllChildrenStopped = FALSE;\r
c4a62a12 357 }\r
8a67d61d 358 }\r
359\r
779ae357 360 if (!AllChildrenStopped) {\r
361 return EFI_DEVICE_ERROR;\r
362 }\r
363\r
364 return EFI_SUCCESS;\r
8a67d61d 365}\r
366\r
367\r
368/**\r
6e4bac4d 369 Creates a child handle with a set of I/O services.\r
8a67d61d 370\r
6e4bac4d 371 @param[in] This Protocol instance pointer.\r
372 @param[in, out] ChildHandle Pointer to the handle of the child to create. If\r
373 it is NULL, then a new handle is created. If\r
779ae357 374 it is not NULL, then the I/O services are added\r
375 to the existing child handle.\r
8a67d61d 376\r
779ae357 377 @retval EFI_SUCCES The protocol was added to ChildHandle.\r
378 @retval EFI_INVALID_PARAMETER ChildHandle is NULL.\r
379 @retval EFI_OUT_OF_RESOURCES There are not enough resources availabe to\r
6e4bac4d 380 create the child.\r
381 @retval Others The child handle was not created.\r
8a67d61d 382\r
383**/\r
384EFI_STATUS\r
385EFIAPI\r
386MnpServiceBindingCreateChild (\r
779ae357 387 IN EFI_SERVICE_BINDING_PROTOCOL *This,\r
388 IN OUT EFI_HANDLE *ChildHandle\r
8a67d61d 389 )\r
390{\r
391 EFI_STATUS Status;\r
392 MNP_SERVICE_DATA *MnpServiceData;\r
393 MNP_INSTANCE_DATA *Instance;\r
779ae357 394 VOID *MnpSb;\r
8a67d61d 395 EFI_TPL OldTpl;\r
396\r
397 if ((This == NULL) || (ChildHandle == NULL)) {\r
8a67d61d 398 return EFI_INVALID_PARAMETER;\r
399 }\r
400\r
401 MnpServiceData = MNP_SERVICE_DATA_FROM_THIS (This);\r
402\r
403 //\r
404 // Allocate buffer for the new instance.\r
405 //\r
e48e37fc 406 Instance = AllocateZeroPool (sizeof (MNP_INSTANCE_DATA));\r
8a67d61d 407 if (Instance == NULL) {\r
e48e37fc 408 DEBUG ((EFI_D_ERROR, "MnpServiceBindingCreateChild: Faild to allocate memory for the new instance.\n"));\r
779ae357 409\r
8a67d61d 410 return EFI_OUT_OF_RESOURCES;\r
411 }\r
412\r
413 //\r
414 // Init the instance data.\r
415 //\r
416 MnpInitializeInstanceData (MnpServiceData, Instance);\r
417\r
418 Status = gBS->InstallMultipleProtocolInterfaces (\r
419 ChildHandle,\r
420 &gEfiManagedNetworkProtocolGuid,\r
421 &Instance->ManagedNetwork,\r
422 NULL\r
423 );\r
424 if (EFI_ERROR (Status)) {\r
e48e37fc 425 DEBUG (\r
426 (EFI_D_ERROR,\r
427 "MnpServiceBindingCreateChild: Failed to install the MNP protocol, %r.\n",\r
8a67d61d 428 Status)\r
429 );\r
779ae357 430\r
8a67d61d 431 goto ErrorExit;\r
432 }\r
433\r
434 //\r
435 // Save the instance's childhandle.\r
436 //\r
437 Instance->Handle = *ChildHandle;\r
438\r
439 Status = gBS->OpenProtocol (\r
779ae357 440 MnpServiceData->ServiceHandle,\r
441 &gEfiManagedNetworkServiceBindingProtocolGuid,\r
442 (VOID **) &MnpSb,\r
8a67d61d 443 gMnpDriverBinding.DriverBindingHandle,\r
444 Instance->Handle,\r
445 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r
446 );\r
447 if (EFI_ERROR (Status)) {\r
448 goto ErrorExit;\r
449 }\r
450\r
451 //\r
452 // Add the child instance into ChildrenList.\r
453 //\r
e48e37fc 454 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
8a67d61d 455\r
e48e37fc 456 InsertTailList (&MnpServiceData->ChildrenList, &Instance->InstEntry);\r
8a67d61d 457 MnpServiceData->ChildrenNumber++;\r
458\r
e48e37fc 459 gBS->RestoreTPL (OldTpl);\r
8a67d61d 460\r
461ErrorExit:\r
462\r
463 if (EFI_ERROR (Status)) {\r
464\r
465 if (Instance->Handle != NULL) {\r
466\r
467 gBS->UninstallMultipleProtocolInterfaces (\r
468 &gEfiManagedNetworkProtocolGuid,\r
469 &Instance->ManagedNetwork,\r
470 NULL\r
471 );\r
472 }\r
473\r
766c7483 474 FreePool (Instance);\r
8a67d61d 475 }\r
476\r
477 return Status;\r
478}\r
479\r
480\r
481/**\r
6e4bac4d 482 Destroys a child handle with a set of I/O services.\r
779ae357 483\r
484 The DestroyChild() function does the opposite of CreateChild(). It removes a\r
485 protocol that was installed by CreateChild() from ChildHandle. If the removed\r
486 protocol is the last protocol on ChildHandle, then ChildHandle is destroyed.\r
487\r
488 @param[in] This Pointer to the EFI_SERVICE_BINDING_PROTOCOL\r
6e4bac4d 489 instance.\r
490 @param[in] ChildHandle Handle of the child to destroy.\r
491\r
779ae357 492 @retval EFI_SUCCES The protocol was removed from ChildHandle.\r
6e4bac4d 493 @retval EFI_UNSUPPORTED ChildHandle does not support the protocol that\r
494 is being removed.\r
495 @retval EFI_INVALID_PARAMETER ChildHandle is not a valid UEFI handle.\r
496 @retval EFI_ACCESS_DENIED The protocol could not be removed from the\r
497 ChildHandle because its services are being\r
498 used.\r
499 @retval Others The child handle was not destroyed.\r
8a67d61d 500\r
501**/\r
502EFI_STATUS\r
503EFIAPI\r
504MnpServiceBindingDestroyChild (\r
779ae357 505 IN EFI_SERVICE_BINDING_PROTOCOL *This,\r
506 IN EFI_HANDLE ChildHandle\r
8a67d61d 507 )\r
508{\r
509 EFI_STATUS Status;\r
510 MNP_SERVICE_DATA *MnpServiceData;\r
511 EFI_MANAGED_NETWORK_PROTOCOL *ManagedNetwork;\r
512 MNP_INSTANCE_DATA *Instance;\r
513 EFI_TPL OldTpl;\r
514\r
515 if ((This == NULL) || (ChildHandle == NULL)) {\r
8a67d61d 516 return EFI_INVALID_PARAMETER;\r
517 }\r
518\r
519 MnpServiceData = MNP_SERVICE_DATA_FROM_THIS (This);\r
520\r
521 //\r
522 // Try to retrieve ManagedNetwork Protocol from ChildHandle.\r
523 //\r
524 Status = gBS->OpenProtocol (\r
525 ChildHandle,\r
526 &gEfiManagedNetworkProtocolGuid,\r
527 (VOID **) &ManagedNetwork,\r
528 gMnpDriverBinding.DriverBindingHandle,\r
529 ChildHandle,\r
530 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
531 );\r
532 if (EFI_ERROR (Status)) {\r
8a67d61d 533 return EFI_UNSUPPORTED;\r
534 }\r
535\r
536 Instance = MNP_INSTANCE_DATA_FROM_THIS (ManagedNetwork);\r
537\r
538 //\r
539 // MnpServiceBindingDestroyChild may be called twice: first called by\r
540 // MnpServiceBindingStop, second called by uninstalling the MNP protocol\r
541 // in this ChildHandle. Use destroyed to make sure the resource clean code\r
542 // will only excecute once.\r
543 //\r
544 if (Instance->Destroyed) {\r
8a67d61d 545 return EFI_SUCCESS;\r
546 }\r
547\r
548 Instance->Destroyed = TRUE;\r
549\r
550 //\r
551 // Close the Simple Network protocol.\r
552 //\r
553 gBS->CloseProtocol (\r
779ae357 554 MnpServiceData->ServiceHandle,\r
555 &gEfiManagedNetworkServiceBindingProtocolGuid,\r
556 MnpServiceData->MnpDeviceData->ImageHandle,\r
8a67d61d 557 ChildHandle\r
558 );\r
559\r
560 //\r
561 // Uninstall the ManagedNetwork protocol.\r
562 //\r
563 Status = gBS->UninstallMultipleProtocolInterfaces (\r
564 ChildHandle,\r
565 &gEfiManagedNetworkProtocolGuid,\r
566 &Instance->ManagedNetwork,\r
567 NULL\r
568 );\r
569 if (EFI_ERROR (Status)) {\r
e48e37fc 570 DEBUG (\r
571 (EFI_D_ERROR,\r
572 "MnpServiceBindingDestroyChild: Failed to uninstall the ManagedNetwork protocol, %r.\n",\r
8a67d61d 573 Status)\r
574 );\r
575\r
576 Instance->Destroyed = FALSE;\r
577 return Status;\r
578 }\r
579\r
e48e37fc 580 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
8a67d61d 581\r
582 //\r
583 // Reset the configuration.\r
584 //\r
585 ManagedNetwork->Configure (ManagedNetwork, NULL);\r
586\r
587 //\r
588 // Try to flush the RcvdPacketQueue.\r
589 //\r
590 MnpFlushRcvdDataQueue (Instance);\r
591\r
592 //\r
593 // Clean the RxTokenMap.\r
594 //\r
595 NetMapClean (&Instance->RxTokenMap);\r
596\r
597 //\r
598 // Remove this instance from the ChildrenList.\r
599 //\r
e48e37fc 600 RemoveEntryList (&Instance->InstEntry);\r
8a67d61d 601 MnpServiceData->ChildrenNumber--;\r
602\r
e48e37fc 603 gBS->RestoreTPL (OldTpl);\r
8a67d61d 604\r
766c7483 605 FreePool (Instance);\r
8a67d61d 606\r
607 return Status;\r
608}\r
609\r
b6c4ecad 610/**\r
611 The entry point for Mnp driver which installs the driver binding and component\r
612 name protocol on its ImageHandle.\r
613\r
6e4bac4d 614 @param[in] ImageHandle The image handle of the driver.\r
615 @param[in] SystemTable The system table.\r
b6c4ecad 616\r
779ae357 617 @retval EFI_SUCCES The driver binding and component name protocols are\r
b6c4ecad 618 successfully installed.\r
6e4bac4d 619 @retval Others Other errors as indicated.\r
8a67d61d 620\r
b6c4ecad 621**/\r
8a67d61d 622EFI_STATUS\r
623EFIAPI\r
624MnpDriverEntryPoint (\r
779ae357 625 IN EFI_HANDLE ImageHandle,\r
626 IN EFI_SYSTEM_TABLE *SystemTable\r
8a67d61d 627 )\r
8a67d61d 628{\r
83cbd279 629 return EfiLibInstallDriverBindingComponentName2 (\r
da1d0201 630 ImageHandle,\r
631 SystemTable,\r
632 &gMnpDriverBinding,\r
633 ImageHandle,\r
634 &gMnpComponentName,\r
83cbd279 635 &gMnpComponentName2\r
da1d0201 636 );\r
8a67d61d 637}\r