Skip to content

Commit c289d14

Browse files
committed
Implement ether-get-mac-address to handle the logic around where an
interface's Ethernet MAC address comes from, and stop fiddling around with properties in dictionaries.
1 parent 2c702df commit c289d14

1 file changed

Lines changed: 41 additions & 35 deletions

File tree

sys/arch/sparc64/sparc64/autoconf.c

Lines changed: 41 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $NetBSD: autoconf.c,v 1.245 2025/09/17 14:20:48 thorpej Exp $ */
1+
/* $NetBSD: autoconf.c,v 1.246 2025/10/13 04:06:13 thorpej Exp $ */
22

33
/*
44
* Copyright (c) 1996
@@ -48,7 +48,7 @@
4848
*/
4949

5050
#include <sys/cdefs.h>
51-
__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.245 2025/09/17 14:20:48 thorpej Exp $");
51+
__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.246 2025/10/13 04:06:13 thorpej Exp $");
5252

5353
#include "opt_ddb.h"
5454
#include "opt_kgdb.h"
@@ -77,6 +77,7 @@ __KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.245 2025/09/17 14:20:48 thorpej Exp $
7777

7878
#include <net/if.h>
7979
#include <net/if_ether.h>
80+
#include <net/ether_calls.h>
8081

8182
#include <dev/cons.h>
8283
#include <sparc64/dev/cons.h>
@@ -1094,6 +1095,39 @@ dev_bi_unit_drive_match(device_t dev, int ctrlnode, int target,
10941095
booted_partition));
10951096
}
10961097

1098+
static int
1099+
sparc64_ether_get_mac_address(device_t dev, devhandle_t call_handle, void *v)
1100+
{
1101+
struct ether_get_mac_address_args *args = v;
1102+
int node = devhandle_to_of(call_handle);
1103+
char name[32], device_type[32];
1104+
1105+
if (OF_getprop(node, "name", name, sizeof(name)) <= 0) {
1106+
name[0] = '\0';
1107+
}
1108+
if (OF_getprop(node, "device_type", device_type,
1109+
sizeof(device_type)) <= 0) {
1110+
device_type[0] = '\0';
1111+
}
1112+
1113+
/*
1114+
* Is it a network interface with FCode?
1115+
*/
1116+
if (strcmp(name, "network") == 0 ||
1117+
strcmp(device_type, "network") == 0) {
1118+
/* XXX without-seeprom */
1119+
prom_getether(node, args->enaddr);
1120+
} else {
1121+
/* No fallback to idprom in this case. */
1122+
if (! prom_get_node_ether(node, args->enaddr)) {
1123+
return ENOENT;
1124+
}
1125+
}
1126+
return 0;
1127+
}
1128+
OF_DEVICE_CALL_REGISTER(ETHER_GET_MAC_ADDRESS_STR,
1129+
sparc64_ether_get_mac_address)
1130+
10971131
/*
10981132
* Called back during autoconfiguration for each device found
10991133
*/
@@ -1228,14 +1262,12 @@ device_register(device_t dev, void *aux)
12281262
return;
12291263

12301264
if (ofnode != 0) {
1231-
uint8_t eaddr[ETHER_ADDR_LEN];
12321265
char tmpstr[32];
12331266
char tmpstr2[32];
12341267
int node;
12351268
uint32_t id = 0;
12361269
uint64_t nwwn = 0, pwwn = 0;
12371270
prop_dictionary_t dict;
1238-
prop_data_t blob;
12391271
prop_number_t pwwnd = NULL, nwwnd = NULL;
12401272
prop_number_t idd = NULL;
12411273

@@ -1247,39 +1279,13 @@ device_register(device_t dev, void *aux)
12471279
tmpstr2[0] = 0;
12481280

12491281
/*
1250-
* If this is a network interface, note the
1251-
* mac address.
1282+
* Is it a network interface with FCode?
1283+
* XXX Would like this to go away.
12521284
*/
1253-
if (strcmp(tmpstr, "network") == 0
1254-
|| strcmp(tmpstr, "ethernet") == 0
1255-
|| strcmp(tmpstr2, "network") == 0
1256-
|| strcmp(tmpstr2, "ethernet") == 0
1257-
|| OF_getprop(ofnode, "mac-address", &eaddr, sizeof(eaddr))
1258-
>= ETHER_ADDR_LEN
1259-
|| OF_getprop(ofnode, "local-mac-address", &eaddr, sizeof(eaddr))
1260-
>= ETHER_ADDR_LEN) {
1261-
1262-
dict = device_properties(dev);
1263-
1264-
/*
1265-
* Is it a network interface with FCode?
1266-
*/
1267-
if (strcmp(tmpstr, "network") == 0 ||
1268-
strcmp(tmpstr2, "network") == 0) {
1269-
prop_dictionary_set_bool(dict,
1270-
"without-seeprom", true);
1271-
prom_getether(ofnode, eaddr);
1272-
} else {
1273-
if (!prom_get_node_ether(ofnode, eaddr))
1274-
goto noether;
1275-
}
1276-
blob = prop_data_create_copy(eaddr, ETHER_ADDR_LEN);
1277-
prop_dictionary_set(dict, "mac-address", blob);
1278-
prop_object_release(blob);
1279-
of_to_dataprop(dict, ofnode, "shared-pins",
1280-
"shared-pins");
1285+
if (strcmp(tmpstr, "network") == 0 ||
1286+
strcmp(tmpstr2, "network") == 0) {
1287+
device_setprop_bool(dev, "without-seeprom", true);
12811288
}
1282-
noether:
12831289

12841290
/* is this a FC node? */
12851291
if (strcmp(tmpstr, "scsi-fcp") == 0) {

0 commit comments

Comments
 (0)