aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMichael Brown <mcb30@ipxe.org>2022-05-23 12:23:53 +0100
committerMichael Brown <mcb30@ipxe.org>2022-05-23 12:23:53 +0100
commit87f1796f158fe3e06d292f4b7e16bad879803b69 (patch)
treebde8ed26787e8c2afd1488e875bdc77976601e31 /src
parent70995397e5bdfd3431e12971aa40630c7014785f (diff)
downloadipxe-87f1796f158fe3e06d292f4b7e16bad879803b69.zip
ipxe-87f1796f158fe3e06d292f4b7e16bad879803b69.tar.gz
ipxe-87f1796f158fe3e06d292f4b7e16bad879803b69.tar.bz2
[ecm] Treat ACPI MAC address as being a non-permanent MAC address
When applying an ACPI-provided system-specific MAC address, apply it to netdev->ll_addr rather than netdev->hw_addr. This allows iPXE scripts to access the permanent MAC address via the ${netX/hwaddr} setting (and thereby provides scripts with a mechanism to ascertain that the NIC is using a MAC address other than its own permanent hardware address). Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src')
-rw-r--r--src/drivers/net/ecm.c28
-rw-r--r--src/drivers/net/ecm.h2
-rw-r--r--src/drivers/net/ncm.c2
3 files changed, 18 insertions, 14 deletions
diff --git a/src/drivers/net/ecm.c b/src/drivers/net/ecm.c
index 826b3b1..68ac962 100644
--- a/src/drivers/net/ecm.c
+++ b/src/drivers/net/ecm.c
@@ -84,24 +84,18 @@ ecm_ethernet_descriptor ( struct usb_configuration_descriptor *config,
*
* @v func USB function
* @v desc Ethernet functional descriptor
- * @v hw_addr Hardware address to fill in
+ * @v netdev Network device
* @ret rc Return status code
*/
int ecm_fetch_mac ( struct usb_function *func,
- struct ecm_ethernet_descriptor *desc, uint8_t *hw_addr ) {
+ struct ecm_ethernet_descriptor *desc,
+ struct net_device *netdev ) {
struct usb_device *usb = func->usb;
char buf[ base16_encoded_len ( ETH_ALEN ) + 1 /* NUL */ ];
+ uint8_t amac[ETH_ALEN];
int len;
int rc;
- /* Use system-specific MAC address, if present and not already used */
- if ( ( ( rc = acpi_mac ( hw_addr ) ) == 0 ) &&
- ! find_netdev_by_ll_addr ( &ethernet_protocol, hw_addr ) ) {
- DBGC ( usb, "USB %s using system-specific MAC %s\n",
- func->name, eth_ntoa ( hw_addr ) );
- return 0;
- }
-
/* Fetch MAC address string */
len = usb_get_string_descriptor ( usb, desc->mac, 0, buf,
sizeof ( buf ) );
@@ -118,7 +112,7 @@ int ecm_fetch_mac ( struct usb_function *func,
}
/* Decode MAC address */
- len = base16_decode ( buf, hw_addr, ETH_ALEN );
+ len = base16_decode ( buf, netdev->hw_addr, ETH_ALEN );
if ( len < 0 ) {
rc = len;
DBGC ( usb, "USB %s could not decode ECM MAC \"%s\": %s\n",
@@ -126,6 +120,16 @@ int ecm_fetch_mac ( struct usb_function *func,
return rc;
}
+ /* Apply system-specific MAC address as current link-layer
+ * address, if present and not already used.
+ */
+ if ( ( ( rc = acpi_mac ( amac ) ) == 0 ) &&
+ ! find_netdev_by_ll_addr ( &ethernet_protocol, amac ) ) {
+ memcpy ( netdev->ll_addr, amac, ETH_ALEN );
+ DBGC ( usb, "USB %s using system-specific MAC %s\n",
+ func->name, eth_ntoa ( netdev->ll_addr ) );
+ }
+
return 0;
}
@@ -474,7 +478,7 @@ static int ecm_probe ( struct usb_function *func,
}
/* Fetch MAC address */
- if ( ( rc = ecm_fetch_mac ( func, ethernet, netdev->hw_addr ) ) != 0 ) {
+ if ( ( rc = ecm_fetch_mac ( func, ethernet, netdev ) ) != 0 ) {
DBGC ( ecm, "ECM %p could not fetch MAC address: %s\n",
ecm, strerror ( rc ) );
goto err_fetch_mac;
diff --git a/src/drivers/net/ecm.h b/src/drivers/net/ecm.h
index 0ad3ddb..a7d03cf 100644
--- a/src/drivers/net/ecm.h
+++ b/src/drivers/net/ecm.h
@@ -88,6 +88,6 @@ ecm_ethernet_descriptor ( struct usb_configuration_descriptor *config,
struct usb_interface_descriptor *interface );
extern int ecm_fetch_mac ( struct usb_function *func,
struct ecm_ethernet_descriptor *desc,
- uint8_t *hw_addr );
+ struct net_device *netdev );
#endif /* _ECM_H */
diff --git a/src/drivers/net/ncm.c b/src/drivers/net/ncm.c
index 1e8088d..2c0f91e 100644
--- a/src/drivers/net/ncm.c
+++ b/src/drivers/net/ncm.c
@@ -598,7 +598,7 @@ static int ncm_probe ( struct usb_function *func,
}
/* Fetch MAC address */
- if ( ( rc = ecm_fetch_mac ( func, ethernet, netdev->hw_addr ) ) != 0 ) {
+ if ( ( rc = ecm_fetch_mac ( func, ethernet, netdev ) ) != 0 ) {
DBGC ( ncm, "NCM %p could not fetch MAC address: %s\n",
ncm, strerror ( rc ) );
goto err_fetch_mac;