2 The entry point of IScsi driver.
4 Copyright (c) 2004 - 2008, Intel Corporation.<BR>
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.
15 #include "IScsiImpl.h"
17 EFI_DRIVER_BINDING_PROTOCOL gIScsiDriverBinding
= {
18 IScsiDriverBindingSupported
,
19 IScsiDriverBindingStart
,
20 IScsiDriverBindingStop
,
26 EFI_GUID mIScsiPrivateGuid
= ISCSI_PRIVATE_GUID
;
30 Tests to see if this driver supports a given controller. If a child device is provided,
31 it further tests to see if this driver supports creating a handle for the specified child device.
33 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
34 @param[in] ControllerHandle The handle of the controller to test. This handle
35 must support a protocol interface that supplies
36 an I/O abstraction to the driver.
37 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path.
38 This parameter is ignored by device drivers, and is optional for bus drivers.
41 @retval EFI_SUCCESS The device specified by ControllerHandle and
42 RemainingDevicePath is supported by the driver specified by This.
43 @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and
44 RemainingDevicePath is already being managed by the driver
46 @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and
47 RemainingDevicePath is already being managed by a different
48 driver or an application that requires exclusive acces.
49 Currently not implemented.
50 @retval EFI_UNSUPPORTED The device specified by ControllerHandle and
51 RemainingDevicePath is not supported by the driver specified by This.
55 IScsiDriverBindingSupported (
56 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
57 IN EFI_HANDLE ControllerHandle
,
58 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
62 EFI_DEVICE_PATH_PROTOCOL
*CurrentDevicePath
;
64 Status
= gBS
->OpenProtocol (
68 This
->DriverBindingHandle
,
70 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
72 if (!EFI_ERROR (Status
)) {
73 return EFI_ALREADY_STARTED
;
76 Status
= gBS
->OpenProtocol (
78 &gEfiTcp4ServiceBindingProtocolGuid
,
80 This
->DriverBindingHandle
,
82 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
84 if (EFI_ERROR (Status
)) {
85 return EFI_UNSUPPORTED
;
88 CurrentDevicePath
= RemainingDevicePath
;
89 if (CurrentDevicePath
!= NULL
) {
90 while (!IsDevicePathEnd (CurrentDevicePath
)) {
91 if ((CurrentDevicePath
->Type
== MESSAGING_DEVICE_PATH
) && (CurrentDevicePath
->SubType
== MSG_ISCSI_DP
)) {
95 CurrentDevicePath
= NextDevicePathNode (CurrentDevicePath
);
98 return EFI_UNSUPPORTED
;
105 Start this driver on ControllerHandle. The Start() function is designed to be
106 invoked from the EFI boot service ConnectController(). As a result, much of
107 the error checking on the parameters to Start() has been moved into this
108 common boot service. It is legal to call Start() from other locations,
109 but the following calling restrictions must be followed or the system behavior will not be deterministic.
110 1. ControllerHandle must be a valid EFI_HANDLE.
111 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned
112 EFI_DEVICE_PATH_PROTOCOL.
113 3. Prior to calling Start(), the Supported() function for the driver specified by This must
114 have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.
116 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
117 @param[in] ControllerHandle The handle of the controller to start. This handle
118 must support a protocol interface that supplies
119 an I/O abstraction to the driver.
120 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path.
121 This parameter is ignored by device drivers, and is optional for bus drivers.
123 @retval EFI_SUCCESS The device was started.
124 @retval EFI_DEVICE_ERROR The device could not be started due to a device error.
125 Currently not implemented.
126 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
127 @retval Others The driver failded to start the device.
131 IScsiDriverBindingStart (
132 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
133 IN EFI_HANDLE ControllerHandle
,
134 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
138 ISCSI_DRIVER_DATA
*Private
;
141 // Try to add a port configuration page for this controller.
143 IScsiConfigUpdateForm (This
->DriverBindingHandle
, ControllerHandle
, TRUE
);
145 Private
= IScsiCreateDriverData (This
->DriverBindingHandle
, ControllerHandle
);
146 if (Private
== NULL
) {
147 return EFI_OUT_OF_RESOURCES
;
150 // Get the iSCSI configuration data of this controller.
152 Status
= IScsiGetConfigData (Private
);
153 if (EFI_ERROR (Status
)) {
157 // Try to login and create an iSCSI session according to the configuration.
159 Status
= IScsiSessionLogin (Private
);
160 if (Status
== EFI_MEDIA_CHANGED
) {
162 // The specified target is not available and the redirection information is
163 // got, login the session again with the updated target address.
165 Status
= IScsiSessionLogin (Private
);
168 if (EFI_ERROR (Status
)) {
172 // Duplicate the Session's tcp connection device path. The source port field
173 // will be set to zero as one iSCSI session is comprised of several iSCSI
176 Private
->DevicePath
= IScsiGetTcpConnDevicePath (Private
);
177 if (Private
->DevicePath
== NULL
) {
181 // Install the updated device path onto the ExtScsiPassThruHandle.
183 Status
= gBS
->InstallProtocolInterface (
184 &Private
->ExtScsiPassThruHandle
,
185 &gEfiDevicePathProtocolGuid
,
186 EFI_NATIVE_INTERFACE
,
189 if (EFI_ERROR (Status
)) {
193 // Install the iSCSI private stuff as a flag to indicate this controller
194 // is already controlled by iSCSI driver.
196 Status
= gBS
->InstallProtocolInterface (
199 EFI_NATIVE_INTERFACE
,
200 &Private
->IScsiIdentifier
202 if (EFI_ERROR (Status
)) {
206 // Update/Publish the iSCSI Boot Firmware Table.
214 IScsiSessionAbort (&Private
->Session
);
215 IScsiCleanDriverData (Private
);
221 Stop this driver on ControllerHandle.
223 Release the control of this controller and remove the IScsi functions. The Stop()
224 function is designed to be invoked from the EFI boot service DisconnectController().
225 As a result, much of the error checking on the parameters to Stop() has been moved
226 into this common boot service. It is legal to call Stop() from other locations,
227 but the following calling restrictions must be followed or the system behavior will not be deterministic.
228 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this
229 same driver's Start() function.
230 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid
231 EFI_HANDLE. In addition, all of these handles must have been created in this driver's
232 Start() function, and the Start() function must have called OpenProtocol() on
233 ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.
235 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
236 @param[in] ControllerHandle A handle to the device being stopped. The handle must
237 support a bus specific I/O protocol for the driver
238 to use to stop the device.
239 @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.Not used.
240 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL
241 if NumberOfChildren is 0.Not used.
243 @retval EFI_SUCCESS The device was stopped.
244 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
248 IScsiDriverBindingStop (
249 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
250 IN EFI_HANDLE ControllerHandle
,
251 IN UINTN NumberOfChildren
,
252 IN EFI_HANDLE
*ChildHandleBuffer
255 EFI_HANDLE IScsiController
;
257 ISCSI_PRIVATE_PROTOCOL
*IScsiIdentifier
;
258 ISCSI_DRIVER_DATA
*Private
;
259 EFI_EXT_SCSI_PASS_THRU_PROTOCOL
*PassThru
;
260 ISCSI_CONNECTION
*Conn
;
262 if (NumberOfChildren
!= 0) {
264 // We should have only one child.
266 Status
= gBS
->OpenProtocol (
267 ChildHandleBuffer
[0],
268 &gEfiExtScsiPassThruProtocolGuid
,
270 This
->DriverBindingHandle
,
272 EFI_OPEN_PROTOCOL_GET_PROTOCOL
274 if (EFI_ERROR (Status
)) {
275 return EFI_DEVICE_ERROR
;
278 Private
= ISCSI_DRIVER_DATA_FROM_EXT_SCSI_PASS_THRU (PassThru
);
279 Conn
= NET_LIST_HEAD (&Private
->Session
.Conns
, ISCSI_CONNECTION
, Link
);
282 // Previously the TCP4 protocol is opened BY_CHILD_CONTROLLER. Just close
283 // the protocol here but not uninstall the device path protocol and
284 // EXT SCSI PASS THRU protocol installed on ExtScsiPassThruHandle.
288 &gEfiTcp4ProtocolGuid
,
290 Private
->ExtScsiPassThruHandle
296 // Get the handle of the controller we are controling.
298 IScsiController
= NetLibGetNicHandle (ControllerHandle
, &gEfiTcp4ProtocolGuid
);
300 Status
= gBS
->OpenProtocol (
303 (VOID
**)&IScsiIdentifier
,
304 This
->DriverBindingHandle
,
306 EFI_OPEN_PROTOCOL_GET_PROTOCOL
308 if (EFI_ERROR (Status
)) {
309 return EFI_DEVICE_ERROR
;
312 Private
= ISCSI_DRIVER_DATA_FROM_IDENTIFIER (IScsiIdentifier
);
315 // Uninstall the private protocol.
317 gBS
->UninstallProtocolInterface (
320 &Private
->IScsiIdentifier
324 // Update the iSCSI Boot Firware Table.
328 IScsiSessionAbort (&Private
->Session
);
329 IScsiCleanDriverData (Private
);
335 Unloads an image(the iSCSI driver).
337 @param[in] ImageHandle Handle that identifies the image to be unloaded.
339 @retval EFI_SUCCESS The image has been unloaded.
340 @retval Others Other errors as indicated.
345 IN EFI_HANDLE ImageHandle
349 UINTN DeviceHandleCount
;
350 EFI_HANDLE
*DeviceHandleBuffer
;
354 // Try to disonnect the driver from the devices it's controlling.
356 Status
= gBS
->LocateHandleBuffer (
363 if (!EFI_ERROR (Status
)) {
364 for (Index
= 0; Index
< DeviceHandleCount
; Index
++) {
365 Status
= gBS
->DisconnectController (
366 DeviceHandleBuffer
[Index
],
372 if (DeviceHandleBuffer
!= NULL
) {
373 gBS
->FreePool (DeviceHandleBuffer
);
377 // Unload the iSCSI configuration form.
379 IScsiConfigFormUnload (gIScsiDriverBinding
.DriverBindingHandle
);
382 // Uninstall the protocols installed by iSCSI driver.
384 Status
= gBS
->UninstallMultipleProtocolInterfaces (
386 &gEfiDriverBindingProtocolGuid
,
387 &gIScsiDriverBinding
,
388 &gEfiComponentName2ProtocolGuid
,
389 &gIScsiComponentName2
,
390 &gEfiComponentNameProtocolGuid
,
391 &gIScsiComponentName
,
392 &gEfiIScsiInitiatorNameProtocolGuid
,
393 &gIScsiInitiatorName
,
401 This is the declaration of an EFI image entry point. This entry point is
402 the same for UEFI Applications, UEFI OS Loaders, and UEFI Drivers including
403 both device drivers and bus drivers. It initialize the global variables and
404 publish the driver binding protocol.
406 @param[in] ImageHandle The firmware allocated handle for the UEFI image.
407 @param[in] SystemTable A pointer to the EFI System Table.
409 @retval EFI_SUCCESS The operation completed successfully.
410 @retval EFI_ACCESS_DENIED EFI_ISCSI_INITIATOR_NAME_PROTOCOL was installed unexpectedly.
411 @retval Others Other errors as indicated.
415 IScsiDriverEntryPoint (
416 IN EFI_HANDLE ImageHandle
,
417 IN EFI_SYSTEM_TABLE
*SystemTable
421 EFI_ISCSI_INITIATOR_NAME_PROTOCOL
*IScsiInitiatorName
;
424 // There should be only one EFI_ISCSI_INITIATOR_NAME_PROTOCOL.
426 Status
= gBS
->LocateProtocol (
427 &gEfiIScsiInitiatorNameProtocolGuid
,
429 (VOID
**) &IScsiInitiatorName
432 if (!EFI_ERROR (Status
)) {
433 return EFI_ACCESS_DENIED
;
437 // Initialize the EFI Driver Library
439 Status
= EfiLibInstallDriverBindingComponentName2 (
442 &gIScsiDriverBinding
,
444 &gIScsiComponentName
,
445 &gIScsiComponentName2
448 if (!EFI_ERROR (Status
)) {
450 // Install the iSCSI Initiator Name Protocol.
452 Status
= gBS
->InstallProtocolInterface (
454 &gEfiIScsiInitiatorNameProtocolGuid
,
455 EFI_NATIVE_INTERFACE
,
458 if (EFI_ERROR (Status
)) {
459 gBS
->UninstallMultipleProtocolInterfaces (
461 &gEfiDriverBindingProtocolGuid
,
462 &gIScsiDriverBinding
,
463 &gEfiComponentName2ProtocolGuid
,
464 &gIScsiComponentName2
,
465 &gEfiComponentNameProtocolGuid
,
466 &gIScsiComponentName
,
473 // Initialize the configuration form of iSCSI.
475 Status
= IScsiConfigFormInit ();
476 if (EFI_ERROR (Status
)) {
477 gBS
->UninstallMultipleProtocolInterfaces (
479 &gEfiDriverBindingProtocolGuid
,
480 &gIScsiDriverBinding
,
481 &gEfiComponentName2ProtocolGuid
,
482 &gIScsiComponentName2
,
483 &gEfiComponentNameProtocolGuid
,
484 &gIScsiComponentName
,
485 &gEfiIScsiInitiatorNameProtocolGuid
,
486 &gIScsiInitiatorName
,