sandbox-raw-bus.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (c) 2018 National Instruments
  4. * Copyright (c) 2018 Joe Hershberger <joe.hershberger@ni.com>
  5. */
  6. #include <common.h>
  7. #include <asm/eth-raw-os.h>
  8. #include <dm.h>
  9. #include <errno.h>
  10. #include <dm/device-internal.h>
  11. #include <dm/lists.h>
  12. static int eth_raw_bus_post_bind(struct udevice *dev)
  13. {
  14. struct sandbox_eth_raw_if_nameindex *ni, *i;
  15. struct udevice *child;
  16. struct eth_sandbox_raw_priv *priv;
  17. char *ub_ifname;
  18. static const char ub_ifname_pfx[] = "host_";
  19. u32 skip_localhost = 0;
  20. ni = sandbox_eth_raw_if_nameindex();
  21. if (!ni)
  22. return -EINVAL;
  23. dev_read_u32(dev, "skip-localhost", &skip_localhost);
  24. for (i = ni; !(i->if_index == 0 && !i->if_name); i++) {
  25. int local = sandbox_eth_raw_os_is_local(i->if_name);
  26. if (local < 0)
  27. continue;
  28. if (skip_localhost && local)
  29. continue;
  30. ub_ifname = calloc(IFNAMSIZ + sizeof(ub_ifname_pfx), 1);
  31. strcpy(ub_ifname, ub_ifname_pfx);
  32. strncat(ub_ifname, i->if_name, IFNAMSIZ);
  33. device_bind_driver(dev, "eth_sandbox_raw", ub_ifname, &child);
  34. device_set_name_alloced(child);
  35. device_probe(child);
  36. priv = dev_get_priv(child);
  37. if (priv) {
  38. strcpy(priv->host_ifname, i->if_name);
  39. priv->host_ifindex = i->if_index;
  40. priv->local = local;
  41. }
  42. }
  43. sandbox_eth_raw_if_freenameindex(ni);
  44. return 0;
  45. }
  46. static const struct udevice_id sandbox_eth_raw_bus_ids[] = {
  47. { .compatible = "sandbox,eth-raw-bus" },
  48. { }
  49. };
  50. U_BOOT_DRIVER(sandbox_eth_raw_bus) = {
  51. .name = "sb_eth_raw_bus",
  52. .id = UCLASS_SIMPLE_BUS,
  53. .of_match = sandbox_eth_raw_bus_ids,
  54. .bind = eth_raw_bus_post_bind,
  55. };