X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=MdeModulePkg%2FUniversal%2FNetwork%2FIScsiDxe%2FIScsiIbft.c;h=dd4189c02b61253e8cfb857eb05e3f9818cfbc42;hb=842d83d65ecb05ef35578ea947f0e3da98b10d1f;hp=78a1e075f080f07fbaccda56e6b5886d3390f781;hpb=fe1e36e550c6ffcd2561903d434683d3939e1942;p=mirror_edk2.git diff --git a/MdeModulePkg/Universal/Network/IScsiDxe/IScsiIbft.c b/MdeModulePkg/Universal/Network/IScsiDxe/IScsiIbft.c index 78a1e075f0..dd4189c02b 100644 --- a/MdeModulePkg/Universal/Network/IScsiDxe/IScsiIbft.c +++ b/MdeModulePkg/Universal/Network/IScsiDxe/IScsiIbft.c @@ -1,8 +1,8 @@ /** @file Implementation for iSCSI Boot Firmware Table publication. -Copyright (c) 2004 - 2008, 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 @@ -10,29 +10,25 @@ 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" +BOOLEAN mIbftInstalled = FALSE; +UINTN mTableKey; + /** Initialize the header of the iSCSI Boot Firmware Table. - @param Header[in] The header of the iSCSI Boot Firmware Table. - - @retval 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 ( - IN EFI_ACPI_ISCSI_BOOT_FIRMWARE_TABLE_HEADER *Header + 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)); @@ -47,18 +43,17 @@ IScsiInitIbfTableHeader ( 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)); } /** Initialize the control section of the iSCSI Boot Firmware Table. - @param Table[in] The ACPI table. - - @param HandleCount[in] The number of the handles associated with iSCSI sessions, it's + @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. - - @retval None. - **/ VOID IScsiInitControlSection ( @@ -75,7 +70,7 @@ IScsiInitControlSection ( 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, @@ -94,15 +89,10 @@ IScsiInitControlSection ( /** Add one item into the heap. - @param Heap[in][out] On input, the current address of the heap; On output, the address of - the heap after the item is added. - - @param Data[in] The data to add into the heap. - - @param Len[in] Length of the Data in byte. - - @retval None. - + @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 ( @@ -123,14 +113,9 @@ IScsiAddHeapItem ( /** Fill the Initiator section of the iSCSI Boot Firmware Table. - @param Table[in] The ACPI table. - - @param Heap[in][out] The heap. - - @param Handle[in] The handle associated with the iSCSI session. - - @retval None. - + @param[in] Table The ACPI table. + @param[in, out] Heap The heap. + @param[in] Handle The handle associated with the iSCSI session. **/ VOID IScsiFillInitiatorSection ( @@ -159,13 +144,13 @@ IScsiFillInitiatorSection ( 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 ; @@ -186,12 +171,8 @@ IScsiFillInitiatorSection ( /** Map the v4 IP address into v6 IP address. - @param V4 The v4 IP address. - - @param V6 The v6 IP address. - - @retval None. - + @param[in] V4 The v4 IP address. + @param[out] V6 The v6 IP address. **/ VOID IScsiMapV4ToV6Addr ( @@ -215,10 +196,10 @@ IScsiMapV4ToV6Addr ( Get the NIC's PCI location and return it accroding to the composited format defined in iSCSI Boot Firmware Table. - @param Controller[in] The handle of the controller. - - @retval UINT16 The composited representation of the NIC PCI location. + @param[in] Controller The handle of the controller. + @return UINT16 The composited representation of the NIC PCI location. + @retval 0 Other errors as indicated. **/ UINT16 IScsiGetNICPciLocation ( @@ -265,45 +246,13 @@ IScsiGetNICPciLocation ( return (UINT16) ((Bus << 8) | (Device << 3) | Function); } -/** - Get the MAC address of the controller. - - @param Controller[in] The handle of the controller. - - @retval EFI_MAC_ADDRESS * The mac address. - -**/ -EFI_MAC_ADDRESS * -IScsiGetMacAddress ( - IN EFI_HANDLE Controller - ) -{ - 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. - @param Table[in] The buffer of the ACPI table. - - @param Heap[in][out] The heap buffer used to store the variable length parameters such as iSCSI name. - - @param HandleCount[in] The number of handles having iSCSI private protocol installed. - - @param Handles[in] The handle buffer. - - @retval None. - + @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 ( @@ -322,7 +271,8 @@ IScsiFillNICAndTargetSections ( UINT16 *SectionOffset; UINTN Index; UINT16 Length; - EFI_MAC_ADDRESS *Mac; + EFI_MAC_ADDRESS MacAddress; + UINTN HwAddressSize; ISCSI_PRIVATE_PROTOCOL *IScsiIdentifier; EFI_STATUS Status; @@ -338,7 +288,7 @@ IScsiFillNICAndTargetSections ( 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 ; @@ -355,7 +305,7 @@ IScsiFillNICAndTargetSections ( 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 | @@ -380,8 +330,11 @@ IScsiFillNICAndTargetSections ( 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. @@ -398,7 +351,7 @@ IScsiFillNICAndTargetSections ( 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; @@ -469,74 +422,69 @@ IScsiFillNICAndTargetSections ( /** Publish and remove the iSCSI Boot Firmware Table according to the iSCSI session status. - - @param None. - - @retval None. - **/ VOID IScsiPublishIbft ( - IN VOID + VOID ) { 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 @@ -547,7 +495,7 @@ IScsiPublishIbft ( // // Allocate 4k bytes to hold the ACPI table. // - Table = AllocatePool (IBFT_MAX_SIZE); + Table = AllocateZeroPool (IBFT_MAX_SIZE); if (Table == NULL) { return ; } @@ -557,28 +505,29 @@ IScsiPublishIbft ( // // 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); }