]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Bus/Scsi/ScsiBusDxe/ScsiBus.c
f4282146c605a16fd58f784e815ab830c6e0b90a
[mirror_edk2.git] / MdeModulePkg / Bus / Scsi / ScsiBusDxe / ScsiBus.c
1 /** @file
2 SCSI Bus driver that layers on every SCSI Pass Thru and
3 Extended SCSI Pass Thru protocol in the system.
4
5 Copyright (c) 2006 - 2008, Intel Corporation. <BR>
6 All rights reserved. This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
10
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13
14 **/
15
16
17 #include "ScsiBus.h"
18
19
20 EFI_DRIVER_BINDING_PROTOCOL gSCSIBusDriverBinding = {
21 SCSIBusDriverBindingSupported,
22 SCSIBusDriverBindingStart,
23 SCSIBusDriverBindingStop,
24 0xa,
25 NULL,
26 NULL
27 };
28
29
30 //
31 // The ScsiBusProtocol is just used to locate ScsiBusDev
32 // structure in the SCSIBusDriverBindingStop(). Then we can
33 // Close all opened protocols and release this structure.
34 //
35 EFI_GUID mScsiBusProtocolGuid = EFI_SCSI_BUS_PROTOCOL_GUID;
36
37 VOID *mWorkingBuffer;
38
39 /**
40 Convert EFI_SCSI_IO_SCSI_REQUEST_PACKET packet to EFI_SCSI_PASS_THRU_SCSI_REQUEST_PACKET packet.
41
42 @param Packet The pointer of EFI_SCSI_IO_SCSI_REQUEST_PACKET
43 @param CommandPacket The pointer of EFI_SCSI_PASS_THRU_SCSI_REQUEST_PACKET
44
45 **/
46 EFI_STATUS
47 EFIAPI
48 ScsiioToPassThruPacket (
49 IN EFI_SCSI_IO_SCSI_REQUEST_PACKET *Packet,
50 OUT EFI_SCSI_PASS_THRU_SCSI_REQUEST_PACKET *CommandPacket
51 );
52
53 /**
54 Convert EFI_SCSI_PASS_THRU_SCSI_REQUEST_PACKET packet to EFI_SCSI_IO_SCSI_REQUEST_PACKET packet.
55
56 @param ScsiPacket The pointer of EFI_SCSI_PASS_THRU_SCSI_REQUEST_PACKET
57 @param Packet The pointer of EFI_SCSI_IO_SCSI_REQUEST_PACKET
58
59 **/
60 EFI_STATUS
61 EFIAPI
62 PassThruToScsiioPacket (
63 IN EFI_SCSI_PASS_THRU_SCSI_REQUEST_PACKET *ScsiPacket,
64 OUT EFI_SCSI_IO_SCSI_REQUEST_PACKET *Packet
65 );
66
67 /**
68 Notify Function in which convert EFI1.0 PassThru Packet back to UEF2.0
69 SCSI IO Packet.
70
71 @param Event The instance of EFI_EVENT.
72 @param Context The parameter passed in.
73
74 **/
75 VOID
76 EFIAPI
77 NotifyFunction (
78 IN EFI_EVENT Event,
79 IN VOID *Context
80 );
81
82 /**
83 The user Entry Point for module ScsiBus. The user code starts with this function.
84
85 @param ImageHandle The firmware allocated handle for the EFI image.
86 @param SystemTable A pointer to the EFI System Table.
87
88 @retval EFI_SUCCESS The entry point is executed successfully.
89 @retval other Some error occurs when executing this entry point.
90
91 **/
92 EFI_STATUS
93 EFIAPI
94 InitializeScsiBus(
95 IN EFI_HANDLE ImageHandle,
96 IN EFI_SYSTEM_TABLE *SystemTable
97 )
98 {
99 EFI_STATUS Status;
100
101 //
102 // Install driver model protocol(s).
103 //
104 Status = EfiLibInstallDriverBindingComponentName2 (
105 ImageHandle,
106 SystemTable,
107 &gSCSIBusDriverBinding,
108 ImageHandle,
109 &gScsiBusComponentName,
110 &gScsiBusComponentName2
111 );
112 ASSERT_EFI_ERROR (Status);
113
114 return Status;
115 }
116
117
118 /**
119 Test to see if this driver supports ControllerHandle.
120
121 This service is called by the EFI boot service ConnectController(). In order
122 to make drivers as small as possible, there are a few calling restrictions for
123 this service. ConnectController() must follow these calling restrictions. If
124 any other agent wishes to call Supported() it must also follow these calling
125 restrictions.
126
127 @param This Protocol instance pointer.
128 @param ControllerHandle Handle of device to test
129 @param RemainingDevicePath Optional parameter use to pick a specific child
130 device to start.
131
132 @retval EFI_SUCCESS This driver supports this device
133 @retval EFI_ALREADY_STARTED This driver is already running on this device
134 @retval other This driver does not support this device
135
136 **/
137 EFI_STATUS
138 EFIAPI
139 SCSIBusDriverBindingSupported (
140 IN EFI_DRIVER_BINDING_PROTOCOL *This,
141 IN EFI_HANDLE Controller,
142 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
143 )
144 {
145 EFI_STATUS Status;
146 EFI_SCSI_PASS_THRU_PROTOCOL *PassThru;
147 EFI_EXT_SCSI_PASS_THRU_PROTOCOL *ExtPassThru;
148 //
149 // Check for the existence of Extended SCSI Pass Thru Protocol and SCSI Pass Thru Protocol
150 //
151 Status = gBS->OpenProtocol (
152 Controller,
153 &gEfiExtScsiPassThruProtocolGuid,
154 (VOID **)&ExtPassThru,
155 This->DriverBindingHandle,
156 Controller,
157 EFI_OPEN_PROTOCOL_BY_DRIVER
158 );
159
160 if (Status == EFI_ALREADY_STARTED) {
161 return EFI_SUCCESS;
162 }
163
164 if (EFI_ERROR (Status)) {
165 Status = gBS->OpenProtocol (
166 Controller,
167 &gEfiScsiPassThruProtocolGuid,
168 (VOID **)&PassThru,
169 This->DriverBindingHandle,
170 Controller,
171 EFI_OPEN_PROTOCOL_BY_DRIVER
172 );
173
174 if (Status == EFI_ALREADY_STARTED) {
175 return EFI_SUCCESS;
176 }
177
178 if (EFI_ERROR (Status)) {
179 return Status;
180 }
181
182 gBS->CloseProtocol (
183 Controller,
184 &gEfiScsiPassThruProtocolGuid,
185 This->DriverBindingHandle,
186 Controller
187 );
188 return EFI_SUCCESS;
189 }
190
191 gBS->CloseProtocol (
192 Controller,
193 &gEfiExtScsiPassThruProtocolGuid,
194 This->DriverBindingHandle,
195 Controller
196 );
197
198 return EFI_SUCCESS;
199 }
200
201
202 /**
203 Start this driver on ControllerHandle.
204
205 This service is called by the EFI boot service ConnectController(). In order
206 to make drivers as small as possible, there are a few calling restrictions for
207 this service. ConnectController() must follow these calling restrictions. If
208 any other agent wishes to call Start() it must also follow these calling
209 restrictions.
210
211 @param This Protocol instance pointer.
212 @param ControllerHandle Handle of device to bind driver to
213 @param RemainingDevicePath Optional parameter use to pick a specific child
214 device to start.
215
216 @retval EFI_SUCCESS This driver is added to ControllerHandle
217 @retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle
218 @retval other This driver does not support this device
219
220 **/
221 EFI_STATUS
222 EFIAPI
223 SCSIBusDriverBindingStart (
224 IN EFI_DRIVER_BINDING_PROTOCOL *This,
225 IN EFI_HANDLE Controller,
226 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
227 )
228 {
229 UINT64 Lun;
230 UINT8 *TargetId;
231 BOOLEAN ScanOtherPuns;
232 BOOLEAN FromFirstTarget;
233 BOOLEAN ExtScsiSupport;
234 EFI_STATUS Status;
235 EFI_STATUS DevicePathStatus;
236 EFI_STATUS PassThruStatus;
237 SCSI_BUS_DEVICE *ScsiBusDev;
238 SCSI_TARGET_ID *ScsiTargetId;
239 EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;
240 EFI_SCSI_PASS_THRU_PROTOCOL *ScsiInterface;
241 EFI_EXT_SCSI_PASS_THRU_PROTOCOL *ExtScsiInterface;
242 EFI_SCSI_BUS_PROTOCOL *BusIdentify;
243
244 TargetId = NULL;
245 ScsiTargetId = NULL;
246 ScanOtherPuns = TRUE;
247 FromFirstTarget = FALSE;
248 ExtScsiSupport = FALSE;
249 PassThruStatus = EFI_SUCCESS;
250
251 ScsiTargetId = AllocateZeroPool(sizeof(SCSI_TARGET_ID));
252 if (ScsiTargetId == NULL) {
253 return EFI_OUT_OF_RESOURCES;
254 }
255
256 TargetId = &ScsiTargetId->ScsiId.ExtScsi[0];
257
258 DevicePathStatus = gBS->OpenProtocol (
259 Controller,
260 &gEfiDevicePathProtocolGuid,
261 (VOID **) &ParentDevicePath,
262 This->DriverBindingHandle,
263 Controller,
264 EFI_OPEN_PROTOCOL_BY_DRIVER
265 );
266 if (EFI_ERROR (DevicePathStatus) && (DevicePathStatus != EFI_ALREADY_STARTED)) {
267 return DevicePathStatus;
268 }
269
270 //
271 // To keep backward compatibility, UEFI ExtPassThru Protocol is supported as well as
272 // EFI PassThru Protocol. From priority perspective, ExtPassThru Protocol is firstly
273 // tried to open on host controller handle. If fails, then PassThru Protocol is tried instead.
274 //
275 Status = gBS->OpenProtocol (
276 Controller,
277 &gEfiExtScsiPassThruProtocolGuid,
278 (VOID **) &ExtScsiInterface,
279 This->DriverBindingHandle,
280 Controller,
281 EFI_OPEN_PROTOCOL_BY_DRIVER
282 );
283 //
284 // Fail to open UEFI ExtendPassThru Protocol, then try to open EFI PassThru Protocol instead.
285 //
286 if (EFI_ERROR(Status) && (Status != EFI_ALREADY_STARTED)) {
287 Status = gBS->OpenProtocol (
288 Controller,
289 &gEfiScsiPassThruProtocolGuid,
290 (VOID **) &ScsiInterface,
291 This->DriverBindingHandle,
292 Controller,
293 EFI_OPEN_PROTOCOL_BY_DRIVER
294 );
295 //
296 // Fail to open EFI PassThru Protocol, Close the DevicePathProtocol if it is opened by this time.
297 //
298 if (EFI_ERROR (Status) && (Status != EFI_ALREADY_STARTED)) {
299 if (!EFI_ERROR(DevicePathStatus)) {
300 gBS->CloseProtocol (
301 Controller,
302 &gEfiDevicePathProtocolGuid,
303 This->DriverBindingHandle,
304 Controller
305 );
306 }
307 return Status;
308 }
309 } else {
310 //
311 // Succeed to open ExtPassThru Protocol, and meanwhile open PassThru Protocol
312 // with BY_DRIVER if it is also present on the handle. The intent is to prevent
313 // another SCSI Bus Driver to work on the same host handle.
314 //
315 ExtScsiSupport = TRUE;
316 PassThruStatus = gBS->OpenProtocol (
317 Controller,
318 &gEfiScsiPassThruProtocolGuid,
319 (VOID **) &ScsiInterface,
320 This->DriverBindingHandle,
321 Controller,
322 EFI_OPEN_PROTOCOL_BY_DRIVER
323 );
324 }
325
326 if (Status != EFI_ALREADY_STARTED) {
327 //
328 // Go through here means either ExtPassThru or PassThru Protocol is successfully opened
329 // on this handle for this time. Then construct Host controller private data.
330 //
331 ScsiBusDev = NULL;
332 ScsiBusDev = AllocateZeroPool(sizeof(SCSI_BUS_DEVICE));
333 if (ScsiBusDev == NULL) {
334 Status = EFI_OUT_OF_RESOURCES;
335 goto ErrorExit;
336 }
337 ScsiBusDev->Signature = SCSI_BUS_DEVICE_SIGNATURE;
338 ScsiBusDev->ExtScsiSupport = ExtScsiSupport;
339 ScsiBusDev->DevicePath = ParentDevicePath;
340 if (ScsiBusDev->ExtScsiSupport) {
341 ScsiBusDev->ExtScsiInterface = ExtScsiInterface;
342 } else {
343 ScsiBusDev->ScsiInterface = ScsiInterface;
344 }
345
346 //
347 // Install EFI_SCSI_BUS_PROTOCOL to the controller handle, So ScsiBusDev could be
348 // retrieved on this controller handle. With ScsiBusDev, we can know which PassThru
349 // Protocol is present on the handle, UEFI ExtPassThru Protocol or EFI PassThru Protocol.
350 //
351 Status = gBS->InstallProtocolInterface (
352 &Controller,
353 &mScsiBusProtocolGuid,
354 EFI_NATIVE_INTERFACE,
355 &ScsiBusDev->BusIdentify
356 );
357 if (EFI_ERROR (Status)) {
358 goto ErrorExit;
359 }
360 } else {
361 //
362 // Go through here means Start() is re-invoked again, nothing special is required to do except
363 // picking up Host controller private information.
364 //
365 Status = gBS->OpenProtocol (
366 Controller,
367 &mScsiBusProtocolGuid,
368 (VOID **) &BusIdentify,
369 This->DriverBindingHandle,
370 Controller,
371 EFI_OPEN_PROTOCOL_GET_PROTOCOL
372 );
373
374 if (EFI_ERROR (Status)) {
375 return Status;
376 }
377 ScsiBusDev = SCSI_BUS_CONTROLLER_DEVICE_FROM_THIS (BusIdentify);
378 }
379
380 if (RemainingDevicePath == NULL) {
381 SetMem (ScsiTargetId, TARGET_MAX_BYTES,0xFF);
382 Lun = 0;
383 FromFirstTarget = TRUE;
384 } else {
385 if (ScsiBusDev->ExtScsiSupport) {
386 ScsiBusDev->ExtScsiInterface->GetTargetLun (ScsiBusDev->ExtScsiInterface, RemainingDevicePath, &TargetId, &Lun);
387 } else {
388 ScsiBusDev->ScsiInterface->GetTargetLun (ScsiBusDev->ScsiInterface, RemainingDevicePath, &ScsiTargetId->ScsiId.Scsi, &Lun);
389 }
390 }
391
392 while(ScanOtherPuns) {
393 if (FromFirstTarget) {
394 //
395 // Remaining Device Path is NULL, scan all the possible Puns in the
396 // SCSI Channel.
397 //
398 if (ScsiBusDev->ExtScsiSupport) {
399 Status = ScsiBusDev->ExtScsiInterface->GetNextTargetLun (ScsiBusDev->ExtScsiInterface, &TargetId, &Lun);
400 } else {
401 Status = ScsiBusDev->ScsiInterface->GetNextDevice (ScsiBusDev->ScsiInterface, &ScsiTargetId->ScsiId.Scsi, &Lun);
402 }
403 if (EFI_ERROR (Status)) {
404 //
405 // no legal Pun and Lun found any more
406 //
407 break;
408 }
409 } else {
410 ScanOtherPuns = FALSE;
411 }
412 //
413 // Avoid creating handle for the host adapter.
414 //
415 if (ScsiBusDev->ExtScsiSupport) {
416 if ((ScsiTargetId->ScsiId.Scsi) == ScsiBusDev->ExtScsiInterface->Mode->AdapterId) {
417 continue;
418 }
419 } else {
420 if ((ScsiTargetId->ScsiId.Scsi) == ScsiBusDev->ScsiInterface->Mode->AdapterId) {
421 continue;
422 }
423 }
424 //
425 // Scan for the scsi device, if it attaches to the scsi bus,
426 // then create handle and install scsi i/o protocol.
427 //
428 Status = ScsiScanCreateDevice (This, Controller, ScsiTargetId, Lun, ScsiBusDev);
429 }
430 FreePool (ScsiTargetId);
431 return EFI_SUCCESS;
432
433 ErrorExit:
434
435 if (ScsiBusDev != NULL) {
436 FreePool (ScsiBusDev);
437 }
438
439 if (ExtScsiSupport) {
440 gBS->CloseProtocol (
441 Controller,
442 &gEfiExtScsiPassThruProtocolGuid,
443 This->DriverBindingHandle,
444 Controller
445 );
446 if (!EFI_ERROR (PassThruStatus)) {
447 gBS->CloseProtocol (
448 Controller,
449 &gEfiScsiPassThruProtocolGuid,
450 This->DriverBindingHandle,
451 Controller
452 );
453 }
454 } else {
455 gBS->CloseProtocol (
456 Controller,
457 &gEfiScsiPassThruProtocolGuid,
458 This->DriverBindingHandle,
459 Controller
460 );
461 }
462 return Status;
463 }
464
465 /**
466 Stop this driver on ControllerHandle.
467
468 This service is called by the EFI boot service DisconnectController().
469 In order to make drivers as small as possible, there are a few calling
470 restrictions for this service. DisconnectController() must follow these
471 calling restrictions. If any other agent wishes to call Stop() it must also
472 follow these calling restrictions.
473
474 @param This Protocol instance pointer.
475 @param ControllerHandle Handle of device to stop driver on
476 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
477 children is zero stop the entire bus driver.
478 @param ChildHandleBuffer List of Child Handles to Stop.
479
480 @retval EFI_SUCCESS This driver is removed ControllerHandle
481 @retval other This driver was not removed from this device
482
483 **/
484 EFI_STATUS
485 EFIAPI
486 SCSIBusDriverBindingStop (
487 IN EFI_DRIVER_BINDING_PROTOCOL *This,
488 IN EFI_HANDLE Controller,
489 IN UINTN NumberOfChildren,
490 IN EFI_HANDLE *ChildHandleBuffer
491 )
492 {
493 EFI_STATUS Status;
494 BOOLEAN AllChildrenStopped;
495 UINTN Index;
496 EFI_SCSI_IO_PROTOCOL *ScsiIo;
497 SCSI_IO_DEV *ScsiIoDevice;
498 VOID *ScsiPassThru;
499 EFI_SCSI_BUS_PROTOCOL *Scsidentifier;
500 SCSI_BUS_DEVICE *ScsiBusDev;
501
502 if (NumberOfChildren == 0) {
503 //
504 // Get the SCSI_BUS_DEVICE
505 //
506 Status = gBS->OpenProtocol (
507 Controller,
508 &mScsiBusProtocolGuid,
509 (VOID **) &Scsidentifier,
510 This->DriverBindingHandle,
511 Controller,
512 EFI_OPEN_PROTOCOL_GET_PROTOCOL
513 );
514
515 if (EFI_ERROR (Status)) {
516 return EFI_DEVICE_ERROR;
517 }
518
519 ScsiBusDev = SCSI_BUS_CONTROLLER_DEVICE_FROM_THIS (Scsidentifier);
520
521 //
522 // Uninstall SCSI Bus Protocol
523 //
524 gBS->UninstallProtocolInterface (
525 Controller,
526 &mScsiBusProtocolGuid,
527 &ScsiBusDev->BusIdentify
528 );
529
530 //
531 // Close the bus driver
532 //
533 if (ScsiBusDev->ExtScsiSupport) {
534 gBS->CloseProtocol (
535 Controller,
536 &gEfiExtScsiPassThruProtocolGuid,
537 This->DriverBindingHandle,
538 Controller
539 );
540 } else {
541 gBS->CloseProtocol (
542 Controller,
543 &gEfiScsiPassThruProtocolGuid,
544 This->DriverBindingHandle,
545 Controller
546 );
547 }
548
549 gBS->CloseProtocol (
550 Controller,
551 &gEfiDevicePathProtocolGuid,
552 This->DriverBindingHandle,
553 Controller
554 );
555 FreePool (ScsiBusDev);
556 return EFI_SUCCESS;
557 }
558
559 AllChildrenStopped = TRUE;
560
561 for (Index = 0; Index < NumberOfChildren; Index++) {
562
563 Status = gBS->OpenProtocol (
564 ChildHandleBuffer[Index],
565 &gEfiScsiIoProtocolGuid,
566 (VOID **) &ScsiIo,
567 This->DriverBindingHandle,
568 Controller,
569 EFI_OPEN_PROTOCOL_GET_PROTOCOL
570 );
571 if (EFI_ERROR (Status)) {
572 AllChildrenStopped = FALSE;
573 continue;
574 }
575
576 ScsiIoDevice = SCSI_IO_DEV_FROM_THIS (ScsiIo);
577 //
578 // Close the child handle
579 //
580 if (ScsiIoDevice->ExtScsiSupport) {
581 Status = gBS->CloseProtocol (
582 Controller,
583 &gEfiExtScsiPassThruProtocolGuid,
584 This->DriverBindingHandle,
585 ChildHandleBuffer[Index]
586 );
587
588 } else {
589 Status = gBS->CloseProtocol (
590 Controller,
591 &gEfiScsiPassThruProtocolGuid,
592 This->DriverBindingHandle,
593 ChildHandleBuffer[Index]
594 );
595 }
596
597 Status = gBS->UninstallMultipleProtocolInterfaces (
598 ChildHandleBuffer[Index],
599 &gEfiDevicePathProtocolGuid,
600 ScsiIoDevice->DevicePath,
601 &gEfiScsiIoProtocolGuid,
602 &ScsiIoDevice->ScsiIo,
603 NULL
604 );
605 if (EFI_ERROR (Status)) {
606 AllChildrenStopped = FALSE;
607 if (ScsiIoDevice->ExtScsiSupport) {
608 gBS->OpenProtocol (
609 Controller,
610 &gEfiExtScsiPassThruProtocolGuid,
611 &ScsiPassThru,
612 This->DriverBindingHandle,
613 ChildHandleBuffer[Index],
614 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
615 );
616 } else {
617 gBS->OpenProtocol (
618 Controller,
619 &gEfiScsiPassThruProtocolGuid,
620 &ScsiPassThru,
621 This->DriverBindingHandle,
622 ChildHandleBuffer[Index],
623 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
624 );
625 }
626 } else {
627 FreePool (ScsiIoDevice);
628 }
629 }
630
631 if (!AllChildrenStopped) {
632 return EFI_DEVICE_ERROR;
633 }
634
635 return EFI_SUCCESS;
636 }
637
638
639 /**
640 Retrieves the device type information of the SCSI Controller.
641
642 @param This Protocol instance pointer.
643 @param DeviceType A pointer to the device type information retrieved from
644 the SCSI Controller.
645
646 @retval EFI_SUCCESS Retrieves the device type information successfully.
647 @retval EFI_INVALID_PARAMETER The DeviceType is NULL.
648
649 **/
650 EFI_STATUS
651 EFIAPI
652 ScsiGetDeviceType (
653 IN EFI_SCSI_IO_PROTOCOL *This,
654 OUT UINT8 *DeviceType
655 )
656 {
657 SCSI_IO_DEV *ScsiIoDevice;
658
659 if (DeviceType == NULL) {
660 return EFI_INVALID_PARAMETER;
661 }
662
663 ScsiIoDevice = SCSI_IO_DEV_FROM_THIS (This);
664 *DeviceType = ScsiIoDevice->ScsiDeviceType;
665 return EFI_SUCCESS;
666 }
667
668
669 /**
670 Retrieves the device location in the SCSI channel.
671
672 @param This Protocol instance pointer.
673 @param Target A pointer to the Target ID of a SCSI device
674 on the SCSI channel.
675 @param Lun A pointer to the LUN of the SCSI device on
676 the SCSI channel.
677
678 @retval EFI_SUCCESS Retrieves the device location successfully.
679 @retval EFI_INVALID_PARAMETER The Target or Lun is NULL.
680
681 **/
682 EFI_STATUS
683 EFIAPI
684 ScsiGetDeviceLocation (
685 IN EFI_SCSI_IO_PROTOCOL *This,
686 IN OUT UINT8 **Target,
687 OUT UINT64 *Lun
688 )
689 {
690 SCSI_IO_DEV *ScsiIoDevice;
691
692 if (Target == NULL || Lun == NULL) {
693 return EFI_INVALID_PARAMETER;
694 }
695
696 ScsiIoDevice = SCSI_IO_DEV_FROM_THIS (This);
697
698 CopyMem (*Target,&ScsiIoDevice->Pun, TARGET_MAX_BYTES);
699
700 *Lun = ScsiIoDevice->Lun;
701
702 return EFI_SUCCESS;
703 }
704
705 /**
706 Resets the SCSI Bus that the SCSI Controller is attached to.
707
708 @param This Protocol instance pointer.
709
710 @retval EFI_SUCCESS The SCSI bus is reset successfully.
711 @retval EFI_DEVICE_ERROR Errors encountered when resetting the SCSI bus.
712 @retval EFI_UNSUPPORTED The bus reset operation is not supported by the
713 SCSI Host Controller.
714 @retval EFI_TIMEOUT A timeout occurred while attempting to reset
715 the SCSI bus.
716 **/
717 EFI_STATUS
718 EFIAPI
719 ScsiResetBus (
720 IN EFI_SCSI_IO_PROTOCOL *This
721 )
722 {
723 SCSI_IO_DEV *ScsiIoDevice;
724
725 ScsiIoDevice = SCSI_IO_DEV_FROM_THIS (This);
726
727 if (ScsiIoDevice->ExtScsiSupport){
728 return ScsiIoDevice->ExtScsiPassThru->ResetChannel (ScsiIoDevice->ExtScsiPassThru);
729 } else {
730 return ScsiIoDevice->ScsiPassThru->ResetChannel (ScsiIoDevice->ScsiPassThru);
731 }
732 }
733
734
735 /**
736 Resets the SCSI Controller that the device handle specifies.
737
738 @param This Protocol instance pointer.
739
740 @retval EFI_SUCCESS Reset the SCSI controller successfully.
741 @retval EFI_DEVICE_ERROR Errors are encountered when resetting the SCSI Controller.
742 @retval EFI_UNSUPPORTED The SCSI bus does not support a device reset operation.
743 @retval EFI_TIMEOUT A timeout occurred while attempting to reset the
744 SCSI Controller.
745 **/
746 EFI_STATUS
747 EFIAPI
748 ScsiResetDevice (
749 IN EFI_SCSI_IO_PROTOCOL *This
750 )
751 {
752 SCSI_IO_DEV *ScsiIoDevice;
753 UINT8 Target[TARGET_MAX_BYTES];
754
755 ScsiIoDevice = SCSI_IO_DEV_FROM_THIS (This);
756 CopyMem (Target,&ScsiIoDevice->Pun, TARGET_MAX_BYTES);
757
758
759 if (ScsiIoDevice->ExtScsiSupport) {
760 return ScsiIoDevice->ExtScsiPassThru->ResetTargetLun (
761 ScsiIoDevice->ExtScsiPassThru,
762 Target,
763 ScsiIoDevice->Lun
764 );
765 } else {
766 return ScsiIoDevice->ScsiPassThru->ResetTarget (
767 ScsiIoDevice->ScsiPassThru,
768 ScsiIoDevice->Pun.ScsiId.Scsi,
769 ScsiIoDevice->Lun
770 );
771 }
772 }
773
774
775 /**
776 Sends a SCSI Request Packet to the SCSI Controller for execution.
777
778 @param This Protocol instance pointer.
779 @param CommandPacket The SCSI request packet to send to the SCSI
780 Controller specified by the device handle.
781 @param Event If the SCSI bus where the SCSI device is attached
782 does not support non-blocking I/O, then Event is
783 ignored, and blocking I/O is performed.
784 If Event is NULL, then blocking I/O is performed.
785 If Event is not NULL and non-blocking I/O is
786 supported, then non-blocking I/O is performed,
787 and Event will be signaled when the SCSI Request
788 Packet completes.
789
790 @retval EFI_SUCCESS The SCSI Request Packet was sent by the host
791 successfully, and TransferLength bytes were
792 transferred to/from DataBuffer.See
793 HostAdapterStatus, TargetStatus,
794 SenseDataLength, and SenseData in that order
795 for additional status information.
796 @retval EFI_BAD_BUFFER_SIZE The SCSI Request Packet was executed,
797 but the entire DataBuffer could not be transferred.
798 The actual number of bytes transferred is returned
799 in TransferLength. See HostAdapterStatus,
800 TargetStatus, SenseDataLength, and SenseData in
801 that order for additional status information.
802 @retval EFI_NOT_READY The SCSI Request Packet could not be sent because
803 there are too many SCSI Command Packets already
804 queued.The caller may retry again later.
805 @retval EFI_DEVICE_ERROR A device error occurred while attempting to send
806 the SCSI Request Packet. See HostAdapterStatus,
807 TargetStatus, SenseDataLength, and SenseData in
808 that order for additional status information.
809 @retval EFI_INVALID_PARAMETER The contents of CommandPacket are invalid.
810 The SCSI Request Packet was not sent, so no
811 additional status information is available.
812 @retval EFI_UNSUPPORTED The command described by the SCSI Request Packet
813 is not supported by the SCSI initiator(i.e., SCSI
814 Host Controller). The SCSI Request Packet was not
815 sent, so no additional status information is
816 available.
817 @retval EFI_TIMEOUT A timeout occurred while waiting for the SCSI
818 Request Packet to execute. See HostAdapterStatus,
819 TargetStatus, SenseDataLength, and SenseData in
820 that order for additional status information.
821 **/
822 EFI_STATUS
823 EFIAPI
824 ScsiExecuteSCSICommand (
825 IN EFI_SCSI_IO_PROTOCOL *This,
826 IN OUT EFI_SCSI_IO_SCSI_REQUEST_PACKET *Packet,
827 IN EFI_EVENT Event OPTIONAL
828 )
829 {
830 SCSI_IO_DEV *ScsiIoDevice;
831 EFI_STATUS Status;
832 UINT8 Target[TARGET_MAX_BYTES];
833 EFI_EVENT PacketEvent;
834 EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET *ExtRequestPacket;
835 SCSI_EVENT_DATA EventData;
836
837 PacketEvent = NULL;
838
839 if (Packet == NULL) {
840 return EFI_INVALID_PARAMETER;
841 }
842
843 ScsiIoDevice = SCSI_IO_DEV_FROM_THIS (This);
844 CopyMem (Target,&ScsiIoDevice->Pun, TARGET_MAX_BYTES);
845
846 if (ScsiIoDevice->ExtScsiSupport) {
847 ExtRequestPacket = (EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET *) Packet;
848 Status = ScsiIoDevice->ExtScsiPassThru->PassThru (
849 ScsiIoDevice->ExtScsiPassThru,
850 Target,
851 ScsiIoDevice->Lun,
852 ExtRequestPacket,
853 Event
854 );
855 } else {
856
857 mWorkingBuffer = AllocatePool (sizeof(EFI_SCSI_PASS_THRU_SCSI_REQUEST_PACKET));
858
859 if (mWorkingBuffer == NULL) {
860 return EFI_DEVICE_ERROR;
861 }
862
863 //
864 // Convert package into EFI1.0, EFI_SCSI_PASS_THRU_SCSI_REQUEST_PACKET.
865 //
866 Status = ScsiioToPassThruPacket(Packet, (EFI_SCSI_PASS_THRU_SCSI_REQUEST_PACKET*)mWorkingBuffer);
867 if (EFI_ERROR(Status)) {
868 FreePool(mWorkingBuffer);
869 return Status;
870 }
871
872 if (((ScsiIoDevice->ScsiPassThru->Mode->Attributes & EFI_SCSI_PASS_THRU_ATTRIBUTES_NONBLOCKIO) != 0) && (Event != NULL)) {
873 EventData.Data1 = (VOID*)Packet;
874 EventData.Data2 = Event;
875 //
876 // Create Event
877 //
878 Status = gBS->CreateEvent (
879 EVT_NOTIFY_SIGNAL,
880 TPL_CALLBACK,
881 NotifyFunction,
882 &EventData,
883 &PacketEvent
884 );
885 if (EFI_ERROR(Status)) {
886 FreePool(mWorkingBuffer);
887 return Status;
888 }
889
890 Status = ScsiIoDevice->ScsiPassThru->PassThru (
891 ScsiIoDevice->ScsiPassThru,
892 ScsiIoDevice->Pun.ScsiId.Scsi,
893 ScsiIoDevice->Lun,
894 mWorkingBuffer,
895 PacketEvent
896 );
897
898 if (EFI_ERROR(Status)) {
899 FreePool(mWorkingBuffer);
900 gBS->CloseEvent(PacketEvent);
901 return Status;
902 }
903
904 } else {
905 //
906 // If there's no event or SCSI Device doesn't support NON-BLOCKING, just convert
907 // EFI1.0 PassThru packet back to UEFI2.0 SCSI IO Packet.
908 //
909 Status = ScsiIoDevice->ScsiPassThru->PassThru (
910 ScsiIoDevice->ScsiPassThru,
911 ScsiIoDevice->Pun.ScsiId.Scsi,
912 ScsiIoDevice->Lun,
913 mWorkingBuffer,
914 Event
915 );
916 if (EFI_ERROR(Status)) {
917 FreePool(mWorkingBuffer);
918 return Status;
919 }
920
921 PassThruToScsiioPacket((EFI_SCSI_PASS_THRU_SCSI_REQUEST_PACKET*)mWorkingBuffer,Packet);
922 //
923 // After converting EFI1.0 PassThru Packet back to UEFI2.0 SCSI IO Packet,
924 // free mWorkingBuffer.
925 //
926 FreePool(mWorkingBuffer);
927 }
928 }
929 return Status;
930 }
931
932
933 /**
934 Scan SCSI Bus to discover the device, and attach ScsiIoProtocol to it.
935
936 @param This Protocol instance pointer
937 @param Controller Controller handle
938 @param TargetId Tartget to be scanned
939 @param Lun The Lun of the SCSI device on the SCSI channel.
940 @param ScsiBusDev The pointer of SCSI_BUS_DEVICE
941
942 @retval EFI_SUCCESS Successfully to discover the device and attach
943 ScsiIoProtocol to it.
944 @retval EFI_OUT_OF_RESOURCES Fail to discover the device.
945
946 **/
947 EFI_STATUS
948 EFIAPI
949 ScsiScanCreateDevice (
950 IN EFI_DRIVER_BINDING_PROTOCOL *This,
951 IN EFI_HANDLE Controller,
952 IN SCSI_TARGET_ID *TargetId,
953 IN UINT64 Lun,
954 IN OUT SCSI_BUS_DEVICE *ScsiBusDev
955 )
956 {
957 EFI_STATUS Status;
958 SCSI_IO_DEV *ScsiIoDevice;
959 EFI_DEVICE_PATH_PROTOCOL *ScsiDevicePath;
960
961 ScsiIoDevice = AllocateZeroPool (sizeof (SCSI_IO_DEV));
962 if (ScsiIoDevice == NULL) {
963 return EFI_OUT_OF_RESOURCES;
964 }
965
966 ScsiIoDevice->Signature = SCSI_IO_DEV_SIGNATURE;
967 CopyMem(&ScsiIoDevice->Pun, TargetId, TARGET_MAX_BYTES);
968 ScsiIoDevice->Lun = Lun;
969
970 if (ScsiBusDev->ExtScsiSupport) {
971 ScsiIoDevice->ExtScsiPassThru = ScsiBusDev->ExtScsiInterface;
972 ScsiIoDevice->ExtScsiSupport = TRUE;
973 ScsiIoDevice->ScsiIo.IoAlign = ScsiIoDevice->ExtScsiPassThru->Mode->IoAlign;
974
975 } else {
976 ScsiIoDevice->ScsiPassThru = ScsiBusDev->ScsiInterface;
977 ScsiIoDevice->ExtScsiSupport = FALSE;
978 ScsiIoDevice->ScsiIo.IoAlign = ScsiIoDevice->ScsiPassThru->Mode->IoAlign;
979 }
980
981 ScsiIoDevice->ScsiIo.GetDeviceType = ScsiGetDeviceType;
982 ScsiIoDevice->ScsiIo.GetDeviceLocation = ScsiGetDeviceLocation;
983 ScsiIoDevice->ScsiIo.ResetBus = ScsiResetBus;
984 ScsiIoDevice->ScsiIo.ResetDevice = ScsiResetDevice;
985 ScsiIoDevice->ScsiIo.ExecuteScsiCommand = ScsiExecuteSCSICommand;
986
987
988 if (!DiscoverScsiDevice (ScsiIoDevice)) {
989 FreePool (ScsiIoDevice);
990 return EFI_OUT_OF_RESOURCES;
991 }
992
993 //
994 // Set Device Path
995 //
996 ScsiDevicePath = NULL;
997 if (ScsiIoDevice->ExtScsiSupport){
998 Status = ScsiIoDevice->ExtScsiPassThru->BuildDevicePath (
999 ScsiIoDevice->ExtScsiPassThru,
1000 &ScsiIoDevice->Pun.ScsiId.ExtScsi[0],
1001 ScsiIoDevice->Lun,
1002 &ScsiDevicePath
1003 );
1004 } else {
1005 Status = ScsiIoDevice->ScsiPassThru->BuildDevicePath (
1006 ScsiIoDevice->ScsiPassThru,
1007 ScsiIoDevice->Pun.ScsiId.Scsi,
1008 ScsiIoDevice->Lun,
1009 &ScsiDevicePath
1010 );
1011 }
1012
1013 if (Status == EFI_OUT_OF_RESOURCES) {
1014 FreePool (ScsiIoDevice);
1015 return Status;
1016 }
1017
1018 ScsiIoDevice->DevicePath = AppendDevicePathNode (
1019 ScsiBusDev->DevicePath,
1020 ScsiDevicePath
1021 );
1022 //
1023 // The memory space for ScsiDevicePath is allocated in
1024 // ScsiPassThru->BuildDevicePath() function; It is no longer used
1025 // after EfiAppendDevicePathNode,so free the memory it occupies.
1026 //
1027 FreePool (ScsiDevicePath);
1028
1029 if (ScsiIoDevice->DevicePath == NULL) {
1030 FreePool (ScsiIoDevice);
1031 return EFI_OUT_OF_RESOURCES;
1032 }
1033
1034 Status = gBS->InstallMultipleProtocolInterfaces (
1035 &ScsiIoDevice->Handle,
1036 &gEfiDevicePathProtocolGuid,
1037 ScsiIoDevice->DevicePath,
1038 &gEfiScsiIoProtocolGuid,
1039 &ScsiIoDevice->ScsiIo,
1040 NULL
1041 );
1042 if (EFI_ERROR (Status)) {
1043 FreePool (ScsiIoDevice->DevicePath);
1044 FreePool (ScsiIoDevice);
1045 return EFI_OUT_OF_RESOURCES;
1046 } else {
1047 if (ScsiBusDev->ExtScsiSupport) {
1048 gBS->OpenProtocol (
1049 Controller,
1050 &gEfiExtScsiPassThruProtocolGuid,
1051 (VOID **) &(ScsiBusDev->ExtScsiInterface),
1052 This->DriverBindingHandle,
1053 ScsiIoDevice->Handle,
1054 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
1055 );
1056 } else {
1057 gBS->OpenProtocol (
1058 Controller,
1059 &gEfiScsiPassThruProtocolGuid,
1060 (VOID **) &(ScsiBusDev->ScsiInterface),
1061 This->DriverBindingHandle,
1062 ScsiIoDevice->Handle,
1063 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
1064 );
1065 }
1066 }
1067 return EFI_SUCCESS;
1068 }
1069
1070
1071 /**
1072 Discovery SCSI Device
1073
1074 @param ScsiIoDevice The pointer of SCSI_IO_DEV
1075
1076 @retval TRUE Find SCSI Device and verify it.
1077 @retval FALSE Unable to find SCSI Device.
1078
1079 **/
1080 BOOLEAN
1081 DiscoverScsiDevice (
1082 IN OUT SCSI_IO_DEV *ScsiIoDevice
1083 )
1084 {
1085 EFI_STATUS Status;
1086 UINT32 InquiryDataLength;
1087 UINT8 SenseDataLength;
1088 UINT8 HostAdapterStatus;
1089 UINT8 TargetStatus;
1090 EFI_SCSI_SENSE_DATA SenseData;
1091 EFI_SCSI_INQUIRY_DATA InquiryData;
1092
1093 HostAdapterStatus = 0;
1094 TargetStatus = 0;
1095 //
1096 // Using Inquiry command to scan for the device
1097 //
1098 InquiryDataLength = sizeof (EFI_SCSI_INQUIRY_DATA);
1099 SenseDataLength = sizeof (EFI_SCSI_SENSE_DATA);
1100
1101 Status = ScsiInquiryCommand (
1102 &ScsiIoDevice->ScsiIo,
1103 EFI_TIMER_PERIOD_SECONDS (1),
1104 (VOID *) &SenseData,
1105 &SenseDataLength,
1106 &HostAdapterStatus,
1107 &TargetStatus,
1108 (VOID *) &InquiryData,
1109 &InquiryDataLength,
1110 FALSE
1111 );
1112 if (EFI_ERROR (Status)) {
1113 return FALSE;
1114 }
1115 //
1116 // Retrieved inquiry data successfully
1117 //
1118 if ((InquiryData.Peripheral_Qualifier != 0) &&
1119 (InquiryData.Peripheral_Qualifier != 3)) {
1120 return FALSE;
1121 }
1122
1123 if (InquiryData.Peripheral_Qualifier == 3) {
1124 if (InquiryData.Peripheral_Type != 0x1f) {
1125 return FALSE;
1126 }
1127 }
1128
1129 if (0x1e >= InquiryData.Peripheral_Type && InquiryData.Peripheral_Type >= 0xa) {
1130 return FALSE;
1131 }
1132
1133 //
1134 // valid device type and peripheral qualifier combination.
1135 //
1136 ScsiIoDevice->ScsiDeviceType = InquiryData.Peripheral_Type;
1137 ScsiIoDevice->RemovableDevice = InquiryData.RMB;
1138 if (InquiryData.Version == 0) {
1139 ScsiIoDevice->ScsiVersion = 0;
1140 } else {
1141 //
1142 // ANSI-approved version
1143 //
1144 ScsiIoDevice->ScsiVersion = (UINT8) (InquiryData.Version & 0x03);
1145 }
1146
1147 return TRUE;
1148 }
1149
1150
1151 /**
1152 Convert EFI_SCSI_IO_SCSI_REQUEST_PACKET packet to EFI_SCSI_PASS_THRU_SCSI_REQUEST_PACKET packet.
1153
1154 @param Packet The pointer of EFI_SCSI_IO_SCSI_REQUEST_PACKET
1155 @param CommandPacket The pointer of EFI_SCSI_PASS_THRU_SCSI_REQUEST_PACKET
1156
1157 **/
1158 EFI_STATUS
1159 EFIAPI
1160 ScsiioToPassThruPacket (
1161 IN EFI_SCSI_IO_SCSI_REQUEST_PACKET *Packet,
1162 OUT EFI_SCSI_PASS_THRU_SCSI_REQUEST_PACKET *CommandPacket
1163 )
1164 {
1165 //
1166 //EFI 1.10 doesn't support Bi-Direction Command.
1167 //
1168 if (Packet->DataDirection == EFI_SCSI_IO_DATA_DIRECTION_BIDIRECTIONAL) {
1169 return EFI_UNSUPPORTED;
1170 }
1171
1172 ZeroMem (CommandPacket, sizeof (EFI_SCSI_PASS_THRU_SCSI_REQUEST_PACKET));
1173
1174 CommandPacket->Timeout = Packet->Timeout;
1175 CommandPacket->Cdb = Packet->Cdb;
1176 CommandPacket->CdbLength = Packet->CdbLength;
1177 CommandPacket->DataDirection = Packet->DataDirection;
1178 CommandPacket->HostAdapterStatus = Packet->HostAdapterStatus;
1179 CommandPacket->TargetStatus = Packet->TargetStatus;
1180 CommandPacket->SenseData = Packet->SenseData;
1181 CommandPacket->SenseDataLength = Packet->SenseDataLength;
1182
1183 if (Packet->DataDirection == EFI_SCSI_IO_DATA_DIRECTION_READ) {
1184 CommandPacket->DataBuffer = Packet->InDataBuffer;
1185 CommandPacket->TransferLength = Packet->InTransferLength;
1186 } else if (Packet->DataDirection == EFI_SCSI_IO_DATA_DIRECTION_WRITE) {
1187 CommandPacket->DataBuffer = Packet->OutDataBuffer;
1188 CommandPacket->TransferLength = Packet->OutTransferLength;
1189 }
1190 return EFI_SUCCESS;
1191 }
1192
1193
1194 /**
1195 Convert EFI_SCSI_PASS_THRU_SCSI_REQUEST_PACKET packet to EFI_SCSI_IO_SCSI_REQUEST_PACKET packet.
1196
1197 @param ScsiPacket The pointer of EFI_SCSI_PASS_THRU_SCSI_REQUEST_PACKET
1198 @param Packet The pointer of EFI_SCSI_IO_SCSI_REQUEST_PACKET
1199
1200 **/
1201 EFI_STATUS
1202 EFIAPI
1203 PassThruToScsiioPacket (
1204 IN EFI_SCSI_PASS_THRU_SCSI_REQUEST_PACKET *ScsiPacket,
1205 OUT EFI_SCSI_IO_SCSI_REQUEST_PACKET *Packet
1206 )
1207 {
1208 Packet->Timeout = ScsiPacket->Timeout;
1209 Packet->Cdb = ScsiPacket->Cdb;
1210 Packet->CdbLength = ScsiPacket->CdbLength;
1211 Packet->DataDirection = ScsiPacket->DataDirection;
1212 Packet->HostAdapterStatus = ScsiPacket->HostAdapterStatus;
1213 Packet->TargetStatus = ScsiPacket->TargetStatus;
1214 Packet->SenseData = ScsiPacket->SenseData;
1215 Packet->SenseDataLength = ScsiPacket->SenseDataLength;
1216
1217 if (ScsiPacket->DataDirection == EFI_SCSI_IO_DATA_DIRECTION_READ) {
1218 Packet->InDataBuffer = ScsiPacket->DataBuffer;
1219 Packet->InTransferLength = ScsiPacket->TransferLength;
1220 } else if (Packet->DataDirection == EFI_SCSI_IO_DATA_DIRECTION_WRITE) {
1221 Packet->OutDataBuffer = ScsiPacket->DataBuffer;
1222 Packet->OutTransferLength = ScsiPacket->TransferLength;
1223 }
1224
1225 return EFI_SUCCESS;
1226 }
1227
1228 /**
1229 Notify Function in which convert EFI1.0 PassThru Packet back to UEF2.0
1230 SCSI IO Packet.
1231
1232 @param Event The instance of EFI_EVENT.
1233 @param Context The parameter passed in.
1234
1235 **/
1236 VOID
1237 EFIAPI
1238 NotifyFunction (
1239 IN EFI_EVENT Event,
1240 IN VOID *Context
1241 )
1242 {
1243 EFI_SCSI_IO_SCSI_REQUEST_PACKET *Packet;
1244 EFI_SCSI_PASS_THRU_SCSI_REQUEST_PACKET *ScsiPacket;
1245 EFI_EVENT CallerEvent;
1246 SCSI_EVENT_DATA *PassData;
1247
1248 PassData = (SCSI_EVENT_DATA*)Context;
1249 Packet = (EFI_SCSI_IO_SCSI_REQUEST_PACKET *)PassData->Data1;
1250 ScsiPacket = (EFI_SCSI_PASS_THRU_SCSI_REQUEST_PACKET*)mWorkingBuffer;
1251
1252 //
1253 // Convert EFI1.0 PassThru packet to UEFI2.0 SCSI IO Packet.
1254 //
1255 PassThruToScsiioPacket(ScsiPacket, Packet);
1256
1257 //
1258 // After converting EFI1.0 PassThru Packet back to UEFI2.0 SCSI IO Packet,
1259 // free mWorkingBuffer.
1260 //
1261 gBS->FreePool(mWorkingBuffer);
1262
1263 //
1264 // Signal Event to tell caller to pick up UEFI2.0 SCSI IO Packet.
1265 //
1266 CallerEvent = PassData->Data2;
1267 gBS->CloseEvent(Event);
1268 gBS->SignalEvent(CallerEvent);
1269 }
1270