2008-04-17 10:28:51 +02:00
|
|
|
/** @file
|
|
|
|
Implementation for iSCSI Boot Firmware Table publication.
|
2007-12-24 03:20:21 +01:00
|
|
|
|
2010-04-24 11:33:45 +02:00
|
|
|
Copyright (c) 2004 - 2010, Intel Corporation. All rights reserved.<BR>
|
|
|
|
This program and the accompanying materials
|
2008-01-22 09:07:35 +01:00
|
|
|
are licensed and made available under the terms and conditions of the BSD License
|
|
|
|
which accompanies this distribution. The full text of the license may be found at
|
|
|
|
http://opensource.org/licenses/bsd-license.php
|
|
|
|
|
|
|
|
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
2007-12-24 03:20:21 +01:00
|
|
|
|
2008-04-17 10:28:51 +02:00
|
|
|
**/
|
2007-12-24 03:20:21 +01:00
|
|
|
|
|
|
|
#include "IScsiImpl.h"
|
|
|
|
|
2009-04-17 10:49:00 +02:00
|
|
|
BOOLEAN mIbftInstalled = FALSE;
|
|
|
|
UINTN mTableKey;
|
|
|
|
|
2008-04-17 10:28:51 +02:00
|
|
|
/**
|
|
|
|
Initialize the header of the iSCSI Boot Firmware Table.
|
|
|
|
|
2009-11-04 09:18:34 +01:00
|
|
|
@param[out] Header The header of the iSCSI Boot Firmware Table.
|
|
|
|
@param[in] OemId The OEM ID.
|
|
|
|
@param[in] OemTableId The OEM table ID for the iBFT.
|
2008-04-17 10:28:51 +02:00
|
|
|
**/
|
2007-12-24 03:20:21 +01:00
|
|
|
VOID
|
|
|
|
IScsiInitIbfTableHeader (
|
2009-07-06 05:06:50 +02:00
|
|
|
OUT EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_HEADER *Header,
|
|
|
|
IN UINT8 *OemId,
|
|
|
|
IN UINT64 *OemTableId
|
2007-12-24 03:20:21 +01:00
|
|
|
)
|
|
|
|
{
|
2008-02-14 10:40:22 +01:00
|
|
|
ZeroMem (Header, sizeof (EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_HEADER));
|
2007-12-24 03:20:21 +01:00
|
|
|
|
|
|
|
Header->Signature = EFI_ACPI_3_0_ISCSI_BOOT_FIRMWARE_TABLE_SIGNATURE;
|
|
|
|
Header->Length = IBFT_HEAP_OFFSET;
|
|
|
|
Header->Revision = EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_REVISION;
|
|
|
|
Header->Checksum = 0;
|
|
|
|
|
|
|
|
Header->OemId[0] = 'I';
|
|
|
|
Header->OemId[1] = 'N';
|
|
|
|
Header->OemId[2] = 'T';
|
|
|
|
Header->OemId[3] = 'E';
|
|
|
|
Header->OemId[4] = 'L';
|
2009-07-06 05:06:50 +02:00
|
|
|
|
|
|
|
CopyMem (Header->OemId, OemId, sizeof (Header->OemId));
|
2010-02-01 06:01:07 +01:00
|
|
|
CopyMem (&Header->OemTableId, OemTableId, sizeof (UINT64));
|
2007-12-24 03:20:21 +01:00
|
|
|
}
|
|
|
|
|
2008-04-17 10:28:51 +02:00
|
|
|
/**
|
|
|
|
Initialize the control section of the iSCSI Boot Firmware Table.
|
|
|
|
|
2008-12-10 04:24:11 +01:00
|
|
|
@param[in] Table The ACPI table.
|
|
|
|
@param[in] HandleCount The number of the handles associated with iSCSI sessions, it's
|
2008-04-17 10:28:51 +02:00
|
|
|
equal to the number of iSCSI sessions.
|
|
|
|
**/
|
2007-12-24 03:20:21 +01:00
|
|
|
VOID
|
|
|
|
IScsiInitControlSection (
|
|
|
|
IN EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_HEADER *Table,
|
|
|
|
IN UINTN HandleCount
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_CONTROL_STRUCTURE *Control;
|
|
|
|
UINTN NumOffset;
|
|
|
|
|
|
|
|
Control = (EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_CONTROL_STRUCTURE *) (Table + 1);
|
|
|
|
|
2008-02-14 10:40:22 +01:00
|
|
|
ZeroMem (Control, sizeof (EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_CONTROL_STRUCTURE));
|
2007-12-24 03:20:21 +01:00
|
|
|
|
|
|
|
Control->Header.StructureId = EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_CONTROL_STRUCTURE_ID;
|
|
|
|
Control->Header.Version = EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_CONTROL_STRUCTURE_VERSION;
|
2010-09-15 09:48:11 +02:00
|
|
|
Control->Header.Length = (UINT16) sizeof (EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_CONTROL_STRUCTURE);
|
2007-12-24 03:20:21 +01:00
|
|
|
|
|
|
|
//
|
|
|
|
// Each session occupies two offsets, one for the NIC section,
|
|
|
|
// the other for the Target section.
|
|
|
|
//
|
|
|
|
NumOffset = 2 * HandleCount;
|
|
|
|
if (NumOffset > 4) {
|
|
|
|
//
|
|
|
|
// Need expand the control section if more than 2 NIC/Target sections
|
|
|
|
// exist.
|
|
|
|
//
|
2008-01-22 08:14:48 +01:00
|
|
|
Control->Header.Length = (UINT16) (Control->Header.Length + (NumOffset - 4) * sizeof (UINT16));
|
2007-12-24 03:20:21 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-17 10:28:51 +02:00
|
|
|
/**
|
|
|
|
Add one item into the heap.
|
|
|
|
|
2008-12-10 04:24:11 +01:00
|
|
|
@param[in, out] Heap On input, the current address of the heap; On output, the address of
|
|
|
|
the heap after the item is added.
|
|
|
|
@param[in] Data The data to add into the heap.
|
|
|
|
@param[in] Len Length of the Data in byte.
|
2008-04-17 10:28:51 +02:00
|
|
|
**/
|
2007-12-24 03:20:21 +01:00
|
|
|
VOID
|
|
|
|
IScsiAddHeapItem (
|
|
|
|
IN OUT UINT8 **Heap,
|
|
|
|
IN VOID *Data,
|
|
|
|
IN UINTN Len
|
|
|
|
)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// Add one byte for the NULL delimiter.
|
|
|
|
//
|
|
|
|
*Heap -= Len + 1;
|
|
|
|
|
2008-02-14 10:40:22 +01:00
|
|
|
CopyMem (*Heap, Data, Len);
|
2007-12-24 03:20:21 +01:00
|
|
|
*(*Heap + Len) = 0;
|
|
|
|
}
|
|
|
|
|
2008-04-17 10:28:51 +02:00
|
|
|
/**
|
|
|
|
Fill the Initiator section of the iSCSI Boot Firmware Table.
|
|
|
|
|
2008-12-10 04:24:11 +01:00
|
|
|
@param[in] Table The ACPI table.
|
|
|
|
@param[in, out] Heap The heap.
|
|
|
|
@param[in] Handle The handle associated with the iSCSI session.
|
2008-04-17 10:28:51 +02:00
|
|
|
**/
|
2007-12-24 03:20:21 +01:00
|
|
|
VOID
|
|
|
|
IScsiFillInitiatorSection (
|
|
|
|
IN EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_HEADER *Table,
|
|
|
|
IN OUT UINT8 **Heap,
|
|
|
|
IN EFI_HANDLE Handle
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_CONTROL_STRUCTURE *Control;
|
|
|
|
EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_INITIATOR_STRUCTURE *Initiator;
|
|
|
|
ISCSI_DRIVER_DATA *DriverData;
|
|
|
|
ISCSI_SESSION *Session;
|
|
|
|
ISCSI_PRIVATE_PROTOCOL *IScsiIdentifier;
|
|
|
|
EFI_STATUS Status;
|
|
|
|
|
|
|
|
Control = (EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_CONTROL_STRUCTURE *) (Table + 1);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Initiator section immediately follows the control section.
|
|
|
|
//
|
|
|
|
Initiator = (EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_INITIATOR_STRUCTURE *) ((UINT8 *) Control + IBFT_ROUNDUP (Control->Header.Length));
|
|
|
|
|
|
|
|
Control->InitiatorOffset = (UINT16) ((UINTN) Initiator - (UINTN) Table);
|
|
|
|
|
2008-02-14 10:40:22 +01:00
|
|
|
ZeroMem (Initiator, sizeof (EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_INITIATOR_STRUCTURE));
|
2007-12-24 03:20:21 +01:00
|
|
|
|
|
|
|
Initiator->Header.StructureId = EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_INITIATOR_STRUCTURE_ID;
|
|
|
|
Initiator->Header.Version = EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_INITIATOR_STRUCTURE_VERSION;
|
2010-09-15 09:48:11 +02:00
|
|
|
Initiator->Header.Length = (UINT16) sizeof (EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_INITIATOR_STRUCTURE);
|
2007-12-24 03:20:21 +01:00
|
|
|
Initiator->Header.Flags = EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_INITIATOR_STRUCTURE_FLAG_BLOCK_VALID | EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_INITIATOR_STRUCTURE_FLAG_BOOT_SELECTED;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Get the identifier from the handle.
|
|
|
|
//
|
2008-12-16 08:17:19 +01:00
|
|
|
Status = gBS->HandleProtocol (Handle, &gIScsiPrivateGuid, (VOID **) &IScsiIdentifier);
|
2007-12-24 03:20:21 +01:00
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
ASSERT (FALSE);
|
|
|
|
return ;
|
|
|
|
}
|
|
|
|
|
|
|
|
DriverData = ISCSI_DRIVER_DATA_FROM_IDENTIFIER (IScsiIdentifier);
|
|
|
|
Session = &DriverData->Session;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Fill the iSCSI Initiator Name into the heap.
|
|
|
|
//
|
|
|
|
IScsiAddHeapItem (Heap, Session->InitiatorName, Session->InitiatorNameLength - 1);
|
|
|
|
|
|
|
|
Initiator->IScsiNameLength = (UINT16) (Session->InitiatorNameLength - 1);
|
|
|
|
Initiator->IScsiNameOffset = (UINT16) ((UINTN) *Heap - (UINTN) Table);
|
|
|
|
}
|
|
|
|
|
2008-04-17 10:28:51 +02:00
|
|
|
/**
|
|
|
|
Map the v4 IP address into v6 IP address.
|
|
|
|
|
2008-12-10 04:24:11 +01:00
|
|
|
@param[in] V4 The v4 IP address.
|
|
|
|
@param[out] V6 The v6 IP address.
|
2008-04-17 10:28:51 +02:00
|
|
|
**/
|
2007-12-24 03:20:21 +01:00
|
|
|
VOID
|
|
|
|
IScsiMapV4ToV6Addr (
|
|
|
|
IN EFI_IPv4_ADDRESS *V4,
|
|
|
|
OUT EFI_IPv6_ADDRESS *V6
|
|
|
|
)
|
|
|
|
{
|
|
|
|
UINTN Index;
|
|
|
|
|
2008-02-14 10:40:22 +01:00
|
|
|
ZeroMem (V6, sizeof (EFI_IPv6_ADDRESS));
|
2007-12-24 03:20:21 +01:00
|
|
|
|
|
|
|
V6->Addr[10] = 0xff;
|
|
|
|
V6->Addr[11] = 0xff;
|
|
|
|
|
|
|
|
for (Index = 0; Index < 4; Index++) {
|
|
|
|
V6->Addr[12 + Index] = V4->Addr[Index];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-17 10:28:51 +02:00
|
|
|
/**
|
2007-12-24 03:20:21 +01:00
|
|
|
Get the NIC's PCI location and return it accroding to the composited
|
|
|
|
format defined in iSCSI Boot Firmware Table.
|
|
|
|
|
2008-12-10 04:24:11 +01:00
|
|
|
@param[in] Controller The handle of the controller.
|
2007-12-24 03:20:21 +01:00
|
|
|
|
2008-12-10 04:24:11 +01:00
|
|
|
@return UINT16 The composited representation of the NIC PCI location.
|
2008-12-12 08:03:44 +01:00
|
|
|
@retval 0 Other errors as indicated.
|
2008-04-17 10:28:51 +02:00
|
|
|
**/
|
|
|
|
UINT16
|
|
|
|
IScsiGetNICPciLocation (
|
|
|
|
IN EFI_HANDLE Controller
|
|
|
|
)
|
2007-12-24 03:20:21 +01:00
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
EFI_DEVICE_PATH_PROTOCOL *DevicePath;
|
|
|
|
EFI_HANDLE PciIoHandle;
|
|
|
|
EFI_PCI_IO_PROTOCOL *PciIo;
|
|
|
|
UINTN Segment;
|
|
|
|
UINTN Bus;
|
|
|
|
UINTN Device;
|
|
|
|
UINTN Function;
|
|
|
|
|
|
|
|
Status = gBS->HandleProtocol (
|
|
|
|
Controller,
|
|
|
|
&gEfiDevicePathProtocolGuid,
|
2008-01-22 08:14:48 +01:00
|
|
|
(VOID **)&DevicePath
|
2007-12-24 03:20:21 +01:00
|
|
|
);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
Status = gBS->LocateDevicePath (
|
|
|
|
&gEfiPciIoProtocolGuid,
|
|
|
|
&DevicePath,
|
|
|
|
&PciIoHandle
|
|
|
|
);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-01-22 08:14:48 +01:00
|
|
|
Status = gBS->HandleProtocol (PciIoHandle, &gEfiPciIoProtocolGuid, (VOID **)&PciIo);
|
2007-12-24 03:20:21 +01:00
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
Status = PciIo->GetLocation (PciIo, &Segment, &Bus, &Device, &Function);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (UINT16) ((Bus << 8) | (Device << 3) | Function);
|
|
|
|
}
|
|
|
|
|
2008-04-17 10:28:51 +02:00
|
|
|
/**
|
|
|
|
Fill the NIC and target sections in iSCSI Boot Firmware Table.
|
|
|
|
|
2008-12-10 04:24:11 +01:00
|
|
|
@param[in] Table The buffer of the ACPI table.
|
|
|
|
@param[in, out] Heap The heap buffer used to store the variable length parameters such as iSCSI name.
|
|
|
|
@param[in] HandleCount Count The number of handles having iSCSI private protocol installed.
|
|
|
|
@param[in] Handles The handle buffer.
|
2008-04-17 10:28:51 +02:00
|
|
|
**/
|
2007-12-24 03:20:21 +01:00
|
|
|
VOID
|
|
|
|
IScsiFillNICAndTargetSections (
|
|
|
|
IN EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_HEADER *Table,
|
|
|
|
IN OUT UINT8 **Heap,
|
|
|
|
IN UINTN HandleCount,
|
|
|
|
IN EFI_HANDLE *Handles
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_CONTROL_STRUCTURE *Control;
|
|
|
|
EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_NIC_STRUCTURE *Nic;
|
|
|
|
EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_TARGET_STRUCTURE *Target;
|
|
|
|
ISCSI_DRIVER_DATA *DriverData;
|
|
|
|
ISCSI_SESSION_CONFIG_DATA *SessionConfigData;
|
|
|
|
ISCSI_CHAP_AUTH_CONFIG_NVDATA *AuthConfig;
|
|
|
|
UINT16 *SectionOffset;
|
|
|
|
UINTN Index;
|
|
|
|
UINT16 Length;
|
2009-12-30 14:47:55 +01:00
|
|
|
EFI_MAC_ADDRESS MacAddress;
|
|
|
|
UINTN HwAddressSize;
|
2007-12-24 03:20:21 +01:00
|
|
|
ISCSI_PRIVATE_PROTOCOL *IScsiIdentifier;
|
|
|
|
EFI_STATUS Status;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Get the offset of the first Nic and Target section.
|
|
|
|
//
|
|
|
|
Control = (EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_CONTROL_STRUCTURE *) (Table + 1);
|
|
|
|
Nic = (EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_NIC_STRUCTURE *) ((UINTN) Table +
|
|
|
|
Control->InitiatorOffset + IBFT_ROUNDUP (sizeof (EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_INITIATOR_STRUCTURE)));
|
|
|
|
Target = (EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_TARGET_STRUCTURE *) ((UINTN) Nic +
|
|
|
|
IBFT_ROUNDUP (sizeof (EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_NIC_STRUCTURE)));
|
|
|
|
|
|
|
|
SectionOffset = &Control->NIC0Offset;
|
|
|
|
|
|
|
|
for (Index = 0; Index < HandleCount; Index++) {
|
2008-12-16 08:17:19 +01:00
|
|
|
Status = gBS->HandleProtocol (Handles[Index], &gIScsiPrivateGuid, (VOID **)&IScsiIdentifier);
|
2007-12-24 03:20:21 +01:00
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
ASSERT (FALSE);
|
|
|
|
return ;
|
|
|
|
}
|
|
|
|
|
|
|
|
DriverData = ISCSI_DRIVER_DATA_FROM_IDENTIFIER (IScsiIdentifier);
|
|
|
|
SessionConfigData = &DriverData->Session.ConfigData;
|
|
|
|
AuthConfig = &DriverData->Session.AuthData.AuthConfig;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Fill the Nic section.
|
|
|
|
//
|
2008-02-14 10:40:22 +01:00
|
|
|
ZeroMem (Nic, sizeof (EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_NIC_STRUCTURE));
|
2007-12-24 03:20:21 +01:00
|
|
|
|
|
|
|
Nic->Header.StructureId = EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_NIC_STRUCTURE_ID;
|
|
|
|
Nic->Header.Version = EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_NIC_STRUCTURE_VERSION;
|
2010-09-15 09:48:11 +02:00
|
|
|
Nic->Header.Length = (UINT16) sizeof (EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_NIC_STRUCTURE);
|
2007-12-24 03:20:21 +01:00
|
|
|
Nic->Header.Index = (UINT8) Index;
|
|
|
|
Nic->Header.Flags = EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_NIC_STRUCTURE_FLAG_BLOCK_VALID |
|
|
|
|
EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_NIC_STRUCTURE_FLAG_BOOT_SELECTED |
|
|
|
|
EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_NIC_STRUCTURE_FLAG_GLOBAL;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Get the subnet mask prefix length.
|
|
|
|
//
|
|
|
|
Nic->SubnetMaskPrefixLength = IScsiGetSubnetMaskPrefixLength (&SessionConfigData->NvData.SubnetMask);
|
|
|
|
|
|
|
|
if (SessionConfigData->NvData.InitiatorInfoFromDhcp) {
|
|
|
|
Nic->Origin = IpPrefixOriginDhcp;
|
|
|
|
} else {
|
|
|
|
Nic->Origin = IpPrefixOriginManual;
|
|
|
|
}
|
|
|
|
//
|
|
|
|
// Map the various v4 addresses into v6 addresses.
|
|
|
|
//
|
|
|
|
IScsiMapV4ToV6Addr (&SessionConfigData->NvData.LocalIp, &Nic->Ip);
|
|
|
|
IScsiMapV4ToV6Addr (&SessionConfigData->NvData.Gateway, &Nic->Gateway);
|
|
|
|
IScsiMapV4ToV6Addr (&SessionConfigData->PrimaryDns, &Nic->PrimaryDns);
|
|
|
|
IScsiMapV4ToV6Addr (&SessionConfigData->SecondaryDns, &Nic->SecondaryDns);
|
|
|
|
IScsiMapV4ToV6Addr (&SessionConfigData->DhcpServer, &Nic->DhcpServer);
|
|
|
|
|
2009-12-30 14:47:55 +01:00
|
|
|
Nic->VLanTag = NetLibGetVlanId (DriverData->Controller);
|
|
|
|
|
|
|
|
Status = NetLibGetMacAddress (DriverData->Controller, &MacAddress, &HwAddressSize);
|
|
|
|
ASSERT (Status == EFI_SUCCESS);
|
|
|
|
CopyMem (Nic->Mac, MacAddress.Addr, sizeof (Nic->Mac));
|
2007-12-24 03:20:21 +01:00
|
|
|
|
|
|
|
//
|
|
|
|
// Get the PCI location of the Nic.
|
|
|
|
//
|
|
|
|
Nic->PciLocation = IScsiGetNICPciLocation (DriverData->Controller);
|
|
|
|
|
|
|
|
*SectionOffset = (UINT16) ((UINTN) Nic - (UINTN) Table);
|
|
|
|
SectionOffset++;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Fill the Target section.
|
|
|
|
//
|
2008-02-14 10:40:22 +01:00
|
|
|
ZeroMem (Target, sizeof (EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_TARGET_STRUCTURE));
|
2007-12-24 03:20:21 +01:00
|
|
|
|
|
|
|
Target->Header.StructureId = EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_TARGET_STRUCTURE_ID;
|
|
|
|
Target->Header.Version = EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_TARGET_STRUCTURE_VERSION;
|
2010-09-15 09:48:11 +02:00
|
|
|
Target->Header.Length = (UINT16) sizeof (EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_TARGET_STRUCTURE);
|
2007-12-24 03:20:21 +01:00
|
|
|
Target->Header.Index = (UINT8) Index;
|
|
|
|
Target->Header.Flags = EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_TARGET_STRUCTURE_FLAG_BLOCK_VALID | EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_TARGET_STRUCTURE_FLAG_BOOT_SELECTED;
|
|
|
|
Target->Port = SessionConfigData->NvData.TargetPort;
|
|
|
|
Target->CHAPType = AuthConfig->CHAPType;
|
|
|
|
Target->NicIndex = (UINT8) Index;
|
|
|
|
|
|
|
|
IScsiMapV4ToV6Addr (&SessionConfigData->NvData.TargetIp, &Target->Ip);
|
2008-02-14 10:40:22 +01:00
|
|
|
CopyMem (Target->BootLun, SessionConfigData->NvData.BootLun, sizeof (Target->BootLun));
|
2007-12-24 03:20:21 +01:00
|
|
|
|
|
|
|
//
|
|
|
|
// Target iSCSI Name, CHAP name/secret, reverse CHAP name/secret.
|
|
|
|
//
|
|
|
|
Length = (UINT16) AsciiStrLen (SessionConfigData->NvData.TargetName);
|
|
|
|
IScsiAddHeapItem (Heap, SessionConfigData->NvData.TargetName, Length);
|
|
|
|
|
|
|
|
Target->IScsiNameLength = Length;
|
|
|
|
Target->IScsiNameOffset = (UINT16) ((UINTN) *Heap - (UINTN) Table);
|
|
|
|
|
|
|
|
if (Target->CHAPType != ISCSI_CHAP_NONE) {
|
|
|
|
//
|
|
|
|
// CHAP Name
|
|
|
|
//
|
|
|
|
Length = (UINT16) AsciiStrLen (AuthConfig->CHAPName);
|
|
|
|
IScsiAddHeapItem (Heap, AuthConfig->CHAPName, Length);
|
|
|
|
Target->CHAPNameLength = Length;
|
|
|
|
Target->CHAPNameOffset = (UINT16) ((UINTN) *Heap - (UINTN) Table);
|
|
|
|
|
|
|
|
//
|
|
|
|
// CHAP Secret
|
|
|
|
//
|
|
|
|
Length = (UINT16) AsciiStrLen (AuthConfig->CHAPSecret);
|
|
|
|
IScsiAddHeapItem (Heap, AuthConfig->CHAPSecret, Length);
|
|
|
|
Target->CHAPSecretLength = Length;
|
|
|
|
Target->CHAPSecretOffset = (UINT16) ((UINTN) *Heap - (UINTN) Table);
|
|
|
|
|
|
|
|
if (Target->CHAPType == ISCSI_CHAP_MUTUAL) {
|
|
|
|
//
|
|
|
|
// Reverse CHAP Name
|
|
|
|
//
|
|
|
|
Length = (UINT16) AsciiStrLen (AuthConfig->ReverseCHAPName);
|
|
|
|
IScsiAddHeapItem (Heap, AuthConfig->ReverseCHAPName, Length);
|
|
|
|
Target->ReverseCHAPNameLength = Length;
|
|
|
|
Target->ReverseCHAPNameOffset = (UINT16) ((UINTN) *Heap - (UINTN) Table);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Reverse CHAP Secret
|
|
|
|
//
|
|
|
|
Length = (UINT16) AsciiStrLen (AuthConfig->ReverseCHAPSecret);
|
|
|
|
IScsiAddHeapItem (Heap, AuthConfig->ReverseCHAPSecret, Length);
|
|
|
|
Target->ReverseCHAPSecretLength = Length;
|
|
|
|
Target->ReverseCHAPSecretOffset = (UINT16) ((UINTN) *Heap - (UINTN) Table);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*SectionOffset = (UINT16) ((UINTN) Target - (UINTN) Table);
|
|
|
|
SectionOffset++;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Advance to the next NIC/Target pair
|
|
|
|
//
|
|
|
|
Nic = (EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_NIC_STRUCTURE *) ((UINTN) Target +
|
|
|
|
IBFT_ROUNDUP (sizeof (EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_TARGET_STRUCTURE)));
|
|
|
|
Target = (EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_TARGET_STRUCTURE *) ((UINTN) Nic +
|
|
|
|
IBFT_ROUNDUP (sizeof (EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_NIC_STRUCTURE)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-17 10:28:51 +02:00
|
|
|
/**
|
2007-12-24 03:20:21 +01:00
|
|
|
Publish and remove the iSCSI Boot Firmware Table according to the iSCSI
|
|
|
|
session status.
|
2008-04-17 10:28:51 +02:00
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
IScsiPublishIbft (
|
2009-01-13 09:44:22 +01:00
|
|
|
VOID
|
2008-04-17 10:28:51 +02:00
|
|
|
)
|
2007-12-24 03:20:21 +01:00
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
2009-04-17 10:49:00 +02:00
|
|
|
EFI_ACPI_TABLE_PROTOCOL *AcpiTableProtocol;
|
2007-12-24 03:20:21 +01:00
|
|
|
EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_HEADER *Table;
|
|
|
|
UINTN HandleCount;
|
|
|
|
EFI_HANDLE *HandleBuffer;
|
|
|
|
UINT8 *Heap;
|
2009-06-24 11:39:47 +02:00
|
|
|
UINT8 Checksum;
|
2009-07-06 05:06:50 +02:00
|
|
|
UINTN Index;
|
|
|
|
EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER *Rsdp;
|
|
|
|
EFI_ACPI_DESCRIPTION_HEADER *Rsdt;
|
2007-12-24 03:20:21 +01:00
|
|
|
|
2009-04-17 10:49:00 +02:00
|
|
|
Status = gBS->LocateProtocol (&gEfiAcpiTableProtocolGuid, NULL, (VOID **)&AcpiTableProtocol);
|
2007-12-24 03:20:21 +01:00
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
return ;
|
|
|
|
}
|
|
|
|
|
2009-07-06 05:06:50 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// Find ACPI table RSD_PTR from system table
|
|
|
|
//
|
|
|
|
for (Index = 0, Rsdp = NULL; Index < gST->NumberOfTableEntries; Index++) {
|
|
|
|
if (CompareGuid (&(gST->ConfigurationTable[Index].VendorGuid), &gEfiAcpi20TableGuid) ||
|
|
|
|
CompareGuid (&(gST->ConfigurationTable[Index].VendorGuid), &gEfiAcpi10TableGuid) ||
|
|
|
|
CompareGuid (&(gST->ConfigurationTable[Index].VendorGuid), &gEfiAcpiTableGuid)
|
|
|
|
) {
|
|
|
|
//
|
|
|
|
// A match was found.
|
|
|
|
//
|
|
|
|
Rsdp = (EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER *) gST->ConfigurationTable[Index].VendorTable;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Rsdp == NULL) {
|
|
|
|
return ;
|
|
|
|
} else {
|
|
|
|
Rsdt = (EFI_ACPI_DESCRIPTION_HEADER *) (UINTN) Rsdp->RsdtAddress;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-17 10:49:00 +02:00
|
|
|
if (mIbftInstalled) {
|
|
|
|
Status = AcpiTableProtocol->UninstallAcpiTable (
|
|
|
|
AcpiTableProtocol,
|
|
|
|
mTableKey
|
|
|
|
);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
return ;
|
2007-12-24 03:20:21 +01:00
|
|
|
}
|
2009-04-17 10:49:00 +02:00
|
|
|
mIbftInstalled = FALSE;
|
2007-12-24 03:20:21 +01:00
|
|
|
}
|
2009-04-17 10:49:00 +02:00
|
|
|
|
2007-12-24 03:20:21 +01:00
|
|
|
//
|
|
|
|
// Get all iSCSI private protocols.
|
|
|
|
//
|
|
|
|
Status = gBS->LocateHandleBuffer (
|
|
|
|
ByProtocol,
|
2008-12-16 08:17:19 +01:00
|
|
|
&gIScsiPrivateGuid,
|
2007-12-24 03:20:21 +01:00
|
|
|
NULL,
|
|
|
|
&HandleCount,
|
|
|
|
&HandleBuffer
|
|
|
|
);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
return ;
|
|
|
|
}
|
|
|
|
//
|
|
|
|
// Allocate 4k bytes to hold the ACPI table.
|
|
|
|
//
|
2009-06-24 11:39:47 +02:00
|
|
|
Table = AllocateZeroPool (IBFT_MAX_SIZE);
|
2007-12-24 03:20:21 +01:00
|
|
|
if (Table == NULL) {
|
|
|
|
return ;
|
|
|
|
}
|
|
|
|
|
2008-01-22 08:14:48 +01:00
|
|
|
Heap = (UINT8 *) Table + IBFT_HEAP_OFFSET;
|
2007-12-24 03:20:21 +01:00
|
|
|
|
|
|
|
//
|
|
|
|
// Fill in the various section of the iSCSI Boot Firmware Table.
|
|
|
|
//
|
2009-07-06 05:06:50 +02:00
|
|
|
IScsiInitIbfTableHeader (Table, Rsdt->OemId, &Rsdt->OemTableId);
|
2007-12-24 03:20:21 +01:00
|
|
|
IScsiInitControlSection (Table, HandleCount);
|
|
|
|
IScsiFillInitiatorSection (Table, &Heap, HandleBuffer[0]);
|
|
|
|
IScsiFillNICAndTargetSections (Table, &Heap, HandleCount, HandleBuffer);
|
|
|
|
|
2009-06-24 11:39:47 +02:00
|
|
|
Checksum = CalculateCheckSum8((UINT8 *)Table, Table->Length);
|
|
|
|
Table->Checksum = Checksum;
|
|
|
|
|
2009-04-17 10:49:00 +02:00
|
|
|
FreePool (HandleBuffer);
|
2007-12-24 03:20:21 +01:00
|
|
|
|
|
|
|
//
|
|
|
|
// Install or update the iBFT table.
|
|
|
|
//
|
2009-04-17 10:49:00 +02:00
|
|
|
Status = AcpiTableProtocol->InstallAcpiTable (
|
|
|
|
AcpiTableProtocol,
|
|
|
|
Table,
|
|
|
|
Table->Length,
|
|
|
|
&mTableKey
|
|
|
|
);
|
|
|
|
if (EFI_ERROR(Status)) {
|
|
|
|
return;
|
2007-12-24 03:20:21 +01:00
|
|
|
}
|
|
|
|
|
2009-04-17 10:49:00 +02:00
|
|
|
mIbftInstalled = TRUE;
|
|
|
|
FreePool (Table);
|
2007-12-24 03:20:21 +01:00
|
|
|
}
|