Skip to content

Commit 2c702df

Browse files
committed
Implememt ether-get-mac-address as a system default device call, and get
completely out of the business of examining bus types and setting properties in dictionaries when dealing with Ethernet MAC addresses.
1 parent 3180416 commit 2c702df

3 files changed

Lines changed: 23 additions & 85 deletions

File tree

sys/arch/sparc/sparc/autoconf.c

Lines changed: 21 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $NetBSD: autoconf.c,v 1.272 2023/12/20 05:33:19 thorpej Exp $ */
1+
/* $NetBSD: autoconf.c,v 1.273 2025/10/13 04:04:52 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.272 2023/12/20 05:33:19 thorpej Exp $");
51+
__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.273 2025/10/13 04:04:52 thorpej Exp $");
5252

5353
#include "opt_ddb.h"
5454
#include "opt_kgdb.h"
@@ -79,6 +79,7 @@ __KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.272 2023/12/20 05:33:19 thorpej Exp $
7979

8080
#include <net/if.h>
8181
#include <net/if_ether.h>
82+
#include <net/ether_calls.h>
8283

8384
#include <dev/cons.h>
8485

@@ -103,9 +104,6 @@ __KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.272 2023/12/20 05:33:19 thorpej Exp $
103104
#include <dev/pci/pcidevs.h>
104105
#include <dev/pci/pcivar.h>
105106
#include <sparc/sparc/msiiepreg.h>
106-
#ifdef MSIIEP
107-
#include <sparc/sparc/pci_fixup.h>
108-
#endif
109107

110108
#ifdef DDB
111109
#include <machine/db_machdep.h>
@@ -1541,7 +1539,6 @@ static int bus_class(device_t);
15411539
static const char *bus_compatible(const char *);
15421540
static int instance_match(device_t, void *, struct bootpath *);
15431541
static void nail_bootdev(device_t, struct bootpath *);
1544-
static void set_network_props(device_t, void *);
15451542

15461543
static struct {
15471544
const char *name;
@@ -1623,44 +1620,28 @@ bus_class(device_t dev)
16231620
return (class);
16241621
}
16251622

1626-
static void
1627-
set_network_props(device_t dev, void *aux)
1623+
static int
1624+
sparc_ether_get_mac_address(device_t dev, devhandle_t call_handle, void *v)
16281625
{
1629-
struct mainbus_attach_args *ma;
1630-
struct sbus_attach_args *sa;
1631-
struct iommu_attach_args *iom;
1632-
struct pci_attach_args *pa;
1633-
uint8_t eaddr[ETHER_ADDR_LEN];
1634-
prop_dictionary_t dict;
1635-
prop_data_t blob;
1636-
int ofnode;
1626+
struct ether_get_mac_address_args *args = v;
1627+
int node;
16371628

1638-
ofnode = 0;
1639-
switch (bus_class(device_parent(dev))) {
1640-
case BUSCLASS_MAINBUS:
1641-
ma = aux;
1642-
ofnode = ma->ma_node;
1643-
break;
1644-
case BUSCLASS_SBUS:
1645-
sa = aux;
1646-
ofnode = sa->sa_node;
1647-
break;
1648-
case BUSCLASS_IOMMU:
1649-
iom = aux;
1650-
ofnode = iom->iom_node;
1651-
break;
1652-
case BUSCLASS_PCI:
1653-
pa = aux;
1654-
ofnode = PCITAG_NODE(pa->pa_tag);
1655-
break;
1629+
/*
1630+
* If we're called with a valid OpenBoot node, then use it.
1631+
* Otherwise, assume we're using a handle-less old-world PROM
1632+
* and use the global MAC address in the ID PROM.
1633+
*/
1634+
if (devhandle_type(call_handle) == DEVHANDLE_TYPE_OPENBOOT) {
1635+
node = prom_devhandle_to_node(call_handle);
1636+
} else {
1637+
node = 0;
16561638
}
16571639

1658-
prom_getether(ofnode, eaddr);
1659-
dict = device_properties(dev);
1660-
blob = prop_data_create_copy(eaddr, ETHER_ADDR_LEN);
1661-
prop_dictionary_set(dict, "mac-address", blob);
1662-
prop_object_release(blob);
1640+
prom_getether(node, args->enaddr);
1641+
return 0;
16631642
}
1643+
SYSDFLT_DEVICE_CALL_REGISTER(ETHER_GET_MAC_ADDRESS_STR,
1644+
sparc_ether_get_mac_address)
16641645

16651646
int
16661647
instance_match(device_t dev, void *aux, struct bootpath *bp)
@@ -1793,12 +1774,6 @@ device_register(device_t dev, void *aux)
17931774
struct bootpath *bp = bootpath_store(0, NULL);
17941775
const char *bpname;
17951776

1796-
#ifdef MSIIEP
1797-
/* Check for PCI devices */
1798-
if (bus_class(device_parent(dev)) == BUSCLASS_PCI)
1799-
set_pci_props(dev);
1800-
#endif
1801-
18021777
/*
18031778
* If device name does not match current bootpath component
18041779
* then there's nothing interesting to consider.
@@ -1845,13 +1820,7 @@ device_register(device_t dev, void *aux)
18451820
device_xname(dev)));
18461821
return;
18471822
}
1848-
} else if (device_is_a(dev, "le") ||
1849-
device_is_a(dev, "hme") ||
1850-
device_is_a(dev, "be") ||
1851-
device_is_a(dev, "ie")) {
1852-
1853-
set_network_props(dev, aux);
1854-
1823+
} else if (device_class(dev) == DV_IFNET) {
18551824
/*
18561825
* LANCE, Happy Meal, or BigMac ethernet device
18571826
*/

sys/arch/sparc/sparc/pci_fixup.c

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $NetBSD: pci_fixup.c,v 1.6 2025/10/03 14:05:13 thorpej Exp $ */
1+
/* $NetBSD: pci_fixup.c,v 1.7 2025/10/13 04:04:52 thorpej Exp $ */
22

33
/*-
44
* Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -492,33 +492,3 @@ mspcic_pci_fixup(int depth, pcitag_t starttag, int *maxbus, uint32_t *io,
492492
printf(" mem used %08x to %08x\n", startmem, *(mem) - 1);
493493
#endif
494494
}
495-
496-
/* ======================================================================
497-
*
498-
* PCI device fixup for autoconf
499-
*/
500-
501-
void
502-
set_pci_props(device_t dev)
503-
{
504-
struct idprom *idp;
505-
506-
/*
507-
* We only handle network devices.
508-
* XXX: We have to set the ethernet address for HME cards here. If
509-
* we leave this to the driver attachment, we will crash when trying
510-
* to map the 16MB Ebus device in if_hme_pci.c.
511-
*/
512-
if (!(device_is_a(dev, "le") || device_is_a(dev, "hme") ||
513-
device_is_a(dev, "be") || device_is_a(dev, "ie")))
514-
return;
515-
516-
/*
517-
* XXX There should be some sort of passthrough capability for
518-
* XXX OpenBoot devhandles.
519-
*/
520-
521-
idp = prom_getidprom();
522-
device_setprop_data(dev, "mac-address", idp->idp_etheraddr,
523-
sizeof(idp->idp_etheraddr));
524-
}

sys/arch/sparc/sparc/pci_fixup.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $NetBSD: pci_fixup.h,v 1.1 2013/04/16 06:57:06 jdc Exp $ */
1+
/* $NetBSD: pci_fixup.h,v 1.2 2025/10/13 04:04:52 thorpej Exp $ */
22

33
/*-
44
* Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -30,4 +30,3 @@
3030
*/
3131

3232
void mspcic_pci_scan(int);
33-
void set_pci_props(device_t);

0 commit comments

Comments
 (0)