1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (c) 2018 National Instruments
4 * Copyright (c) 2018 Joe Hershberger <joe.hershberger@ni.com>
8 #include <asm/eth-raw-os.h>
11 #include <dm/device-internal.h>
14 static int eth_raw_bus_post_bind(struct udevice *dev)
16 struct sandbox_eth_raw_if_nameindex *ni, *i;
17 struct udevice *child;
18 struct eth_sandbox_raw_priv *priv;
20 static const char ub_ifname_pfx[] = "host_";
21 u32 skip_localhost = 0;
23 ni = sandbox_eth_raw_if_nameindex();
27 dev_read_u32(dev, "skip-localhost", &skip_localhost);
28 for (i = ni; !(i->if_index == 0 && !i->if_name); i++) {
29 int local = sandbox_eth_raw_os_is_local(i->if_name);
33 if (skip_localhost && local)
36 ub_ifname = calloc(IFNAMSIZ + sizeof(ub_ifname_pfx), 1);
37 strcpy(ub_ifname, ub_ifname_pfx);
38 strncat(ub_ifname, i->if_name, IFNAMSIZ);
39 device_bind_driver(dev, "eth_sandbox_raw", ub_ifname, &child);
41 device_set_name_alloced(child);
43 priv = dev_get_priv(child);
45 strcpy(priv->host_ifname, i->if_name);
46 priv->host_ifindex = i->if_index;
51 sandbox_eth_raw_if_freenameindex(ni);
56 static const struct udevice_id sandbox_eth_raw_bus_ids[] = {
57 { .compatible = "sandbox,eth-raw-bus" },
61 U_BOOT_DRIVER(sandbox_eth_raw_bus) = {
62 .name = "sb_eth_raw_bus",
63 .id = UCLASS_SIMPLE_BUS,
64 .of_match = sandbox_eth_raw_bus_ids,
65 .bind = eth_raw_bus_post_bind,