Commit | Line | Data |
---|---|---|
12618416 | 1 | /** @file\r |
fd82de4e | 2 | The entry point of IScsi driver.\r |
6a690e23 | 3 | \r |
d1102dba | 4 | Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.<BR>\r |
e5eed7d3 | 5 | This program and the accompanying materials\r |
7a444476 | 6 | are licensed and made available under the terms and conditions of the BSD License\r |
7 | which accompanies this distribution. The full text of the license may be found at\r | |
8 | http://opensource.org/licenses/bsd-license.php\r | |
9 | \r | |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
6a690e23 | 12 | \r |
12618416 | 13 | **/\r |
6a690e23 | 14 | \r |
15 | #include "IScsiImpl.h"\r | |
16 | \r | |
17 | EFI_DRIVER_BINDING_PROTOCOL gIScsiDriverBinding = {\r | |
18 | IScsiDriverBindingSupported,\r | |
19 | IScsiDriverBindingStart,\r | |
20 | IScsiDriverBindingStop,\r | |
21 | 0xa,\r | |
22 | NULL,\r | |
23 | NULL\r | |
24 | };\r | |
25 | \r | |
05a30011 | 26 | /**\r |
d1102dba LG |
27 | Tests to see if this driver supports the RemainingDevicePath.\r |
28 | \r | |
29 | @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This\r | |
30 | parameter is ignored by device drivers, and is optional for bus\r | |
31 | drivers. For bus drivers, if this parameter is not NULL, then\r | |
32 | the bus driver must determine if the bus controller specified\r | |
33 | by ControllerHandle and the child controller specified\r | |
34 | by RemainingDevicePath are both supported by this\r | |
05a30011 WJ |
35 | bus driver.\r |
36 | \r | |
37 | @retval EFI_SUCCESS The RemainingDevicePath is supported or NULL.\r | |
38 | @retval EFI_UNSUPPORTED The device specified by ControllerHandle and\r | |
39 | RemainingDevicePath is not supported by the driver specified by This.\r | |
40 | **/\r | |
41 | EFI_STATUS\r | |
42 | IScsiIsDevicePathSupported (\r | |
43 | IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL\r | |
44 | )\r | |
45 | {\r | |
46 | EFI_DEVICE_PATH_PROTOCOL *CurrentDevicePath;\r | |
47 | \r | |
48 | CurrentDevicePath = RemainingDevicePath;\r | |
49 | if (CurrentDevicePath != NULL) {\r | |
50 | while (!IsDevicePathEnd (CurrentDevicePath)) {\r | |
51 | if ((CurrentDevicePath->Type == MESSAGING_DEVICE_PATH) && (CurrentDevicePath->SubType == MSG_ISCSI_DP)) {\r | |
52 | return EFI_SUCCESS;\r | |
53 | }\r | |
54 | \r | |
55 | CurrentDevicePath = NextDevicePathNode (CurrentDevicePath);\r | |
56 | }\r | |
57 | \r | |
58 | return EFI_UNSUPPORTED;\r | |
59 | }\r | |
60 | \r | |
61 | return EFI_SUCCESS;\r | |
62 | }\r | |
63 | \r | |
fd82de4e | 64 | /**\r |
d1102dba | 65 | Tests to see if this driver supports a given controller. If a child device is provided,\r |
fd82de4e | 66 | it further tests to see if this driver supports creating a handle for the specified child device.\r |
67 | \r | |
68 | @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r | |
d1102dba LG |
69 | @param[in] ControllerHandle The handle of the controller to test. This handle\r |
70 | must support a protocol interface that supplies\r | |
fd82de4e | 71 | an I/O abstraction to the driver.\r |
d1102dba | 72 | @param[in] RemainingDevicePath A pointer to the remaining portion of a device path.\r |
fd82de4e | 73 | This parameter is ignored by device drivers, and is optional for bus drivers.\r |
74 | \r | |
75 | \r | |
76 | @retval EFI_SUCCESS The device specified by ControllerHandle and\r | |
77 | RemainingDevicePath is supported by the driver specified by This.\r | |
78 | @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and\r | |
79 | RemainingDevicePath is already being managed by the driver\r | |
80 | specified by This.\r | |
81 | @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and\r | |
82 | RemainingDevicePath is already being managed by a different\r | |
83 | driver or an application that requires exclusive acces.\r | |
84 | Currently not implemented.\r | |
85 | @retval EFI_UNSUPPORTED The device specified by ControllerHandle and\r | |
86 | RemainingDevicePath is not supported by the driver specified by This.\r | |
12618416 | 87 | **/\r |
88 | EFI_STATUS\r | |
89 | EFIAPI\r | |
90 | IScsiDriverBindingSupported (\r | |
fd82de4e | 91 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r |
12618416 | 92 | IN EFI_HANDLE ControllerHandle,\r |
fd82de4e | 93 | IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL\r |
12618416 | 94 | )\r |
6a690e23 | 95 | {\r |
96 | EFI_STATUS Status;\r | |
6a690e23 | 97 | \r |
98 | Status = gBS->OpenProtocol (\r | |
99 | ControllerHandle,\r | |
c8ad2d7a | 100 | &gEfiCallerIdGuid,\r |
6a690e23 | 101 | NULL,\r |
102 | This->DriverBindingHandle,\r | |
103 | ControllerHandle,\r | |
104 | EFI_OPEN_PROTOCOL_TEST_PROTOCOL\r | |
105 | );\r | |
106 | if (!EFI_ERROR (Status)) {\r | |
107 | return EFI_ALREADY_STARTED;\r | |
108 | }\r | |
109 | \r | |
110 | Status = gBS->OpenProtocol (\r | |
111 | ControllerHandle,\r | |
112 | &gEfiTcp4ServiceBindingProtocolGuid,\r | |
113 | NULL,\r | |
114 | This->DriverBindingHandle,\r | |
115 | ControllerHandle,\r | |
116 | EFI_OPEN_PROTOCOL_TEST_PROTOCOL\r | |
117 | );\r | |
118 | if (EFI_ERROR (Status)) {\r | |
119 | return EFI_UNSUPPORTED;\r | |
120 | }\r | |
121 | \r | |
05a30011 WJ |
122 | Status = IScsiIsDevicePathSupported (RemainingDevicePath);\r |
123 | if (EFI_ERROR (Status)) {\r | |
124 | return EFI_UNSUPPORTED;\r | |
125 | }\r | |
6a690e23 | 126 | \r |
05a30011 WJ |
127 | if (IScsiDhcpIsConfigured (ControllerHandle)) {\r |
128 | Status = gBS->OpenProtocol (\r | |
129 | ControllerHandle,\r | |
130 | &gEfiDhcp4ServiceBindingProtocolGuid,\r | |
131 | NULL,\r | |
132 | This->DriverBindingHandle,\r | |
133 | ControllerHandle,\r | |
134 | EFI_OPEN_PROTOCOL_TEST_PROTOCOL\r | |
135 | );\r | |
136 | if (EFI_ERROR (Status)) {\r | |
137 | return EFI_UNSUPPORTED;\r | |
6a690e23 | 138 | }\r |
6a690e23 | 139 | }\r |
140 | \r | |
141 | return EFI_SUCCESS;\r | |
142 | }\r | |
143 | \r | |
12618416 | 144 | /**\r |
d1102dba LG |
145 | Start this driver on ControllerHandle.\r |
146 | \r | |
147 | The Start() function is designed to be invoked from the EFI boot service ConnectController().\r | |
148 | As a result, much of the error checking on the parameters to Start() has been moved into this\r | |
149 | common boot service. It is legal to call Start() from other locations, but the following calling\r | |
55a64ae0 | 150 | restrictions must be followed or the system behavior will not be deterministic.\r |
fd82de4e | 151 | 1. ControllerHandle must be a valid EFI_HANDLE.\r |
152 | 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned\r | |
153 | EFI_DEVICE_PATH_PROTOCOL.\r | |
154 | 3. Prior to calling Start(), the Supported() function for the driver specified by This must\r | |
d1102dba | 155 | have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.\r |
fd82de4e | 156 | \r |
157 | @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r | |
d1102dba LG |
158 | @param[in] ControllerHandle The handle of the controller to start. This handle\r |
159 | must support a protocol interface that supplies\r | |
fd82de4e | 160 | an I/O abstraction to the driver.\r |
d1102dba | 161 | @param[in] RemainingDevicePath A pointer to the remaining portion of a device path.\r |
fd82de4e | 162 | This parameter is ignored by device drivers, and is optional for bus drivers.\r |
163 | \r | |
164 | @retval EFI_SUCCESS The device was started.\r | |
165 | @retval EFI_DEVICE_ERROR The device could not be started due to a device error.\r | |
166 | Currently not implemented.\r | |
167 | @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.\r | |
168 | @retval Others The driver failded to start the device.\r | |
12618416 | 169 | **/\r |
6a690e23 | 170 | EFI_STATUS\r |
171 | EFIAPI\r | |
172 | IScsiDriverBindingStart (\r | |
fd82de4e | 173 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r |
6a690e23 | 174 | IN EFI_HANDLE ControllerHandle,\r |
fd82de4e | 175 | IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL\r |
6a690e23 | 176 | )\r |
6a690e23 | 177 | {\r |
178 | EFI_STATUS Status;\r | |
179 | ISCSI_DRIVER_DATA *Private;\r | |
fd627b16 | 180 | VOID *Interface;\r |
181 | \r | |
182 | Private = IScsiCreateDriverData (This->DriverBindingHandle, ControllerHandle);\r | |
183 | if (Private == NULL) {\r | |
184 | return EFI_OUT_OF_RESOURCES;\r | |
185 | }\r | |
186 | \r | |
187 | //\r | |
188 | // Create a underlayer child instance, but not need to configure it. Just open ChildHandle\r | |
189 | // via BY_DRIVER. That is, establishing the relationship between ControllerHandle and ChildHandle.\r | |
190 | // Therefore, when DisconnectController(), especially VLAN virtual controller handle,\r | |
191 | // IScsiDriverBindingStop() will be called.\r | |
192 | //\r | |
193 | Status = NetLibCreateServiceChild (\r | |
194 | ControllerHandle,\r | |
195 | This->DriverBindingHandle,\r | |
196 | &gEfiTcp4ServiceBindingProtocolGuid,\r | |
197 | &Private->ChildHandle\r | |
198 | );\r | |
199 | \r | |
200 | if (EFI_ERROR (Status)) {\r | |
201 | goto ON_ERROR;\r | |
202 | }\r | |
203 | \r | |
204 | Status = gBS->OpenProtocol (\r | |
205 | Private->ChildHandle,\r | |
206 | &gEfiTcp4ProtocolGuid,\r | |
207 | &Interface,\r | |
208 | This->DriverBindingHandle,\r | |
209 | ControllerHandle,\r | |
210 | EFI_OPEN_PROTOCOL_BY_DRIVER\r | |
211 | );\r | |
212 | if (EFI_ERROR (Status)) {\r | |
213 | goto ON_ERROR;\r | |
214 | }\r | |
215 | \r | |
05a30011 | 216 | //\r |
d1102dba | 217 | // Always install private protocol no matter what happens later. We need to\r |
fd627b16 | 218 | // keep the relationship between ControllerHandle and ChildHandle.\r |
219 | //\r | |
220 | Status = gBS->InstallProtocolInterface (\r | |
221 | &ControllerHandle,\r | |
c8ad2d7a | 222 | &gEfiCallerIdGuid,\r |
fd627b16 | 223 | EFI_NATIVE_INTERFACE,\r |
224 | &Private->IScsiIdentifier\r | |
225 | );\r | |
226 | if (EFI_ERROR (Status)) {\r | |
227 | goto ON_ERROR;\r | |
228 | }\r | |
6a690e23 | 229 | \r |
230 | //\r | |
231 | // Try to add a port configuration page for this controller.\r | |
232 | //\r | |
233 | IScsiConfigUpdateForm (This->DriverBindingHandle, ControllerHandle, TRUE);\r | |
234 | \r | |
6a690e23 | 235 | //\r |
236 | // Get the iSCSI configuration data of this controller.\r | |
237 | //\r | |
238 | Status = IScsiGetConfigData (Private);\r | |
239 | if (EFI_ERROR (Status)) {\r | |
240 | goto ON_ERROR;\r | |
241 | }\r | |
242 | //\r | |
243 | // Try to login and create an iSCSI session according to the configuration.\r | |
244 | //\r | |
245 | Status = IScsiSessionLogin (Private);\r | |
246 | if (Status == EFI_MEDIA_CHANGED) {\r | |
247 | //\r | |
248 | // The specified target is not available and the redirection information is\r | |
249 | // got, login the session again with the updated target address.\r | |
250 | //\r | |
251 | Status = IScsiSessionLogin (Private);\r | |
252 | }\r | |
253 | \r | |
254 | if (EFI_ERROR (Status)) {\r | |
255 | goto ON_ERROR;\r | |
256 | }\r | |
257 | //\r | |
258 | // Duplicate the Session's tcp connection device path. The source port field\r | |
259 | // will be set to zero as one iSCSI session is comprised of several iSCSI\r | |
260 | // connections.\r | |
261 | //\r | |
262 | Private->DevicePath = IScsiGetTcpConnDevicePath (Private);\r | |
263 | if (Private->DevicePath == NULL) {\r | |
264 | goto ON_ERROR;\r | |
265 | }\r | |
266 | //\r | |
267 | // Install the updated device path onto the ExtScsiPassThruHandle.\r | |
268 | //\r | |
269 | Status = gBS->InstallProtocolInterface (\r | |
270 | &Private->ExtScsiPassThruHandle,\r | |
271 | &gEfiDevicePathProtocolGuid,\r | |
272 | EFI_NATIVE_INTERFACE,\r | |
273 | Private->DevicePath\r | |
274 | );\r | |
275 | if (EFI_ERROR (Status)) {\r | |
276 | goto ON_ERROR;\r | |
277 | }\r | |
fd627b16 | 278 | \r |
0e402402 WJ |
279 | //\r |
280 | // ISCSI children should share the default Tcp child, just open the default Tcp child via BY_CHILD_CONTROLLER.\r | |
281 | //\r | |
282 | Status = gBS->OpenProtocol (\r | |
283 | Private->ChildHandle, /// Default Tcp child\r | |
284 | &gEfiTcp4ProtocolGuid,\r | |
285 | &Interface,\r | |
286 | This->DriverBindingHandle,\r | |
287 | Private->ExtScsiPassThruHandle,\r | |
288 | EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r | |
d1102dba | 289 | );\r |
0e402402 WJ |
290 | if (EFI_ERROR (Status)) {\r |
291 | gBS->UninstallMultipleProtocolInterfaces (\r | |
292 | Private->ExtScsiPassThruHandle,\r | |
293 | &gEfiExtScsiPassThruProtocolGuid,\r | |
294 | &Private->IScsiExtScsiPassThru,\r | |
295 | &gEfiDevicePathProtocolGuid,\r | |
296 | Private->DevicePath,\r | |
297 | NULL\r | |
298 | );\r | |
d1102dba | 299 | \r |
0e402402 WJ |
300 | goto ON_ERROR;\r |
301 | }\r | |
302 | \r | |
6a690e23 | 303 | //\r |
304 | // Update/Publish the iSCSI Boot Firmware Table.\r | |
305 | //\r | |
306 | IScsiPublishIbft ();\r | |
307 | \r | |
308 | return EFI_SUCCESS;\r | |
309 | \r | |
310 | ON_ERROR:\r | |
311 | \r | |
312 | IScsiSessionAbort (&Private->Session);\r | |
6a690e23 | 313 | \r |
314 | return Status;\r | |
315 | }\r | |
316 | \r | |
12618416 | 317 | /**\r |
d1102dba LG |
318 | Stop this driver on ControllerHandle.\r |
319 | \r | |
fd82de4e | 320 | Release the control of this controller and remove the IScsi functions. The Stop()\r |
d1102dba LG |
321 | function is designed to be invoked from the EFI boot service DisconnectController().\r |
322 | As a result, much of the error checking on the parameters to Stop() has been moved\r | |
323 | into this common boot service. It is legal to call Stop() from other locations,\r | |
fd82de4e | 324 | but the following calling restrictions must be followed or the system behavior will not be deterministic.\r |
325 | 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this\r | |
326 | same driver's Start() function.\r | |
327 | 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid\r | |
328 | EFI_HANDLE. In addition, all of these handles must have been created in this driver's\r | |
329 | Start() function, and the Start() function must have called OpenProtocol() on\r | |
330 | ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.\r | |
d1102dba | 331 | \r |
fd82de4e | 332 | @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r |
d1102dba LG |
333 | @param[in] ControllerHandle A handle to the device being stopped. The handle must\r |
334 | support a bus specific I/O protocol for the driver\r | |
fd82de4e | 335 | to use to stop the device.\r |
336 | @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.Not used.\r | |
d1102dba | 337 | @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL\r |
fd82de4e | 338 | if NumberOfChildren is 0.Not used.\r |
339 | \r | |
340 | @retval EFI_SUCCESS The device was stopped.\r | |
341 | @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.\r | |
e3761c71 ZL |
342 | @retval EFI_INVALID_PARAMETER Child handle is NULL.\r |
343 | @retval EFI_ACCESS_DENIED The protocol could not be removed from the Handle\r | |
344 | because its interfaces are being used.\r | |
345 | \r | |
12618416 | 346 | **/\r |
6a690e23 | 347 | EFI_STATUS\r |
348 | EFIAPI\r | |
349 | IScsiDriverBindingStop (\r | |
350 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
351 | IN EFI_HANDLE ControllerHandle,\r | |
352 | IN UINTN NumberOfChildren,\r | |
c5de0d55 | 353 | IN EFI_HANDLE *ChildHandleBuffer OPTIONAL\r |
6a690e23 | 354 | )\r |
6a690e23 | 355 | {\r |
356 | EFI_HANDLE IScsiController;\r | |
357 | EFI_STATUS Status;\r | |
358 | ISCSI_PRIVATE_PROTOCOL *IScsiIdentifier;\r | |
359 | ISCSI_DRIVER_DATA *Private;\r | |
360 | EFI_EXT_SCSI_PASS_THRU_PROTOCOL *PassThru;\r | |
361 | ISCSI_CONNECTION *Conn;\r | |
362 | \r | |
363 | if (NumberOfChildren != 0) {\r | |
364 | //\r | |
365 | // We should have only one child.\r | |
366 | //\r | |
367 | Status = gBS->OpenProtocol (\r | |
368 | ChildHandleBuffer[0],\r | |
369 | &gEfiExtScsiPassThruProtocolGuid,\r | |
370 | (VOID **) &PassThru,\r | |
371 | This->DriverBindingHandle,\r | |
372 | ControllerHandle,\r | |
373 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
374 | );\r | |
375 | if (EFI_ERROR (Status)) {\r | |
376 | return EFI_DEVICE_ERROR;\r | |
377 | }\r | |
378 | \r | |
379 | Private = ISCSI_DRIVER_DATA_FROM_EXT_SCSI_PASS_THRU (PassThru);\r | |
380 | Conn = NET_LIST_HEAD (&Private->Session.Conns, ISCSI_CONNECTION, Link);\r | |
381 | \r | |
382 | //\r | |
383 | // Previously the TCP4 protocol is opened BY_CHILD_CONTROLLER. Just close\r | |
384 | // the protocol here but not uninstall the device path protocol and\r | |
385 | // EXT SCSI PASS THRU protocol installed on ExtScsiPassThruHandle.\r | |
386 | //\r | |
0e402402 WJ |
387 | gBS->CloseProtocol (\r |
388 | Private->ChildHandle,\r | |
389 | &gEfiTcp4ProtocolGuid,\r | |
390 | Private->Image,\r | |
391 | Private->ExtScsiPassThruHandle\r | |
392 | );\r | |
d1102dba | 393 | \r |
6a690e23 | 394 | gBS->CloseProtocol (\r |
395 | Conn->Tcp4Io.Handle,\r | |
396 | &gEfiTcp4ProtocolGuid,\r | |
397 | Private->Image,\r | |
398 | Private->ExtScsiPassThruHandle\r | |
399 | );\r | |
400 | \r | |
401 | return EFI_SUCCESS;\r | |
402 | }\r | |
403 | //\r | |
404 | // Get the handle of the controller we are controling.\r | |
405 | //\r | |
406 | IScsiController = NetLibGetNicHandle (ControllerHandle, &gEfiTcp4ProtocolGuid);\r | |
407 | \r | |
408 | Status = gBS->OpenProtocol (\r | |
409 | IScsiController,\r | |
c8ad2d7a | 410 | &gEfiCallerIdGuid,\r |
6a690e23 | 411 | (VOID **)&IScsiIdentifier,\r |
412 | This->DriverBindingHandle,\r | |
413 | ControllerHandle,\r | |
414 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
415 | );\r | |
416 | if (EFI_ERROR (Status)) {\r | |
417 | return EFI_DEVICE_ERROR;\r | |
418 | }\r | |
419 | \r | |
420 | Private = ISCSI_DRIVER_DATA_FROM_IDENTIFIER (IScsiIdentifier);\r | |
421 | \r | |
fd627b16 | 422 | if (Private->ChildHandle != NULL) {\r |
423 | Status = gBS->CloseProtocol (\r | |
424 | Private->ChildHandle,\r | |
425 | &gEfiTcp4ProtocolGuid,\r | |
426 | This->DriverBindingHandle,\r | |
427 | IScsiController\r | |
428 | );\r | |
429 | \r | |
430 | ASSERT (!EFI_ERROR (Status));\r | |
431 | \r | |
432 | Status = NetLibDestroyServiceChild (\r | |
433 | IScsiController,\r | |
434 | This->DriverBindingHandle,\r | |
435 | &gEfiTcp4ServiceBindingProtocolGuid,\r | |
436 | Private->ChildHandle\r | |
437 | );\r | |
438 | ASSERT (!EFI_ERROR (Status));\r | |
439 | }\r | |
440 | \r | |
441 | IScsiConfigUpdateForm (This->DriverBindingHandle, IScsiController, FALSE);\r | |
442 | \r | |
6a690e23 | 443 | //\r |
444 | // Uninstall the private protocol.\r | |
445 | //\r | |
446 | gBS->UninstallProtocolInterface (\r | |
447 | IScsiController,\r | |
c8ad2d7a | 448 | &gEfiCallerIdGuid,\r |
6a690e23 | 449 | &Private->IScsiIdentifier\r |
450 | );\r | |
451 | \r | |
452 | //\r | |
453 | // Update the iSCSI Boot Firware Table.\r | |
454 | //\r | |
455 | IScsiPublishIbft ();\r | |
456 | \r | |
457 | IScsiSessionAbort (&Private->Session);\r | |
e3761c71 ZL |
458 | Status = IScsiCleanDriverData (Private);\r |
459 | if (EFI_ERROR (Status)) {\r | |
460 | return Status;\r | |
461 | }\r | |
6a690e23 | 462 | \r |
463 | return EFI_SUCCESS;\r | |
464 | }\r | |
465 | \r | |
12618416 | 466 | /**\r |
fd82de4e | 467 | Unloads an image(the iSCSI driver).\r |
6a690e23 | 468 | \r |
fd82de4e | 469 | @param[in] ImageHandle Handle that identifies the image to be unloaded.\r |
6a690e23 | 470 | \r |
fd82de4e | 471 | @retval EFI_SUCCESS The image has been unloaded.\r |
963dbb30 | 472 | @retval Others Other errors as indicated.\r |
12618416 | 473 | **/\r |
474 | EFI_STATUS\r | |
475 | EFIAPI\r | |
476 | EfiIScsiUnload (\r | |
477 | IN EFI_HANDLE ImageHandle\r | |
478 | )\r | |
6a690e23 | 479 | {\r |
18b24f92 FS |
480 | EFI_STATUS Status;\r |
481 | UINTN DeviceHandleCount;\r | |
482 | EFI_HANDLE *DeviceHandleBuffer;\r | |
483 | UINTN Index;\r | |
484 | EFI_COMPONENT_NAME_PROTOCOL *ComponentName;\r | |
485 | EFI_COMPONENT_NAME2_PROTOCOL *ComponentName2;\r | |
6a690e23 | 486 | \r |
487 | //\r | |
488 | // Try to disonnect the driver from the devices it's controlling.\r | |
489 | //\r | |
490 | Status = gBS->LocateHandleBuffer (\r | |
491 | AllHandles,\r | |
492 | NULL,\r | |
493 | NULL,\r | |
494 | &DeviceHandleCount,\r | |
495 | &DeviceHandleBuffer\r | |
496 | );\r | |
18b24f92 FS |
497 | if (EFI_ERROR (Status)) {\r |
498 | return Status;\r | |
499 | }\r | |
6a690e23 | 500 | \r |
18b24f92 FS |
501 | for (Index = 0; Index < DeviceHandleCount; Index++) {\r |
502 | Status = IScsiTestManagedDevice (\r | |
503 | DeviceHandleBuffer[Index],\r | |
504 | gIScsiDriverBinding.DriverBindingHandle,\r | |
505 | &gEfiTcp4ProtocolGuid\r | |
506 | );\r | |
507 | if (EFI_ERROR (Status)) {\r | |
508 | continue;\r | |
6a690e23 | 509 | }\r |
18b24f92 FS |
510 | Status = gBS->DisconnectController (\r |
511 | DeviceHandleBuffer[Index],\r | |
512 | gIScsiDriverBinding.DriverBindingHandle,\r | |
513 | NULL\r | |
514 | );\r | |
515 | if (EFI_ERROR (Status)) {\r | |
516 | goto ON_EXIT;\r | |
517 | }\r | |
d1102dba | 518 | }\r |
18b24f92 | 519 | \r |
6a690e23 | 520 | //\r |
521 | // Unload the iSCSI configuration form.\r | |
522 | //\r | |
18b24f92 FS |
523 | Status = IScsiConfigFormUnload (gIScsiDriverBinding.DriverBindingHandle);\r |
524 | if (EFI_ERROR (Status)) {\r | |
525 | goto ON_EXIT;\r | |
526 | }\r | |
6a690e23 | 527 | \r |
528 | //\r | |
18b24f92 FS |
529 | // Uninstall the ComponentName and ComponentName2 protocol from iSCSI4 driver binding handle\r |
530 | // if it has been installed.\r | |
6a690e23 | 531 | //\r |
18b24f92 FS |
532 | Status = gBS->HandleProtocol (\r |
533 | gIScsiDriverBinding.DriverBindingHandle,\r | |
534 | &gEfiComponentNameProtocolGuid,\r | |
535 | (VOID **) &ComponentName\r | |
536 | );\r | |
537 | if (!EFI_ERROR (Status)) {\r | |
538 | Status = gBS->UninstallMultipleProtocolInterfaces (\r | |
539 | gIScsiDriverBinding.DriverBindingHandle,\r | |
540 | &gEfiComponentNameProtocolGuid,\r | |
541 | ComponentName,\r | |
542 | NULL\r | |
543 | );\r | |
544 | if (EFI_ERROR (Status)) {\r | |
545 | goto ON_EXIT;\r | |
546 | }\r | |
547 | }\r | |
d1102dba | 548 | \r |
18b24f92 FS |
549 | Status = gBS->HandleProtocol (\r |
550 | gIScsiDriverBinding.DriverBindingHandle,\r | |
551 | &gEfiComponentName2ProtocolGuid,\r | |
552 | (VOID **) &ComponentName2\r | |
553 | );\r | |
554 | if (!EFI_ERROR (Status)) {\r | |
555 | gBS->UninstallMultipleProtocolInterfaces (\r | |
556 | gIScsiDriverBinding.DriverBindingHandle,\r | |
557 | &gEfiComponentName2ProtocolGuid,\r | |
558 | ComponentName2,\r | |
559 | NULL\r | |
560 | );\r | |
561 | if (EFI_ERROR (Status)) {\r | |
562 | goto ON_EXIT;\r | |
563 | }\r | |
564 | }\r | |
565 | \r | |
6a690e23 | 566 | Status = gBS->UninstallMultipleProtocolInterfaces (\r |
567 | ImageHandle,\r | |
568 | &gEfiDriverBindingProtocolGuid,\r | |
569 | &gIScsiDriverBinding,\r | |
6a690e23 | 570 | &gEfiIScsiInitiatorNameProtocolGuid,\r |
571 | &gIScsiInitiatorName,\r | |
572 | NULL\r | |
573 | );\r | |
18b24f92 | 574 | ON_EXIT:\r |
6a690e23 | 575 | \r |
18b24f92 FS |
576 | if (DeviceHandleBuffer != NULL) {\r |
577 | FreePool (DeviceHandleBuffer);\r | |
578 | }\r | |
d1102dba | 579 | \r |
6a690e23 | 580 | return Status;\r |
581 | }\r | |
582 | \r | |
12618416 | 583 | /**\r |
fd82de4e | 584 | This is the declaration of an EFI image entry point. This entry point is\r |
585 | the same for UEFI Applications, UEFI OS Loaders, and UEFI Drivers including\r | |
d1102dba | 586 | both device drivers and bus drivers. It initialize the global variables and\r |
fd82de4e | 587 | publish the driver binding protocol.\r |
6a690e23 | 588 | \r |
fd82de4e | 589 | @param[in] ImageHandle The firmware allocated handle for the UEFI image.\r |
590 | @param[in] SystemTable A pointer to the EFI System Table.\r | |
6a690e23 | 591 | \r |
fd82de4e | 592 | @retval EFI_SUCCESS The operation completed successfully.\r |
593 | @retval EFI_ACCESS_DENIED EFI_ISCSI_INITIATOR_NAME_PROTOCOL was installed unexpectedly.\r | |
963dbb30 | 594 | @retval Others Other errors as indicated.\r |
12618416 | 595 | **/\r |
596 | EFI_STATUS\r | |
597 | EFIAPI\r | |
598 | IScsiDriverEntryPoint (\r | |
599 | IN EFI_HANDLE ImageHandle,\r | |
600 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
601 | )\r | |
6a690e23 | 602 | {\r |
f2a94e25 | 603 | EFI_STATUS Status;\r |
604 | EFI_ISCSI_INITIATOR_NAME_PROTOCOL *IScsiInitiatorName;\r | |
605 | \r | |
606 | //\r | |
607 | // There should be only one EFI_ISCSI_INITIATOR_NAME_PROTOCOL.\r | |
608 | //\r | |
609 | Status = gBS->LocateProtocol (\r | |
610 | &gEfiIScsiInitiatorNameProtocolGuid,\r | |
611 | NULL,\r | |
b4df5011 | 612 | (VOID**) &IScsiInitiatorName\r |
f2a94e25 | 613 | );\r |
614 | \r | |
615 | if (!EFI_ERROR (Status)) {\r | |
616 | return EFI_ACCESS_DENIED;\r | |
617 | }\r | |
6a690e23 | 618 | \r |
619 | //\r | |
620 | // Initialize the EFI Driver Library\r | |
621 | //\r | |
622 | Status = EfiLibInstallDriverBindingComponentName2 (\r | |
623 | ImageHandle,\r | |
624 | SystemTable,\r | |
625 | &gIScsiDriverBinding,\r | |
626 | ImageHandle,\r | |
627 | &gIScsiComponentName,\r | |
628 | &gIScsiComponentName2\r | |
629 | );\r | |
6a690e23 | 630 | \r |
631 | if (!EFI_ERROR (Status)) {\r | |
f2a94e25 | 632 | //\r |
633 | // Install the iSCSI Initiator Name Protocol.\r | |
634 | //\r | |
6a690e23 | 635 | Status = gBS->InstallProtocolInterface (\r |
636 | &ImageHandle,\r | |
637 | &gEfiIScsiInitiatorNameProtocolGuid,\r | |
638 | EFI_NATIVE_INTERFACE,\r | |
639 | &gIScsiInitiatorName\r | |
640 | );\r | |
641 | if (EFI_ERROR (Status)) {\r | |
642 | gBS->UninstallMultipleProtocolInterfaces (\r | |
643 | ImageHandle,\r | |
644 | &gEfiDriverBindingProtocolGuid,\r | |
645 | &gIScsiDriverBinding,\r | |
646 | &gEfiComponentName2ProtocolGuid,\r | |
647 | &gIScsiComponentName2,\r | |
648 | &gEfiComponentNameProtocolGuid,\r | |
649 | &gIScsiComponentName,\r | |
650 | NULL\r | |
651 | );\r | |
f2a94e25 | 652 | return Status;\r |
653 | }\r | |
d1102dba | 654 | \r |
f2a94e25 | 655 | //\r |
656 | // Initialize the configuration form of iSCSI.\r | |
657 | //\r | |
963dbb30 | 658 | Status = IScsiConfigFormInit ();\r |
f2a94e25 | 659 | if (EFI_ERROR (Status)) {\r |
660 | gBS->UninstallMultipleProtocolInterfaces (\r | |
661 | ImageHandle,\r | |
662 | &gEfiDriverBindingProtocolGuid,\r | |
663 | &gIScsiDriverBinding,\r | |
664 | &gEfiComponentName2ProtocolGuid,\r | |
665 | &gIScsiComponentName2,\r | |
666 | &gEfiComponentNameProtocolGuid,\r | |
667 | &gIScsiComponentName,\r | |
668 | &gEfiIScsiInitiatorNameProtocolGuid,\r | |
669 | &gIScsiInitiatorName,\r | |
670 | NULL\r | |
671 | );\r | |
6a690e23 | 672 | }\r |
673 | }\r | |
6a690e23 | 674 | return Status;\r |
675 | }\r | |
676 | \r |