mirror of
https://github.com/ipxe/ipxe
synced 2025-12-21 04:20:17 +03:00
[netdevice] Separate out the concept of hardware and link-layer addresses
The hardware address is an intrinsic property of the hardware, while the link-layer address can be changed at runtime. This separation is exposed via APIs such as PXE and EFI, but is currently elided by gPXE. Expose the hardware and link-layer addresses as separate properties within a net device. Drivers should now fill in hw_addr, which will be used to initialise ll_addr at the time of calling register_netdev().
This commit is contained in:
@@ -928,7 +928,7 @@ static int a3c90x_probe(struct pci_device *pci,
|
||||
/* load eeprom contents to inf_3c90x->eeprom */
|
||||
a3c90x_internal_ReadEepromContents(inf_3c90x);
|
||||
|
||||
HWAddr = netdev->ll_addr;
|
||||
HWAddr = netdev->hw_addr;
|
||||
|
||||
/* Retrieve the Hardware address */
|
||||
HWAddr[0] = inf_3c90x->eeprom[eepromHwAddrOffset + 0] >> 8;
|
||||
|
||||
@@ -594,12 +594,12 @@ static void b44_load_mac_and_phy_addr(struct b44_private *bp)
|
||||
|
||||
/* Load MAC address, note byteswapping */
|
||||
b44_read_eeprom(bp, &eeprom[0]);
|
||||
bp->netdev->ll_addr[0] = eeprom[79];
|
||||
bp->netdev->ll_addr[1] = eeprom[78];
|
||||
bp->netdev->ll_addr[2] = eeprom[81];
|
||||
bp->netdev->ll_addr[3] = eeprom[80];
|
||||
bp->netdev->ll_addr[4] = eeprom[83];
|
||||
bp->netdev->ll_addr[5] = eeprom[82];
|
||||
bp->netdev->hw_addr[0] = eeprom[79];
|
||||
bp->netdev->hw_addr[1] = eeprom[78];
|
||||
bp->netdev->hw_addr[2] = eeprom[81];
|
||||
bp->netdev->hw_addr[3] = eeprom[80];
|
||||
bp->netdev->hw_addr[4] = eeprom[83];
|
||||
bp->netdev->hw_addr[5] = eeprom[82];
|
||||
|
||||
/* Load PHY address */
|
||||
bp->phy_addr = eeprom[90] & 0x1f;
|
||||
|
||||
@@ -853,7 +853,7 @@ e1000_probe ( struct pci_device *pdev,
|
||||
if ( e1000_read_mac_addr ( &adapter->hw ) )
|
||||
DBG ( "EEPROM Read Error\n" );
|
||||
|
||||
memcpy ( netdev->ll_addr, adapter->hw.mac_addr, ETH_ALEN );
|
||||
memcpy ( netdev->hw_addr, adapter->hw.mac_addr, ETH_ALEN );
|
||||
|
||||
/* print bus type/speed/width info */
|
||||
{
|
||||
|
||||
@@ -4181,7 +4181,7 @@ efab_probe ( struct pci_device *pci,
|
||||
if ( rc )
|
||||
goto fail3;
|
||||
|
||||
memcpy ( netdev->ll_addr, efab->mac_addr, ETH_ALEN );
|
||||
memcpy ( netdev->hw_addr, efab->mac_addr, ETH_ALEN );
|
||||
|
||||
netdev_link_up ( netdev );
|
||||
rc = register_netdev ( netdev );
|
||||
|
||||
@@ -608,27 +608,24 @@ static struct net_device_operations ipoib_operations = {
|
||||
};
|
||||
|
||||
/**
|
||||
* Update IPoIB dynamic Infiniband parameters
|
||||
* Handle link status change
|
||||
*
|
||||
* @v ipoib IPoIB device
|
||||
*
|
||||
* The Infiniband port GID and partition key will change at runtime,
|
||||
* when the link is established (or lost). The MAC address is based
|
||||
* on the port GID, and the broadcast GID is based on the partition
|
||||
* key. This function recalculates these IPoIB device parameters.
|
||||
* @v ibdev Infiniband device
|
||||
*/
|
||||
static void ipoib_set_ib_params ( struct ipoib_device *ipoib ) {
|
||||
struct ib_device *ibdev = ipoib->ibdev;
|
||||
struct net_device *netdev = ipoib->netdev;
|
||||
struct ipoib_mac *mac;
|
||||
void ipoib_link_state_changed ( struct ib_device *ibdev ) {
|
||||
struct net_device *netdev = ib_get_ownerdata ( ibdev );
|
||||
struct ipoib_device *ipoib = netdev->priv;
|
||||
struct ipoib_mac *mac = ( ( struct ipoib_mac * ) netdev->ll_addr );
|
||||
int rc;
|
||||
|
||||
/* Calculate GID portion of MAC address based on port GID */
|
||||
mac = ( ( struct ipoib_mac * ) netdev->ll_addr );
|
||||
memcpy ( &mac->gid, &ibdev->gid, sizeof ( mac->gid ) );
|
||||
/* Leave existing broadcast group */
|
||||
ipoib_leave_broadcast_group ( ipoib );
|
||||
|
||||
/* Calculate broadcast GID based on partition key */
|
||||
memcpy ( &ipoib->broadcast, &ipoib_broadcast,
|
||||
sizeof ( ipoib->broadcast ) );
|
||||
/* Update MAC address based on potentially-new GID prefix */
|
||||
memcpy ( &mac->gid.u.half[0], &ibdev->gid.u.half[0],
|
||||
sizeof ( mac->gid.u.half[0] ) );
|
||||
|
||||
/* Update broadcast GID based on potentially-new partition key */
|
||||
ipoib->broadcast.gid.u.words[2] = htons ( ibdev->pkey );
|
||||
|
||||
/* Set net device link state to reflect Infiniband link state */
|
||||
@@ -637,25 +634,6 @@ static void ipoib_set_ib_params ( struct ipoib_device *ipoib ) {
|
||||
} else {
|
||||
netdev_link_down ( netdev );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle link status change
|
||||
*
|
||||
* @v ibdev Infiniband device
|
||||
*/
|
||||
void ipoib_link_state_changed ( struct ib_device *ibdev ) {
|
||||
struct net_device *netdev = ib_get_ownerdata ( ibdev );
|
||||
struct ipoib_device *ipoib = netdev->priv;
|
||||
int rc;
|
||||
|
||||
/* Leave existing broadcast group */
|
||||
ipoib_leave_broadcast_group ( ipoib );
|
||||
|
||||
/* Update MAC address and broadcast GID based on new port GID
|
||||
* and partition key.
|
||||
*/
|
||||
ipoib_set_ib_params ( ipoib );
|
||||
|
||||
/* Join new broadcast group */
|
||||
if ( ib_link_ok ( ibdev ) &&
|
||||
@@ -675,6 +653,7 @@ void ipoib_link_state_changed ( struct ib_device *ibdev ) {
|
||||
int ipoib_probe ( struct ib_device *ibdev ) {
|
||||
struct net_device *netdev;
|
||||
struct ipoib_device *ipoib;
|
||||
struct ipoib_mac *mac;
|
||||
int rc;
|
||||
|
||||
/* Allocate network device */
|
||||
@@ -685,16 +664,19 @@ int ipoib_probe ( struct ib_device *ibdev ) {
|
||||
ipoib = netdev->priv;
|
||||
ib_set_ownerdata ( ibdev, netdev );
|
||||
netdev->dev = ibdev->dev;
|
||||
netdev->ll_broadcast = ( ( uint8_t * ) &ipoib->broadcast );
|
||||
memset ( ipoib, 0, sizeof ( *ipoib ) );
|
||||
ipoib->netdev = netdev;
|
||||
ipoib->ibdev = ibdev;
|
||||
|
||||
/* Calculate as much of the broadcast GID and the MAC address
|
||||
* as we can. We won't know either of these in full until we
|
||||
* have link-up.
|
||||
*/
|
||||
ipoib_set_ib_params ( ipoib );
|
||||
/* Extract hardware address */
|
||||
mac = ( ( struct ipoib_mac * ) netdev->hw_addr );
|
||||
memcpy ( &mac->gid.u.half[1], &ibdev->gid.u.half[1],
|
||||
sizeof ( mac->gid.u.half[1] ) );
|
||||
|
||||
/* Set default broadcast address */
|
||||
memcpy ( &ipoib->broadcast, &ipoib_broadcast,
|
||||
sizeof ( ipoib->broadcast ) );
|
||||
netdev->ll_broadcast = ( ( uint8_t * ) &ipoib->broadcast );
|
||||
|
||||
/* Register network device */
|
||||
if ( ( rc = register_netdev ( netdev ) ) != 0 )
|
||||
|
||||
@@ -99,7 +99,7 @@ int legacy_probe ( void *hwdev,
|
||||
set_drvdata ( hwdev, netdev );
|
||||
netdev->dev = dev;
|
||||
|
||||
nic.node_addr = netdev->ll_addr;
|
||||
nic.node_addr = netdev->hw_addr;
|
||||
nic.irqno = dev->desc.irq;
|
||||
|
||||
if ( ! probe ( &nic, hwdev ) ) {
|
||||
|
||||
@@ -1814,7 +1814,7 @@ mtnic_probe(struct pci_device *pci,
|
||||
/* Program the MAC address */
|
||||
mac = priv->mtnic->fw.mac[port_index];
|
||||
for (mac_idx = 0; mac_idx < MAC_ADDRESS_SIZE; ++mac_idx) {
|
||||
mtnic->netdev[port_index]->ll_addr[MAC_ADDRESS_SIZE - mac_idx - 1] = mac & 0xFF;
|
||||
mtnic->netdev[port_index]->hw_addr[MAC_ADDRESS_SIZE - mac_idx - 1] = mac & 0xFF;
|
||||
mac = mac >> 8;
|
||||
}
|
||||
|
||||
|
||||
@@ -204,7 +204,7 @@ static int natsemi_probe (struct pci_device *pci,
|
||||
last = prev_bytes[1] >> 7;
|
||||
for ( i = 0 ; i < ETH_ALEN ; i++ ) {
|
||||
last1 = ll_addr_encoded[i] >> 7;
|
||||
netdev->ll_addr[i] = ll_addr_encoded[i] << 1 | last;
|
||||
netdev->hw_addr[i] = ll_addr_encoded[i] << 1 | last;
|
||||
last = last1;
|
||||
}
|
||||
|
||||
|
||||
@@ -1897,10 +1897,10 @@ static int phantom_init_cmdpeg ( struct phantom_nic *phantom ) {
|
||||
* Read Phantom MAC address
|
||||
*
|
||||
* @v phanton_port Phantom NIC
|
||||
* @v ll_addr Buffer to fill with MAC address
|
||||
* @v hw_addr Buffer to fill with MAC address
|
||||
*/
|
||||
static void phantom_get_macaddr ( struct phantom_nic *phantom,
|
||||
uint8_t *ll_addr ) {
|
||||
uint8_t *hw_addr ) {
|
||||
union {
|
||||
uint8_t mac_addr[2][ETH_ALEN];
|
||||
uint32_t dwords[3];
|
||||
@@ -1917,11 +1917,11 @@ static void phantom_get_macaddr ( struct phantom_nic *phantom,
|
||||
|
||||
/* Copy out the relevant MAC address */
|
||||
for ( i = 0 ; i < ETH_ALEN ; i++ ) {
|
||||
ll_addr[ ETH_ALEN - i - 1 ] =
|
||||
hw_addr[ ETH_ALEN - i - 1 ] =
|
||||
u.mac_addr[ phantom->port & 1 ][i];
|
||||
}
|
||||
DBGC ( phantom, "Phantom %p MAC address is %s\n",
|
||||
phantom, eth_ntoa ( ll_addr ) );
|
||||
phantom, eth_ntoa ( hw_addr ) );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2045,7 +2045,7 @@ static int phantom_probe ( struct pci_device *pci,
|
||||
goto err_init_rcvpeg;
|
||||
|
||||
/* Read MAC addresses */
|
||||
phantom_get_macaddr ( phantom, netdev->ll_addr );
|
||||
phantom_get_macaddr ( phantom, netdev->hw_addr );
|
||||
|
||||
/* Skip if boot disabled on NIC */
|
||||
if ( ( rc = phantom_check_boot_enable ( phantom ) ) != 0 )
|
||||
|
||||
@@ -250,7 +250,7 @@ static int pnic_probe ( struct pci_device *pci,
|
||||
|
||||
/* Get MAC address */
|
||||
status = pnic_command ( pnic, PNIC_CMD_READ_MAC, NULL, 0,
|
||||
netdev->ll_addr, ETH_ALEN, NULL );
|
||||
netdev->hw_addr, ETH_ALEN, NULL );
|
||||
|
||||
/* Mark as link up; PNIC has no concept of link state */
|
||||
netdev_link_up ( netdev );
|
||||
|
||||
@@ -2209,9 +2209,9 @@ rtl8169_probe ( struct pci_device *pdev, const struct pci_device_id *ent )
|
||||
|
||||
/* Get MAC address */
|
||||
for ( i = 0; i < MAC_ADDR_LEN; i++ )
|
||||
netdev->ll_addr[i] = RTL_R8 ( MAC0 + i );
|
||||
netdev->hw_addr[i] = RTL_R8 ( MAC0 + i );
|
||||
|
||||
DBG ( "%s\n", eth_ntoa ( netdev->ll_addr ) );
|
||||
DBG ( "%s\n", eth_ntoa ( netdev->hw_addr ) );
|
||||
|
||||
rtl8169_init_phy ( netdev, tp );
|
||||
|
||||
|
||||
@@ -525,7 +525,7 @@ static int rtl_probe ( struct pci_device *pci,
|
||||
/* Reset the NIC, set up EEPROM access and read MAC address */
|
||||
rtl_reset ( netdev );
|
||||
rtl_init_eeprom ( netdev );
|
||||
nvs_read ( &rtl->eeprom.nvs, EE_MAC, netdev->ll_addr, ETH_ALEN );
|
||||
nvs_read ( &rtl->eeprom.nvs, EE_MAC, netdev->hw_addr, ETH_ALEN );
|
||||
|
||||
/* Mark as link up; we don't yet handle link state */
|
||||
netdev_link_up ( netdev );
|
||||
|
||||
@@ -813,7 +813,7 @@ static int rtl818x_probe(struct pci_device *pdev,
|
||||
free(hwinfo);
|
||||
|
||||
DBG("rtl818x: Realtek RTL818%s (RF chip %s) with address %s\n",
|
||||
chip_name, priv->rf->name, netdev_hwaddr(dev->netdev));
|
||||
chip_name, priv->rf->name, netdev_addr(dev->netdev));
|
||||
|
||||
return 0;
|
||||
|
||||
|
||||
@@ -2210,14 +2210,14 @@ static struct net_device *sky2_init_netdev(struct sky2_hw *hw,
|
||||
sky2->port = port;
|
||||
|
||||
/* read the mac address */
|
||||
memcpy(dev->ll_addr, (void *)(hw->regs + B2_MAC_1 + port * 8), ETH_ALEN);
|
||||
memcpy(dev->hw_addr, (void *)(hw->regs + B2_MAC_1 + port * 8), ETH_ALEN);
|
||||
|
||||
return dev;
|
||||
}
|
||||
|
||||
static void sky2_show_addr(struct net_device *dev)
|
||||
{
|
||||
DBG2(PFX "%s: addr %s\n", dev->name, netdev_hwaddr(dev));
|
||||
DBG2(PFX "%s: addr %s\n", dev->name, netdev_addr(dev));
|
||||
}
|
||||
|
||||
#if DBGLVL_MAX
|
||||
|
||||
Reference in New Issue
Block a user