Commit 8d9bde0dbb1972f7cfff3757238abe311e21d4d0

Authored by Hannu Lounento
Committed by Stefano Babic
1 parent e0a75fed9e

net: e1000: implement eth_write_hwaddr

Implement programming MAC address to the hardware, i.e. external flash
seen as EEPROM.

MAC address is only written if it differs from what is already stored in
flash or if reading the current MAC address fails.

Signed-off-by: Hannu Lounento <hannu.lounento@ge.com>
CC: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Martyn Welch <martyn.welch@collabora.co.uk>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk>

Showing 1 changed file with 40 additions and 0 deletions Side-by-side Diff

... ... @@ -5649,6 +5649,45 @@
5649 5649 return len ? 1 : 0;
5650 5650 }
5651 5651  
  5652 +static int e1000_write_hwaddr(struct eth_device *dev)
  5653 +{
  5654 +#ifndef CONFIG_E1000_NO_NVM
  5655 + unsigned char *mac = dev->enetaddr;
  5656 + unsigned char current_mac[6];
  5657 + struct e1000_hw *hw = dev->priv;
  5658 + uint16_t data[3];
  5659 + int ret_val, i;
  5660 +
  5661 + DEBUGOUT("%s: mac=%pM\n", __func__, mac);
  5662 +
  5663 + memset(current_mac, 0, 6);
  5664 +
  5665 + /* Read from EEPROM, not from registers, to make sure
  5666 + * the address is persistently configured
  5667 + */
  5668 + ret_val = e1000_read_mac_addr_from_eeprom(hw, current_mac);
  5669 + DEBUGOUT("%s: current mac=%pM\n", __func__, current_mac);
  5670 +
  5671 + /* Only write to EEPROM if the given address is different or
  5672 + * reading the current address failed
  5673 + */
  5674 + if (!ret_val && memcmp(current_mac, mac, 6) == 0)
  5675 + return 0;
  5676 +
  5677 + for (i = 0; i < 3; ++i)
  5678 + data[i] = mac[i * 2 + 1] << 8 | mac[i * 2];
  5679 +
  5680 + ret_val = e1000_write_eeprom_srwr(hw, 0x0, 3, data);
  5681 +
  5682 + if (!ret_val)
  5683 + ret_val = e1000_update_eeprom_checksum_i210(hw);
  5684 +
  5685 + return ret_val;
  5686 +#else
  5687 + return 0;
  5688 +#endif
  5689 +}
  5690 +
5652 5691 /**************************************************************************
5653 5692 PROBE - Look for an adapter, this routine's visible to the outside
5654 5693 You should omit the last argument struct pci_device * for a non-PCI NIC
... ... @@ -5698,6 +5737,7 @@
5698 5737 nic->recv = e1000_poll;
5699 5738 nic->send = e1000_transmit;
5700 5739 nic->halt = e1000_disable;
  5740 + nic->write_hwaddr = e1000_write_hwaddr;
5701 5741 eth_register(nic);
5702 5742 }
5703 5743