[ipxe-devel] [PATCH 2/3] igbvf: Assign random MAC address if none is set

Hannes Reinecke hare at suse.de
Fri May 30 07:18:17 UTC 2014


If the VF doesn't have a MAC address assigned we should create
a random MAC address. Not doing so results in the probe function
to abort and an unuseable device.

Signed-off-by: Hannes Reinecke <hare at suse.de>
---
 src/drivers/net/igbvf/igbvf_main.c | 52 +++++++++++++++++++++++---------------
 1 file changed, 31 insertions(+), 21 deletions(-)

diff --git a/src/drivers/net/igbvf/igbvf_main.c b/src/drivers/net/igbvf/igbvf_main.c
index cd189ec..2370538 100644
--- a/src/drivers/net/igbvf/igbvf_main.c
+++ b/src/drivers/net/igbvf/igbvf_main.c
@@ -433,6 +433,10 @@ void igbvf_reset ( struct igbvf_adapter *adapter )
 	if ( mac->ops.reset_hw(hw) )
 		DBG ("PF still resetting\n");
 
+	if ( is_valid_ether_addr( netdev->hw_addr )) {
+		memcpy ( adapter->hw.mac.addr, netdev->hw_addr, ETH_ALEN);
+	}
+
 	mac->ops.init_hw ( hw );
 
 	if ( is_valid_ether_addr(adapter->hw.mac.addr) ) {
@@ -452,36 +456,36 @@ extern void igbvf_init_function_pointers_vf(struct e1000_hw *hw);
  **/
 static int __devinit igbvf_sw_init ( struct igbvf_adapter *adapter )
 {
-        struct e1000_hw *hw = &adapter->hw;
-        struct pci_device *pdev = adapter->pdev;
-        int rc;
+	struct e1000_hw *hw = &adapter->hw;
+	struct pci_device *pdev = adapter->pdev;
+	int rc;
 
-        /* PCI config space info */
+	/* PCI config space info */
 
-        hw->vendor_id = pdev->vendor;
-        hw->device_id = pdev->device;
+	hw->vendor_id = pdev->vendor;
+	hw->device_id = pdev->device;
 
-        pci_read_config_byte ( pdev, PCI_REVISION_ID, &hw->revision_id );
+	pci_read_config_byte ( pdev, PCI_REVISION_ID, &hw->revision_id );
 
-        pci_read_config_word ( pdev, PCI_COMMAND, &hw->bus.pci_cmd_word );
+	pci_read_config_word ( pdev, PCI_COMMAND, &hw->bus.pci_cmd_word );
 
-        adapter->max_frame_size = MAXIMUM_ETHERNET_VLAN_SIZE + ETH_HLEN + ETH_FCS_LEN;
-        adapter->min_frame_size = ETH_ZLEN + ETH_FCS_LEN;
+	adapter->max_frame_size = MAXIMUM_ETHERNET_VLAN_SIZE + ETH_HLEN + ETH_FCS_LEN;
+	adapter->min_frame_size = ETH_ZLEN + ETH_FCS_LEN;
 
 	/* Set various function pointers */
-        igbvf_init_function_pointers_vf ( &adapter->hw );
+	igbvf_init_function_pointers_vf ( &adapter->hw );
 
 	rc = adapter->hw.mac.ops.init_params ( &adapter->hw );
 	if (rc) {
-                DBG ("hw.mac.ops.init_params(&adapter->hw) Failure\n");
+		DBG ("hw.mac.ops.init_params(&adapter->hw) Failure\n");
 		return rc;
-        }
+	}
 
 	rc = adapter->hw.mbx.ops.init_params ( &adapter->hw );
 	if (rc) {
-                DBG ("hw.mbx.ops.init_params(&adapter->hw) Failure\n");
+		DBG ("hw.mbx.ops.init_params(&adapter->hw) Failure\n");
 		return rc;
-        }
+	}
 
 	/* Explicitly disable IRQ since the NIC can be in any state. */
 	igbvf_irq_disable ( adapter );
@@ -877,12 +881,18 @@ int igbvf_probe ( struct pci_device *pdev )
 
 	if ( ! is_valid_ether_addr( netdev->hw_addr ) ) {
 		DBG ("Invalid MAC Address: "
-		        "%02x:%02x:%02x:%02x:%02x:%02x\n",
-		        netdev->hw_addr[0], netdev->hw_addr[1],
-		        netdev->hw_addr[2], netdev->hw_addr[3],
-		        netdev->hw_addr[4], netdev->hw_addr[5]);
-		err = -EIO;
-		goto err_hw_init;
+		     "%02x:%02x:%02x:%02x:%02x:%02x\n",
+		     netdev->hw_addr[0], netdev->hw_addr[1],
+		     netdev->hw_addr[2], netdev->hw_addr[3],
+		     netdev->hw_addr[4], netdev->hw_addr[5]);
+		netdev->hw_addr[0] = random();
+		netdev->hw_addr[1] = random();
+		netdev->hw_addr[2] = random();
+		netdev->hw_addr[3] = random();
+		netdev->hw_addr[4] = random();
+		netdev->hw_addr[5] = random();
+		netdev->hw_addr[0] &= 0xfe; /* clear multicasts bit */
+		netdev->hw_addr[0] |= 0x02; /* set local assignment bit */
 	}
 
 	/* reset the hardware with the new settings */
-- 
1.8.4.5




More information about the ipxe-devel mailing list