From 9a0d9e072fdb4994de7c46e50dace126fe6ce6a0 Mon Sep 17 00:00:00 2001 From: David Wu Date: Fri, 4 May 2018 15:37:37 +0800 Subject: drivers/net: Check "ethernet_mac" when the device index is 1 It is a special case for the Fizz firmware branch, when the device index is 1, it will check "ethernet_mac" first and then "ethernet_mac0". For single NIC: config.device_index = "1", maps to "ethernet_mac" For multiple NICs: config.device_index = "1", maps to "ethernet_mac0" BUG=b:77836343 BRANCH=Fizz TEST=Add device index in device tree && Program the mac address to VPD in shell vpd -s ethernet_mac= or vpd -s ethernet-mac[0-9]= && reboot the system. Ensure the MAC address was fetched correctly by ifconfig command. Change-Id: I67fd2e999c8f9d8782f294fcafa84b8da970a3a6 Signed-off-by: David Wu Reviewed-on: https://review.coreboot.org/26051 Tested-by: build bot (Jenkins) Reviewed-by: Patrick Georgi --- src/drivers/net/r8168.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src/drivers/net/r8168.c') diff --git a/src/drivers/net/r8168.c b/src/drivers/net/r8168.c index 288888d4a8..5280cb67ec 100644 --- a/src/drivers/net/r8168.c +++ b/src/drivers/net/r8168.c @@ -67,7 +67,7 @@ static size_t search(const char *p, const u8 *a, size_t lengthp, for (j = 0; j <= lengtha - lengthp; j++) { for (i = 0; i < lengthp && p[i] == a[i + j]; i++) ; - if (i >= lengthp) + if (i >= lengthp && a[j - 1] == lengthp) return j; } return lengtha; @@ -187,13 +187,18 @@ static void program_mac_address(struct device *dev, u16 io_base) /* Default MAC Address of 00:E0:4C:00:C0:B0 */ u8 mac[6] = { 0x00, 0xe0, 0x4c, 0x00, 0xc0, 0xb0 }; struct drivers_net_config *config = dev->chip_info; + bool mac_found = false; /* check the VPD for the mac address */ if (IS_ENABLED(CONFIG_RT8168_GET_MAC_FROM_VPD)) { /* Current implementation is up to 10 NIC cards */ if (config && config->device_index <= MAX_DEVICE_SUPPORT) { - if (fetch_mac_string_vpd(macstrbuf, config->device_index) - != CB_SUCCESS) + /* check "ethernet_mac" first when the device index is 1 */ + if (config->device_index == 1 && + fetch_mac_string_vpd(macstrbuf, 0) == CB_SUCCESS) + mac_found = true; + if (!mac_found && fetch_mac_string_vpd(macstrbuf, + config->device_index) != CB_SUCCESS) printk(BIOS_ERR, "r8168: mac address not found in VPD," " using default 00:e0:4c:00:c0:b0\n"); } else { -- cgit v1.2.3