From: Sowmini Varadhan Date: Wed, 4 Nov 2015 19:39:56 +0000 (-0500) Subject: i40e: Look up MAC address in Open Firmware or IDPROM X-Git-Tag: v4.1.12-92~239^2~1 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=5e6d2560d42b78cf606f7dd1a29934a4a9e67f8b;p=users%2Fjedix%2Flinux-maple.git i40e: Look up MAC address in Open Firmware or IDPROM This is the i40e equivalent of commit c762dff24c06 ("ixgbe: Look up MAC address in Open Firmware or IDPROM"). As with that fix, attempt to look up the MAC address in Open Firmware on systems that support it, and use IDPROM on SPARC if no OF address is found. In the case of the i40e there is an assumption that the default mac address has already been set up as the primary mac filter on probe, so if this filter is obtained from the Open Firmware or IDPROM, an explicit write is needed via i40e_aq_mac_address_write() and i40e_aq_add_macvlan() invocation. Reviewed-by: Martin K. Petersen Signed-off-by: Sowmini Varadhan Reviewed-by: Andy Shevchenko (cherry picked from commit c7a3fd4e5d009b6b5bc90ee373aac232a7089068) --- diff --git a/drivers/net/ethernet/intel/i40e/i40e_main.c b/drivers/net/ethernet/intel/i40e/i40e_main.c index 5b5bea159bd5..29d80fd50855 100644 --- a/drivers/net/ethernet/intel/i40e/i40e_main.c +++ b/drivers/net/ethernet/intel/i40e/i40e_main.c @@ -24,6 +24,15 @@ * ******************************************************************************/ +#include +#include +#include + +#ifdef CONFIG_SPARC +#include +#include +#endif + /* Local includes */ #include "i40e.h" #include "i40e_diag.h" @@ -8688,6 +8697,44 @@ err_vsi: return NULL; } +/** + * i40e_macaddr_init - explicitly write the mac address filters. This + * is needed when the macaddr has been obtained by other means than + * the default, e.g., from Open Firmware or IDPROM. + * + * @vsi: pointer to the vsi. + * @macaddr: the MAC address + * + * Returns 0 on success, negative on failure + **/ +static int i40e_macaddr_init(struct i40e_vsi *vsi, u8 *macaddr) +{ + int ret, aq_err; + struct i40e_aqc_add_macvlan_element_data element; + + ret = i40e_aq_mac_address_write(&vsi->back->hw, + I40E_AQC_WRITE_TYPE_LAA_WOL, + macaddr, NULL); + if (ret) { + dev_info(&vsi->back->pdev->dev, + "Addr change for VSI failed: %d\n", ret); + return -EADDRNOTAVAIL; + } + + memset(&element, 0, sizeof(element)); + ether_addr_copy(element.mac_addr, macaddr); + element.flags = cpu_to_le16(I40E_AQC_MACVLAN_ADD_PERFECT_MATCH); + ret = i40e_aq_add_macvlan(&vsi->back->hw, vsi->seid, &element, 1, NULL); + aq_err = vsi->back->hw.aq.asq_last_status; + if (aq_err != I40E_AQ_RC_OK) { + dev_info(&vsi->back->pdev->dev, + "add filter failed err %s aq_err %s\n", + i40e_stat_str(&vsi->back->hw, ret), + i40e_aq_str(&vsi->back->hw, aq_err)); + } + return ret; +} + /** * i40e_vsi_setup - Set up a VSI by a given type * @pf: board private structure @@ -8816,6 +8863,9 @@ struct i40e_vsi *i40e_vsi_setup(struct i40e_pf *pf, u8 type, case I40E_VSI_VMDQ2: case I40E_VSI_FCOE: ret = i40e_config_netdev(vsi); + if (ret) + goto err_netdev; + ret = i40e_macaddr_init(vsi, pf->hw.mac.addr); if (ret) goto err_netdev; ret = register_netdev(vsi->netdev); @@ -9612,6 +9662,36 @@ static void i40e_print_features(struct i40e_pf *pf) kfree(string); } +/** + * i40e_get_platform_mac_addr - get mac address from Open Firmware + * or IDPROM if supported by the platform + * + * @pdev: PCI device information struct + * @mac_addr: the MAC address to be returned + * + * Look up the MAC address in Open Firmware on systems that support it, + * and use IDPROM on SPARC if no OF address is found. + * + * Returns 0 on success, negative on failure + **/ +static int i40e_get_platform_mac_addr(struct pci_dev *pdev, u8 *mac_addr) +{ + struct device_node *dp = pci_device_to_OF_node(pdev); + const unsigned char *addr; + + addr = of_get_mac_address(dp); + if (addr) { + ether_addr_copy(mac_addr, addr); + return 0; + } +#ifdef CONFIG_SPARC + ether_addr_copy(mac_addr, idprom->id_ethaddr); + return 0; +#else + return -EINVAL; +#endif /* CONFIG_SPARC */ +} + /** * i40e_probe - Device initialization routine * @pdev: PCI device information struct @@ -9802,7 +9882,9 @@ static int i40e_probe(struct pci_dev *pdev, const struct pci_device_id *ent) i40e_aq_stop_lldp(hw, true, NULL); } - i40e_get_mac_addr(hw, hw->mac.addr); + err = i40e_get_platform_mac_addr(pdev, hw->mac.addr); + if (err) + i40e_get_mac_addr(hw, hw->mac.addr); if (!is_valid_ether_addr(hw->mac.addr)) { dev_info(&pdev->dev, "invalid MAC address %pM\n", hw->mac.addr); err = -EIO;