diff mbox series

[1/3] dm: core: add 'netif' field to struct udevice for NET_LWIP

Message ID 20250306142525.3079189-2-jerome.forissier@linaro.org
State New
Headers show
Series net: lwip: map struct udevice to struct netif | expand

Commit Message

Jerome Forissier March 6, 2025, 2:25 p.m. UTC
When NET_LWIP is enabled, the network stack operates on 'struct netif'
pointers to represent network interfaces, while U-Boot natively uses
struct udevice. Therefore there should be a 1:1 mapping between a
(network) udevice and a netif. This association is only implemented in
one way by netif::state which is a private opaque pointer that we
use to store the udevice. But the udevice doesn't have any equivalent
to store the netif. In the initial design of the lwIP integration it
was decided to re-create a new netif each time an operation on a
udevice is needed. Retrospectively, it was a bad choice since it
causes needless allocations and makes debugging more difficult since
netif identifiers keep changing: et0, et1, et2, etc.

Therefore, introduce a 'struct netif *' field in struct udevice. A
follow-up patch will use it to look up a netif from a udevice and avoid
unnecessary allocations.

Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
---
 include/dm/device.h | 5 +++++
 1 file changed, 5 insertions(+)
diff mbox series

Patch

diff --git a/include/dm/device.h b/include/dm/device.h
index add67f9ec06..230aceb4142 100644
--- a/include/dm/device.h
+++ b/include/dm/device.h
@@ -20,6 +20,7 @@ 
 #include <linux/printk.h>
 
 struct driver_info;
+struct netif;
 
 /* Driver is active (probed). Cleared when it is removed */
 #define DM_FLAG_ACTIVATED		(1 << 0)
@@ -166,6 +167,7 @@  enum {
  * @dma_offset: Offset between the physical address space (CPU's) and the
  *		device's bus address space
  * @iommu: IOMMU device associated with this device
+ * @netif: lwIP device associated with this device
  */
 struct udevice {
 	const struct driver *driver;
@@ -198,6 +200,9 @@  struct udevice {
 #if CONFIG_IS_ENABLED(IOMMU)
 	struct udevice *iommu;
 #endif
+#if CONFIG_IS_ENABLED(NET_LWIP)
+	struct netif *netif;
+#endif
 };
 
 static inline int dm_udevice_size(void)