X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=MdeModulePkg%2FUniversal%2FNetwork%2FIScsiDxe%2FIScsiIbft.c;h=dd4189c02b61253e8cfb857eb05e3f9818cfbc42;hb=842d83d65ecb05ef35578ea947f0e3da98b10d1f;hp=cd4be8b3c93df622d4b410559df855035f26e062;hpb=e48e37fce2611df7a52aff271835ff72ee396d9b;p=mirror_edk2.git diff --git a/MdeModulePkg/Universal/Network/IScsiDxe/IScsiIbft.c b/MdeModulePkg/Universal/Network/IScsiDxe/IScsiIbft.c index cd4be8b3c9..dd4189c02b 100644 --- a/MdeModulePkg/Universal/Network/IScsiDxe/IScsiIbft.c +++ b/MdeModulePkg/Universal/Network/IScsiDxe/IScsiIbft.c @@ -1,7 +1,8 @@ -/*++ +/** @file + Implementation for iSCSI Boot Firmware Table publication. -Copyright (c) 2004 - 2007, Intel Corporation -All rights reserved. This program and the accompanying materials +Copyright (c) 2004 - 2011, Intel Corporation. All rights reserved.
+This program and the accompanying materials 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 @@ -9,38 +10,26 @@ 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. -Module Name: - - IScsiIbft.c - -Abstract: - - Implementation for iSCSI Boot Firmware Table publication. - ---*/ +**/ #include "IScsiImpl.h" -STATIC -VOID -IScsiInitIbfTableHeader ( - IN EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_HEADER *Header - ) -/*++ - -Routine Description: +BOOLEAN mIbftInstalled = FALSE; +UINTN mTableKey; +/** Initialize the header of the iSCSI Boot Firmware Table. -Arguments: - - Header - The header of the iSCSI Boot Firmware Table. - -Returns: - - None. - ---*/ + @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. +**/ +VOID +IScsiInitIbfTableHeader ( + OUT EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_HEADER *Header, + IN UINT8 *OemId, + IN UINT64 *OemTableId + ) { ZeroMem (Header, sizeof (EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_HEADER)); @@ -54,31 +43,23 @@ Returns: Header->OemId[2] = 'T'; Header->OemId[3] = 'E'; Header->OemId[4] = 'L'; + + CopyMem (Header->OemId, OemId, sizeof (Header->OemId)); + CopyMem (&Header->OemTableId, OemTableId, sizeof (UINT64)); } -STATIC +/** + Initialize the control section of the iSCSI Boot Firmware Table. + + @param[in] Table The ACPI table. + @param[in] HandleCount The number of the handles associated with iSCSI sessions, it's + equal to the number of iSCSI sessions. +**/ VOID IScsiInitControlSection ( IN EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_HEADER *Table, IN UINTN HandleCount ) -/*++ - -Routine Description: - - Initialize the control section of the iSCSI Boot Firmware Table. - -Arguments: - - Table - The ACPI table. - HandleCount - The number of the handles associated with iSCSI sessions, it's - equal to the number of iSCSI sessions. - -Returns: - - None. - ---*/ { EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_CONTROL_STRUCTURE *Control; UINTN NumOffset; @@ -89,7 +70,7 @@ Returns: Control->Header.StructureId = EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_CONTROL_STRUCTURE_ID; Control->Header.Version = EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_CONTROL_STRUCTURE_VERSION; - Control->Header.Length = sizeof (EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_CONTROL_STRUCTURE); + Control->Header.Length = (UINT16) sizeof (EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_CONTROL_STRUCTURE); // // Each session occupies two offsets, one for the NIC section, @@ -105,31 +86,20 @@ Returns: } } -STATIC +/** + Add one item into the heap. + + @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. +**/ VOID IScsiAddHeapItem ( IN OUT UINT8 **Heap, IN VOID *Data, IN UINTN Len ) -/*++ - -Routine Description: - - Add one item into the heap. - -Arguments: - - Heap - On input, the current address of the heap; On output, the address of - the heap after the item is added. - Data - The data to add into the heap. - Len - Length of the Data in byte. - -Returns: - - None. - ---*/ { // // Add one byte for the NULL delimiter. @@ -140,30 +110,19 @@ Returns: *(*Heap + Len) = 0; } -STATIC +/** + Fill the Initiator section of the iSCSI Boot Firmware Table. + + @param[in] Table The ACPI table. + @param[in, out] Heap The heap. + @param[in] Handle The handle associated with the iSCSI session. +**/ VOID IScsiFillInitiatorSection ( IN EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_HEADER *Table, IN OUT UINT8 **Heap, IN EFI_HANDLE Handle ) -/*++ - -Routine Description: - - Fill the Initiator section of the iSCSI Boot Firmware Table. - -Arguments: - - Table - The ACPI table. - Heap - The heap. - Handle - The handle associated with the iSCSI session. - -Returns: - - None. - ---*/ { EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_CONTROL_STRUCTURE *Control; EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_INITIATOR_STRUCTURE *Initiator; @@ -185,13 +144,13 @@ Returns: Initiator->Header.StructureId = EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_INITIATOR_STRUCTURE_ID; Initiator->Header.Version = EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_INITIATOR_STRUCTURE_VERSION; - Initiator->Header.Length = sizeof (EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_INITIATOR_STRUCTURE); + Initiator->Header.Length = (UINT16) sizeof (EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_INITIATOR_STRUCTURE); 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. // - Status = gBS->HandleProtocol (Handle, &mIScsiPrivateGuid, (VOID **) &IScsiIdentifier); + Status = gBS->HandleProtocol (Handle, &gEfiCallerIdGuid, (VOID **) &IScsiIdentifier); if (EFI_ERROR (Status)) { ASSERT (FALSE); return ; @@ -209,28 +168,17 @@ Returns: Initiator->IScsiNameOffset = (UINT16) ((UINTN) *Heap - (UINTN) Table); } -STATIC +/** + Map the v4 IP address into v6 IP address. + + @param[in] V4 The v4 IP address. + @param[out] V6 The v6 IP address. +**/ VOID IScsiMapV4ToV6Addr ( IN EFI_IPv4_ADDRESS *V4, OUT EFI_IPv6_ADDRESS *V6 ) -/*++ - -Routine Description: - - Map the v4 IP address into v6 IP address. - -Arguments: - - V4 - The v4 IP address. - V6 - The v6 IP address. - -Returns: - - None. - ---*/ { UINTN Index; @@ -244,27 +192,19 @@ Returns: } } -STATIC -UINT16 -IScsiGetNICPciLocation ( - IN EFI_HANDLE Controller - ) -/*++ - -Routine Description: - +/** Get the NIC's PCI location and return it accroding to the composited format defined in iSCSI Boot Firmware Table. - -Arguments: - - Controller - The handle of the controller. -Returns: + @param[in] Controller The handle of the controller. - UINT16 - The composited representation of the NIC PCI location. - ---*/ + @return UINT16 The composited representation of the NIC PCI location. + @retval 0 Other errors as indicated. +**/ +UINT16 +IScsiGetNICPciLocation ( + IN EFI_HANDLE Controller + ) { EFI_STATUS Status; EFI_DEVICE_PATH_PROTOCOL *DevicePath; @@ -306,41 +246,14 @@ Returns: return (UINT16) ((Bus << 8) | (Device << 3) | Function); } -STATIC -EFI_MAC_ADDRESS * -IScsiGetMacAddress ( - IN EFI_HANDLE Controller - ) -/*++ - -Routine Description: - - Get the MAC address of the controller. - -Arguments: - - Controller - The handle of the controller. - -Returns: - - EFI_MAC_ADDRESS * - The mac address. - ---*/ -{ - EFI_STATUS Status; - EFI_SIMPLE_NETWORK_PROTOCOL *Snp; - - Status = gBS->HandleProtocol ( - Controller, - &gEfiSimpleNetworkProtocolGuid, - (VOID **) &Snp - ); - ASSERT_EFI_ERROR (Status); - - return &Snp->Mode->PermanentAddress; -} +/** + Fill the NIC and target sections in iSCSI Boot Firmware Table. -STATIC + @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. +**/ VOID IScsiFillNICAndTargetSections ( IN EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_HEADER *Table, @@ -348,24 +261,6 @@ IScsiFillNICAndTargetSections ( IN UINTN HandleCount, IN EFI_HANDLE *Handles ) -/*++ - -Routine Description: - - Fill the NIC and target sections in iSCSI Boot Firmware Table. - -Arguments: - - Table - The buffer of the ACPI table. - Heap - The heap buffer used to store the variable length parameters such as iSCSI name. - HandleCount - The number of handles having iSCSI private protocol installed. - Handles - The handle buffer. - -Returns: - - None. - ---*/ { EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_CONTROL_STRUCTURE *Control; EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_NIC_STRUCTURE *Nic; @@ -376,7 +271,8 @@ Returns: UINT16 *SectionOffset; UINTN Index; UINT16 Length; - EFI_MAC_ADDRESS *Mac; + EFI_MAC_ADDRESS MacAddress; + UINTN HwAddressSize; ISCSI_PRIVATE_PROTOCOL *IScsiIdentifier; EFI_STATUS Status; @@ -392,7 +288,7 @@ Returns: SectionOffset = &Control->NIC0Offset; for (Index = 0; Index < HandleCount; Index++) { - Status = gBS->HandleProtocol (Handles[Index], &mIScsiPrivateGuid, (VOID **)&IScsiIdentifier); + Status = gBS->HandleProtocol (Handles[Index], &gEfiCallerIdGuid, (VOID **)&IScsiIdentifier); if (EFI_ERROR (Status)) { ASSERT (FALSE); return ; @@ -409,7 +305,7 @@ Returns: Nic->Header.StructureId = EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_NIC_STRUCTURE_ID; Nic->Header.Version = EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_NIC_STRUCTURE_VERSION; - Nic->Header.Length = sizeof (EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_NIC_STRUCTURE); + Nic->Header.Length = (UINT16) sizeof (EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_NIC_STRUCTURE); 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 | @@ -434,8 +330,11 @@ Returns: IScsiMapV4ToV6Addr (&SessionConfigData->SecondaryDns, &Nic->SecondaryDns); IScsiMapV4ToV6Addr (&SessionConfigData->DhcpServer, &Nic->DhcpServer); - Mac = IScsiGetMacAddress (DriverData->Controller); - CopyMem (Nic->Mac, Mac, sizeof (Nic->Mac)); + Nic->VLanTag = NetLibGetVlanId (DriverData->Controller); + + Status = NetLibGetMacAddress (DriverData->Controller, &MacAddress, &HwAddressSize); + ASSERT (Status == EFI_SUCCESS); + CopyMem (Nic->Mac, MacAddress.Addr, sizeof (Nic->Mac)); // // Get the PCI location of the Nic. @@ -452,7 +351,7 @@ Returns: Target->Header.StructureId = EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_TARGET_STRUCTURE_ID; Target->Header.Version = EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_TARGET_STRUCTURE_VERSION; - Target->Header.Length = sizeof (EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_TARGET_STRUCTURE); + Target->Header.Length = (UINT16) sizeof (EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_TARGET_STRUCTURE); 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; @@ -520,84 +419,72 @@ Returns: } } +/** + Publish and remove the iSCSI Boot Firmware Table according to the iSCSI + session status. +**/ VOID IScsiPublishIbft ( - IN VOID + VOID ) -/*++ - -Routine Description: - - Publish and remove the iSCSI Boot Firmware Table according to the iSCSI - session status. - -Arguments: - - None. - -Returns: - - None. - ---*/ { EFI_STATUS Status; - UINTN TableHandle; - EFI_ACPI_SUPPORT_PROTOCOL *AcpiSupport; + EFI_ACPI_TABLE_PROTOCOL *AcpiTableProtocol; EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_HEADER *Table; UINTN HandleCount; EFI_HANDLE *HandleBuffer; UINT8 *Heap; - INTN Index; - EFI_ACPI_TABLE_VERSION Version; - UINT32 Signature; + UINT8 Checksum; + UINTN Index; + EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER *Rsdp; + EFI_ACPI_DESCRIPTION_HEADER *Rsdt; - Status = gBS->LocateProtocol (&gEfiAcpiSupportProtocolGuid, NULL, (VOID **)&AcpiSupport); + Status = gBS->LocateProtocol (&gEfiAcpiTableProtocolGuid, NULL, (VOID **)&AcpiTableProtocol); if (EFI_ERROR (Status)) { return ; } + + // - // Try to remove the old iSCSI Boot Firmware Table. + // Find ACPI table RSD_PTR from system table // - for (Index = 0;; Index++) { - Status = AcpiSupport->GetAcpiTable ( - AcpiSupport, - Index, - (VOID **)&Table, - &Version, - &TableHandle - ); - if (EFI_ERROR (Status)) { + 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; } + } - Signature = Table->Signature; - gBS->FreePool (Table); + if (Rsdp == NULL) { + return ; + } else { + Rsdt = (EFI_ACPI_DESCRIPTION_HEADER *) (UINTN) Rsdp->RsdtAddress; + } - if (Signature == EFI_ACPI_3_0_ISCSI_BOOT_FIRMWARE_TABLE_SIGNATURE) { - // - // Remove the table. - // - Status = AcpiSupport->SetAcpiTable ( - AcpiSupport, - NULL, - FALSE, - Version, - &TableHandle - ); - if (EFI_ERROR (Status)) { - return ; - } - break; + if (mIbftInstalled) { + Status = AcpiTableProtocol->UninstallAcpiTable ( + AcpiTableProtocol, + mTableKey + ); + if (EFI_ERROR (Status)) { + return ; } + mIbftInstalled = FALSE; } + // // Get all iSCSI private protocols. // Status = gBS->LocateHandleBuffer ( ByProtocol, - &mIScsiPrivateGuid, + &gEfiCallerIdGuid, NULL, &HandleCount, &HandleBuffer @@ -608,7 +495,7 @@ Returns: // // Allocate 4k bytes to hold the ACPI table. // - Table = AllocatePool (IBFT_MAX_SIZE); + Table = AllocateZeroPool (IBFT_MAX_SIZE); if (Table == NULL) { return ; } @@ -618,28 +505,29 @@ Returns: // // Fill in the various section of the iSCSI Boot Firmware Table. // - IScsiInitIbfTableHeader (Table); + IScsiInitIbfTableHeader (Table, Rsdt->OemId, &Rsdt->OemTableId); IScsiInitControlSection (Table, HandleCount); IScsiFillInitiatorSection (Table, &Heap, HandleBuffer[0]); IScsiFillNICAndTargetSections (Table, &Heap, HandleCount, HandleBuffer); - gBS->FreePool (HandleBuffer); + Checksum = CalculateCheckSum8((UINT8 *)Table, Table->Length); + Table->Checksum = Checksum; - TableHandle = 0; + FreePool (HandleBuffer); // // Install or update the iBFT table. // - Status = AcpiSupport->SetAcpiTable ( - AcpiSupport, - Table, - TRUE, - EFI_ACPI_TABLE_VERSION_3_0, - &TableHandle - ); - if (!EFI_ERROR (Status)) { - AcpiSupport->PublishTables (AcpiSupport, EFI_ACPI_TABLE_VERSION_3_0); + Status = AcpiTableProtocol->InstallAcpiTable ( + AcpiTableProtocol, + Table, + Table->Length, + &mTableKey + ); + if (EFI_ERROR(Status)) { + return; } - gBS->FreePool (Table); + mIbftInstalled = TRUE; + FreePool (Table); }