[U-Boot] [RFC PATCH] net: rtl8169: allow multiple devices
Stephen Warren
swarren at wwwdotorg.org
Thu Apr 21 01:31:50 CEST 2016
From: Stephen Warren <swarren at nvidia.com>
Currently, if multiple rtl8169 devices exist on the PCI bus, they all
get the same name, which prevents the user from selecting which to use
via the ethact environment variable. Port the auto-naming code from the
e1000 driver to solve this.
Signed-off-by: Stephen Warren <swarren at nvidia.com>
---
Having to put this code into each Ethernet driver seems a bit odd. Surely
the core should handle this; should eth_get_dev_by_name() parse "#n" out
of the ethact value and compare it to the device sequence number?
It looks like I should be able to set ethprime to e.g. eth0, eth1, etc.
and this should work. However, I couldn't get ethprime to behave sensibly,
and I'm not sure what its semantics are supposed to be. Specifically,
ethprime seems to only be used if ethact isn't set, yet accessing the
network (e.g. running "dhcp zImage") seems to set ethact, thus preventing
any further modification to ethprime from having any effect. Equally,
simply running e.g. "dhcp zImage" twice in a row doesn't seem to work;
perhaps the subsequent attempts perform another lookup by name from ethact
rather than just using the same device pointer from before? Is ethprime
intended to be functional at present, or is it some legacy feature that's
bit-rotted and should be removed?
---
drivers/net/rtl8169.c | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/drivers/net/rtl8169.c b/drivers/net/rtl8169.c
index 163b9df55c9b..0ccddcabc478 100644
--- a/drivers/net/rtl8169.c
+++ b/drivers/net/rtl8169.c
@@ -1192,6 +1192,22 @@ static int rtl8169_eth_probe(struct udevice *dev)
return 0;
}
+static int rtl8169_eth_bind(struct udevice *dev)
+{
+ static int num_cards;
+ char name[20];
+
+ /*
+ * A simple way to number the devices. When device tree is used this
+ * is unnecessary, but when the device is just discovered on the PCI
+ * bus we need a name. We could instead have the uclass figure out
+ * which devices are different and number them.
+ */
+ sprintf(name, "RTL8169#%d", num_cards++);
+
+ return device_set_name(dev, name);
+}
+
static const struct eth_ops rtl8169_eth_ops = {
.start = rtl8169_eth_start,
.send = rtl8169_eth_send,
@@ -1208,6 +1224,7 @@ U_BOOT_DRIVER(eth_rtl8169) = {
.name = "eth_rtl8169",
.id = UCLASS_ETH,
.of_match = rtl8169_eth_ids,
+ .bind = rtl8169_eth_bind,
.probe = rtl8169_eth_probe,
.ops = &rtl8169_eth_ops,
.priv_auto_alloc_size = sizeof(struct rtl8169_private),
--
2.8.1
More information about the U-Boot
mailing list