TianoCore EDK2 master
Loading...
Searching...
No Matches
IScsiExtScsiPassThru.c
Go to the documentation of this file.
1
9#include "IScsiImpl.h"
10
11EFI_EXT_SCSI_PASS_THRU_PROTOCOL gIScsiExtScsiPassThruProtocolTemplate = {
12 NULL,
20};
21
73EFIAPI
76 IN UINT8 *Target,
77 IN UINT64 Lun,
79 IN EFI_EVENT Event OPTIONAL
80 )
81{
82 EFI_STATUS Status;
83 ISCSI_DRIVER_DATA *Private;
84
85 if (Target[0] != 0) {
86 return EFI_INVALID_PARAMETER;
87 }
88
89 if ((Packet == NULL) || (Packet->Cdb == NULL)) {
90 return EFI_INVALID_PARAMETER;
91 }
92
93 Status = IScsiExecuteScsiCommand (This, Target, Lun, Packet);
94 if ((Status != EFI_SUCCESS) && (Status != EFI_NOT_READY)) {
95 //
96 // Try to reinstate the session and re-execute the Scsi command.
97 //
98 Private = ISCSI_DRIVER_DATA_FROM_EXT_SCSI_PASS_THRU (This);
99 if (EFI_ERROR (IScsiSessionReinstatement (Private->Session))) {
100 return EFI_DEVICE_ERROR;
101 }
102
103 Status = IScsiExecuteScsiCommand (This, Target, Lun, Packet);
104 }
105
106 return Status;
107}
108
139EFIAPI
142 IN OUT UINT8 **Target,
143 IN OUT UINT64 *Lun
144 )
145{
146 ISCSI_DRIVER_DATA *Private;
147 ISCSI_SESSION_CONFIG_NVDATA *ConfigNvData;
148 UINT8 TargetId[TARGET_MAX_BYTES];
149
150 Private = ISCSI_DRIVER_DATA_FROM_EXT_SCSI_PASS_THRU (This);
151 ConfigNvData = &Private->Session->ConfigData->SessionConfigData;
152
153 if (((*Target)[0] == 0) && (CompareMem (Lun, ConfigNvData->BootLun, sizeof (UINT64)) == 0)) {
154 //
155 // Only one <Target, Lun> pair per iSCSI Driver instance.
156 //
157 return EFI_NOT_FOUND;
158 }
159
160 SetMem (TargetId, TARGET_MAX_BYTES, 0xFF);
161 if (CompareMem (*Target, TargetId, TARGET_MAX_BYTES) == 0) {
162 (*Target)[0] = 0;
163 CopyMem (Lun, ConfigNvData->BootLun, sizeof (UINT64));
164
165 return EFI_SUCCESS;
166 }
167
168 return EFI_INVALID_PARAMETER;
169}
170
198EFIAPI
201 IN UINT8 *Target,
202 IN UINT64 Lun,
203 IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath
204 )
205{
206 ISCSI_DRIVER_DATA *Private;
207 ISCSI_SESSION *Session;
208 ISCSI_SESSION_CONFIG_NVDATA *ConfigNvData;
210 EFI_DEV_PATH *Node;
211 UINTN DevPathNodeLen;
212
213 if (DevicePath == NULL) {
214 return EFI_INVALID_PARAMETER;
215 }
216
217 if (Target[0] != 0) {
218 return EFI_NOT_FOUND;
219 }
220
221 Private = ISCSI_DRIVER_DATA_FROM_EXT_SCSI_PASS_THRU (This);
222 Session = Private->Session;
223 ConfigNvData = &Session->ConfigData->SessionConfigData;
224 AuthConfig = Session->AuthData.CHAP.AuthConfig;
225
226 if (CompareMem (&Lun, ConfigNvData->BootLun, sizeof (UINT64)) != 0) {
227 return EFI_NOT_FOUND;
228 }
229
230 DevPathNodeLen = sizeof (ISCSI_DEVICE_PATH) + AsciiStrLen (ConfigNvData->TargetName) + 1;
231 Node = AllocateZeroPool (DevPathNodeLen);
232 if (Node == NULL) {
233 return EFI_OUT_OF_RESOURCES;
234 }
235
236 Node->DevPath.Type = MESSAGING_DEVICE_PATH;
237 Node->DevPath.SubType = MSG_ISCSI_DP;
238 SetDevicePathNodeLength (&Node->DevPath, DevPathNodeLen);
239
240 //
241 // 0 for TCP, others are reserved.
242 //
243 Node->Iscsi.NetworkProtocol = 0;
244
245 Node->Iscsi.LoginOption = 0;
246
247 switch (Session->AuthType) {
248 case ISCSI_AUTH_TYPE_NONE:
249 Node->Iscsi.LoginOption |= 0x0800;
250 break;
251
252 case ISCSI_AUTH_TYPE_CHAP:
253 //
254 // Bit12: 0=CHAP_BI, 1=CHAP_UNI
255 //
256 if (AuthConfig->CHAPType == ISCSI_CHAP_UNI) {
257 Node->Iscsi.LoginOption |= 0x1000;
258 }
259
260 break;
261
262 default:
263 break;
264 }
265
266 CopyMem (&Node->Iscsi.Lun, ConfigNvData->BootLun, sizeof (UINT64));
267 Node->Iscsi.TargetPortalGroupTag = Session->TargetPortalGroupTag;
268 AsciiStrCpyS ((CHAR8 *)Node + sizeof (ISCSI_DEVICE_PATH), AsciiStrLen (ConfigNvData->TargetName) + 1, ConfigNvData->TargetName);
269
270 *DevicePath = (EFI_DEVICE_PATH_PROTOCOL *)Node;
271
272 return EFI_SUCCESS;
273}
274
297EFIAPI
300 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,
301 OUT UINT8 **Target,
302 OUT UINT64 *Lun
303 )
304{
305 ISCSI_DRIVER_DATA *Private;
306 ISCSI_SESSION_CONFIG_NVDATA *ConfigNvData;
307
308 if ((DevicePath == NULL) || (Target == NULL) || (Lun == NULL)) {
309 return EFI_INVALID_PARAMETER;
310 }
311
312 if ((DevicePath->Type != MESSAGING_DEVICE_PATH) ||
313 (DevicePath->SubType != MSG_ISCSI_DP) ||
314 (DevicePathNodeLength (DevicePath) <= sizeof (ISCSI_DEVICE_PATH))
315 )
316 {
317 return EFI_UNSUPPORTED;
318 }
319
320 Private = ISCSI_DRIVER_DATA_FROM_EXT_SCSI_PASS_THRU (This);
321 ConfigNvData = &Private->Session->ConfigData->SessionConfigData;
322
323 SetMem (*Target, TARGET_MAX_BYTES, 0xFF);
324 (*Target)[0] = 0;
325
326 if (AsciiStrCmp (ConfigNvData->TargetName, (CHAR8 *)DevicePath + sizeof (ISCSI_DEVICE_PATH)) != 0) {
327 return EFI_UNSUPPORTED;
328 }
329
330 CopyMem (Lun, ConfigNvData->BootLun, sizeof (UINT64));
331
332 return EFI_SUCCESS;
333}
334
345EFIAPI
348 )
349{
350 return EFI_UNSUPPORTED;
351}
352
364EFIAPI
367 IN UINT8 *Target,
368 IN UINT64 Lun
369 )
370{
371 return EFI_UNSUPPORTED;
372}
373
396EFIAPI
399 IN OUT UINT8 **Target
400 )
401{
402 UINT8 TargetId[TARGET_MAX_BYTES];
403
404 SetMem (TargetId, TARGET_MAX_BYTES, 0xFF);
405
406 if (CompareMem (*Target, TargetId, TARGET_MAX_BYTES) == 0) {
407 (*Target)[0] = 0;
408 return EFI_SUCCESS;
409 } else if ((*Target)[0] == 0) {
410 return EFI_NOT_FOUND;
411 } else {
412 return EFI_INVALID_PARAMETER;
413 }
414}
UINT64 UINTN
UINTN EFIAPI AsciiStrLen(IN CONST CHAR8 *String)
Definition: String.c:641
INTN EFIAPI AsciiStrCmp(IN CONST CHAR8 *FirstString, IN CONST CHAR8 *SecondString)
Definition: String.c:716
RETURN_STATUS EFIAPI AsciiStrCpyS(OUT CHAR8 *Destination, IN UINTN DestMax, IN CONST CHAR8 *Source)
Definition: SafeString.c:1797
INTN EFIAPI CompareMem(IN CONST VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI SetMem(OUT VOID *Buffer, IN UINTN Length, IN UINT8 Value)
Definition: SetMemWrapper.c:38
#define MSG_ISCSI_DP
Definition: DevicePath.h:925
#define MESSAGING_DEVICE_PATH
Definition: DevicePath.h:321
UINT16 EFIAPI SetDevicePathNodeLength(IN OUT VOID *Node, IN UINTN Length)
UINTN EFIAPI DevicePathNodeLength(IN CONST VOID *Node)
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
EFI_STATUS EFIAPI IScsiExtScsiPassThruResetTargetLun(IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This, IN UINT8 *Target, IN UINT64 Lun)
EFI_STATUS EFIAPI IScsiExtScsiPassThruBuildDevicePath(IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This, IN UINT8 *Target, IN UINT64 Lun, IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath)
EFI_STATUS EFIAPI IScsiExtScsiPassThruGetNextTargetLun(IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This, IN OUT UINT8 **Target, IN OUT UINT64 *Lun)
EFI_STATUS EFIAPI IScsiExtScsiPassThruGetNextTarget(IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This, IN OUT UINT8 **Target)
EFI_STATUS EFIAPI IScsiExtScsiPassThruGetTargetLun(IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This, IN EFI_DEVICE_PATH_PROTOCOL *DevicePath, OUT UINT8 **Target, OUT UINT64 *Lun)
EFI_STATUS EFIAPI IScsiExtScsiPassThruResetChannel(IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This)
EFI_STATUS EFIAPI IScsiExtScsiPassThruFunction(IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This, IN UINT8 *Target, IN UINT64 Lun, IN OUT EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET *Packet, IN EFI_EVENT Event OPTIONAL)
EFI_STATUS IScsiSessionReinstatement(IN ISCSI_SESSION *Session)
Definition: IScsiProto.c:3095
EFI_STATUS IScsiExecuteScsiCommand(IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *PassThru, IN UINT8 *Target, IN UINT64 Lun, IN OUT EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET *Packet)
Definition: IScsiProto.c:2904
#define NULL
Definition: Base.h:319
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_EVENT
Definition: UefiBaseType.h:37
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
UINT16 TargetPortalGroupTag
Definition: DevicePath.h:944
UINT16 NetworkProtocol
Definition: DevicePath.h:931