edk2/RedfishPkg/Library/PlatformHostInterfaceBmcUsbNicLib/PlatformHostInterfaceBmcUsbNicLib.h
Michael Kubacki 6181c85fa9 RedfishPkg: Replace include guards with #pragma once
Replace traditional `#ifndef`/`#define`/`#endif` include guards with
`#pragma` once.

`#pragma once` is a widely supported preprocessor directive that
prevents header files from being included multiple times. It is
supported by all toolchains used to build edk2: GCC, Clang/LLVM, and
MSVC.

Compared to macro-based include guards, `#pragma once`:

- Eliminates the risk of macro name collisions or copy/paste errors
  where two headers inadvertently use the same guard macro.
- Eliminate inconsistency in the way include guard macros are named
  (e.g., some files use `__FILE_H__`, others use `FILE_H_`, etc.).
- Reduces boilerplate (three lines replaced by one).
- Avoids polluting the macro namespace with guard symbols.
- Can improve build times as the preprocessor can skip re-opening the
  file entirely, rather than re-reading it to find the matching
  `#endif` ("multiple-include optimization").
  - Note that some compilers may already optimize traditional include
    guards, by recognzining the idiomatic pattern.

This change is made acknowledging that overall portability of the
code will technically be reduced, as `#pragma once` is not part of the
C/C++ standards.

However, this is considered acceptable given:

1. edk2 already defines a subset of supported compilers in
   BaseTools/Conf/tools_def.template, all of which have supported
   `#pragma once` for over two decades.
2. There have been concerns raised to the project about inconsistent
   include guard naming and potential macro collisions.

Approximate compiler support dates:

- MSVC: Supported since Visual C++ 4.2 (1996)
- GCC: Supported since 3.4 (2004)
  (http://gnu.ist.utl.pt/software/gcc/gcc-3.4/changes.html)
- Clang (LLVM based): Since initial release in 2007

Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
2026-02-23 21:01:28 +00:00

82 lines
3.8 KiB
C

/** @file
Header file to provide the platform Redfish Host Interface information
of USB NIC Device exposed by BMC.
Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#pragma once
#include <Uefi.h>
#include <IndustryStandard/Ipmi.h>
#include <IndustryStandard/IpmiNetFnApp.h>
#include <IndustryStandard/IpmiNetFnTransport.h>
#include <IndustryStandard/RedfishHostInterfaceIpmi.h>
#include <IndustryStandard/SmBios.h>
#include <Library/BaseLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/DebugLib.h>
#include <Library/DevicePathLib.h>
#include <Library/IpmiCommandLib.h>
#include <Library/RedfishHostInterfaceLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/DevicePathLib.h>
#include <Library/RedfishDebugLib.h>
#include <Protocol/EdkIIRedfishCredential2.h>
#include <Protocol/SimpleNetwork.h>
#include <Protocol/UsbIo.h>
#define BMC_USB_NIC_HOST_INTERFASCE_READINESS_GUID \
{ \
0xDD96F5D7, 0x4AE1, 0x4E6C, {0xA1, 0x30, 0xA5, 0xAC, 0x77, 0xDD, 0xE4, 0xA5} \
}
//
// This is the structure for BMC exposed
// USB NIC information.
//
typedef struct {
LIST_ENTRY NextInstance; ///< Link to the next instance.
BOOLEAN IsExposedByBmc; ///< Flag indicates this USB NIC is
///< exposed by BMC.
BOOLEAN IsSuppportedHostInterface; ///< This BMC USB NIC is supported
///< as Redfish host interface
EFI_SIMPLE_NETWORK_PROTOCOL *ThisSnp; ///< The SNP instance associated with
///< this USB NIC.
EFI_USB_IO_PROTOCOL *ThisUsbIo; ///< The USBIO instance associated with
///< this USB NIC.
UINT16 UsbVendorId; ///< USB Vendor ID of this BMC exposed USB NIC.
UINT16 UsbProductId; ///< USB Product ID of this BMC exposed USB NIC.
UINTN MacAddressSize; ///< HW address size.
UINT8 *MacAddress; ///< HW address.
UINT8 IpmiLanChannelNumber; ///< BMC IPMI Lan Channel number.
//
// Below is the infortmation for building SMBIOS type 42.
//
UINT8 IpAssignedType; ///< Redfish service IP assign type.
UINT8 IpAddressFormat; ///< Redfish service IP version.
UINT8 HostIpAddressIpv4[4]; ///< Host IP address.
UINT8 RedfishIpAddressIpv4[4]; ///< Redfish service IP address.
UINT8 SubnetMaskIpv4[4]; ///< Subnet mask.
UINT8 GatewayIpv4[4]; ///< Gateway IP address.
UINT16 VLanId; ///< VLAN ID.
BOOLEAN CredentialBootstrapping; ///< If Credential bootstrapping is
///< supported.
} HOST_INTERFACE_BMC_USB_NIC_INFO;
//
// This is the structure for caching
// BMC IPMI LAN Channel
//
typedef struct {
LIST_ENTRY NextInstance; ///< Link to the next IPMI LAN Channel.
UINT8 Channel; ///< IPMI Channel number.
EFI_MAC_ADDRESS MacAddress; ///< IPMI LAN Channel MAC address.
UINT8 MacAddressSize; ///< MAC address size;
} BMC_IPMI_LAN_CHANNEL_INFO;