2 The entry point of IScsi driver
4 Copyright (c) 2004 - 2008, Intel Corporation
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 The entry point of IScsi driver
22 #include "IScsiImpl.h"
24 EFI_DRIVER_BINDING_PROTOCOL gIScsiDriverBinding
= {
25 IScsiDriverBindingSupported
,
26 IScsiDriverBindingStart
,
27 IScsiDriverBindingStop
,
33 EFI_GUID mIScsiPrivateGuid
= ISCSI_PRIVATE_GUID
;
36 Test to see if IScsi driver supports the given controller.
38 @param This[in] Protocol instance pointer.
40 @param ControllerHandle[in] Handle of controller to test.
42 @param RemainingDevicePath[in] Optional parameter use to pick a specific child device to start.
44 @retval EFI_SUCCES This driver supports the controller.
46 @retval EFI_ALREADY_STARTED This driver is already running on this device.
48 @retval EFI_UNSUPPORTED This driver doesn't support the controller.
53 IScsiDriverBindingSupported (
54 IN EFI_DRIVER_BINDING_PROTOCOL
* This
,
55 IN EFI_HANDLE ControllerHandle
,
56 IN EFI_DEVICE_PATH_PROTOCOL
* RemainingDevicePath OPTIONAL
60 EFI_DEVICE_PATH_PROTOCOL
*CurrentDevicePath
;
62 Status
= gBS
->OpenProtocol (
66 This
->DriverBindingHandle
,
68 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
70 if (!EFI_ERROR (Status
)) {
71 return EFI_ALREADY_STARTED
;
74 Status
= gBS
->OpenProtocol (
76 &gEfiTcp4ServiceBindingProtocolGuid
,
78 This
->DriverBindingHandle
,
80 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
82 if (EFI_ERROR (Status
)) {
83 return EFI_UNSUPPORTED
;
86 CurrentDevicePath
= RemainingDevicePath
;
87 if (CurrentDevicePath
!= NULL
) {
88 while (!IsDevicePathEnd (CurrentDevicePath
)) {
89 if ((CurrentDevicePath
->Type
== MESSAGING_DEVICE_PATH
) && (CurrentDevicePath
->SubType
== MSG_ISCSI_DP
)) {
93 CurrentDevicePath
= NextDevicePathNode (CurrentDevicePath
);
96 return EFI_UNSUPPORTED
;
103 Start to manage the controller.
105 @param This[in] Protocol instance pointer.
107 @param ControllerHandle[in] Handle of the controller.
109 @param RemainingDevicePath[in] Optional parameter use to pick a specific child device to start.
111 @retval EFI_SUCCES This driver supports this device.
113 @retval EFI_ALREADY_STARTED This driver is already running on this device.
118 IScsiDriverBindingStart (
119 IN EFI_DRIVER_BINDING_PROTOCOL
* This
,
120 IN EFI_HANDLE ControllerHandle
,
121 IN EFI_DEVICE_PATH_PROTOCOL
* RemainingDevicePath OPTIONAL
125 ISCSI_DRIVER_DATA
*Private
;
128 // Try to add a port configuration page for this controller.
130 IScsiConfigUpdateForm (This
->DriverBindingHandle
, ControllerHandle
, TRUE
);
132 Private
= IScsiCreateDriverData (This
->DriverBindingHandle
, ControllerHandle
);
133 if (Private
== NULL
) {
134 return EFI_OUT_OF_RESOURCES
;
137 // Get the iSCSI configuration data of this controller.
139 Status
= IScsiGetConfigData (Private
);
140 if (EFI_ERROR (Status
)) {
144 // Try to login and create an iSCSI session according to the configuration.
146 Status
= IScsiSessionLogin (Private
);
147 if (Status
== EFI_MEDIA_CHANGED
) {
149 // The specified target is not available and the redirection information is
150 // got, login the session again with the updated target address.
152 Status
= IScsiSessionLogin (Private
);
155 if (EFI_ERROR (Status
)) {
159 // Duplicate the Session's tcp connection device path. The source port field
160 // will be set to zero as one iSCSI session is comprised of several iSCSI
163 Private
->DevicePath
= IScsiGetTcpConnDevicePath (Private
);
164 if (Private
->DevicePath
== NULL
) {
168 // Install the updated device path onto the ExtScsiPassThruHandle.
170 Status
= gBS
->InstallProtocolInterface (
171 &Private
->ExtScsiPassThruHandle
,
172 &gEfiDevicePathProtocolGuid
,
173 EFI_NATIVE_INTERFACE
,
176 if (EFI_ERROR (Status
)) {
180 // Install the iSCSI private stuff as a flag to indicate this controller
181 // is already controlled by iSCSI driver.
183 Status
= gBS
->InstallProtocolInterface (
186 EFI_NATIVE_INTERFACE
,
187 &Private
->IScsiIdentifier
189 if (EFI_ERROR (Status
)) {
193 // Update/Publish the iSCSI Boot Firmware Table.
201 IScsiSessionAbort (&Private
->Session
);
202 IScsiCleanDriverData (Private
);
208 Release the control of this controller and remove the IScsi functions.
210 @param This[in] Protocol instance pointer.
212 @param ControllerHandle[in] Handle of controller to stop.
214 @param NumberOfChildren[in] Not used.
216 @param ChildHandleBuffer[in] Not used.
218 @retval EFI_SUCCES This driver supports this device.
223 IScsiDriverBindingStop (
224 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
225 IN EFI_HANDLE ControllerHandle
,
226 IN UINTN NumberOfChildren
,
227 IN EFI_HANDLE
*ChildHandleBuffer
230 EFI_HANDLE IScsiController
;
232 ISCSI_PRIVATE_PROTOCOL
*IScsiIdentifier
;
233 ISCSI_DRIVER_DATA
*Private
;
234 EFI_EXT_SCSI_PASS_THRU_PROTOCOL
*PassThru
;
235 ISCSI_CONNECTION
*Conn
;
237 if (NumberOfChildren
!= 0) {
239 // We should have only one child.
241 Status
= gBS
->OpenProtocol (
242 ChildHandleBuffer
[0],
243 &gEfiExtScsiPassThruProtocolGuid
,
245 This
->DriverBindingHandle
,
247 EFI_OPEN_PROTOCOL_GET_PROTOCOL
249 if (EFI_ERROR (Status
)) {
250 return EFI_DEVICE_ERROR
;
253 Private
= ISCSI_DRIVER_DATA_FROM_EXT_SCSI_PASS_THRU (PassThru
);
254 Conn
= NET_LIST_HEAD (&Private
->Session
.Conns
, ISCSI_CONNECTION
, Link
);
257 // Previously the TCP4 protocol is opened BY_CHILD_CONTROLLER. Just close
258 // the protocol here but not uninstall the device path protocol and
259 // EXT SCSI PASS THRU protocol installed on ExtScsiPassThruHandle.
263 &gEfiTcp4ProtocolGuid
,
265 Private
->ExtScsiPassThruHandle
271 // Get the handle of the controller we are controling.
273 IScsiController
= NetLibGetNicHandle (ControllerHandle
, &gEfiTcp4ProtocolGuid
);
275 Status
= gBS
->OpenProtocol (
278 (VOID
**)&IScsiIdentifier
,
279 This
->DriverBindingHandle
,
281 EFI_OPEN_PROTOCOL_GET_PROTOCOL
283 if (EFI_ERROR (Status
)) {
284 return EFI_DEVICE_ERROR
;
287 Private
= ISCSI_DRIVER_DATA_FROM_IDENTIFIER (IScsiIdentifier
);
290 // Uninstall the private protocol.
292 gBS
->UninstallProtocolInterface (
295 &Private
->IScsiIdentifier
299 // Update the iSCSI Boot Firware Table.
303 IScsiSessionAbort (&Private
->Session
);
304 IScsiCleanDriverData (Private
);
310 Unload the iSCSI driver.
312 @param ImageHandle[in] The handle of the driver image.
314 @retval EFI_SUCCESS The driver is unloaded.
316 @retval EFI_DEVICE_ERROR Some unexpected error happened.
322 IN EFI_HANDLE ImageHandle
326 UINTN DeviceHandleCount
;
327 EFI_HANDLE
*DeviceHandleBuffer
;
331 // Try to disonnect the driver from the devices it's controlling.
333 Status
= gBS
->LocateHandleBuffer (
340 if (!EFI_ERROR (Status
)) {
341 for (Index
= 0; Index
< DeviceHandleCount
; Index
++) {
342 Status
= gBS
->DisconnectController (
343 DeviceHandleBuffer
[Index
],
349 if (DeviceHandleBuffer
!= NULL
) {
350 gBS
->FreePool (DeviceHandleBuffer
);
354 // Unload the iSCSI configuration form.
356 IScsiConfigFormUnload (gIScsiDriverBinding
.DriverBindingHandle
);
359 // Uninstall the protocols installed by iSCSI driver.
361 Status
= gBS
->UninstallMultipleProtocolInterfaces (
363 &gEfiDriverBindingProtocolGuid
,
364 &gIScsiDriverBinding
,
365 &gEfiComponentName2ProtocolGuid
,
366 &gIScsiComponentName2
,
367 &gEfiComponentNameProtocolGuid
,
368 &gIScsiComponentName
,
369 &gEfiIScsiInitiatorNameProtocolGuid
,
370 &gIScsiInitiatorName
,
378 Initialize the global variables publish the driver binding protocol.
380 @param ImageHandle[in] The handle of the driver image.
382 @param SystemTable[in] The EFI system table.
384 @retval EFI_SUCCESS The protocols are installed.
386 @retval EFI_DEVICE_ERROR Some unexpected error happened.
391 IScsiDriverEntryPoint (
392 IN EFI_HANDLE ImageHandle
,
393 IN EFI_SYSTEM_TABLE
*SystemTable
397 EFI_ISCSI_INITIATOR_NAME_PROTOCOL
*IScsiInitiatorName
;
400 // There should be only one EFI_ISCSI_INITIATOR_NAME_PROTOCOL.
402 Status
= gBS
->LocateProtocol (
403 &gEfiIScsiInitiatorNameProtocolGuid
,
405 (VOID
**) &IScsiInitiatorName
408 if (!EFI_ERROR (Status
)) {
409 return EFI_ACCESS_DENIED
;
413 // Initialize the EFI Driver Library
415 Status
= EfiLibInstallDriverBindingComponentName2 (
418 &gIScsiDriverBinding
,
420 &gIScsiComponentName
,
421 &gIScsiComponentName2
424 if (!EFI_ERROR (Status
)) {
426 // Install the iSCSI Initiator Name Protocol.
428 Status
= gBS
->InstallProtocolInterface (
430 &gEfiIScsiInitiatorNameProtocolGuid
,
431 EFI_NATIVE_INTERFACE
,
434 if (EFI_ERROR (Status
)) {
435 gBS
->UninstallMultipleProtocolInterfaces (
437 &gEfiDriverBindingProtocolGuid
,
438 &gIScsiDriverBinding
,
439 &gEfiComponentName2ProtocolGuid
,
440 &gIScsiComponentName2
,
441 &gEfiComponentNameProtocolGuid
,
442 &gIScsiComponentName
,
449 // Initialize the configuration form of iSCSI.
451 Status
= IScsiConfigFormInit (gIScsiDriverBinding
.DriverBindingHandle
);
452 if (EFI_ERROR (Status
)) {
453 gBS
->UninstallMultipleProtocolInterfaces (
455 &gEfiDriverBindingProtocolGuid
,
456 &gIScsiDriverBinding
,
457 &gEfiComponentName2ProtocolGuid
,
458 &gIScsiComponentName2
,
459 &gEfiComponentNameProtocolGuid
,
460 &gIScsiComponentName
,
461 &gEfiIScsiInitiatorNameProtocolGuid
,
462 &gIScsiInitiatorName
,