-/* $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
*
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.
-/* $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
*
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