]> git.proxmox.com Git - mirror_edk2.git/blob - NetworkPkg/IScsiDxe/ComponentName.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / NetworkPkg / IScsiDxe / ComponentName.c
1 /** @file
2 UEFI Component Name(2) protocol implementation for iSCSI.
3
4 Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7 **/
8
9 #include "IScsiImpl.h"
10
11 //
12 // EFI Component Name Protocol
13 //
14 GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL gIScsiComponentName = {
15 IScsiComponentNameGetDriverName,
16 IScsiComponentNameGetControllerName,
17 "eng"
18 };
19
20 //
21 // EFI Component Name 2 Protocol
22 //
23 GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gIScsiComponentName2 = {
24 (EFI_COMPONENT_NAME2_GET_DRIVER_NAME)IScsiComponentNameGetDriverName,
25 (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME)IScsiComponentNameGetControllerName,
26 "en"
27 };
28
29 GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mIScsiDriverNameTable[] = {
30 {
31 "eng;en",
32 L"iSCSI Driver"
33 },
34 {
35 NULL,
36 NULL
37 }
38 };
39
40 GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE *gIScsiControllerNameTable = NULL;
41
42 /**
43 Retrieves a Unicode string that is the user readable name of the driver.
44
45 This function retrieves the user readable name of a driver in the form of a
46 Unicode string. If the driver specified by This has a user readable name in
47 the language specified by Language, then a pointer to the driver name is
48 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
49 by This does not support the language specified by Language,
50 then EFI_UNSUPPORTED is returned.
51
52 @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
53 EFI_COMPONENT_NAME_PROTOCOL instance.
54
55 @param[in] Language A pointer to a Null-terminated ASCII string
56 array indicating the language. This is the
57 language of the driver name that the caller is
58 requesting, and it must match one of the
59 languages specified in SupportedLanguages. The
60 number of languages supported by a driver is up
61 to the driver writer. Language is specified
62 in RFC 4646 or ISO 639-2 language code format.
63
64 @param[out] DriverName A pointer to the Unicode string to return.
65 This Unicode string is the name of the
66 driver specified by This in the language
67 specified by Language.
68
69 @retval EFI_SUCCESS The Unicode string for the Driver specified by
70 This and the language specified by Language was
71 returned in DriverName.
72
73 @retval EFI_INVALID_PARAMETER Language is NULL.
74
75 @retval EFI_INVALID_PARAMETER DriverName is NULL.
76
77 @retval EFI_UNSUPPORTED The driver specified by This does not support
78 the language specified by Language.
79
80 **/
81 EFI_STATUS
82 EFIAPI
83 IScsiComponentNameGetDriverName (
84 IN EFI_COMPONENT_NAME_PROTOCOL *This,
85 IN CHAR8 *Language,
86 OUT CHAR16 **DriverName
87 )
88 {
89 return LookupUnicodeString2 (
90 Language,
91 This->SupportedLanguages,
92 mIScsiDriverNameTable,
93 DriverName,
94 (BOOLEAN)(This == &gIScsiComponentName)
95 );
96 }
97
98 /**
99 Update the component name for the iSCSI instance.
100
101 @param[in] IScsiExtScsiPassThru A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance.
102 @param[in] Ipv6Flag TRUE if IP6 network stack is used.
103
104 @retval EFI_SUCCESS Update the ControllerNameTable of this instance successfully.
105 @retval EFI_INVALID_PARAMETER The input parameter is invalid.
106 @retval EFI_UNSUPPORTED Can't get the corresponding NIC info from the Controller handle.
107
108 **/
109 EFI_STATUS
110 UpdateName (
111 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *IScsiExtScsiPassThru,
112 IN BOOLEAN Ipv6Flag
113 )
114 {
115 EFI_STATUS Status;
116 CHAR16 HandleName[80];
117 ISCSI_DRIVER_DATA *Private;
118 UINT8 NicIndex;
119
120 if (IScsiExtScsiPassThru == NULL) {
121 return EFI_INVALID_PARAMETER;
122 }
123
124 Private = ISCSI_DRIVER_DATA_FROM_EXT_SCSI_PASS_THRU (IScsiExtScsiPassThru);
125 NicIndex = Private->Session->ConfigData->NicIndex;
126
127 UnicodeSPrint (
128 HandleName,
129 sizeof (HandleName),
130 L"iSCSI (%s, NicIndex=%d)",
131 Ipv6Flag ? L"IPv6" : L"IPv4",
132 NicIndex
133 );
134
135 if (gIScsiControllerNameTable != NULL) {
136 FreeUnicodeStringTable (gIScsiControllerNameTable);
137 gIScsiControllerNameTable = NULL;
138 }
139
140 Status = AddUnicodeString2 (
141 "eng",
142 gIScsiComponentName.SupportedLanguages,
143 &gIScsiControllerNameTable,
144 HandleName,
145 TRUE
146 );
147 if (EFI_ERROR (Status)) {
148 return Status;
149 }
150
151 return AddUnicodeString2 (
152 "en",
153 gIScsiComponentName2.SupportedLanguages,
154 &gIScsiControllerNameTable,
155 HandleName,
156 FALSE
157 );
158 }
159
160 /**
161 Retrieves a Unicode string that is the user readable name of the controller
162 that is being managed by a driver.
163
164 This function retrieves the user readable name of the controller specified by
165 ControllerHandle and ChildHandle in the form of a Unicode string. If the
166 driver specified by This has a user readable name in the language specified by
167 Language, then a pointer to the controller name is returned in ControllerName,
168 and EFI_SUCCESS is returned. If the driver specified by This is not currently
169 managing the controller specified by ControllerHandle and ChildHandle,
170 then EFI_UNSUPPORTED is returned. If the driver specified by This does not
171 support the language specified by Language, then EFI_UNSUPPORTED is returned.
172
173 @param[in] This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
174 EFI_COMPONENT_NAME_PROTOCOL instance.
175
176 @param[in] ControllerHandle The handle of a controller that the driver
177 specified by This is managing. This handle
178 specifies the controller whose name is to be
179 returned.
180
181 @param[in] ChildHandle The handle of the child controller to retrieve
182 the name of. This is an optional parameter that
183 may be NULL. It will be NULL for device
184 drivers. It will also be NULL for a bus drivers
185 that wish to retrieve the name of the bus
186 controller. It will not be NULL for a bus
187 driver that wishes to retrieve the name of a
188 child controller.
189
190 @param[in] Language A pointer to a Null-terminated ASCII string
191 array indicating the language. This is the
192 language of the driver name that the caller is
193 requesting, and it must match one of the
194 languages specified in SupportedLanguages. The
195 number of languages supported by a driver is up
196 to the driver writer. Language is specified in
197 RFC 4646 or ISO 639-2 language code format.
198
199 @param[out] ControllerName A pointer to the Unicode string to return.
200 This Unicode string is the name of the
201 controller specified by ControllerHandle and
202 ChildHandle in the language specified by
203 Language, from the point of view of the driver
204 specified by This.
205
206 @retval EFI_SUCCESS The Unicode string for the user readable name in
207 the language specified by Language for the
208 driver specified by This was returned in
209 DriverName.
210
211 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
212
213 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL, and it is not a valid
214 EFI_HANDLE.
215
216 @retval EFI_INVALID_PARAMETER Language is NULL.
217
218 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
219
220 @retval EFI_UNSUPPORTED The driver specified by This is not currently
221 managing the controller specified by
222 ControllerHandle and ChildHandle.
223
224 @retval EFI_UNSUPPORTED The driver specified by This does not support
225 the language specified by Language.
226
227 **/
228 EFI_STATUS
229 EFIAPI
230 IScsiComponentNameGetControllerName (
231 IN EFI_COMPONENT_NAME_PROTOCOL *This,
232 IN EFI_HANDLE ControllerHandle,
233 IN EFI_HANDLE ChildHandle OPTIONAL,
234 IN CHAR8 *Language,
235 OUT CHAR16 **ControllerName
236 )
237 {
238 EFI_STATUS Status;
239
240 EFI_HANDLE IScsiController;
241 BOOLEAN Ipv6Flag;
242 EFI_GUID *IScsiPrivateGuid;
243 ISCSI_PRIVATE_PROTOCOL *IScsiIdentifier;
244
245 EFI_EXT_SCSI_PASS_THRU_PROTOCOL *IScsiExtScsiPassThru;
246
247 if (ControllerHandle == NULL) {
248 return EFI_UNSUPPORTED;
249 }
250
251 //
252 // Get the handle of the controller we are controlling.
253 //
254 IScsiController = NetLibGetNicHandle (ControllerHandle, &gEfiTcp4ProtocolGuid);
255 if (IScsiController != NULL) {
256 IScsiPrivateGuid = &gIScsiV4PrivateGuid;
257 Ipv6Flag = FALSE;
258 } else {
259 IScsiController = NetLibGetNicHandle (ControllerHandle, &gEfiTcp6ProtocolGuid);
260 if (IScsiController != NULL) {
261 IScsiPrivateGuid = &gIScsiV6PrivateGuid;
262 Ipv6Flag = TRUE;
263 } else {
264 return EFI_UNSUPPORTED;
265 }
266 }
267
268 Status = gBS->OpenProtocol (
269 IScsiController,
270 IScsiPrivateGuid,
271 (VOID **)&IScsiIdentifier,
272 NULL,
273 NULL,
274 EFI_OPEN_PROTOCOL_GET_PROTOCOL
275 );
276 if (EFI_ERROR (Status)) {
277 return Status;
278 }
279
280 if (ChildHandle != NULL) {
281 if (!Ipv6Flag) {
282 //
283 // Make sure this driver produced ChildHandle
284 //
285 Status = EfiTestChildHandle (
286 ControllerHandle,
287 ChildHandle,
288 &gEfiTcp4ProtocolGuid
289 );
290 if (EFI_ERROR (Status)) {
291 return Status;
292 }
293 } else {
294 //
295 // Make sure this driver produced ChildHandle
296 //
297 Status = EfiTestChildHandle (
298 ControllerHandle,
299 ChildHandle,
300 &gEfiTcp6ProtocolGuid
301 );
302 if (EFI_ERROR (Status)) {
303 return Status;
304 }
305 }
306
307 //
308 // Retrieve an instance of a produced protocol from ChildHandle
309 //
310 Status = gBS->OpenProtocol (
311 ChildHandle,
312 &gEfiExtScsiPassThruProtocolGuid,
313 (VOID **)&IScsiExtScsiPassThru,
314 NULL,
315 NULL,
316 EFI_OPEN_PROTOCOL_GET_PROTOCOL
317 );
318 if (EFI_ERROR (Status)) {
319 return Status;
320 }
321
322 //
323 // Update the component name for this child handle.
324 //
325 Status = UpdateName (IScsiExtScsiPassThru, Ipv6Flag);
326 if (EFI_ERROR (Status)) {
327 return Status;
328 }
329 }
330
331 return LookupUnicodeString2 (
332 Language,
333 This->SupportedLanguages,
334 gIScsiControllerNameTable,
335 ControllerName,
336 (BOOLEAN)(This == &gIScsiComponentName)
337 );
338 }