1 /** @file
2   EFI_EXT_SCSI_PASS_THRU_PROTOCOL as defined in UEFI 2.0.
3   This protocol provides services that allow SCSI Pass Thru commands
4   to be sent to SCSI devices attached to a SCSI channel.
5 
6   Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR>
7   This program and the accompanying materials
8   are licensed and made available under the terms and conditions of the BSD License
9   which accompanies this distribution.  The full text of the license may be found at
10   http://opensource.org/licenses/bsd-license.php
11 
12   THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13   WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
14 
15 **/
16 
17 #ifndef __EXT_SCSI_PASS_THROUGH_PROTOCOL_H__
18 #define __EXT_SCSI_PASS_THROUGH_PROTOCOL_H__
19 
20 #define EFI_EXT_SCSI_PASS_THRU_PROTOCOL_GUID \
21   { \
22     0x143b7632, 0xb81b, 0x4cb7, {0xab, 0xd3, 0xb6, 0x25, 0xa5, 0xb9, 0xbf, 0xfe } \
23   }
24 
25 typedef struct _EFI_EXT_SCSI_PASS_THRU_PROTOCOL EFI_EXT_SCSI_PASS_THRU_PROTOCOL;
26 
27 #define TARGET_MAX_BYTES                             0x10
28 
29 #define EFI_EXT_SCSI_PASS_THRU_ATTRIBUTES_PHYSICAL   0x0001
30 #define EFI_EXT_SCSI_PASS_THRU_ATTRIBUTES_LOGICAL    0x0002
31 #define EFI_EXT_SCSI_PASS_THRU_ATTRIBUTES_NONBLOCKIO 0x0004
32 
33 //
34 // DataDirection
35 //
36 #define EFI_EXT_SCSI_DATA_DIRECTION_READ             0
37 #define EFI_EXT_SCSI_DATA_DIRECTION_WRITE            1
38 #define EFI_EXT_SCSI_DATA_DIRECTION_BIDIRECTIONAL    2
39 //
40 // HostAdapterStatus
41 //
42 #define EFI_EXT_SCSI_STATUS_HOST_ADAPTER_OK                    0x00
43 #define EFI_EXT_SCSI_STATUS_HOST_ADAPTER_TIMEOUT_COMMAND       0x09
44 #define EFI_EXT_SCSI_STATUS_HOST_ADAPTER_TIMEOUT               0x0b
45 #define EFI_EXT_SCSI_STATUS_HOST_ADAPTER_MESSAGE_REJECT        0x0d
46 #define EFI_EXT_SCSI_STATUS_HOST_ADAPTER_BUS_RESET             0x0e
47 #define EFI_EXT_SCSI_STATUS_HOST_ADAPTER_PARITY_ERROR          0x0f
48 #define EFI_EXT_SCSI_STATUS_HOST_ADAPTER_REQUEST_SENSE_FAILED  0x10
49 #define EFI_EXT_SCSI_STATUS_HOST_ADAPTER_SELECTION_TIMEOUT     0x11
50 #define EFI_EXT_SCSI_STATUS_HOST_ADAPTER_DATA_OVERRUN_UNDERRUN 0x12
51 #define EFI_EXT_SCSI_STATUS_HOST_ADAPTER_BUS_FREE              0x13
52 #define EFI_EXT_SCSI_STATUS_HOST_ADAPTER_PHASE_ERROR           0x14
53 #define EFI_EXT_SCSI_STATUS_HOST_ADAPTER_OTHER                 0x7f
54 //
55 // TargetStatus
56 //
57 #define EFI_EXT_SCSI_STATUS_TARGET_GOOD                        0x00
58 #define EFI_EXT_SCSI_STATUS_TARGET_CHECK_CONDITION             0x02
59 #define EFI_EXT_SCSI_STATUS_TARGET_CONDITION_MET               0x04
60 #define EFI_EXT_SCSI_STATUS_TARGET_BUSY                        0x08
61 #define EFI_EXT_SCSI_STATUS_TARGET_INTERMEDIATE                0x10
62 #define EFI_EXT_SCSI_STATUS_TARGET_INTERMEDIATE_CONDITION_MET  0x14
63 #define EFI_EXT_SCSI_STATUS_TARGET_RESERVATION_CONFLICT        0x18
64 #define EFI_EXT_SCSI_STATUS_TARGET_TASK_SET_FULL               0x28
65 #define EFI_EXT_SCSI_STATUS_TARGET_ACA_ACTIVE                  0x30
66 #define EFI_EXT_SCSI_STATUS_TARGET_TASK_ABORTED                0x40
67 
68 typedef struct {
69   ///
70   /// The Target ID of the host adapter on the SCSI channel.
71   ///
72   UINT32 AdapterId;
73   ///
74   /// Additional information on the attributes of the SCSI channel.
75   ///
76   UINT32 Attributes;
77   ///
78   /// Supplies the alignment requirement for any buffer used in a data transfer.
79   ///
80   UINT32 IoAlign;
81 } EFI_EXT_SCSI_PASS_THRU_MODE;
82 
83 typedef struct {
84   ///
85   /// The timeout, in 100 ns units, to use for the execution of this SCSI
86   /// Request Packet. A Timeout value of 0 means that this function
87   /// will wait indefinitely for the SCSI Request Packet to execute. If
88   /// Timeout is greater than zero, then this function will return
89   /// EFI_TIMEOUT if the time required to execute the SCSI
90   /// Request Packet is greater than Timeout.
91   ///
92   UINT64 Timeout;
93   ///
94   /// A pointer to the data buffer to transfer between the SCSI
95   /// controller and the SCSI device for read and bidirectional commands.
96   ///
97   VOID   *InDataBuffer;
98   ///
99   /// A pointer to the data buffer to transfer between the SCSI
100   /// controller and the SCSI device for write or bidirectional commands.
101   ///
102   VOID   *OutDataBuffer;
103   ///
104   /// A pointer to the sense data that was generated by the execution of
105   /// the SCSI Request Packet.
106   ///
107   VOID   *SenseData;
108   ///
109   /// A pointer to buffer that contains the Command Data Block to
110   /// send to the SCSI device specified by Target and Lun.
111   ///
112   VOID   *Cdb;
113   ///
114   /// On Input, the size, in bytes, of InDataBuffer. On output, the
115   /// number of bytes transferred between the SCSI controller and the SCSI device.
116   ///
117   UINT32 InTransferLength;
118   ///
119   /// On Input, the size, in bytes of OutDataBuffer. On Output, the
120   /// Number of bytes transferred between SCSI Controller and the SCSI device.
121   ///
122   UINT32 OutTransferLength;
123   ///
124   /// The length, in bytes, of the buffer Cdb. The standard values are 6,
125   /// 10, 12, and 16, but other values are possible if a variable length CDB is used.
126   ///
127   UINT8  CdbLength;
128   ///
129   /// The direction of the data transfer. 0 for reads, 1 for writes. A
130   /// value of 2 is Reserved for Bi-Directional SCSI commands.
131   ///
132   UINT8  DataDirection;
133   ///
134   /// The status of the host adapter specified by This when the SCSI
135   /// Request Packet was executed on the target device.
136   ///
137   UINT8  HostAdapterStatus;
138   ///
139   /// The status returned by the device specified by Target and Lun
140   /// when the SCSI Request Packet was executed.
141   ///
142   UINT8  TargetStatus;
143   ///
144   /// On input, the length in bytes of the SenseData buffer. On
145   /// output, the number of bytes written to the SenseData buffer.
146   ///
147   UINT8  SenseDataLength;
148 } EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET;
149 
150 /**
151   Sends a SCSI Request Packet to a SCSI device that is attached to the SCSI channel. This function
152   supports both blocking I/O and nonblocking I/O. The blocking I/O functionality is required, and the
153   nonblocking I/O functionality is optional.
154 
155   @param  This    A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance.
156   @param  Target  The Target is an array of size TARGET_MAX_BYTES and it represents
157                   the id of the SCSI device to send the SCSI Request Packet. Each
158                   transport driver may choose to utilize a subset of this size to suit the needs
159                   of transport target representation. For example, a Fibre Channel driver
160                   may use only 8 bytes (WWN) to represent an FC target.
161   @param  Lun     The LUN of the SCSI device to send the SCSI Request Packet.
162   @param  Packet  A pointer to the SCSI Request Packet to send to the SCSI device
163                   specified by Target and Lun.
164   @param  Event   If nonblocking I/O is not supported then Event is ignored, and blocking
165                   I/O is performed. If Event is NULL, then blocking I/O is performed. If
166                   Event is not NULL and non blocking I/O is supported, then
167                   nonblocking I/O is performed, and Event will be signaled when the
168                   SCSI Request Packet completes.
169 
170   @retval EFI_SUCCESS           The SCSI Request Packet was sent by the host. For bi-directional
171                                 commands, InTransferLength bytes were transferred from
172                                 InDataBuffer. For write and bi-directional commands,
173                                 OutTransferLength bytes were transferred by
174                                 OutDataBuffer.
175   @retval EFI_BAD_BUFFER_SIZE   The SCSI Request Packet was not executed. The number of bytes that
176                                 could be transferred is returned in InTransferLength. For write
177                                 and bi-directional commands, OutTransferLength bytes were
178                                 transferred by OutDataBuffer.
179   @retval EFI_NOT_READY         The SCSI Request Packet could not be sent because there are too many
180                                 SCSI Request Packets already queued. The caller may retry again later.
181   @retval EFI_DEVICE_ERROR      A device error occurred while attempting to send the SCSI Request
182                                 Packet.
183   @retval EFI_INVALID_PARAMETER Target, Lun, or the contents of ScsiRequestPacket are invalid.
184   @retval EFI_UNSUPPORTED       The command described by the SCSI Request Packet is not supported
185                                 by the host adapter. This includes the case of Bi-directional SCSI
186                                 commands not supported by the implementation. The SCSI Request
187                                 Packet was not sent, so no additional status information is available.
188   @retval EFI_TIMEOUT           A timeout occurred while waiting for the SCSI Request Packet to execute.
189 
190 **/
191 typedef
192 EFI_STATUS
193 (EFIAPI *EFI_EXT_SCSI_PASS_THRU_PASSTHRU)(
194   IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL                *This,
195   IN UINT8                                          *Target,
196   IN UINT64                                         Lun,
197   IN OUT EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET *Packet,
198   IN EFI_EVENT                                      Event     OPTIONAL
199   );
200 
201 /**
202   Used to retrieve the list of legal Target IDs and LUNs for SCSI devices on a SCSI channel. These
203   can either be the list SCSI devices that are actually present on the SCSI channel, or the list of legal
204   Target Ids and LUNs for the SCSI channel. Regardless, the caller of this function must probe the
205   Target ID and LUN returned to see if a SCSI device is actually present at that location on the SCSI
206   channel.
207 
208   @param  This   A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance.
209   @param  Target On input, a pointer to the Target ID (an array of size
210                  TARGET_MAX_BYTES) of a SCSI device present on the SCSI channel.
211                  On output, a pointer to the Target ID (an array of
212                  TARGET_MAX_BYTES) of the next SCSI device present on a SCSI
213                  channel. An input value of 0xF(all bytes in the array are 0xF) in the
214                  Target array retrieves the Target ID of the first SCSI device present on a
215                  SCSI channel.
216   @param  Lun    On input, a pointer to the LUN of a SCSI device present on the SCSI
217                  channel. On output, a pointer to the LUN of the next SCSI device present
218                  on a SCSI channel.
219 
220   @retval EFI_SUCCESS           The Target ID and LUN of the next SCSI device on the SCSI
221                                 channel was returned in Target and Lun.
222   @retval EFI_INVALID_PARAMETER Target array is not all 0xF, and Target and Lun were
223                                 not returned on a previous call to GetNextTargetLun().
224   @retval EFI_NOT_FOUND         There are no more SCSI devices on this SCSI channel.
225 
226 **/
227 typedef
228 EFI_STATUS
229 (EFIAPI *EFI_EXT_SCSI_PASS_THRU_GET_NEXT_TARGET_LUN)(
230   IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL                *This,
231   IN OUT UINT8                                      **Target,
232   IN OUT UINT64                                     *Lun
233   );
234 
235 /**
236   Used to allocate and build a device path node for a SCSI device on a SCSI channel.
237 
238   @param  This       A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance.
239   @param  Target     The Target is an array of size TARGET_MAX_BYTES and it specifies the
240                      Target ID of the SCSI device for which a device path node is to be
241                      allocated and built. Transport drivers may chose to utilize a subset of
242                      this size to suit the representation of targets. For example, a Fibre
243                      Channel driver may use only 8 bytes (WWN) in the array to represent a
244                      FC target.
245   @param  Lun        The LUN of the SCSI device for which a device path node is to be
246                      allocated and built.
247   @param  DevicePath A pointer to a single device path node that describes the SCSI device
248                      specified by Target and Lun. This function is responsible for
249                      allocating the buffer DevicePath with the boot service
250                      AllocatePool(). It is the caller's responsibility to free
251                      DevicePath when the caller is finished with DevicePath.
252 
253   @retval EFI_SUCCESS           The device path node that describes the SCSI device specified by
254                                 Target and Lun was allocated and returned in
255                                 DevicePath.
256   @retval EFI_INVALID_PARAMETER DevicePath is NULL.
257   @retval EFI_NOT_FOUND         The SCSI devices specified by Target and Lun does not exist
258                                 on the SCSI channel.
259   @retval EFI_OUT_OF_RESOURCES  There are not enough resources to allocate DevicePath.
260 
261 **/
262 typedef
263 EFI_STATUS
264 (EFIAPI *EFI_EXT_SCSI_PASS_THRU_BUILD_DEVICE_PATH)(
265   IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL               *This,
266   IN UINT8                                         *Target,
267   IN UINT64                                        Lun,
268   IN OUT EFI_DEVICE_PATH_PROTOCOL                  **DevicePath
269   );
270 
271 /**
272   Used to translate a device path node to a Target ID and LUN.
273 
274   @param  This       A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance.
275   @param  DevicePath A pointer to a single device path node that describes the SCSI device
276                      on the SCSI channel.
277   @param  Target     A pointer to the Target Array which represents the ID of a SCSI device
278                      on the SCSI channel.
279   @param  Lun        A pointer to the LUN of a SCSI device on the SCSI channel.
280 
281   @retval EFI_SUCCESS           DevicePath was successfully translated to a Target ID and
282                                 LUN, and they were returned in Target and Lun.
283   @retval EFI_INVALID_PARAMETER DevicePath or Target or Lun is NULL.
284   @retval EFI_NOT_FOUND         A valid translation from DevicePath to a Target ID and LUN
285                                 does not exist.
286   @retval EFI_UNSUPPORTED       This driver does not support the device path node type in
287                                  DevicePath.
288 
289 **/
290 typedef
291 EFI_STATUS
292 (EFIAPI *EFI_EXT_SCSI_PASS_THRU_GET_TARGET_LUN)(
293   IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL               *This,
294   IN EFI_DEVICE_PATH_PROTOCOL                      *DevicePath,
295   OUT UINT8                                        **Target,
296   OUT UINT64                                       *Lun
297   );
298 
299 /**
300   Resets a SCSI channel. This operation resets all the SCSI devices connected to the SCSI channel.
301 
302   @param  This A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance.
303 
304   @retval EFI_SUCCESS      The SCSI channel was reset.
305   @retval EFI_DEVICE_ERROR A device error occurred while attempting to reset the SCSI channel.
306   @retval EFI_TIMEOUT      A timeout occurred while attempting to reset the SCSI channel.
307   @retval EFI_UNSUPPORTED  The SCSI channel does not support a channel reset operation.
308 
309 **/
310 typedef
311 EFI_STATUS
312 (EFIAPI *EFI_EXT_SCSI_PASS_THRU_RESET_CHANNEL)(
313   IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL               *This
314   );
315 
316 /**
317   Resets a SCSI logical unit that is connected to a SCSI channel.
318 
319   @param  This   A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance.
320   @param  Target The Target is an array of size TARGET_MAX_BYTE and it represents the
321                  target port ID of the SCSI device containing the SCSI logical unit to
322                  reset. Transport drivers may chose to utilize a subset of this array to suit
323                  the representation of their targets.
324   @param  Lun    The LUN of the SCSI device to reset.
325 
326   @retval EFI_SUCCESS           The SCSI device specified by Target and Lun was reset.
327   @retval EFI_INVALID_PARAMETER Target or Lun is NULL.
328   @retval EFI_TIMEOUT           A timeout occurred while attempting to reset the SCSI device
329                                 specified by Target and Lun.
330   @retval EFI_UNSUPPORTED       The SCSI channel does not support a target reset operation.
331   @retval EFI_DEVICE_ERROR      A device error occurred while attempting to reset the SCSI device
332                                  specified by Target and Lun.
333 
334 **/
335 typedef
336 EFI_STATUS
337 (EFIAPI *EFI_EXT_SCSI_PASS_THRU_RESET_TARGET_LUN)(
338   IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL               *This,
339   IN UINT8                                         *Target,
340   IN UINT64                                        Lun
341   );
342 
343 /**
344   Used to retrieve the list of legal Target IDs for SCSI devices on a SCSI channel. These can either
345   be the list SCSI devices that are actually present on the SCSI channel, or the list of legal Target IDs
346   for the SCSI channel. Regardless, the caller of this function must probe the Target ID returned to
347   see if a SCSI device is actually present at that location on the SCSI channel.
348 
349   @param  This   A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance.
350   @param  Target (TARGET_MAX_BYTES) of a SCSI device present on the SCSI channel.
351                  On output, a pointer to the Target ID (an array of
352                  TARGET_MAX_BYTES) of the next SCSI device present on a SCSI
353                  channel. An input value of 0xF(all bytes in the array are 0xF) in the
354                  Target array retrieves the Target ID of the first SCSI device present on a
355                  SCSI channel.
356 
357   @retval EFI_SUCCESS           The Target ID of the next SCSI device on the SCSI
358                                 channel was returned in Target.
359   @retval EFI_INVALID_PARAMETER Target or Lun is NULL.
360   @retval EFI_TIMEOUT           Target array is not all 0xF, and Target was not
361                                 returned on a previous call to GetNextTarget().
362   @retval EFI_NOT_FOUND         There are no more SCSI devices on this SCSI channel.
363 
364 **/
365 typedef
366 EFI_STATUS
367 (EFIAPI *EFI_EXT_SCSI_PASS_THRU_GET_NEXT_TARGET)(
368   IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL               *This,
369   IN OUT UINT8                                     **Target
370   );
371 
372 ///
373 /// The EFI_EXT_SCSI_PASS_THRU_PROTOCOL provides information about a SCSI channel
374 /// and the ability to send SCI Request Packets to any SCSI device attached to
375 /// that SCSI channel. The information includes the Target ID of the host controller
376 /// on the SCSI channel and the attributes of the SCSI channel.
377 ///
378 struct _EFI_EXT_SCSI_PASS_THRU_PROTOCOL {
379   ///
380   /// A pointer to the EFI_EXT_SCSI_PASS_THRU_MODE data for this SCSI channel.
381   ///
382   EFI_EXT_SCSI_PASS_THRU_MODE                *Mode;
383   EFI_EXT_SCSI_PASS_THRU_PASSTHRU            PassThru;
384   EFI_EXT_SCSI_PASS_THRU_GET_NEXT_TARGET_LUN GetNextTargetLun;
385   EFI_EXT_SCSI_PASS_THRU_BUILD_DEVICE_PATH   BuildDevicePath;
386   EFI_EXT_SCSI_PASS_THRU_GET_TARGET_LUN      GetTargetLun;
387   EFI_EXT_SCSI_PASS_THRU_RESET_CHANNEL       ResetChannel;
388   EFI_EXT_SCSI_PASS_THRU_RESET_TARGET_LUN    ResetTargetLun;
389   EFI_EXT_SCSI_PASS_THRU_GET_NEXT_TARGET     GetNextTarget;
390 };
391 
392 extern EFI_GUID gEfiExtScsiPassThruProtocolGuid;
393 
394 #endif
395