summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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