]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/Network/MnpDxe/MnpDriver.c
1. Add EFI_COMPONENT_NAME2_PROTOCOL support for UNDI driver.
[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
284ee2e8 4Copyright (c) 2005 - 2011, Intel Corporation. All rights reserved.<BR>\r
e5eed7d3 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
0b29a17e 468 Instance->Handle,\r
8a67d61d 469 &gEfiManagedNetworkProtocolGuid,\r
470 &Instance->ManagedNetwork,\r
471 NULL\r
472 );\r
473 }\r
474\r
766c7483 475 FreePool (Instance);\r
8a67d61d 476 }\r
477\r
478 return Status;\r
479}\r
480\r
481\r
482/**\r
6e4bac4d 483 Destroys a child handle with a set of I/O services.\r
779ae357 484\r
485 The DestroyChild() function does the opposite of CreateChild(). It removes a\r
486 protocol that was installed by CreateChild() from ChildHandle. If the removed\r
487 protocol is the last protocol on ChildHandle, then ChildHandle is destroyed.\r
488\r
489 @param[in] This Pointer to the EFI_SERVICE_BINDING_PROTOCOL\r
6e4bac4d 490 instance.\r
491 @param[in] ChildHandle Handle of the child to destroy.\r
492\r
779ae357 493 @retval EFI_SUCCES The protocol was removed from ChildHandle.\r
6e4bac4d 494 @retval EFI_UNSUPPORTED ChildHandle does not support the protocol that\r
495 is being removed.\r
284ee2e8 496 @retval EFI_INVALID_PARAMETER ChildHandle is NULL.\r
6e4bac4d 497 @retval EFI_ACCESS_DENIED The protocol could not be removed from the\r
498 ChildHandle because its services are being\r
499 used.\r
500 @retval Others The child handle was not destroyed.\r
8a67d61d 501\r
502**/\r
503EFI_STATUS\r
504EFIAPI\r
505MnpServiceBindingDestroyChild (\r
779ae357 506 IN EFI_SERVICE_BINDING_PROTOCOL *This,\r
507 IN EFI_HANDLE ChildHandle\r
8a67d61d 508 )\r
509{\r
510 EFI_STATUS Status;\r
511 MNP_SERVICE_DATA *MnpServiceData;\r
512 EFI_MANAGED_NETWORK_PROTOCOL *ManagedNetwork;\r
513 MNP_INSTANCE_DATA *Instance;\r
514 EFI_TPL OldTpl;\r
515\r
516 if ((This == NULL) || (ChildHandle == NULL)) {\r
8a67d61d 517 return EFI_INVALID_PARAMETER;\r
518 }\r
519\r
520 MnpServiceData = MNP_SERVICE_DATA_FROM_THIS (This);\r
521\r
522 //\r
523 // Try to retrieve ManagedNetwork Protocol from ChildHandle.\r
524 //\r
525 Status = gBS->OpenProtocol (\r
526 ChildHandle,\r
527 &gEfiManagedNetworkProtocolGuid,\r
528 (VOID **) &ManagedNetwork,\r
529 gMnpDriverBinding.DriverBindingHandle,\r
530 ChildHandle,\r
531 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
532 );\r
533 if (EFI_ERROR (Status)) {\r
8a67d61d 534 return EFI_UNSUPPORTED;\r
535 }\r
536\r
537 Instance = MNP_INSTANCE_DATA_FROM_THIS (ManagedNetwork);\r
538\r
539 //\r
540 // MnpServiceBindingDestroyChild may be called twice: first called by\r
541 // MnpServiceBindingStop, second called by uninstalling the MNP protocol\r
542 // in this ChildHandle. Use destroyed to make sure the resource clean code\r
543 // will only excecute once.\r
544 //\r
545 if (Instance->Destroyed) {\r
8a67d61d 546 return EFI_SUCCESS;\r
547 }\r
548\r
549 Instance->Destroyed = TRUE;\r
550\r
551 //\r
552 // Close the Simple Network protocol.\r
553 //\r
554 gBS->CloseProtocol (\r
779ae357 555 MnpServiceData->ServiceHandle,\r
556 &gEfiManagedNetworkServiceBindingProtocolGuid,\r
557 MnpServiceData->MnpDeviceData->ImageHandle,\r
8a67d61d 558 ChildHandle\r
559 );\r
560\r
561 //\r
562 // Uninstall the ManagedNetwork protocol.\r
563 //\r
564 Status = gBS->UninstallMultipleProtocolInterfaces (\r
565 ChildHandle,\r
566 &gEfiManagedNetworkProtocolGuid,\r
567 &Instance->ManagedNetwork,\r
568 NULL\r
569 );\r
570 if (EFI_ERROR (Status)) {\r
e48e37fc 571 DEBUG (\r
572 (EFI_D_ERROR,\r
573 "MnpServiceBindingDestroyChild: Failed to uninstall the ManagedNetwork protocol, %r.\n",\r
8a67d61d 574 Status)\r
575 );\r
576\r
577 Instance->Destroyed = FALSE;\r
578 return Status;\r
579 }\r
580\r
e48e37fc 581 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
8a67d61d 582\r
583 //\r
584 // Reset the configuration.\r
585 //\r
586 ManagedNetwork->Configure (ManagedNetwork, NULL);\r
587\r
588 //\r
589 // Try to flush the RcvdPacketQueue.\r
590 //\r
591 MnpFlushRcvdDataQueue (Instance);\r
592\r
593 //\r
594 // Clean the RxTokenMap.\r
595 //\r
596 NetMapClean (&Instance->RxTokenMap);\r
597\r
598 //\r
599 // Remove this instance from the ChildrenList.\r
600 //\r
e48e37fc 601 RemoveEntryList (&Instance->InstEntry);\r
8a67d61d 602 MnpServiceData->ChildrenNumber--;\r
603\r
e48e37fc 604 gBS->RestoreTPL (OldTpl);\r
8a67d61d 605\r
766c7483 606 FreePool (Instance);\r
8a67d61d 607\r
608 return Status;\r
609}\r
610\r
b6c4ecad 611/**\r
612 The entry point for Mnp driver which installs the driver binding and component\r
613 name protocol on its ImageHandle.\r
614\r
6e4bac4d 615 @param[in] ImageHandle The image handle of the driver.\r
616 @param[in] SystemTable The system table.\r
b6c4ecad 617\r
779ae357 618 @retval EFI_SUCCES The driver binding and component name protocols are\r
b6c4ecad 619 successfully installed.\r
6e4bac4d 620 @retval Others Other errors as indicated.\r
8a67d61d 621\r
b6c4ecad 622**/\r
8a67d61d 623EFI_STATUS\r
624EFIAPI\r
625MnpDriverEntryPoint (\r
779ae357 626 IN EFI_HANDLE ImageHandle,\r
627 IN EFI_SYSTEM_TABLE *SystemTable\r
8a67d61d 628 )\r
8a67d61d 629{\r
83cbd279 630 return EfiLibInstallDriverBindingComponentName2 (\r
da1d0201 631 ImageHandle,\r
632 SystemTable,\r
633 &gMnpDriverBinding,\r
634 ImageHandle,\r
635 &gMnpComponentName,\r
83cbd279 636 &gMnpComponentName2\r
da1d0201 637 );\r
8a67d61d 638}\r