]> git.proxmox.com Git - mirror_edk2.git/blob - NetworkPkg/IScsiDxe/IScsiMisc.h
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / NetworkPkg / IScsiDxe / IScsiMisc.h
1 /** @file
2 Miscellaneous definitions for iSCSI driver.
3
4 Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7 **/
8
9 #ifndef _ISCSI_MISC_H_
10 #define _ISCSI_MISC_H_
11
12 typedef struct _ISCSI_DRIVER_DATA ISCSI_DRIVER_DATA;
13
14 ///
15 /// IPv4 Device Path Node Length
16 ///
17 #define IP4_NODE_LEN_NEW_VERSIONS 27
18
19 ///
20 /// IPv6 Device Path Node Length
21 ///
22 #define IP6_NODE_LEN_OLD_VERSIONS 43
23 #define IP6_NODE_LEN_NEW_VERSIONS 60
24
25 ///
26 /// The ignored field StaticIpAddress's offset in old IPv6 Device Path
27 ///
28 #define IP6_OLD_IPADDRESS_OFFSET 42
29
30 #pragma pack(1)
31 typedef struct _ISCSI_SESSION_CONFIG_NVDATA {
32 UINT16 TargetPort;
33 UINT8 Enabled;
34 UINT8 IpMode;
35
36 EFI_IP_ADDRESS LocalIp;
37 EFI_IPv4_ADDRESS SubnetMask;
38 EFI_IP_ADDRESS Gateway;
39
40 BOOLEAN InitiatorInfoFromDhcp;
41 BOOLEAN TargetInfoFromDhcp;
42
43 CHAR8 TargetName[ISCSI_NAME_MAX_SIZE];
44 EFI_IP_ADDRESS TargetIp;
45 UINT8 PrefixLength;
46 UINT8 BootLun[8];
47
48 UINT16 ConnectTimeout; ///< timeout value in milliseconds.
49 UINT8 ConnectRetryCount;
50 UINT8 IsId[6];
51
52 BOOLEAN RedirectFlag;
53 UINT16 OriginalTargetPort; // The port of proxy/virtual target.
54 EFI_IP_ADDRESS OriginalTargetIp; // The address of proxy/virtual target.
55
56 BOOLEAN DnsMode; // Flag indicate whether the Target address is expressed as URL format.
57 CHAR8 TargetUrl[ISCSI_TARGET_URI_MAX_SIZE];
58 } ISCSI_SESSION_CONFIG_NVDATA;
59 #pragma pack()
60
61 /**
62 Calculate the prefix length of the IPv4 subnet mask.
63
64 @param[in] SubnetMask The IPv4 subnet mask.
65
66 @return The prefix length of the subnet mask.
67 @retval 0 Other errors as indicated.
68
69 **/
70 UINT8
71 IScsiGetSubnetMaskPrefixLength (
72 IN EFI_IPv4_ADDRESS *SubnetMask
73 );
74
75 /**
76 Convert the hexadecimal encoded LUN string into the 64-bit LUN.
77
78 @param[in] Str The hexadecimal encoded LUN string.
79 @param[out] Lun Storage to return the 64-bit LUN.
80
81 @retval EFI_SUCCESS The 64-bit LUN is stored in Lun.
82 @retval EFI_INVALID_PARAMETER The string is malformatted.
83
84 **/
85 EFI_STATUS
86 IScsiAsciiStrToLun (
87 IN CHAR8 *Str,
88 OUT UINT8 *Lun
89 );
90
91 /**
92 Convert the 64-bit LUN into the hexadecimal encoded LUN string.
93
94 @param[in] Lun The 64-bit LUN.
95 @param[out] String The storage to return the hexadecimal encoded LUN string.
96
97 **/
98 VOID
99 IScsiLunToUnicodeStr (
100 IN UINT8 *Lun,
101 OUT CHAR16 *String
102 );
103
104 /**
105 Convert the mac address into a hexadecimal encoded "-" separated string.
106
107 @param[in] Mac The mac address.
108 @param[in] Len Length in bytes of the mac address.
109 @param[in] VlanId VLAN ID of the network device.
110 @param[out] Str The storage to return the mac string.
111
112 **/
113 VOID
114 IScsiMacAddrToStr (
115 IN EFI_MAC_ADDRESS *Mac,
116 IN UINT32 Len,
117 IN UINT16 VlanId,
118 OUT CHAR16 *Str
119 );
120
121 /**
122 Convert the formatted IP address into the binary IP address.
123
124 @param[in] Str The UNICODE string.
125 @param[in] IpMode Indicates whether the IP address is v4 or v6.
126 @param[out] Ip The storage to return the ASCII string.
127
128 @retval EFI_SUCCESS The binary IP address is returned in Ip.
129 @retval EFI_INVALID_PARAMETER The IP string is malformatted or IpMode is
130 invalid.
131
132 **/
133 EFI_STATUS
134 IScsiAsciiStrToIp (
135 IN CHAR8 *Str,
136 IN UINT8 IpMode,
137 OUT EFI_IP_ADDRESS *Ip
138 );
139
140 /**
141 Convert the binary encoded buffer into a hexadecimal encoded string.
142
143 @param[in] BinBuffer The buffer containing the binary data.
144 @param[in] BinLength Length of the binary buffer.
145 @param[in, out] HexStr Pointer to the string.
146 @param[in, out] HexLength The length of the string.
147
148 @retval EFI_SUCCESS The binary data is converted to the hexadecimal string
149 and the length of the string is updated.
150 @retval EFI_BUFFER_TOO_SMALL The string is too small.
151 @retval EFI_BAD_BUFFER_SIZE BinLength is too large for hex encoding.
152 @retval EFI_INVALID_PARAMETER The IP string is malformatted.
153
154 **/
155 EFI_STATUS
156 IScsiBinToHex (
157 IN UINT8 *BinBuffer,
158 IN UINT32 BinLength,
159 IN OUT CHAR8 *HexStr,
160 IN OUT UINT32 *HexLength
161 );
162
163 /**
164 Convert the hexadecimal string into a binary encoded buffer.
165
166 @param[in, out] BinBuffer The binary buffer.
167 @param[in, out] BinLength Length of the binary buffer.
168 @param[in] HexStr The hexadecimal string.
169
170 @retval EFI_SUCCESS The hexadecimal string is converted into a
171 binary encoded buffer.
172 @retval EFI_INVALID_PARAMETER Invalid hex encoding found in HexStr.
173 @retval EFI_BAD_BUFFER_SIZE The length of HexStr is too large for decoding:
174 the decoded size cannot be expressed in
175 BinLength on output.
176 @retval EFI_BUFFER_TOO_SMALL The binary buffer is too small to hold the
177 converted data.
178 **/
179 EFI_STATUS
180 IScsiHexToBin (
181 IN OUT UINT8 *BinBuffer,
182 IN OUT UINT32 *BinLength,
183 IN CHAR8 *HexStr
184 );
185
186 /**
187 Convert the decimal-constant string or hex-constant string into a numerical value.
188
189 @param[in] Str String in decimal or hex.
190
191 @return The numerical value.
192
193 **/
194 UINTN
195 IScsiNetNtoi (
196 IN CHAR8 *Str
197 );
198
199 /**
200 Generate random numbers.
201
202 @param[in, out] Rand The buffer to contain random numbers.
203 @param[in] RandLength The length of the Rand buffer.
204
205 **/
206 VOID
207 IScsiGenRandom (
208 IN OUT UINT8 *Rand,
209 IN UINTN RandLength
210 );
211
212 /**
213 Record the NIC information in a global structure.
214
215 @param[in] Controller The handle of the controller.
216 @param[in] Image Handle of the image.
217
218 @retval EFI_SUCCESS The operation is completed.
219 @retval EFI_OUT_OF_RESOURCES Do not have sufficient resource to finish this
220 operation.
221
222 **/
223 EFI_STATUS
224 IScsiAddNic (
225 IN EFI_HANDLE Controller,
226 IN EFI_HANDLE Image
227 );
228
229 /**
230 Delete the recorded NIC information from a global structure. Also delete corresponding
231 attempts.
232
233 @param[in] Controller The handle of the controller.
234
235 @retval EFI_SUCCESS The operation completed.
236 @retval EFI_NOT_FOUND The NIC information to be deleted is not recorded.
237
238 **/
239 EFI_STATUS
240 IScsiRemoveNic (
241 IN EFI_HANDLE Controller
242 );
243
244 /**
245 Create and initialize the Attempts.
246
247 @param[in] AttemptNum The number of Attempts will be created.
248
249 @retval EFI_SUCCESS The Attempts have been created successfully.
250 @retval Others Failed to create the Attempt.
251
252 **/
253 EFI_STATUS
254 IScsiCreateAttempts (
255 IN UINTN AttemptNum
256 );
257
258 /**
259 Create the iSCSI configuration Keywords for each attempt.
260
261 @param[in] KeywordNum The number Sets of Keywords will be created.
262
263 @retval EFI_SUCCESS The operation is completed.
264 @retval Others Failed to create the Keywords.
265
266 **/
267 EFI_STATUS
268 IScsiCreateKeywords (
269 IN UINTN KeywordNum
270 );
271
272 /**
273
274 Free the attempt configure data variable.
275
276 **/
277 VOID
278 IScsiCleanAttemptVariable (
279 IN VOID
280 );
281
282 /**
283 Get the recorded NIC information from a global structure by the Index.
284
285 @param[in] NicIndex The index indicates the position of NIC info.
286
287 @return Pointer to the NIC info or NULL if not found.
288
289 **/
290 ISCSI_NIC_INFO *
291 IScsiGetNicInfoByIndex (
292 IN UINT8 NicIndex
293 );
294
295 /**
296 Get the NIC's PCI location and return it according to the composited
297 format defined in iSCSI Boot Firmware Table.
298
299 @param[in] Controller The handle of the controller.
300 @param[out] Bus The bus number.
301 @param[out] Device The device number.
302 @param[out] Function The function number.
303
304 @return The composited representation of the NIC PCI location.
305
306 **/
307 UINT16
308 IScsiGetNICPciLocation (
309 IN EFI_HANDLE Controller,
310 OUT UINTN *Bus,
311 OUT UINTN *Device,
312 OUT UINTN *Function
313 );
314
315 /**
316 Read the EFI variable (VendorGuid/Name) and return a dynamically allocated
317 buffer, and the size of the buffer. If failure, return NULL.
318
319 @param[in] Name String part of EFI variable name.
320 @param[in] VendorGuid GUID part of EFI variable name.
321 @param[out] VariableSize Returns the size of the EFI variable that was read.
322
323 @return Dynamically allocated memory that contains a copy of the EFI variable.
324 @return Caller is responsible freeing the buffer.
325 @retval NULL Variable was not read.
326
327 **/
328 VOID *
329 IScsiGetVariableAndSize (
330 IN CHAR16 *Name,
331 IN EFI_GUID *VendorGuid,
332 OUT UINTN *VariableSize
333 );
334
335 /**
336 Create the iSCSI driver data.
337
338 @param[in] Image The handle of the driver image.
339 @param[in] Controller The handle of the controller.
340
341 @return The iSCSI driver data created.
342 @retval NULL Other errors as indicated.
343
344 **/
345 ISCSI_DRIVER_DATA *
346 IScsiCreateDriverData (
347 IN EFI_HANDLE Image,
348 IN EFI_HANDLE Controller
349 );
350
351 /**
352 Clean the iSCSI driver data.
353
354 @param[in] Private The iSCSI driver data.
355
356 @retval EFI_SUCCESS The clean operation is successful.
357 @retval Others Other errors as indicated.
358
359 **/
360 EFI_STATUS
361 IScsiCleanDriverData (
362 IN ISCSI_DRIVER_DATA *Private
363 );
364
365 /**
366 Check wheather the Controller handle is configured to use DHCP protocol.
367
368 @param[in] Controller The handle of the controller.
369 @param[in] IpVersion IP_VERSION_4 or IP_VERSION_6.
370
371 @retval TRUE The handle of the controller need the Dhcp protocol.
372 @retval FALSE The handle of the controller does not need the Dhcp protocol.
373
374 **/
375 BOOLEAN
376 IScsiDhcpIsConfigured (
377 IN EFI_HANDLE Controller,
378 IN UINT8 IpVersion
379 );
380
381 /**
382 Check wheather the Controller handle is configured to use DNS protocol.
383
384 @param[in] Controller The handle of the controller.
385
386 @retval TRUE The handle of the controller need the DNS protocol.
387 @retval FALSE The handle of the controller does not need the DNS protocol.
388
389 **/
390 BOOLEAN
391 IScsiDnsIsConfigured (
392 IN EFI_HANDLE Controller
393 );
394
395 /**
396 Get the various configuration data of this iSCSI instance.
397
398 @param[in] Private The iSCSI driver data.
399
400 @retval EFI_SUCCESS Obtained the configuration of this instance.
401 @retval EFI_ABORTED The operation was aborted.
402 @retval Others Other errors as indicated.
403
404 **/
405 EFI_STATUS
406 IScsiGetConfigData (
407 IN ISCSI_DRIVER_DATA *Private
408 );
409
410 /**
411 Get the device path of the iSCSI tcp connection and update it.
412
413 @param[in] Session The iSCSI session data.
414
415 @return The updated device path.
416 @retval NULL Other errors as indicated.
417
418 **/
419 EFI_DEVICE_PATH_PROTOCOL *
420 IScsiGetTcpConnDevicePath (
421 IN ISCSI_SESSION *Session
422 );
423
424 /**
425 Abort the session when the transition from BS to RT is initiated.
426
427 @param[in] Event The event signaled.
428 @param[in] Context The iSCSI driver data.
429
430 **/
431 VOID
432 EFIAPI
433 IScsiOnExitBootService (
434 IN EFI_EVENT Event,
435 IN VOID *Context
436 );
437
438 /**
439 Tests whether a controller handle is being managed by IScsi driver.
440
441 This function tests whether the driver specified by DriverBindingHandle is
442 currently managing the controller specified by ControllerHandle. This test
443 is performed by evaluating if the protocol specified by ProtocolGuid is
444 present on ControllerHandle and is was opened by DriverBindingHandle and Nic
445 Device handle with an attribute of EFI_OPEN_PROTOCOL_BY_DRIVER.
446 If ProtocolGuid is NULL, then ASSERT().
447
448 @param ControllerHandle A handle for a controller to test.
449 @param DriverBindingHandle Specifies the driver binding handle for the
450 driver.
451 @param ProtocolGuid Specifies the protocol that the driver specified
452 by DriverBindingHandle opens in its Start()
453 function.
454
455 @retval EFI_SUCCESS ControllerHandle is managed by the driver
456 specified by DriverBindingHandle.
457 @retval EFI_UNSUPPORTED ControllerHandle is not managed by the driver
458 specified by DriverBindingHandle.
459
460 **/
461 EFI_STATUS
462 EFIAPI
463 IScsiTestManagedDevice (
464 IN EFI_HANDLE ControllerHandle,
465 IN EFI_HANDLE DriverBindingHandle,
466 IN EFI_GUID *ProtocolGuid
467 );
468
469 #endif