summaryrefslogtreecommitdiff
path: root/sys/dev/ofw
diff options
context:
space:
mode:
authorDavid Gwynne <dlg@cvs.openbsd.org>2023-04-03 01:30:34 +0000
committerDavid Gwynne <dlg@cvs.openbsd.org>2023-04-03 01:30:34 +0000
commit459e718ff348709e874b5d9053adc4401efe715d (patch)
treeb485150b3899d0b5763d5fc0408b6b91f2f5c83f /sys/dev/ofw
parenta9b2c6747d3cf466fc89aeeb84c5656a78cacf7a (diff)
add glue for network interfaces to be found by fdt/ofw node or phandle.
if we're going to support switch chips (eg, marvell link street switches as found on a3700 boards like the espressobin), then the device tree for switch ports identifies which network interface they're connected by by a reference (phandle) across the device tree. this lets network drivers register the ifnet struct with the associated node and phandle so the switch can find it and configure it for use with the switch. ok kettenis@
Diffstat (limited to 'sys/dev/ofw')
-rw-r--r--sys/dev/ofw/ofw_misc.c42
-rw-r--r--sys/dev/ofw/ofw_misc.h19
2 files changed, 59 insertions, 2 deletions
diff --git a/sys/dev/ofw/ofw_misc.c b/sys/dev/ofw/ofw_misc.c
index f4c80f10981..2e42efc0686 100644
--- a/sys/dev/ofw/ofw_misc.c
+++ b/sys/dev/ofw/ofw_misc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ofw_misc.c,v 1.38 2022/12/17 11:54:32 kettenis Exp $ */
+/* $OpenBSD: ofw_misc.c,v 1.39 2023/04/03 01:30:32 dlg Exp $ */
/*
* Copyright (c) 2017-2021 Mark Kettenis
*
@@ -119,6 +119,46 @@ regmap_read_4(struct regmap *rm, bus_size_t offset)
return bus_space_read_4(rm->rm_tag, rm->rm_handle, offset);
}
+/*
+ * Network interface support.
+ */
+
+LIST_HEAD(, if_device) if_devices =
+ LIST_HEAD_INITIALIZER(if_devices);
+
+void
+if_register(struct if_device *ifd)
+{
+ ifd->if_phandle = OF_getpropint(ifd->if_node, "phandle", 0);
+
+ LIST_INSERT_HEAD(&if_devices, ifd, if_list);
+}
+
+struct ifnet *
+if_bynode(int node)
+{
+ struct if_device *ifd;
+
+ LIST_FOREACH(ifd, &if_devices, if_list) {
+ if (ifd->if_node == node)
+ return (ifd->if_ifp);
+ }
+
+ return (NULL);
+}
+
+struct ifnet *
+if_byphandle(uint32_t phandle)
+{
+ struct if_device *ifd;
+
+ LIST_FOREACH(ifd, &if_devices, if_list) {
+ if (ifd->if_phandle == phandle)
+ return (ifd->if_ifp);
+ }
+
+ return (NULL);
+}
/*
* PHY support.
diff --git a/sys/dev/ofw/ofw_misc.h b/sys/dev/ofw/ofw_misc.h
index efb0d3ad58f..43847cf1f7a 100644
--- a/sys/dev/ofw/ofw_misc.h
+++ b/sys/dev/ofw/ofw_misc.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: ofw_misc.h,v 1.27 2022/12/12 19:18:25 kettenis Exp $ */
+/* $OpenBSD: ofw_misc.h,v 1.28 2023/04/03 01:30:33 dlg Exp $ */
/*
* Copyright (c) 2017-2021 Mark Kettenis
*
@@ -30,6 +30,23 @@ struct regmap *regmap_byphandle(uint32_t);
uint32_t regmap_read_4(struct regmap *, bus_size_t);
void regmap_write_4(struct regmap *, bus_size_t, uint32_t);
+/* Interface support */
+
+struct ifnet;
+
+struct if_device {
+ int if_node;
+ struct ifnet *if_ifp;
+
+ LIST_ENTRY(if_device) if_list;
+ uint32_t if_phandle;
+};
+
+void if_register(struct if_device *);
+
+struct ifnet *if_bynode(int);
+struct ifnet *if_byphandle(uint32_t);
+
/* PHY support */
#define PHY_NONE 0