]>
Commit | Line | Data |
---|---|---|
1 | /** @file\r | |
2 | The entry point of IScsi driver.\r | |
3 | \r | |
4 | Copyright (c) 2004 - 2009, Intel Corporation.<BR>\r | |
5 | All rights reserved. This program and the accompanying materials\r | |
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 | |
12 | \r | |
13 | **/\r | |
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 | |
26 | EFI_GUID gIScsiPrivateGuid = ISCSI_PRIVATE_GUID;\r | |
27 | \r | |
28 | \r | |
29 | /**\r | |
30 | Tests to see if this driver supports a given controller. If a child device is provided, \r | |
31 | it further tests to see if this driver supports creating a handle for the specified child device.\r | |
32 | \r | |
33 | @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r | |
34 | @param[in] ControllerHandle The handle of the controller to test. This handle \r | |
35 | must support a protocol interface that supplies \r | |
36 | an I/O abstraction to the driver.\r | |
37 | @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. \r | |
38 | This parameter is ignored by device drivers, and is optional for bus drivers.\r | |
39 | \r | |
40 | \r | |
41 | @retval EFI_SUCCESS The device specified by ControllerHandle and\r | |
42 | RemainingDevicePath is supported by the driver specified by This.\r | |
43 | @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and\r | |
44 | RemainingDevicePath is already being managed by the driver\r | |
45 | specified by This.\r | |
46 | @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and\r | |
47 | RemainingDevicePath is already being managed by a different\r | |
48 | driver or an application that requires exclusive acces.\r | |
49 | Currently not implemented.\r | |
50 | @retval EFI_UNSUPPORTED The device specified by ControllerHandle and\r | |
51 | RemainingDevicePath is not supported by the driver specified by This.\r | |
52 | **/\r | |
53 | EFI_STATUS\r | |
54 | EFIAPI\r | |
55 | IScsiDriverBindingSupported (\r | |
56 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
57 | IN EFI_HANDLE ControllerHandle,\r | |
58 | IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL\r | |
59 | )\r | |
60 | {\r | |
61 | EFI_STATUS Status;\r | |
62 | EFI_DEVICE_PATH_PROTOCOL *CurrentDevicePath;\r | |
63 | \r | |
64 | Status = gBS->OpenProtocol (\r | |
65 | ControllerHandle,\r | |
66 | &gIScsiPrivateGuid,\r | |
67 | NULL,\r | |
68 | This->DriverBindingHandle,\r | |
69 | ControllerHandle,\r | |
70 | EFI_OPEN_PROTOCOL_TEST_PROTOCOL\r | |
71 | );\r | |
72 | if (!EFI_ERROR (Status)) {\r | |
73 | return EFI_ALREADY_STARTED;\r | |
74 | }\r | |
75 | \r | |
76 | Status = gBS->OpenProtocol (\r | |
77 | ControllerHandle,\r | |
78 | &gEfiTcp4ServiceBindingProtocolGuid,\r | |
79 | NULL,\r | |
80 | This->DriverBindingHandle,\r | |
81 | ControllerHandle,\r | |
82 | EFI_OPEN_PROTOCOL_TEST_PROTOCOL\r | |
83 | );\r | |
84 | if (EFI_ERROR (Status)) {\r | |
85 | return EFI_UNSUPPORTED;\r | |
86 | }\r | |
87 | \r | |
88 | CurrentDevicePath = RemainingDevicePath;\r | |
89 | if (CurrentDevicePath != NULL) {\r | |
90 | while (!IsDevicePathEnd (CurrentDevicePath)) {\r | |
91 | if ((CurrentDevicePath->Type == MESSAGING_DEVICE_PATH) && (CurrentDevicePath->SubType == MSG_ISCSI_DP)) {\r | |
92 | return EFI_SUCCESS;\r | |
93 | }\r | |
94 | \r | |
95 | CurrentDevicePath = NextDevicePathNode (CurrentDevicePath);\r | |
96 | }\r | |
97 | \r | |
98 | return EFI_UNSUPPORTED;\r | |
99 | }\r | |
100 | \r | |
101 | return EFI_SUCCESS;\r | |
102 | }\r | |
103 | \r | |
104 | /**\r | |
105 | Start this driver on ControllerHandle. \r | |
106 | \r | |
107 | The Start() function is designed to be invoked from the EFI boot service ConnectController(). \r | |
108 | As a result, much of the error checking on the parameters to Start() has been moved into this \r | |
109 | common boot service. It is legal to call Start() from other locations, but the following calling \r | |
110 | restrictions must be followed or the system behavior will not be deterministic.\r | |
111 | 1. ControllerHandle must be a valid EFI_HANDLE.\r | |
112 | 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned\r | |
113 | EFI_DEVICE_PATH_PROTOCOL.\r | |
114 | 3. Prior to calling Start(), the Supported() function for the driver specified by This must\r | |
115 | have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS. \r | |
116 | \r | |
117 | @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r | |
118 | @param[in] ControllerHandle The handle of the controller to start. This handle \r | |
119 | must support a protocol interface that supplies \r | |
120 | an I/O abstraction to the driver.\r | |
121 | @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. \r | |
122 | This parameter is ignored by device drivers, and is optional for bus drivers.\r | |
123 | \r | |
124 | @retval EFI_SUCCESS The device was started.\r | |
125 | @retval EFI_DEVICE_ERROR The device could not be started due to a device error.\r | |
126 | Currently not implemented.\r | |
127 | @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.\r | |
128 | @retval Others The driver failded to start the device.\r | |
129 | **/\r | |
130 | EFI_STATUS\r | |
131 | EFIAPI\r | |
132 | IScsiDriverBindingStart (\r | |
133 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
134 | IN EFI_HANDLE ControllerHandle,\r | |
135 | IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL\r | |
136 | )\r | |
137 | {\r | |
138 | EFI_STATUS Status;\r | |
139 | ISCSI_DRIVER_DATA *Private;\r | |
140 | \r | |
141 | //\r | |
142 | // Try to add a port configuration page for this controller.\r | |
143 | //\r | |
144 | IScsiConfigUpdateForm (This->DriverBindingHandle, ControllerHandle, TRUE);\r | |
145 | \r | |
146 | Private = IScsiCreateDriverData (This->DriverBindingHandle, ControllerHandle);\r | |
147 | if (Private == NULL) {\r | |
148 | return EFI_OUT_OF_RESOURCES;\r | |
149 | }\r | |
150 | //\r | |
151 | // Get the iSCSI configuration data of this controller.\r | |
152 | //\r | |
153 | Status = IScsiGetConfigData (Private);\r | |
154 | if (EFI_ERROR (Status)) {\r | |
155 | goto ON_ERROR;\r | |
156 | }\r | |
157 | //\r | |
158 | // Try to login and create an iSCSI session according to the configuration.\r | |
159 | //\r | |
160 | Status = IScsiSessionLogin (Private);\r | |
161 | if (Status == EFI_MEDIA_CHANGED) {\r | |
162 | //\r | |
163 | // The specified target is not available and the redirection information is\r | |
164 | // got, login the session again with the updated target address.\r | |
165 | //\r | |
166 | Status = IScsiSessionLogin (Private);\r | |
167 | }\r | |
168 | \r | |
169 | if (EFI_ERROR (Status)) {\r | |
170 | goto ON_ERROR;\r | |
171 | }\r | |
172 | //\r | |
173 | // Duplicate the Session's tcp connection device path. The source port field\r | |
174 | // will be set to zero as one iSCSI session is comprised of several iSCSI\r | |
175 | // connections.\r | |
176 | //\r | |
177 | Private->DevicePath = IScsiGetTcpConnDevicePath (Private);\r | |
178 | if (Private->DevicePath == NULL) {\r | |
179 | goto ON_ERROR;\r | |
180 | }\r | |
181 | //\r | |
182 | // Install the updated device path onto the ExtScsiPassThruHandle.\r | |
183 | //\r | |
184 | Status = gBS->InstallProtocolInterface (\r | |
185 | &Private->ExtScsiPassThruHandle,\r | |
186 | &gEfiDevicePathProtocolGuid,\r | |
187 | EFI_NATIVE_INTERFACE,\r | |
188 | Private->DevicePath\r | |
189 | );\r | |
190 | if (EFI_ERROR (Status)) {\r | |
191 | goto ON_ERROR;\r | |
192 | }\r | |
193 | //\r | |
194 | // Install the iSCSI private stuff as a flag to indicate this controller\r | |
195 | // is already controlled by iSCSI driver.\r | |
196 | //\r | |
197 | Status = gBS->InstallProtocolInterface (\r | |
198 | &ControllerHandle,\r | |
199 | &gIScsiPrivateGuid,\r | |
200 | EFI_NATIVE_INTERFACE,\r | |
201 | &Private->IScsiIdentifier\r | |
202 | );\r | |
203 | if (EFI_ERROR (Status)) {\r | |
204 | goto ON_ERROR;\r | |
205 | }\r | |
206 | //\r | |
207 | // Update/Publish the iSCSI Boot Firmware Table.\r | |
208 | //\r | |
209 | IScsiPublishIbft ();\r | |
210 | \r | |
211 | return EFI_SUCCESS;\r | |
212 | \r | |
213 | ON_ERROR:\r | |
214 | \r | |
215 | IScsiSessionAbort (&Private->Session);\r | |
216 | IScsiCleanDriverData (Private);\r | |
217 | \r | |
218 | return Status;\r | |
219 | }\r | |
220 | \r | |
221 | /**\r | |
222 | Stop this driver on ControllerHandle. \r | |
223 | \r | |
224 | Release the control of this controller and remove the IScsi functions. The Stop()\r | |
225 | function is designed to be invoked from the EFI boot service DisconnectController(). \r | |
226 | As a result, much of the error checking on the parameters to Stop() has been moved \r | |
227 | into this common boot service. It is legal to call Stop() from other locations, \r | |
228 | but the following calling restrictions must be followed or the system behavior will not be deterministic.\r | |
229 | 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this\r | |
230 | same driver's Start() function.\r | |
231 | 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid\r | |
232 | EFI_HANDLE. In addition, all of these handles must have been created in this driver's\r | |
233 | Start() function, and the Start() function must have called OpenProtocol() on\r | |
234 | ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.\r | |
235 | \r | |
236 | @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r | |
237 | @param[in] ControllerHandle A handle to the device being stopped. The handle must \r | |
238 | support a bus specific I/O protocol for the driver \r | |
239 | to use to stop the device.\r | |
240 | @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.Not used.\r | |
241 | @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL \r | |
242 | if NumberOfChildren is 0.Not used.\r | |
243 | \r | |
244 | @retval EFI_SUCCESS The device was stopped.\r | |
245 | @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.\r | |
246 | **/\r | |
247 | EFI_STATUS\r | |
248 | EFIAPI\r | |
249 | IScsiDriverBindingStop (\r | |
250 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
251 | IN EFI_HANDLE ControllerHandle,\r | |
252 | IN UINTN NumberOfChildren,\r | |
253 | IN EFI_HANDLE *ChildHandleBuffer OPTIONAL\r | |
254 | )\r | |
255 | {\r | |
256 | EFI_HANDLE IScsiController;\r | |
257 | EFI_STATUS Status;\r | |
258 | ISCSI_PRIVATE_PROTOCOL *IScsiIdentifier;\r | |
259 | ISCSI_DRIVER_DATA *Private;\r | |
260 | EFI_EXT_SCSI_PASS_THRU_PROTOCOL *PassThru;\r | |
261 | ISCSI_CONNECTION *Conn;\r | |
262 | \r | |
263 | if (NumberOfChildren != 0) {\r | |
264 | //\r | |
265 | // We should have only one child.\r | |
266 | //\r | |
267 | Status = gBS->OpenProtocol (\r | |
268 | ChildHandleBuffer[0],\r | |
269 | &gEfiExtScsiPassThruProtocolGuid,\r | |
270 | (VOID **) &PassThru,\r | |
271 | This->DriverBindingHandle,\r | |
272 | ControllerHandle,\r | |
273 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
274 | );\r | |
275 | if (EFI_ERROR (Status)) {\r | |
276 | return EFI_DEVICE_ERROR;\r | |
277 | }\r | |
278 | \r | |
279 | Private = ISCSI_DRIVER_DATA_FROM_EXT_SCSI_PASS_THRU (PassThru);\r | |
280 | Conn = NET_LIST_HEAD (&Private->Session.Conns, ISCSI_CONNECTION, Link);\r | |
281 | \r | |
282 | //\r | |
283 | // Previously the TCP4 protocol is opened BY_CHILD_CONTROLLER. Just close\r | |
284 | // the protocol here but not uninstall the device path protocol and\r | |
285 | // EXT SCSI PASS THRU protocol installed on ExtScsiPassThruHandle.\r | |
286 | //\r | |
287 | gBS->CloseProtocol (\r | |
288 | Conn->Tcp4Io.Handle,\r | |
289 | &gEfiTcp4ProtocolGuid,\r | |
290 | Private->Image,\r | |
291 | Private->ExtScsiPassThruHandle\r | |
292 | );\r | |
293 | \r | |
294 | return EFI_SUCCESS;\r | |
295 | }\r | |
296 | //\r | |
297 | // Get the handle of the controller we are controling.\r | |
298 | //\r | |
299 | IScsiController = NetLibGetNicHandle (ControllerHandle, &gEfiTcp4ProtocolGuid);\r | |
300 | \r | |
301 | Status = gBS->OpenProtocol (\r | |
302 | IScsiController,\r | |
303 | &gIScsiPrivateGuid,\r | |
304 | (VOID **)&IScsiIdentifier,\r | |
305 | This->DriverBindingHandle,\r | |
306 | ControllerHandle,\r | |
307 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
308 | );\r | |
309 | if (EFI_ERROR (Status)) {\r | |
310 | return EFI_DEVICE_ERROR;\r | |
311 | }\r | |
312 | \r | |
313 | Private = ISCSI_DRIVER_DATA_FROM_IDENTIFIER (IScsiIdentifier);\r | |
314 | \r | |
315 | //\r | |
316 | // Uninstall the private protocol.\r | |
317 | //\r | |
318 | gBS->UninstallProtocolInterface (\r | |
319 | IScsiController,\r | |
320 | &gIScsiPrivateGuid,\r | |
321 | &Private->IScsiIdentifier\r | |
322 | );\r | |
323 | \r | |
324 | //\r | |
325 | // Update the iSCSI Boot Firware Table.\r | |
326 | //\r | |
327 | IScsiPublishIbft ();\r | |
328 | \r | |
329 | IScsiSessionAbort (&Private->Session);\r | |
330 | IScsiCleanDriverData (Private);\r | |
331 | \r | |
332 | return EFI_SUCCESS;\r | |
333 | }\r | |
334 | \r | |
335 | /**\r | |
336 | Unloads an image(the iSCSI driver).\r | |
337 | \r | |
338 | @param[in] ImageHandle Handle that identifies the image to be unloaded.\r | |
339 | \r | |
340 | @retval EFI_SUCCESS The image has been unloaded.\r | |
341 | @retval Others Other errors as indicated.\r | |
342 | **/\r | |
343 | EFI_STATUS\r | |
344 | EFIAPI\r | |
345 | EfiIScsiUnload (\r | |
346 | IN EFI_HANDLE ImageHandle\r | |
347 | )\r | |
348 | {\r | |
349 | EFI_STATUS Status;\r | |
350 | UINTN DeviceHandleCount;\r | |
351 | EFI_HANDLE *DeviceHandleBuffer;\r | |
352 | UINTN Index;\r | |
353 | \r | |
354 | //\r | |
355 | // Try to disonnect the driver from the devices it's controlling.\r | |
356 | //\r | |
357 | Status = gBS->LocateHandleBuffer (\r | |
358 | AllHandles,\r | |
359 | NULL,\r | |
360 | NULL,\r | |
361 | &DeviceHandleCount,\r | |
362 | &DeviceHandleBuffer\r | |
363 | );\r | |
364 | if (!EFI_ERROR (Status)) {\r | |
365 | for (Index = 0; Index < DeviceHandleCount; Index++) {\r | |
366 | Status = gBS->DisconnectController (\r | |
367 | DeviceHandleBuffer[Index],\r | |
368 | ImageHandle,\r | |
369 | NULL\r | |
370 | );\r | |
371 | }\r | |
372 | \r | |
373 | if (DeviceHandleBuffer != NULL) {\r | |
374 | FreePool (DeviceHandleBuffer);\r | |
375 | }\r | |
376 | }\r | |
377 | //\r | |
378 | // Unload the iSCSI configuration form.\r | |
379 | //\r | |
380 | IScsiConfigFormUnload (gIScsiDriverBinding.DriverBindingHandle);\r | |
381 | \r | |
382 | //\r | |
383 | // Uninstall the protocols installed by iSCSI driver.\r | |
384 | //\r | |
385 | Status = gBS->UninstallMultipleProtocolInterfaces (\r | |
386 | ImageHandle,\r | |
387 | &gEfiDriverBindingProtocolGuid,\r | |
388 | &gIScsiDriverBinding,\r | |
389 | &gEfiComponentName2ProtocolGuid,\r | |
390 | &gIScsiComponentName2,\r | |
391 | &gEfiComponentNameProtocolGuid,\r | |
392 | &gIScsiComponentName,\r | |
393 | &gEfiIScsiInitiatorNameProtocolGuid,\r | |
394 | &gIScsiInitiatorName,\r | |
395 | NULL\r | |
396 | );\r | |
397 | \r | |
398 | return Status;\r | |
399 | }\r | |
400 | \r | |
401 | /**\r | |
402 | This is the declaration of an EFI image entry point. This entry point is\r | |
403 | the same for UEFI Applications, UEFI OS Loaders, and UEFI Drivers including\r | |
404 | both device drivers and bus drivers. It initialize the global variables and \r | |
405 | publish the driver binding protocol.\r | |
406 | \r | |
407 | @param[in] ImageHandle The firmware allocated handle for the UEFI image.\r | |
408 | @param[in] SystemTable A pointer to the EFI System Table.\r | |
409 | \r | |
410 | @retval EFI_SUCCESS The operation completed successfully.\r | |
411 | @retval EFI_ACCESS_DENIED EFI_ISCSI_INITIATOR_NAME_PROTOCOL was installed unexpectedly.\r | |
412 | @retval Others Other errors as indicated.\r | |
413 | **/\r | |
414 | EFI_STATUS\r | |
415 | EFIAPI\r | |
416 | IScsiDriverEntryPoint (\r | |
417 | IN EFI_HANDLE ImageHandle,\r | |
418 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
419 | )\r | |
420 | {\r | |
421 | EFI_STATUS Status;\r | |
422 | EFI_ISCSI_INITIATOR_NAME_PROTOCOL *IScsiInitiatorName;\r | |
423 | \r | |
424 | //\r | |
425 | // There should be only one EFI_ISCSI_INITIATOR_NAME_PROTOCOL.\r | |
426 | //\r | |
427 | Status = gBS->LocateProtocol (\r | |
428 | &gEfiIScsiInitiatorNameProtocolGuid,\r | |
429 | NULL,\r | |
430 | (VOID**) &IScsiInitiatorName\r | |
431 | );\r | |
432 | \r | |
433 | if (!EFI_ERROR (Status)) {\r | |
434 | return EFI_ACCESS_DENIED;\r | |
435 | }\r | |
436 | \r | |
437 | //\r | |
438 | // Initialize the EFI Driver Library\r | |
439 | //\r | |
440 | Status = EfiLibInstallDriverBindingComponentName2 (\r | |
441 | ImageHandle,\r | |
442 | SystemTable,\r | |
443 | &gIScsiDriverBinding,\r | |
444 | ImageHandle,\r | |
445 | &gIScsiComponentName,\r | |
446 | &gIScsiComponentName2\r | |
447 | );\r | |
448 | \r | |
449 | if (!EFI_ERROR (Status)) {\r | |
450 | //\r | |
451 | // Install the iSCSI Initiator Name Protocol.\r | |
452 | //\r | |
453 | Status = gBS->InstallProtocolInterface (\r | |
454 | &ImageHandle,\r | |
455 | &gEfiIScsiInitiatorNameProtocolGuid,\r | |
456 | EFI_NATIVE_INTERFACE,\r | |
457 | &gIScsiInitiatorName\r | |
458 | );\r | |
459 | if (EFI_ERROR (Status)) {\r | |
460 | gBS->UninstallMultipleProtocolInterfaces (\r | |
461 | ImageHandle,\r | |
462 | &gEfiDriverBindingProtocolGuid,\r | |
463 | &gIScsiDriverBinding,\r | |
464 | &gEfiComponentName2ProtocolGuid,\r | |
465 | &gIScsiComponentName2,\r | |
466 | &gEfiComponentNameProtocolGuid,\r | |
467 | &gIScsiComponentName,\r | |
468 | NULL\r | |
469 | );\r | |
470 | return Status;\r | |
471 | }\r | |
472 | \r | |
473 | //\r | |
474 | // Initialize the configuration form of iSCSI.\r | |
475 | //\r | |
476 | Status = IScsiConfigFormInit ();\r | |
477 | if (EFI_ERROR (Status)) {\r | |
478 | gBS->UninstallMultipleProtocolInterfaces (\r | |
479 | ImageHandle,\r | |
480 | &gEfiDriverBindingProtocolGuid,\r | |
481 | &gIScsiDriverBinding,\r | |
482 | &gEfiComponentName2ProtocolGuid,\r | |
483 | &gIScsiComponentName2,\r | |
484 | &gEfiComponentNameProtocolGuid,\r | |
485 | &gIScsiComponentName,\r | |
486 | &gEfiIScsiInitiatorNameProtocolGuid,\r | |
487 | &gIScsiInitiatorName,\r | |
488 | NULL\r | |
489 | );\r | |
490 | }\r | |
491 | }\r | |
492 | return Status;\r | |
493 | }\r | |
494 | \r |