From dcb7c317c2ec3034b926945c0faf2334a0b9b7d6 Mon Sep 17 00:00:00 2001 From: Kilian Krause Date: Tue, 10 Jun 2025 17:18:10 +0200 Subject: [PATCH] mb/siemens/mc_rpl1: Enable Intel I210 MACPHY driver Enable the i210 driver for this variant which uses I210 MACPHYs. Additionally, add a function to retrieve a valid MAC Address for the given MACPHY. Change-Id: If519194f52910e4ace59095a997bafff7eab44ca Signed-off-by: Kilian Krause Reviewed-on: https://review.coreboot.org/c/coreboot/+/88887 Tested-by: build bot (Jenkins) Reviewed-by: Mario Scheithauer --- src/mainboard/siemens/mc_rpl/mainboard.c | 79 +++++++++++++++++++ .../siemens/mc_rpl/variants/mc_rpl1/Kconfig | 1 + 2 files changed, 80 insertions(+) diff --git a/src/mainboard/siemens/mc_rpl/mainboard.c b/src/mainboard/siemens/mc_rpl/mainboard.c index 46741323c8..fe3e1e6216 100644 --- a/src/mainboard/siemens/mc_rpl/mainboard.c +++ b/src/mainboard/siemens/mc_rpl/mainboard.c @@ -6,6 +6,85 @@ #include #include #include +#include +#include + + +#define MAX_PATH_DEPTH 12 +#define MAX_NUM_MAPPINGS 10 + +/** \brief This function can decide if a given MAC address is valid or not. +* Currently, addresses filled with 0xff or 0x00 are not valid. + * @param mac Buffer to the MAC address to check + * @return 0 if address is not valid, otherwise 1 + */ +static uint8_t is_mac_adr_valid(uint8_t mac[MAC_ADDR_LEN]) +{ + for (size_t i = 0; i < MAC_ADDR_LEN; i++) { + if (mac[i] != 0x00 && mac[i] != 0xff) + return 1; + if (mac[i] != mac[0]) + return 1; + } + return 0; +} + +/** \brief This function will search for a MAC address which can be assigned + * to a MACPHY. + * @param dev pointer to PCI device + * @param mac buffer where to store the MAC address + * @return cb_err CB_ERR or CB_SUCCESS + */ + +enum cb_err mainboard_get_mac_address(struct device *dev, uint8_t mac[MAC_ADDR_LEN]) +{ + struct bus *parent = dev->upstream; + uint8_t buf[16], mapping[16], i = 0, chain_len = 0; + + memset(buf, 0, sizeof(buf)); + memset(mapping, 0, sizeof(mapping)); + + /* The first entry in the tree is the device itself. */ + buf[0] = dev->path.pci.devfn; + chain_len = 1; + for (i = 1; i < MAX_PATH_DEPTH && parent->dev->upstream->subordinate; i++) { + buf[i] = parent->dev->path.pci.devfn; + chain_len++; + parent = parent->dev->upstream; + } + if (i == MAX_PATH_DEPTH) { + /* The path is deeper than MAX_PATH_DEPTH devices, error. */ + printk(BIOS_ERR, "Too many bridges for %s\n", dev_path(dev)); + return CB_ERR; + } + /* + * Now construct the mapping based on the device chain starting from + * root bridge device to the device itself. + */ + mapping[0] = 1; + mapping[1] = chain_len; + for (i = 0; i < chain_len; i++) + mapping[i + 4] = buf[chain_len - i - 1]; + + /* Open main hwinfo block */ + if (hwilib_find_blocks("hwinfo.hex") != CB_SUCCESS) + return CB_ERR; + /* Now try to find a valid MAC address in hwinfo for this mapping. */ + for (i = 0; i < MAX_NUM_MAPPINGS; i++) { + if (hwilib_get_field(XMac1Mapping + i, buf, 16) != 16) + continue; + if (memcmp(buf, mapping, chain_len + 4)) + continue; + /* There is a matching mapping available, get MAC address. */ + if (hwilib_get_field(XMac1 + i, mac, MAC_ADDR_LEN) == MAC_ADDR_LEN) { + if (is_mac_adr_valid(mac)) + return CB_SUCCESS; + } + return CB_ERR; + } + /* No MAC address found for */ + return CB_ERR; +} static void mainboard_init(void *chip_info) { diff --git a/src/mainboard/siemens/mc_rpl/variants/mc_rpl1/Kconfig b/src/mainboard/siemens/mc_rpl/variants/mc_rpl1/Kconfig index f57e2cbf0d..a56d4c5b7a 100644 --- a/src/mainboard/siemens/mc_rpl/variants/mc_rpl1/Kconfig +++ b/src/mainboard/siemens/mc_rpl/variants/mc_rpl1/Kconfig @@ -9,6 +9,7 @@ config BOARD_SPECIFIC_OPTIONS select MEMORY_MAPPED_TPM select TPM_MEASURED_BOOT select TPM_MEASURED_BOOT_INIT_BOOTBLOCK + select DRIVER_INTEL_I210 config UART_FOR_CONSOLE int