From: Dima Ruinskiy Some systems implement a system MAC address object in the ACPI table, using either \\_SB.AMAC or \\MACA object names. This system MAC address, when enabled, is intended to override the permanent MAC address of the any network controller attached via a docking station. The purpose is to allow the host PC retain its network identity in a corporate environment, regardless of the specific docking station it is connected to. The expectation is that only one docking station is attached at a time, or that only a single network controller is plugged in at a time. Implement seamless passthrough of the system MAC address to the I225/I226 network controller, by looking up the relevant ACPI object names and using them to initialize the MAC address. Limit the lookup only to controllers that are Thunderbolt-attached, as these are the only docking stations that can pass through an I225/I226 controller to the host. On systems where the feature is disabled or unsupported, the ACPI objects do not exist or do not contain a valid Ethernet MAC, the default MAC address of the device is used. Signed-off-by: Dima Ruinskiy Tested-by: Chia-Lin Kao (AceLan) Tested-by: Narpat Mali Reviewed-by: Jose Ignacio Tornos Martinez Signed-off-by: Tony Nguyen --- drivers/net/ethernet/intel/igc/igc_main.c | 70 +++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/drivers/net/ethernet/intel/igc/igc_main.c b/drivers/net/ethernet/intel/igc/igc_main.c index 1fb5f3cbe93c..1c7fb61f1041 100644 --- a/drivers/net/ethernet/intel/igc/igc_main.c +++ b/drivers/net/ethernet/intel/igc/igc_main.c @@ -1,6 +1,8 @@ // SPDX-License-Identifier: GPL-2.0 /* Copyright (c) 2018 Intel Corporation */ +#include +#include #include #include #include @@ -7106,6 +7108,58 @@ static enum hrtimer_restart igc_qbv_scheduling_timer(struct hrtimer *timer) return HRTIMER_NORESTART; } +static bool igc_get_acpi_mac_passthru(u8 *mac) +{ + static const struct { + const char *name; + acpi_object_type type; + u32 length; + } sources[] = { + { "\\_SB.AMAC", ACPI_TYPE_BUFFER, 23 }, + { "\\MACA", ACPI_TYPE_STRING, 22 }, + }; + struct acpi_buffer buffer; + union acpi_object *obj; + bool mac_found = false; + acpi_status status; + u8 buf[ETH_ALEN] __aligned(2); + int i; + + if (!IS_ENABLED(CONFIG_ACPI)) + return false; + + for (i = 0; i < ARRAY_SIZE(sources) && !mac_found; i++) { + buffer.length = ACPI_ALLOCATE_BUFFER; + buffer.pointer = NULL; + + status = acpi_evaluate_object(NULL, (char *)sources[i].name, + NULL, &buffer); + if (ACPI_FAILURE(status)) + continue; + + obj = buffer.pointer; + if (!obj || obj->type != sources[i].type || + obj->string.length != sources[i].length || + !obj->string.pointer) + goto free_obj; + + if (strncmp(obj->string.pointer, "_AUXMAC_#", 9) || + obj->string.pointer[21] != '#') + goto free_obj; + + if (hex2bin(buf, obj->string.pointer + 9, ETH_ALEN) || + !is_valid_ether_addr(buf)) + goto free_obj; + + ether_addr_copy(mac, buf); + mac_found = true; +free_obj: + ACPI_FREE(obj); + } + + return mac_found; +} + /** * igc_probe - Device Initialization Routine * @pdev: PCI device information struct @@ -7272,6 +7326,22 @@ static int igc_probe(struct pci_dev *pdev, /* copy the MAC address out of the NVM */ if (hw->mac.ops.read_mac_addr(hw)) dev_err(&pdev->dev, "NVM Read Error\n"); + + /* For devices behind a Thunderbolt/USB4 dock, look for a + * system-provided MAC in the ACPI table + */ + if (pci_is_thunderbolt_attached(pdev) && + igc_get_acpi_mac_passthru(hw->mac.addr)) { + /* Set the permanent MAC address. Leave blank if invalid + * to reflect there is something wrong with the NVM MAC. + */ + if (is_valid_ether_addr(hw->mac.perm_addr)) + ether_addr_copy(netdev->perm_addr, hw->mac.perm_addr); + netdev->addr_assign_type = NET_ADDR_STOLEN; + dev_info(&pdev->dev, + "Using ACPI pass-thru MAC addr %pM\n", + hw->mac.addr); + } } eth_hw_addr_set(netdev, hw->mac.addr); -- 2.47.1 From: Pawel Dembicki The M88E1112 can be strapped or EEPROM-configured to bridge SGMII to 100BASE-FX. In this mode the driver still needs the SGMII PHY register access path to identify the external PHY, but the MAC link setup must follow the SERDES media path rather than copper setup. Decode the M88E1112 MAC Control 1 mode field and switch the I210 media type and physical interface setup callback when the PHY reports 100BASE-FX mode. The driver only observes the Marvell mode. It does not program the 88E1112 registers or its EEPROM. The board must configure it through firmware or straps before probe. Signed-off-by: Pawel Dembicki Tested-by: Rinitha S (A Contingent worker at Intel) Signed-off-by: Tony Nguyen --- drivers/net/ethernet/intel/igb/e1000_82575.c | 12 +++++++++++- drivers/net/ethernet/intel/igb/e1000_defines.h | 1 + 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/intel/igb/e1000_82575.c b/drivers/net/ethernet/intel/igb/e1000_82575.c index 44a85ad749a4..72c42d9d6f47 100644 --- a/drivers/net/ethernet/intel/igb/e1000_82575.c +++ b/drivers/net/ethernet/intel/igb/e1000_82575.c @@ -264,9 +264,19 @@ static s32 igb_init_phy_params_82575(struct e1000_hw *hw) data = FIELD_GET(E1000_M88E1112_MAC_CTRL_1_MODE_MASK, data); if (data == E1000_M88E1112_AUTO_COPPER_SGMII || - data == E1000_M88E1112_AUTO_COPPER_BASEX) + data == E1000_M88E1112_AUTO_COPPER_BASEX) { hw->mac.ops.check_for_link = igb_check_for_link_media_swap; + } else if (data == E1000_M88E1112_100BASE_FX) { + /* The driver only detects this strap/EEPROM + * mode. 88E1112 register and EEPROM setup must + * be done outside igb before probe/reset. + */ + hw->phy.media_type = + e1000_media_type_internal_serdes; + hw->mac.ops.setup_physical_interface = + igb_setup_serdes_link_82575; + } } if (phy->id == M88E1512_E_PHY_ID) { ret_val = igb_initialize_M88E1512_phy(hw); diff --git a/drivers/net/ethernet/intel/igb/e1000_defines.h b/drivers/net/ethernet/intel/igb/e1000_defines.h index 7e6f9aa2d57b..25104328eae6 100644 --- a/drivers/net/ethernet/intel/igb/e1000_defines.h +++ b/drivers/net/ethernet/intel/igb/e1000_defines.h @@ -615,6 +615,7 @@ #define E1000_MEDIA_PORT_COPPER 1 #define E1000_MEDIA_PORT_OTHER 2 +#define E1000_M88E1112_100BASE_FX 0x0 #define E1000_M88E1112_AUTO_COPPER_SGMII 0x2 #define E1000_M88E1112_AUTO_COPPER_BASEX 0x3 #define E1000_M88E1112_STATUS_LINK 0x0004 /* Interface Link Bit */ -- 2.47.1 From: Pawel Dembicki igb_get_module_info() and igb_get_module_eeprom() use igb_read_phy_reg_i2c(), which accesses the external PHY register space. On designs with an external SGMII PHY this returns PHY register contents instead of the SFP module EEPROM requested by ethtool -m. Use igb_read_sfp_data_byte() for module EEPROM reads. The legacy ethtool module EEPROM offset space maps directly to the I210 I2CCMD module address space: offsets 0x000-0x0ff address the SFP base EEPROM and offsets 0x100-0x1ff address the diagnostics EEPROM. Signed-off-by: Pawel Dembicki Tested-by: Rinitha S (A Contingent worker at Intel) Signed-off-by: Tony Nguyen --- drivers/net/ethernet/intel/igb/igb_ethtool.c | 39 ++++++-------------- 1 file changed, 12 insertions(+), 27 deletions(-) diff --git a/drivers/net/ethernet/intel/igb/igb_ethtool.c b/drivers/net/ethernet/intel/igb/igb_ethtool.c index ccc7302dc7bd..12d449bb062e 100644 --- a/drivers/net/ethernet/intel/igb/igb_ethtool.c +++ b/drivers/net/ethernet/intel/igb/igb_ethtool.c @@ -3208,7 +3208,7 @@ static int igb_get_module_info(struct net_device *netdev, struct igb_adapter *adapter = netdev_priv(netdev); struct e1000_hw *hw = &adapter->hw; u32 status = 0; - u16 sff8472_rev, addr_mode; + u8 sff8472_rev, addr_mode; bool page_swap = false; if ((hw->phy.media_type == e1000_media_type_copper) || @@ -3216,22 +3216,26 @@ static int igb_get_module_info(struct net_device *netdev, return -EOPNOTSUPP; /* Check whether we support SFF-8472 or not */ - status = igb_read_phy_reg_i2c(hw, IGB_SFF_8472_COMP, &sff8472_rev); + status = igb_read_sfp_data_byte(hw, + E1000_I2CCMD_SFP_DATA_ADDR(IGB_SFF_8472_COMP), + &sff8472_rev); if (status) return -EIO; /* addressing mode is not supported */ - status = igb_read_phy_reg_i2c(hw, IGB_SFF_8472_SWAP, &addr_mode); + status = igb_read_sfp_data_byte(hw, + E1000_I2CCMD_SFP_DATA_ADDR(IGB_SFF_8472_SWAP), + &addr_mode); if (status) return -EIO; /* addressing mode is not supported */ - if ((addr_mode & 0xFF) & IGB_SFF_ADDRESSING_MODE) { + if (addr_mode & IGB_SFF_ADDRESSING_MODE) { hw_dbg("Address change required to access page 0xA2, but not supported. Please report the module type to the driver maintainers.\n"); page_swap = true; } - if ((sff8472_rev & 0xFF) == IGB_SFF_8472_UNSUP || page_swap) { + if (sff8472_rev == IGB_SFF_8472_UNSUP || page_swap) { /* We have an SFP, but it does not support SFF-8472 */ modinfo->type = ETH_MODULE_SFF_8079; modinfo->eeprom_len = ETH_MODULE_SFF_8079_LEN; @@ -3250,36 +3254,17 @@ static int igb_get_module_eeprom(struct net_device *netdev, struct igb_adapter *adapter = netdev_priv(netdev); struct e1000_hw *hw = &adapter->hw; u32 status = 0; - u16 *dataword; - u16 first_word, last_word; int i = 0; if (ee->len == 0) return -EINVAL; - first_word = ee->offset >> 1; - last_word = (ee->offset + ee->len - 1) >> 1; - - dataword = kmalloc_objs(u16, last_word - first_word + 1); - if (!dataword) - return -ENOMEM; - - /* Read EEPROM block, SFF-8079/SFF-8472, word at a time */ - for (i = 0; i < last_word - first_word + 1; i++) { - status = igb_read_phy_reg_i2c(hw, (first_word + i) * 2, - &dataword[i]); - if (status) { - /* Error occurred while reading module */ - kfree(dataword); + for (i = 0; i < ee->len; i++) { + status = igb_read_sfp_data_byte(hw, ee->offset + i, &data[i]); + if (status) return -EIO; - } - - be16_to_cpus(&dataword[i]); } - memcpy(data, (u8 *)dataword + (ee->offset & 1), ee->len); - kfree(dataword); - return 0; } -- 2.47.1 From: Yalagada Pavan Kumar When reading the EEPROM address length, e100_eeprom_read() can return an invalid length. This value is then used as a shift count when calculating eeprom_wc, resulting in a shift-out-of-bounds UBSAN warning. Stop EEPROM address probing if the detected address length exceeds the initial address length to prevent addr_len from underflowing. Validate addr_len after reading it from the EEPROM in both e100_eeprom_load() and e100_eeprom_save(), and return -EIO if the value is zero or greater than 8. Reported-by: syzbot+e0abb1d45ac291ebebeb@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=e0abb1d45ac291ebebeb Signed-off-by: Yalagada Pavan Kumar Reviewed-by: Aleksandr Loktionov --- drivers/net/ethernet/intel/e100.c | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/drivers/net/ethernet/intel/e100.c b/drivers/net/ethernet/intel/e100.c index 29960762e64a..cd8190386652 100644 --- a/drivers/net/ethernet/intel/e100.c +++ b/drivers/net/ethernet/intel/e100.c @@ -744,7 +744,14 @@ static __le16 e100_eeprom_read(struct nic *nic, u16 *addr_len, u16 addr) * complete address. Use this to adjust addr_len. */ ctrl = ioread8(&nic->csr->eeprom_ctrl_lo); if (!(ctrl & eedo) && i > 16) { - *addr_len -= (i - 16); + u16 len = i - 16; + + if (len > *addr_len) { + *addr_len = 0; + break; + } + + *addr_len -= len; i = 17; } @@ -765,7 +772,15 @@ static int e100_eeprom_load(struct nic *nic) /* Try reading with an 8-bit addr len to discover actual addr len */ e100_eeprom_read(nic, &addr_len, 0); - nic->eeprom_wc = 1 << addr_len; + + if (!addr_len || addr_len > 8) { + netif_err(nic, probe, nic->netdev, + "Invalid EEPROM address length %u\n", + addr_len); + return -EIO; + } + + nic->eeprom_wc = (u16)BIT(addr_len); for (addr = 0; addr < nic->eeprom_wc; addr++) { nic->eeprom[addr] = e100_eeprom_read(nic, &addr_len, addr); @@ -791,7 +806,15 @@ static int e100_eeprom_save(struct nic *nic, u16 start, u16 count) /* Try reading with an 8-bit addr len to discover actual addr len */ e100_eeprom_read(nic, &addr_len, 0); - nic->eeprom_wc = 1 << addr_len; + + if (!addr_len || addr_len > 8) { + netif_err(nic, probe, nic->netdev, + "Invalid EEPROM address length %u\n", + addr_len); + return -EIO; + } + + nic->eeprom_wc = (u16)BIT(addr_len); if (start + count >= nic->eeprom_wc) return -EINVAL; -- 2.47.1