VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/Firmware/NetworkPkg/IScsiDxe/IScsiDriver.c@ 69222

Last change on this file since 69222 was 58466, checked in by vboxsync, 9 years ago

EFI/Firmware: Merged in the svn:eol-style, svn:mime-type and trailing whitespace cleanup that was done after the initial UDK2014.SP1 import: svn merge /vendor/edk2/UDK2014.SP1 /vendor/edk2/current .

  • Property svn:eol-style set to native
File size: 56.7 KB
Line 
1/** @file
2 The entry point of IScsi driver.
3
4Copyright (c) 2004 - 2015, Intel Corporation. All rights reserved.<BR>
5This program and the accompanying materials
6are licensed and made available under the terms and conditions of the BSD License
7which accompanies this distribution. The full text of the license may be found at
8http://opensource.org/licenses/bsd-license.php
9
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13**/
14
15#include "IScsiImpl.h"
16
17EFI_DRIVER_BINDING_PROTOCOL gIScsiIp4DriverBinding = {
18 IScsiIp4DriverBindingSupported,
19 IScsiIp4DriverBindingStart,
20 IScsiIp4DriverBindingStop,
21 0xa,
22 NULL,
23 NULL
24};
25
26EFI_DRIVER_BINDING_PROTOCOL gIScsiIp6DriverBinding = {
27 IScsiIp6DriverBindingSupported,
28 IScsiIp6DriverBindingStart,
29 IScsiIp6DriverBindingStop,
30 0xa,
31 NULL,
32 NULL
33};
34
35EFI_GUID gIScsiV4PrivateGuid = ISCSI_V4_PRIVATE_GUID;
36EFI_GUID gIScsiV6PrivateGuid = ISCSI_V6_PRIVATE_GUID;
37ISCSI_PRIVATE_DATA *mPrivate = NULL;
38
39/**
40 Tests to see if this driver supports the RemainingDevicePath.
41
42 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
43 parameter is ignored by device drivers, and is optional for bus
44 drivers. For bus drivers, if this parameter is not NULL, then
45 the bus driver must determine if the bus controller specified
46 by ControllerHandle and the child controller specified
47 by RemainingDevicePath are both supported by this
48 bus driver.
49
50 @retval EFI_SUCCESS The RemainingDevicePath is supported or NULL.
51 @retval EFI_UNSUPPORTED The device specified by ControllerHandle and
52 RemainingDevicePath is not supported by the driver specified by This.
53**/
54EFI_STATUS
55IScsiIsDevicePathSupported (
56 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
57 )
58{
59 EFI_DEVICE_PATH_PROTOCOL *CurrentDevicePath;
60
61 CurrentDevicePath = RemainingDevicePath;
62 if (CurrentDevicePath != NULL) {
63 while (!IsDevicePathEnd (CurrentDevicePath)) {
64 if ((CurrentDevicePath->Type == MESSAGING_DEVICE_PATH) && (CurrentDevicePath->SubType == MSG_ISCSI_DP)) {
65 return EFI_SUCCESS;
66 }
67
68 CurrentDevicePath = NextDevicePathNode (CurrentDevicePath);
69 }
70
71 return EFI_UNSUPPORTED;
72 }
73
74 return EFI_SUCCESS;
75}
76
77
78/**
79 Tests to see if this driver supports a given controller. This is the worker function for
80 IScsiIp4(6)DriverBindingSupported.
81
82 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
83 @param[in] ControllerHandle The handle of the controller to test. This handle
84 must support a protocol interface that supplies
85 an I/O abstraction to the driver.
86 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
87 parameter is ignored by device drivers, and is optional for bus
88 drivers. For bus drivers, if this parameter is not NULL, then
89 the bus driver must determine if the bus controller specified
90 by ControllerHandle and the child controller specified
91 by RemainingDevicePath are both supported by this
92 bus driver.
93 @param[in] IpVersion IP_VERSION_4 or IP_VERSION_6.
94
95 @retval EFI_SUCCESS The device specified by ControllerHandle and
96 RemainingDevicePath is supported by the driver specified by This.
97 @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and
98 RemainingDevicePath is already being managed by the driver
99 specified by This.
100 @retval EFI_UNSUPPORTED The device specified by ControllerHandle and
101 RemainingDevicePath is not supported by the driver specified by This.
102**/
103EFI_STATUS
104EFIAPI
105IScsiSupported (
106 IN EFI_DRIVER_BINDING_PROTOCOL *This,
107 IN EFI_HANDLE ControllerHandle,
108 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL,
109 IN UINT8 IpVersion
110 )
111{
112 EFI_STATUS Status;
113 EFI_GUID *IScsiServiceBindingGuid;
114 EFI_GUID *TcpServiceBindingGuid;
115 EFI_GUID *DhcpServiceBindingGuid;
116
117 if (IpVersion == IP_VERSION_4) {
118 IScsiServiceBindingGuid = &gIScsiV4PrivateGuid;
119 TcpServiceBindingGuid = &gEfiTcp4ServiceBindingProtocolGuid;
120 DhcpServiceBindingGuid = &gEfiDhcp4ServiceBindingProtocolGuid;
121 } else {
122 IScsiServiceBindingGuid = &gIScsiV6PrivateGuid;
123 TcpServiceBindingGuid = &gEfiTcp6ServiceBindingProtocolGuid;
124 DhcpServiceBindingGuid = &gEfiDhcp6ServiceBindingProtocolGuid;
125 }
126
127 Status = gBS->OpenProtocol (
128 ControllerHandle,
129 IScsiServiceBindingGuid,
130 NULL,
131 This->DriverBindingHandle,
132 ControllerHandle,
133 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
134 );
135 if (!EFI_ERROR (Status)) {
136 return EFI_ALREADY_STARTED;
137 }
138
139 Status = gBS->OpenProtocol (
140 ControllerHandle,
141 TcpServiceBindingGuid,
142 NULL,
143 This->DriverBindingHandle,
144 ControllerHandle,
145 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
146 );
147 if (EFI_ERROR (Status)) {
148 return EFI_UNSUPPORTED;
149 }
150
151 Status = IScsiIsDevicePathSupported (RemainingDevicePath);
152 if (EFI_ERROR (Status)) {
153 return EFI_UNSUPPORTED;
154 }
155
156 if (IScsiDhcpIsConfigured (ControllerHandle, IpVersion)) {
157 Status = gBS->OpenProtocol (
158 ControllerHandle,
159 DhcpServiceBindingGuid,
160 NULL,
161 This->DriverBindingHandle,
162 ControllerHandle,
163 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
164 );
165 if (EFI_ERROR (Status)) {
166 return EFI_UNSUPPORTED;
167 }
168 }
169
170 return EFI_SUCCESS;
171}
172
173
174/**
175 Start to manage the controller. This is the worker function for
176 IScsiIp4(6)DriverBindingStart.
177
178 @param[in] Image Handle of the image.
179 @param[in] ControllerHandle Handle of the controller.
180 @param[in] IpVersion IP_VERSION_4 or IP_VERSION_6.
181
182 @retval EFI_SUCCES This driver was started.
183 @retval EFI_ALREADY_STARTED This driver is already running on this device.
184 @retval EFI_INVALID_PARAMETER Any input parameter is invalid.
185 @retval EFI_NOT_FOUND There is no sufficient information to establish
186 the iScsi session.
187 @retval EFI_DEVICE_ERROR Failed to get TCP connection device path.
188
189**/
190EFI_STATUS
191IScsiStart (
192 IN EFI_HANDLE Image,
193 IN EFI_HANDLE ControllerHandle,
194 IN UINT8 IpVersion
195 )
196{
197 EFI_STATUS Status;
198 ISCSI_DRIVER_DATA *Private;
199 LIST_ENTRY *Entry;
200 LIST_ENTRY *NextEntry;
201 ISCSI_ATTEMPT_CONFIG_NVDATA *AttemptConfigData;
202 ISCSI_SESSION *Session;
203 UINT8 Index;
204 EFI_EXT_SCSI_PASS_THRU_PROTOCOL *ExistIScsiExtScsiPassThru;
205 ISCSI_DRIVER_DATA *ExistPrivate;
206 UINT8 *AttemptConfigOrder;
207 UINTN AttemptConfigOrderSize;
208 UINT8 BootSelected;
209 EFI_HANDLE *HandleBuffer;
210 UINTN NumberOfHandles;
211 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
212 EFI_GUID *IScsiPrivateGuid;
213 EFI_GUID *TcpServiceBindingGuid;
214 CHAR16 MacString[ISCSI_MAX_MAC_STRING_LEN];
215 BOOLEAN NeedUpdate;
216 VOID *Interface;
217 EFI_GUID *ProtocolGuid;
218
219 //
220 // Test to see if iSCSI driver supports the given controller.
221 //
222
223 if (IpVersion == IP_VERSION_4) {
224 IScsiPrivateGuid = &gIScsiV4PrivateGuid;
225 TcpServiceBindingGuid = &gEfiTcp4ServiceBindingProtocolGuid;
226 ProtocolGuid = &gEfiTcp4ProtocolGuid;
227 } else if (IpVersion == IP_VERSION_6) {
228 IScsiPrivateGuid = &gIScsiV6PrivateGuid;
229 TcpServiceBindingGuid = &gEfiTcp6ServiceBindingProtocolGuid;
230 ProtocolGuid = &gEfiTcp6ProtocolGuid;
231 } else {
232 return EFI_INVALID_PARAMETER;
233 }
234
235 Status = gBS->OpenProtocol (
236 ControllerHandle,
237 IScsiPrivateGuid,
238 NULL,
239 Image,
240 ControllerHandle,
241 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
242 );
243 if (!EFI_ERROR (Status)) {
244 return EFI_ALREADY_STARTED;
245 }
246
247 Status = gBS->OpenProtocol (
248 ControllerHandle,
249 TcpServiceBindingGuid,
250 NULL,
251 Image,
252 ControllerHandle,
253 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
254 );
255 if (EFI_ERROR (Status)) {
256 return EFI_UNSUPPORTED;
257 }
258
259 //
260 // Record the incoming NIC info.
261 //
262 Status = IScsiAddNic (ControllerHandle);
263 if (EFI_ERROR (Status)) {
264 return Status;
265 }
266
267 //
268 // Create the instance private data.
269 //
270 Private = IScsiCreateDriverData (Image, ControllerHandle);
271 if (Private == NULL) {
272 return EFI_OUT_OF_RESOURCES;
273 }
274
275 //
276 // Create a underlayer child instance, but not need to configure it. Just open ChildHandle
277 // via BY_DRIVER. That is, establishing the relationship between ControllerHandle and ChildHandle.
278 // Therefore, when DisconnectController(), especially VLAN virtual controller handle,
279 // IScsiDriverBindingStop() will be called.
280 //
281 Status = NetLibCreateServiceChild (
282 ControllerHandle,
283 Image,
284 TcpServiceBindingGuid,
285 &Private->ChildHandle
286 );
287
288 if (EFI_ERROR (Status)) {
289 goto ON_ERROR;
290 }
291
292 Status = gBS->OpenProtocol (
293 Private->ChildHandle, /// Default Tcp child
294 ProtocolGuid,
295 &Interface,
296 Image,
297 ControllerHandle,
298 EFI_OPEN_PROTOCOL_BY_DRIVER
299 );
300
301 if (EFI_ERROR (Status)) {
302 goto ON_ERROR;
303 }
304
305 //
306 // Always install private protocol no matter what happens later. We need to
307 // keep the relationship between ControllerHandle and ChildHandle.
308 //
309 Status = gBS->InstallProtocolInterface (
310 &ControllerHandle,
311 IScsiPrivateGuid,
312 EFI_NATIVE_INTERFACE,
313 &Private->IScsiIdentifier
314 );
315 if (EFI_ERROR (Status)) {
316 goto ON_ERROR;
317 }
318
319 if (IpVersion == IP_VERSION_4) {
320 mPrivate->Ipv6Flag = FALSE;
321 } else {
322 mPrivate->Ipv6Flag = TRUE;
323 }
324
325 //
326 // Get the current iSCSI configuration data.
327 //
328 Status = IScsiGetConfigData (Private);
329 if (EFI_ERROR (Status)) {
330 goto ON_ERROR;
331 }
332
333 //
334 // If there is already a successul attempt, check whether this attempt is the
335 // first "enabled for MPIO" attempt. If not, still try the first attempt.
336 // In single path mode, try all attempts.
337 //
338 ExistPrivate = NULL;
339 Status = EFI_NOT_FOUND;
340
341 if (mPrivate->OneSessionEstablished && mPrivate->EnableMpio) {
342 AttemptConfigData = NULL;
343 NET_LIST_FOR_EACH (Entry, &mPrivate->AttemptConfigs) {
344 AttemptConfigData = NET_LIST_USER_STRUCT (Entry, ISCSI_ATTEMPT_CONFIG_NVDATA, Link);
345 if (AttemptConfigData->SessionConfigData.Enabled == ISCSI_ENABLED_FOR_MPIO) {
346 break;
347 }
348 }
349
350 if (AttemptConfigData == NULL) {
351 goto ON_ERROR;
352 }
353
354 if (AttemptConfigData->AttemptConfigIndex == mPrivate->BootSelectedIndex) {
355 goto ON_EXIT;
356 }
357
358 //
359 // Uninstall the original ExtScsiPassThru first.
360 //
361
362 //
363 // Locate all ExtScsiPassThru protocol instances.
364 //
365 Status = gBS->LocateHandleBuffer (
366 ByProtocol,
367 &gEfiExtScsiPassThruProtocolGuid,
368 NULL,
369 &NumberOfHandles,
370 &HandleBuffer
371 );
372 if (EFI_ERROR (Status)) {
373 goto ON_ERROR;
374 }
375
376 //
377 // Find ExtScsiPassThru protocol instance produced by this driver.
378 //
379 ExistIScsiExtScsiPassThru = NULL;
380 for (Index = 0; Index < NumberOfHandles && ExistIScsiExtScsiPassThru == NULL; Index++) {
381 Status = gBS->HandleProtocol (
382 HandleBuffer[Index],
383 &gEfiDevicePathProtocolGuid,
384 (VOID **) &DevicePath
385 );
386 if (EFI_ERROR (Status)) {
387 continue;
388 }
389
390 while (!IsDevicePathEnd (DevicePath)) {
391 if ((DevicePath->Type == MESSAGING_DEVICE_PATH) && (DevicePath->SubType == MSG_MAC_ADDR_DP)) {
392 //
393 // Get the ExtScsiPassThru protocol instance.
394 //
395 Status = gBS->HandleProtocol (
396 HandleBuffer[Index],
397 &gEfiExtScsiPassThruProtocolGuid,
398 (VOID **) &ExistIScsiExtScsiPassThru
399 );
400 ASSERT_EFI_ERROR (Status);
401 break;
402 }
403
404 DevicePath = NextDevicePathNode (DevicePath);
405 }
406 }
407
408 FreePool (HandleBuffer);
409
410 if (ExistIScsiExtScsiPassThru == NULL) {
411 Status = EFI_NOT_FOUND;
412 goto ON_ERROR;
413 }
414
415 ExistPrivate = ISCSI_DRIVER_DATA_FROM_EXT_SCSI_PASS_THRU (ExistIScsiExtScsiPassThru);
416
417 Status = gBS->UninstallProtocolInterface (
418 ExistPrivate->ExtScsiPassThruHandle,
419 &gEfiExtScsiPassThruProtocolGuid,
420 &ExistPrivate->IScsiExtScsiPassThru
421 );
422 if (EFI_ERROR (Status)) {
423 goto ON_ERROR;
424 }
425 }
426
427 //
428 // Install the Ext SCSI PASS THRU protocol.
429 //
430 Status = gBS->InstallProtocolInterface (
431 &Private->ExtScsiPassThruHandle,
432 &gEfiExtScsiPassThruProtocolGuid,
433 EFI_NATIVE_INTERFACE,
434 &Private->IScsiExtScsiPassThru
435 );
436 if (EFI_ERROR (Status)) {
437 goto ON_ERROR;
438 }
439
440 BootSelected = 0;
441
442 NET_LIST_FOR_EACH_SAFE (Entry, NextEntry, &mPrivate->AttemptConfigs) {
443 AttemptConfigData = NET_LIST_USER_STRUCT (Entry, ISCSI_ATTEMPT_CONFIG_NVDATA, Link);
444 //
445 // Don't process the attempt that does not associate with the current NIC or
446 // this attempt is disabled or established.
447 //
448 if (AttemptConfigData->NicIndex != mPrivate->CurrentNic ||
449 AttemptConfigData->SessionConfigData.Enabled == ISCSI_DISABLED ||
450 AttemptConfigData->ValidPath) {
451 continue;
452 }
453
454 //
455 // In multipath mode, don't process attempts configured for single path.
456 // In default single path mode, don't process attempts configured for multipath.
457 //
458 if ((mPrivate->EnableMpio &&
459 AttemptConfigData->SessionConfigData.Enabled != ISCSI_ENABLED_FOR_MPIO) ||
460 (!mPrivate->EnableMpio &&
461 AttemptConfigData->SessionConfigData.Enabled != ISCSI_ENABLED)) {
462 continue;
463 }
464
465 //
466 // Don't process the attempt that fails to get the init/target information from DHCP.
467 //
468 if (AttemptConfigData->SessionConfigData.InitiatorInfoFromDhcp &&
469 !AttemptConfigData->DhcpSuccess) {
470 if (!mPrivate->EnableMpio && mPrivate->ValidSinglePathCount > 0) {
471 mPrivate->ValidSinglePathCount--;
472 }
473 continue;
474 }
475
476 //
477 // Don't process the autoconfigure path if it is already established.
478 //
479 if (AttemptConfigData->SessionConfigData.IpMode == IP_MODE_AUTOCONFIG &&
480 AttemptConfigData->AutoConfigureMode == IP_MODE_AUTOCONFIG_SUCCESS) {
481 continue;
482 }
483
484 //
485 // Don't process the attempt if its IP mode is not in the current IP version.
486 //
487 if (!mPrivate->Ipv6Flag) {
488 if (AttemptConfigData->SessionConfigData.IpMode == IP_MODE_IP6) {
489 continue;
490 }
491 if (AttemptConfigData->SessionConfigData.IpMode == IP_MODE_AUTOCONFIG &&
492 AttemptConfigData->AutoConfigureMode == IP_MODE_AUTOCONFIG_IP6) {
493 continue;
494 }
495 } else {
496 if (AttemptConfigData->SessionConfigData.IpMode == IP_MODE_IP4) {
497 continue;
498 }
499 if (AttemptConfigData->SessionConfigData.IpMode == IP_MODE_AUTOCONFIG &&
500 AttemptConfigData->AutoConfigureMode == IP_MODE_AUTOCONFIG_IP4) {
501 continue;
502 }
503 }
504
505 //
506 // Fill in the Session and init it.
507 //
508 Session = (ISCSI_SESSION *) AllocateZeroPool (sizeof (ISCSI_SESSION));
509 if (Session == NULL) {
510 Status = EFI_OUT_OF_RESOURCES;
511 goto ON_ERROR;
512 }
513
514 Session->Private = Private;
515 Session->ConfigData = AttemptConfigData;
516 Session->AuthType = AttemptConfigData->AuthenticationType;
517
518 AsciiStrToUnicodeStr (AttemptConfigData->MacString, MacString);
519 UnicodeSPrint (
520 mPrivate->PortString,
521 (UINTN) ISCSI_NAME_IFR_MAX_SIZE,
522 L"%s%d",
523 MacString,
524 (UINTN) AttemptConfigData->AttemptConfigIndex
525 );
526
527 if (Session->AuthType == ISCSI_AUTH_TYPE_CHAP) {
528 Session->AuthData.CHAP.AuthConfig = &AttemptConfigData->AuthConfigData.CHAP;
529 }
530
531 IScsiSessionInit (Session, FALSE);
532
533 //
534 // Try to login and create an iSCSI session according to the configuration.
535 //
536 Status = IScsiSessionLogin (Session);
537 if (Status == EFI_MEDIA_CHANGED) {
538 //
539 // The specified target is not available, and the redirection information is
540 // received. Login the session again with the updated target address.
541 //
542 Status = IScsiSessionLogin (Session);
543 } else if (Status == EFI_NOT_READY) {
544 Status = IScsiSessionReLogin (Session);
545 }
546
547 if (EFI_ERROR (Status)) {
548 //
549 // In Single path mode, only the successful attempt will be recorded in iBFT;
550 // in multi-path mode, all the attempt entries in MPIO will be recorded in iBFT.
551 //
552 if (!mPrivate->EnableMpio && mPrivate->ValidSinglePathCount > 0) {
553 mPrivate->ValidSinglePathCount--;
554 }
555
556 FreePool (Session);
557
558 } else {
559 AttemptConfigData->ValidPath = TRUE;
560
561 //
562 // Do not record the attempt in iBFT if it login with KRB5.
563 // TODO: record KRB5 attempt information in the iSCSI device path.
564 //
565 if (Session->AuthType == ISCSI_AUTH_TYPE_KRB) {
566 if (!mPrivate->EnableMpio && mPrivate->ValidSinglePathCount > 0) {
567 mPrivate->ValidSinglePathCount--;
568 }
569
570 AttemptConfigData->ValidiBFTPath = FALSE;
571 } else {
572 AttemptConfigData->ValidiBFTPath = TRUE;
573 }
574
575 //
576 // IScsi session success. Update the attempt state to NVR.
577 //
578 if (AttemptConfigData->SessionConfigData.IpMode == IP_MODE_AUTOCONFIG) {
579 AttemptConfigData->AutoConfigureMode = IP_MODE_AUTOCONFIG_SUCCESS;
580 }
581
582 gRT->SetVariable (
583 mPrivate->PortString,
584 &gEfiIScsiInitiatorNameProtocolGuid,
585 ISCSI_CONFIG_VAR_ATTR,
586 sizeof (ISCSI_ATTEMPT_CONFIG_NVDATA),
587 AttemptConfigData
588 );
589
590 //
591 // Select the first login session. Abort others.
592 //
593 if (Private->Session == NULL) {
594 Private->Session = Session;
595 BootSelected = AttemptConfigData->AttemptConfigIndex;
596 //
597 // Don't validate other attempt in multipath mode if one is success.
598 //
599 if (mPrivate->EnableMpio) {
600 break;
601 }
602 } else {
603 IScsiSessionAbort (Session);
604 FreePool (Session);
605 }
606 }
607 }
608
609 //
610 // All attempts configured for this driver instance are not valid.
611 //
612 if (Private->Session == NULL) {
613 Status = gBS->UninstallProtocolInterface (
614 Private->ExtScsiPassThruHandle,
615 &gEfiExtScsiPassThruProtocolGuid,
616 &Private->IScsiExtScsiPassThru
617 );
618 ASSERT_EFI_ERROR (Status);
619 Private->ExtScsiPassThruHandle = NULL;
620
621 //
622 // Reinstall the original ExtScsiPassThru back.
623 //
624 if (mPrivate->OneSessionEstablished && ExistPrivate != NULL) {
625 Status = gBS->InstallProtocolInterface (
626 &ExistPrivate->ExtScsiPassThruHandle,
627 &gEfiExtScsiPassThruProtocolGuid,
628 EFI_NATIVE_INTERFACE,
629 &ExistPrivate->IScsiExtScsiPassThru
630 );
631 if (EFI_ERROR (Status)) {
632 goto ON_ERROR;
633 }
634
635 goto ON_EXIT;
636 }
637
638 Status = EFI_NOT_FOUND;
639
640 goto ON_ERROR;
641 }
642
643 NeedUpdate = TRUE;
644 //
645 // More than one attempt successes.
646 //
647 if (Private->Session != NULL && mPrivate->OneSessionEstablished) {
648
649 AttemptConfigOrder = IScsiGetVariableAndSize (
650 L"AttemptOrder",
651 &gIScsiConfigGuid,
652 &AttemptConfigOrderSize
653 );
654 if (AttemptConfigOrder == NULL) {
655 goto ON_ERROR;
656 }
657 for (Index = 0; Index < AttemptConfigOrderSize / sizeof (UINT8); Index++) {
658 if (AttemptConfigOrder[Index] == mPrivate->BootSelectedIndex ||
659 AttemptConfigOrder[Index] == BootSelected) {
660 break;
661 }
662 }
663
664 if (mPrivate->EnableMpio) {
665 //
666 // Use the attempt in earlier order. Abort the later one in MPIO.
667 //
668 if (AttemptConfigOrder[Index] == mPrivate->BootSelectedIndex) {
669 IScsiSessionAbort (Private->Session);
670 FreePool (Private->Session);
671 Private->Session = NULL;
672 gBS->UninstallProtocolInterface (
673 Private->ExtScsiPassThruHandle,
674 &gEfiExtScsiPassThruProtocolGuid,
675 &Private->IScsiExtScsiPassThru
676 );
677 Private->ExtScsiPassThruHandle = NULL;
678
679 //
680 // Reinstall the original ExtScsiPassThru back.
681 //
682 Status = gBS->InstallProtocolInterface (
683 &ExistPrivate->ExtScsiPassThruHandle,
684 &gEfiExtScsiPassThruProtocolGuid,
685 EFI_NATIVE_INTERFACE,
686 &ExistPrivate->IScsiExtScsiPassThru
687 );
688 if (EFI_ERROR (Status)) {
689 goto ON_ERROR;
690 }
691
692 goto ON_EXIT;
693 } else {
694 if (AttemptConfigOrder[Index] != BootSelected) {
695 goto ON_ERROR;
696 }
697 mPrivate->BootSelectedIndex = BootSelected;
698 //
699 // Clear the resource in ExistPrivate.
700 //
701 gBS->UninstallProtocolInterface (
702 ExistPrivate->Controller,
703 IScsiPrivateGuid,
704 &ExistPrivate->IScsiIdentifier
705 );
706
707 IScsiRemoveNic (ExistPrivate->Controller);
708 if (ExistPrivate->Session != NULL) {
709 IScsiSessionAbort (ExistPrivate->Session);
710 }
711
712 IScsiCleanDriverData (ExistPrivate);
713 }
714 } else {
715 //
716 // Use the attempt in earlier order as boot selected in single path mode.
717 //
718 if (AttemptConfigOrder[Index] == mPrivate->BootSelectedIndex) {
719 NeedUpdate = FALSE;
720 }
721 }
722
723 }
724
725 if (NeedUpdate) {
726 mPrivate->OneSessionEstablished = TRUE;
727 mPrivate->BootSelectedIndex = BootSelected;
728 }
729
730 //
731 // Duplicate the Session's tcp connection device path. The source port field
732 // will be set to zero as one iSCSI session is comprised of several iSCSI
733 // connections.
734 //
735 Private->DevicePath = IScsiGetTcpConnDevicePath (Private->Session);
736 if (Private->DevicePath == NULL) {
737 Status = EFI_DEVICE_ERROR;
738 goto ON_ERROR;
739 }
740 //
741 // Install the updated device path onto the ExtScsiPassThruHandle.
742 //
743 Status = gBS->InstallProtocolInterface (
744 &Private->ExtScsiPassThruHandle,
745 &gEfiDevicePathProtocolGuid,
746 EFI_NATIVE_INTERFACE,
747 Private->DevicePath
748 );
749 if (EFI_ERROR (Status)) {
750 goto ON_ERROR;
751 }
752
753 //
754 // ISCSI children should share the default Tcp child, just open the default Tcp child via BY_CHILD_CONTROLLER.
755 //
756 Status = gBS->OpenProtocol (
757 Private->ChildHandle, /// Default Tcp child
758 ProtocolGuid,
759 &Interface,
760 Image,
761 Private->ExtScsiPassThruHandle,
762 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
763 );
764 if (EFI_ERROR (Status)) {
765 gBS->UninstallMultipleProtocolInterfaces (
766 Private->ExtScsiPassThruHandle,
767 &gEfiExtScsiPassThruProtocolGuid,
768 &Private->IScsiExtScsiPassThru,
769 &gEfiDevicePathProtocolGuid,
770 Private->DevicePath,
771 NULL
772 );
773
774 goto ON_ERROR;
775 }
776
777ON_EXIT:
778
779 //
780 // Update/Publish the iSCSI Boot Firmware Table.
781 //
782 if (mPrivate->BootSelectedIndex != 0) {
783 IScsiPublishIbft ();
784 }
785
786 return EFI_SUCCESS;
787
788ON_ERROR:
789
790 if (Private->Session != NULL) {
791 IScsiSessionAbort (Private->Session);
792 }
793
794 return Status;
795}
796
797/**
798 Stops a device controller or a bus controller. This is the worker function for
799 IScsiIp4(6)DriverBindingStop.
800
801 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
802 @param[in] ControllerHandle A handle to the device being stopped. The handle must
803 support a bus specific I/O protocol for the driver
804 to use to stop the device.
805 @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.
806 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL
807 if NumberOfChildren is 0.
808 @param[in] IpVersion IP_VERSION_4 or IP_VERSION_6.
809
810 @retval EFI_SUCCESS The device was stopped.
811 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
812
813**/
814EFI_STATUS
815EFIAPI
816IScsiStop (
817 IN EFI_DRIVER_BINDING_PROTOCOL *This,
818 IN EFI_HANDLE ControllerHandle,
819 IN UINTN NumberOfChildren,
820 IN EFI_HANDLE *ChildHandleBuffer OPTIONAL,
821 IN UINT8 IpVersion
822 )
823{
824 EFI_HANDLE IScsiController;
825 EFI_STATUS Status;
826 ISCSI_PRIVATE_PROTOCOL *IScsiIdentifier;
827 ISCSI_DRIVER_DATA *Private;
828 EFI_EXT_SCSI_PASS_THRU_PROTOCOL *PassThru;
829 ISCSI_CONNECTION *Conn;
830 EFI_GUID *ProtocolGuid;
831 EFI_GUID *TcpServiceBindingGuid;
832 EFI_GUID *TcpProtocolGuid;
833
834
835 if (NumberOfChildren != 0) {
836 //
837 // We should have only one child.
838 //
839 Status = gBS->OpenProtocol (
840 ChildHandleBuffer[0],
841 &gEfiExtScsiPassThruProtocolGuid,
842 (VOID **) &PassThru,
843 This->DriverBindingHandle,
844 ControllerHandle,
845 EFI_OPEN_PROTOCOL_GET_PROTOCOL
846 );
847 if (EFI_ERROR (Status)) {
848 return EFI_DEVICE_ERROR;
849 }
850
851 Private = ISCSI_DRIVER_DATA_FROM_EXT_SCSI_PASS_THRU (PassThru);
852 Conn = NET_LIST_HEAD (&Private->Session->Conns, ISCSI_CONNECTION, Link);
853
854 //
855 // Previously the TCP protocol is opened BY_CHILD_CONTROLLER. Just close
856 // the protocol here, but do not uninstall the device path protocol and
857 // EXT SCSI PASS THRU protocol installed on ExtScsiPassThruHandle.
858 //
859 if (IpVersion == IP_VERSION_4) {
860 ProtocolGuid = &gEfiTcp4ProtocolGuid;
861 } else {
862 ProtocolGuid = &gEfiTcp6ProtocolGuid;
863 }
864
865 gBS->CloseProtocol (
866 Private->ChildHandle,
867 ProtocolGuid,
868 Private->Image,
869 Private->ExtScsiPassThruHandle
870 );
871
872 gBS->CloseProtocol (
873 Conn->TcpIo.Handle,
874 ProtocolGuid,
875 Private->Image,
876 Private->ExtScsiPassThruHandle
877 );
878
879 return EFI_SUCCESS;
880 }
881
882 //
883 // Get the handle of the controller we are controling.
884 //
885 if (IpVersion == IP_VERSION_4) {
886 ProtocolGuid = &gIScsiV4PrivateGuid;
887 TcpProtocolGuid = &gEfiTcp4ProtocolGuid;
888 TcpServiceBindingGuid = &gEfiTcp4ServiceBindingProtocolGuid;
889 } else {
890 ProtocolGuid = &gIScsiV6PrivateGuid;
891 TcpProtocolGuid = &gEfiTcp6ProtocolGuid;
892 TcpServiceBindingGuid = &gEfiTcp6ServiceBindingProtocolGuid;
893 }
894 IScsiController = NetLibGetNicHandle (ControllerHandle, TcpProtocolGuid);
895 if (IScsiController == NULL) {
896 return EFI_SUCCESS;
897 }
898
899 Status = gBS->OpenProtocol (
900 IScsiController,
901 ProtocolGuid,
902 (VOID **) &IScsiIdentifier,
903 This->DriverBindingHandle,
904 ControllerHandle,
905 EFI_OPEN_PROTOCOL_GET_PROTOCOL
906 );
907 if (EFI_ERROR (Status)) {
908 return EFI_DEVICE_ERROR;
909 }
910
911 Private = ISCSI_DRIVER_DATA_FROM_IDENTIFIER (IScsiIdentifier);
912 ASSERT (Private != NULL);
913
914 if (Private->ChildHandle != NULL) {
915 Status = gBS->CloseProtocol (
916 Private->ChildHandle,
917 TcpProtocolGuid,
918 This->DriverBindingHandle,
919 IScsiController
920 );
921
922 ASSERT (!EFI_ERROR (Status));
923
924 Status = NetLibDestroyServiceChild (
925 IScsiController,
926 This->DriverBindingHandle,
927 TcpServiceBindingGuid,
928 Private->ChildHandle
929 );
930
931 ASSERT (!EFI_ERROR (Status));
932 }
933
934 gBS->UninstallProtocolInterface (
935 IScsiController,
936 ProtocolGuid,
937 &Private->IScsiIdentifier
938 );
939
940 //
941 // Remove this NIC.
942 //
943 IScsiRemoveNic (IScsiController);
944
945 //
946 // Update the iSCSI Boot Firware Table.
947 //
948 IScsiPublishIbft ();
949
950 if (Private->Session != NULL) {
951 IScsiSessionAbort (Private->Session);
952 }
953
954 IScsiCleanDriverData (Private);
955
956 return EFI_SUCCESS;
957}
958
959/**
960 Tests to see if this driver supports a given controller. If a child device is provided,
961 it tests to see if this driver supports creating a handle for the specified child device.
962
963 This function checks to see if the driver specified by This supports the device specified by
964 ControllerHandle. Drivers typically use the device path attached to
965 ControllerHandle and/or the services from the bus I/O abstraction attached to
966 ControllerHandle to determine if the driver supports ControllerHandle. This function
967 may be called many times during platform initialization. In order to reduce boot times, the tests
968 performed by this function must be very small and take as little time as possible to execute. This
969 function must not change the state of any hardware devices, and this function must be aware that the
970 device specified by ControllerHandle may already be managed by the same driver or a
971 different driver. This function must match its calls to AllocatePages() with FreePages(),
972 AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().
973 Since ControllerHandle may have been previously started by the same driver, if a protocol is
974 already in the opened state, then it must not be closed with CloseProtocol(). This is required
975 to guarantee the state of ControllerHandle is not modified by this function.
976
977 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
978 @param[in] ControllerHandle The handle of the controller to test. This handle
979 must support a protocol interface that supplies
980 an I/O abstraction to the driver.
981 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
982 parameter is ignored by device drivers, and is optional for bus
983 drivers. For bus drivers, if this parameter is not NULL, then
984 the bus driver must determine if the bus controller specified
985 by ControllerHandle and the child controller specified
986 by RemainingDevicePath are both supported by this
987 bus driver.
988
989 @retval EFI_SUCCESS The device specified by ControllerHandle and
990 RemainingDevicePath is supported by the driver specified by This.
991 @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and
992 RemainingDevicePath is already managed by the driver
993 specified by This.
994 @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and
995 RemainingDevicePath is already managed by a different
996 driver or an application that requires exclusive access.
997 Currently not implemented.
998 @retval EFI_UNSUPPORTED The device specified by ControllerHandle and
999 RemainingDevicePath is not supported by the driver specified by This.
1000**/
1001EFI_STATUS
1002EFIAPI
1003IScsiIp4DriverBindingSupported (
1004 IN EFI_DRIVER_BINDING_PROTOCOL *This,
1005 IN EFI_HANDLE ControllerHandle,
1006 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
1007 )
1008{
1009 return IScsiSupported (
1010 This,
1011 ControllerHandle,
1012 RemainingDevicePath,
1013 IP_VERSION_4
1014 );
1015}
1016
1017/**
1018 Starts a device controller or a bus controller.
1019
1020 The Start() function is designed to be invoked from the EFI boot service ConnectController().
1021 As a result, much of the error checking on the parameters to Start() has been moved into this
1022 common boot service. It is legal to call Start() from other locations,
1023 but the following calling restrictions must be followed or the system behavior will not be deterministic.
1024 1. ControllerHandle must be a valid EFI_HANDLE.
1025 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned
1026 EFI_DEVICE_PATH_PROTOCOL.
1027 3. Prior to calling Start(), the Supported() function for the driver specified by This must
1028 have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.
1029
1030 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
1031 @param[in] ControllerHandle The handle of the controller to start. This handle
1032 must support a protocol interface that supplies
1033 an I/O abstraction to the driver.
1034 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
1035 parameter is ignored by device drivers, and is optional for bus
1036 drivers. For a bus driver, if this parameter is NULL, then handles
1037 for all the children of Controller are created by this driver.
1038 If this parameter is not NULL and the first Device Path Node is
1039 not the End of Device Path Node, then only the handle for the
1040 child device specified by the first Device Path Node of
1041 RemainingDevicePath is created by this driver.
1042 If the first Device Path Node of RemainingDevicePath is
1043 the End of Device Path Node, no child handle is created by this
1044 driver.
1045
1046 @retval EFI_SUCCESS The device was started.
1047 @retval EFI_DEVICE_ERROR The device could not be started due to a device error. Currently not implemented.
1048 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
1049 @retval Others The driver failed to start the device.
1050
1051**/
1052EFI_STATUS
1053EFIAPI
1054IScsiIp4DriverBindingStart (
1055 IN EFI_DRIVER_BINDING_PROTOCOL *This,
1056 IN EFI_HANDLE ControllerHandle,
1057 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
1058 )
1059{
1060 EFI_STATUS Status;
1061
1062 Status = IScsiStart (This->DriverBindingHandle, ControllerHandle, IP_VERSION_4);
1063 if (Status == EFI_ALREADY_STARTED) {
1064 Status = EFI_SUCCESS;
1065 }
1066
1067 return Status;
1068}
1069
1070/**
1071 Stops a device controller or a bus controller.
1072
1073 The Stop() function is designed to be invoked from the EFI boot service DisconnectController().
1074 As a result, much of the error checking on the parameters to Stop() has been moved
1075 into this common boot service. It is legal to call Stop() from other locations,
1076 but the following calling restrictions must be followed or the system behavior will not be deterministic.
1077 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this
1078 same driver's Start() function.
1079 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid
1080 EFI_HANDLE. In addition, all of these handles must have been created in this driver's
1081 Start() function, and the Start() function must have called OpenProtocol() on
1082 ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.
1083
1084 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
1085 @param[in] ControllerHandle A handle to the device being stopped. The handle must
1086 support a bus specific I/O protocol for the driver
1087 to use to stop the device.
1088 @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.
1089 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL
1090 if NumberOfChildren is 0.
1091
1092 @retval EFI_SUCCESS The device was stopped.
1093 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
1094
1095**/
1096EFI_STATUS
1097EFIAPI
1098IScsiIp4DriverBindingStop (
1099 IN EFI_DRIVER_BINDING_PROTOCOL *This,
1100 IN EFI_HANDLE ControllerHandle,
1101 IN UINTN NumberOfChildren,
1102 IN EFI_HANDLE *ChildHandleBuffer OPTIONAL
1103 )
1104{
1105 return IScsiStop (
1106 This,
1107 ControllerHandle,
1108 NumberOfChildren,
1109 ChildHandleBuffer,
1110 IP_VERSION_4
1111 );
1112}
1113
1114/**
1115 Tests to see if this driver supports a given controller. If a child device is provided,
1116 it tests to see if this driver supports creating a handle for the specified child device.
1117
1118 This function checks to see if the driver specified by This supports the device specified by
1119 ControllerHandle. Drivers typically use the device path attached to
1120 ControllerHandle and/or the services from the bus I/O abstraction attached to
1121 ControllerHandle to determine if the driver supports ControllerHandle. This function
1122 may be called many times during platform initialization. In order to reduce boot times, the tests
1123 performed by this function must be very small and take as little time as possible to execute. This
1124 function must not change the state of any hardware devices, and this function must be aware that the
1125 device specified by ControllerHandle may already be managed by the same driver or a
1126 different driver. This function must match its calls to AllocatePages() with FreePages(),
1127 AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().
1128 Since ControllerHandle may have been previously started by the same driver, if a protocol is
1129 already in the opened state, then it must not be closed with CloseProtocol(). This is required
1130 to guarantee the state of ControllerHandle is not modified by this function.
1131
1132 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
1133 @param[in] ControllerHandle The handle of the controller to test. This handle
1134 must support a protocol interface that supplies
1135 an I/O abstraction to the driver.
1136 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
1137 parameter is ignored by device drivers, and is optional for bus
1138 drivers. For bus drivers, if this parameter is not NULL, then
1139 the bus driver must determine if the bus controller specified
1140 by ControllerHandle and the child controller specified
1141 by RemainingDevicePath are both supported by this
1142 bus driver.
1143
1144 @retval EFI_SUCCESS The device specified by ControllerHandle and
1145 RemainingDevicePath is supported by the driver specified by This.
1146 @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and
1147 RemainingDevicePath is already managed by the driver
1148 specified by This.
1149 @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and
1150 RemainingDevicePath is already managed by a different
1151 driver or an application that requires exclusive access.
1152 Currently not implemented.
1153 @retval EFI_UNSUPPORTED The device specified by ControllerHandle and
1154 RemainingDevicePath is not supported by the driver specified by This.
1155**/
1156EFI_STATUS
1157EFIAPI
1158IScsiIp6DriverBindingSupported (
1159 IN EFI_DRIVER_BINDING_PROTOCOL *This,
1160 IN EFI_HANDLE ControllerHandle,
1161 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
1162 )
1163{
1164 return IScsiSupported (
1165 This,
1166 ControllerHandle,
1167 RemainingDevicePath,
1168 IP_VERSION_6
1169 );
1170}
1171
1172/**
1173 Starts a device controller or a bus controller.
1174
1175 The Start() function is designed to be invoked from the EFI boot service ConnectController().
1176 As a result, much of the error checking on the parameters to Start() has been moved into this
1177 common boot service. It is legal to call Start() from other locations,
1178 but the following calling restrictions must be followed or the system behavior will not be deterministic.
1179 1. ControllerHandle must be a valid EFI_HANDLE.
1180 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned
1181 EFI_DEVICE_PATH_PROTOCOL.
1182 3. Prior to calling Start(), the Supported() function for the driver specified by This must
1183 have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.
1184
1185 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
1186 @param[in] ControllerHandle The handle of the controller to start. This handle
1187 must support a protocol interface that supplies
1188 an I/O abstraction to the driver.
1189 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
1190 parameter is ignored by device drivers, and is optional for bus
1191 drivers. For a bus driver, if this parameter is NULL, then handles
1192 for all the children of Controller are created by this driver.
1193 If this parameter is not NULL and the first Device Path Node is
1194 not the End of Device Path Node, then only the handle for the
1195 child device specified by the first Device Path Node of
1196 RemainingDevicePath is created by this driver.
1197 If the first Device Path Node of RemainingDevicePath is
1198 the End of Device Path Node, no child handle is created by this
1199 driver.
1200
1201 @retval EFI_SUCCESS The device was started.
1202 @retval EFI_DEVICE_ERROR The device could not be started due to a device error. Currently not implemented.
1203 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
1204 @retval Others The driver failed to start the device.
1205
1206**/
1207EFI_STATUS
1208EFIAPI
1209IScsiIp6DriverBindingStart (
1210 IN EFI_DRIVER_BINDING_PROTOCOL *This,
1211 IN EFI_HANDLE ControllerHandle,
1212 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
1213 )
1214{
1215 EFI_STATUS Status;
1216
1217 Status = IScsiStart (This->DriverBindingHandle, ControllerHandle, IP_VERSION_6);
1218 if (Status == EFI_ALREADY_STARTED) {
1219 Status = EFI_SUCCESS;
1220 }
1221
1222 return Status;
1223}
1224
1225/**
1226 Stops a device controller or a bus controller.
1227
1228 The Stop() function is designed to be invoked from the EFI boot service DisconnectController().
1229 As a result, much of the error checking on the parameters to Stop() has been moved
1230 into this common boot service. It is legal to call Stop() from other locations,
1231 but the following calling restrictions must be followed or the system behavior will not be deterministic.
1232 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this
1233 same driver's Start() function.
1234 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid
1235 EFI_HANDLE. In addition, all of these handles must have been created in this driver's
1236 Start() function, and the Start() function must have called OpenProtocol() on
1237 ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.
1238
1239 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
1240 @param[in] ControllerHandle A handle to the device being stopped. The handle must
1241 support a bus specific I/O protocol for the driver
1242 to use to stop the device.
1243 @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.
1244 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL
1245 if NumberOfChildren is 0.
1246
1247 @retval EFI_SUCCESS The device was stopped.
1248 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
1249
1250**/
1251EFI_STATUS
1252EFIAPI
1253IScsiIp6DriverBindingStop (
1254 IN EFI_DRIVER_BINDING_PROTOCOL *This,
1255 IN EFI_HANDLE ControllerHandle,
1256 IN UINTN NumberOfChildren,
1257 IN EFI_HANDLE *ChildHandleBuffer OPTIONAL
1258 )
1259{
1260 return IScsiStop (
1261 This,
1262 ControllerHandle,
1263 NumberOfChildren,
1264 ChildHandleBuffer,
1265 IP_VERSION_6
1266 );
1267}
1268
1269/**
1270 Unload the iSCSI driver.
1271
1272 @param[in] ImageHandle The handle of the driver image.
1273
1274 @retval EFI_SUCCESS The driver is unloaded.
1275 @retval EFI_DEVICE_ERROR An unexpected error occurred.
1276
1277**/
1278EFI_STATUS
1279EFIAPI
1280IScsiUnload (
1281 IN EFI_HANDLE ImageHandle
1282 )
1283{
1284 EFI_STATUS Status;
1285 UINTN DeviceHandleCount;
1286 EFI_HANDLE *DeviceHandleBuffer;
1287 UINTN Index;
1288 EFI_COMPONENT_NAME_PROTOCOL *ComponentName;
1289 EFI_COMPONENT_NAME2_PROTOCOL *ComponentName2;
1290
1291 //
1292 // Try to disonnect the driver from the devices it's controlling.
1293 //
1294 Status = gBS->LocateHandleBuffer (
1295 AllHandles,
1296 NULL,
1297 NULL,
1298 &DeviceHandleCount,
1299 &DeviceHandleBuffer
1300 );
1301 if (EFI_ERROR (Status)) {
1302 return Status;
1303 }
1304
1305 //
1306 // Disconnect the iSCSI4 driver from the controlled device.
1307 //
1308 for (Index = 0; Index < DeviceHandleCount; Index++) {
1309 Status = IScsiTestManagedDevice (
1310 DeviceHandleBuffer[Index],
1311 gIScsiIp4DriverBinding.DriverBindingHandle,
1312 &gEfiTcp4ProtocolGuid)
1313 ;
1314 if (EFI_ERROR (Status)) {
1315 continue;
1316 }
1317 Status = gBS->DisconnectController (
1318 DeviceHandleBuffer[Index],
1319 gIScsiIp4DriverBinding.DriverBindingHandle,
1320 NULL
1321 );
1322 if (EFI_ERROR (Status)) {
1323 goto ON_EXIT;
1324 }
1325 }
1326
1327 //
1328 // Disconnect the iSCSI6 driver from the controlled device.
1329 //
1330 for (Index = 0; Index < DeviceHandleCount; Index++) {
1331 Status = IScsiTestManagedDevice (
1332 DeviceHandleBuffer[Index],
1333 gIScsiIp6DriverBinding.DriverBindingHandle,
1334 &gEfiTcp6ProtocolGuid
1335 );
1336 if (EFI_ERROR (Status)) {
1337 continue;
1338 }
1339 Status = gBS->DisconnectController (
1340 DeviceHandleBuffer[Index],
1341 gIScsiIp6DriverBinding.DriverBindingHandle,
1342 NULL
1343 );
1344 if (EFI_ERROR (Status)) {
1345 goto ON_EXIT;
1346 }
1347 }
1348
1349 //
1350 // Unload the iSCSI configuration form.
1351 //
1352 Status = IScsiConfigFormUnload (gIScsiIp4DriverBinding.DriverBindingHandle);
1353 if (EFI_ERROR (Status)) {
1354 goto ON_EXIT;
1355 }
1356
1357 //
1358 // Uninstall the protocols installed by iSCSI driver.
1359 //
1360 Status = gBS->UninstallMultipleProtocolInterfaces (
1361 ImageHandle,
1362 &gEfiAuthenticationInfoProtocolGuid,
1363 &gIScsiAuthenticationInfo,
1364 NULL
1365 );
1366 if (EFI_ERROR (Status)) {
1367 goto ON_EXIT;
1368 }
1369
1370 if (gIScsiControllerNameTable!= NULL) {
1371 Status = FreeUnicodeStringTable (gIScsiControllerNameTable);
1372 if (EFI_ERROR (Status)) {
1373 goto ON_EXIT;
1374 }
1375 gIScsiControllerNameTable = NULL;
1376 }
1377
1378 //
1379 // Uninstall the ComponentName and ComponentName2 protocol from iSCSI4 driver binding handle
1380 // if it has been installed.
1381 //
1382 Status = gBS->HandleProtocol (
1383 gIScsiIp4DriverBinding.DriverBindingHandle,
1384 &gEfiComponentNameProtocolGuid,
1385 (VOID **) &ComponentName
1386 );
1387 if (!EFI_ERROR (Status)) {
1388 Status = gBS->UninstallMultipleProtocolInterfaces (
1389 gIScsiIp4DriverBinding.DriverBindingHandle,
1390 &gEfiComponentNameProtocolGuid,
1391 ComponentName,
1392 NULL
1393 );
1394 if (EFI_ERROR (Status)) {
1395 goto ON_EXIT;
1396 }
1397 }
1398
1399 Status = gBS->HandleProtocol (
1400 gIScsiIp4DriverBinding.DriverBindingHandle,
1401 &gEfiComponentName2ProtocolGuid,
1402 (VOID **) &ComponentName2
1403 );
1404 if (!EFI_ERROR (Status)) {
1405 gBS->UninstallMultipleProtocolInterfaces (
1406 gIScsiIp4DriverBinding.DriverBindingHandle,
1407 &gEfiComponentName2ProtocolGuid,
1408 ComponentName2,
1409 NULL
1410 );
1411 if (EFI_ERROR (Status)) {
1412 goto ON_EXIT;
1413 }
1414 }
1415
1416 //
1417 // Uninstall the ComponentName and ComponentName2 protocol from iSCSI6 driver binding handle
1418 // if it has been installed.
1419 //
1420 Status = gBS->HandleProtocol (
1421 gIScsiIp6DriverBinding.DriverBindingHandle,
1422 &gEfiComponentNameProtocolGuid,
1423 (VOID **) &ComponentName
1424 );
1425 if (!EFI_ERROR (Status)) {
1426 Status = gBS->UninstallMultipleProtocolInterfaces (
1427 gIScsiIp6DriverBinding.DriverBindingHandle,
1428 &gEfiComponentNameProtocolGuid,
1429 ComponentName,
1430 NULL
1431 );
1432 if (EFI_ERROR (Status)) {
1433 goto ON_EXIT;
1434 }
1435 }
1436
1437 Status = gBS->HandleProtocol (
1438 gIScsiIp6DriverBinding.DriverBindingHandle,
1439 &gEfiComponentName2ProtocolGuid,
1440 (VOID **) &ComponentName2
1441 );
1442 if (!EFI_ERROR (Status)) {
1443 gBS->UninstallMultipleProtocolInterfaces (
1444 gIScsiIp6DriverBinding.DriverBindingHandle,
1445 &gEfiComponentName2ProtocolGuid,
1446 ComponentName2,
1447 NULL
1448 );
1449 if (EFI_ERROR (Status)) {
1450 goto ON_EXIT;
1451 }
1452 }
1453
1454 //
1455 // Uninstall the IScsiInitiatorNameProtocol and all the driver binding protocols.
1456 //
1457 Status = gBS->UninstallMultipleProtocolInterfaces (
1458 gIScsiIp4DriverBinding.DriverBindingHandle,
1459 &gEfiDriverBindingProtocolGuid,
1460 &gIScsiIp4DriverBinding,
1461 &gEfiIScsiInitiatorNameProtocolGuid,
1462 &gIScsiInitiatorName,
1463 NULL
1464 );
1465 if (EFI_ERROR (Status)) {
1466 goto ON_EXIT;
1467 }
1468
1469 Status = gBS->UninstallMultipleProtocolInterfaces (
1470 gIScsiIp6DriverBinding.DriverBindingHandle,
1471 &gEfiDriverBindingProtocolGuid,
1472 &gIScsiIp6DriverBinding,
1473 NULL
1474 );
1475
1476ON_EXIT:
1477
1478 if (DeviceHandleBuffer != NULL) {
1479 FreePool (DeviceHandleBuffer);
1480 }
1481
1482 return Status;
1483}
1484
1485/**
1486 This is the declaration of an EFI image entry point. This entry point is
1487 the same for UEFI Applications, UEFI OS Loaders, and UEFI Drivers including
1488 both device drivers and bus drivers.
1489
1490 The entry point for iSCSI driver which initializes the global variables and
1491 installs the driver binding, component name protocol, iSCSI initiator name
1492 protocol and Authentication Info protocol on its image.
1493
1494 @param[in] ImageHandle The firmware allocated handle for the UEFI image.
1495 @param[in] SystemTable A pointer to the EFI System Table.
1496
1497 @retval EFI_SUCCESS The operation completed successfully.
1498 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
1499
1500**/
1501EFI_STATUS
1502EFIAPI
1503IScsiDriverEntryPoint (
1504 IN EFI_HANDLE ImageHandle,
1505 IN EFI_SYSTEM_TABLE *SystemTable
1506 )
1507{
1508 EFI_STATUS Status;
1509 EFI_ISCSI_INITIATOR_NAME_PROTOCOL *IScsiInitiatorName;
1510 EFI_AUTHENTICATION_INFO_PROTOCOL *AuthenticationInfo;
1511
1512 //
1513 // There should be only one EFI_ISCSI_INITIATOR_NAME_PROTOCOL.
1514 //
1515 Status = gBS->LocateProtocol (
1516 &gEfiIScsiInitiatorNameProtocolGuid,
1517 NULL,
1518 (VOID **) &IScsiInitiatorName
1519 );
1520 if (!EFI_ERROR (Status)) {
1521 return EFI_ACCESS_DENIED;
1522 }
1523
1524 //
1525 // Initialize the EFI Driver Library.
1526 //
1527 Status = EfiLibInstallDriverBindingComponentName2 (
1528 ImageHandle,
1529 SystemTable,
1530 &gIScsiIp4DriverBinding,
1531 ImageHandle,
1532 &gIScsiComponentName,
1533 &gIScsiComponentName2
1534 );
1535 if (EFI_ERROR (Status)) {
1536 return Status;
1537 }
1538
1539 Status = EfiLibInstallDriverBindingComponentName2 (
1540 ImageHandle,
1541 SystemTable,
1542 &gIScsiIp6DriverBinding,
1543 NULL,
1544 &gIScsiComponentName,
1545 &gIScsiComponentName2
1546 );
1547 if (EFI_ERROR (Status)) {
1548 goto Error1;
1549 }
1550
1551 //
1552 // Install the iSCSI Initiator Name Protocol.
1553 //
1554 Status = gBS->InstallProtocolInterface (
1555 &ImageHandle,
1556 &gEfiIScsiInitiatorNameProtocolGuid,
1557 EFI_NATIVE_INTERFACE,
1558 &gIScsiInitiatorName
1559 );
1560 if (EFI_ERROR (Status)) {
1561 goto Error2;
1562 }
1563
1564 //
1565 // Create the private data structures.
1566 //
1567 mPrivate = AllocateZeroPool (sizeof (ISCSI_PRIVATE_DATA));
1568 if (mPrivate == NULL) {
1569 Status = EFI_OUT_OF_RESOURCES;
1570 goto Error3;
1571 }
1572
1573 InitializeListHead (&mPrivate->NicInfoList);
1574 InitializeListHead (&mPrivate->AttemptConfigs);
1575
1576 //
1577 // Initialize the configuration form of iSCSI.
1578 //
1579 Status = IScsiConfigFormInit (gIScsiIp4DriverBinding.DriverBindingHandle);
1580 if (EFI_ERROR (Status)) {
1581 goto Error4;
1582 }
1583
1584 //
1585 // There should be only one EFI_AUTHENTICATION_INFO_PROTOCOL. If already exists,
1586 // do not produce the protocol instance.
1587 //
1588 Status = gBS->LocateProtocol (
1589 &gEfiAuthenticationInfoProtocolGuid,
1590 NULL,
1591 (VOID **) &AuthenticationInfo
1592 );
1593 if (Status == EFI_NOT_FOUND) {
1594 Status = gBS->InstallProtocolInterface (
1595 &ImageHandle,
1596 &gEfiAuthenticationInfoProtocolGuid,
1597 EFI_NATIVE_INTERFACE,
1598 &gIScsiAuthenticationInfo
1599 );
1600 if (EFI_ERROR (Status)) {
1601 goto Error5;
1602 }
1603 }
1604
1605 return EFI_SUCCESS;
1606
1607Error5:
1608 IScsiConfigFormUnload (gIScsiIp4DriverBinding.DriverBindingHandle);
1609
1610Error4:
1611 FreePool (mPrivate);
1612
1613Error3:
1614 gBS->UninstallMultipleProtocolInterfaces (
1615 ImageHandle,
1616 &gEfiIScsiInitiatorNameProtocolGuid,
1617 &gIScsiInitiatorName,
1618 NULL
1619 );
1620
1621Error2:
1622 gBS->UninstallMultipleProtocolInterfaces (
1623 gIScsiIp6DriverBinding.DriverBindingHandle,
1624 &gEfiDriverBindingProtocolGuid,
1625 &gIScsiIp6DriverBinding,
1626 &gEfiComponentName2ProtocolGuid,
1627 &gIScsiComponentName2,
1628 &gEfiComponentNameProtocolGuid,
1629 &gIScsiComponentName,
1630 NULL
1631 );
1632
1633Error1:
1634 gBS->UninstallMultipleProtocolInterfaces (
1635 ImageHandle,
1636 &gEfiDriverBindingProtocolGuid,
1637 &gIScsiIp4DriverBinding,
1638 &gEfiComponentName2ProtocolGuid,
1639 &gIScsiComponentName2,
1640 &gEfiComponentNameProtocolGuid,
1641 &gIScsiComponentName,
1642 NULL
1643 );
1644
1645 return Status;
1646}
1647
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette