summaryrefslogtreecommitdiffstats
path: root/target/linux/generic/files/drivers/net/phy
diff options
context:
space:
mode:
authorjogo <jogo@3c298f89-4303-0410-b956-a3cf2f4a3e73>2011-07-27 18:00:18 +0000
committerjogo <jogo@3c298f89-4303-0410-b956-a3cf2f4a3e73>2011-07-27 18:00:18 +0000
commit6c853478d6a9ef2ebf74d438fc343ae0b5f0e786 (patch)
treeabee889c94a256789fdcbc913c8ed7b75bc3cc40 /target/linux/generic/files/drivers/net/phy
parent2ed51448ae64a1c4883ce7c76befce1f357b457e (diff)
swconfig: Add generic switch identifiers
Also make switches available under a generic name "switch<num>" for device name agnostic access. The old device name is used as an alias for backward compatibility. git-svn-id: svn://svn.openwrt.org/openwrt/trunk@27800 3c298f89-4303-0410-b956-a3cf2f4a3e73
Diffstat (limited to 'target/linux/generic/files/drivers/net/phy')
-rw-r--r--target/linux/generic/files/drivers/net/phy/rtl8366rb.c2
-rw-r--r--target/linux/generic/files/drivers/net/phy/rtl8366s.c2
-rw-r--r--target/linux/generic/files/drivers/net/phy/swconfig.c35
3 files changed, 32 insertions, 7 deletions
diff --git a/target/linux/generic/files/drivers/net/phy/rtl8366rb.c b/target/linux/generic/files/drivers/net/phy/rtl8366rb.c
index c95368148..b337408b5 100644
--- a/target/linux/generic/files/drivers/net/phy/rtl8366rb.c
+++ b/target/linux/generic/files/drivers/net/phy/rtl8366rb.c
@@ -1116,7 +1116,7 @@ static int rtl8366rb_switch_init(struct rtl8366_smi *smi)
dev->ports = RTL8366RB_NUM_PORTS;
dev->vlans = RTL8366RB_NUM_VIDS;
dev->ops = &rtl8366_ops;
- dev->devname = dev_name(smi->parent);
+ dev->alias = dev_name(smi->parent);
err = register_switch(dev, NULL);
if (err)
diff --git a/target/linux/generic/files/drivers/net/phy/rtl8366s.c b/target/linux/generic/files/drivers/net/phy/rtl8366s.c
index 8fa1ed186..e2d8402cf 100644
--- a/target/linux/generic/files/drivers/net/phy/rtl8366s.c
+++ b/target/linux/generic/files/drivers/net/phy/rtl8366s.c
@@ -945,7 +945,7 @@ static int rtl8366s_switch_init(struct rtl8366_smi *smi)
dev->ports = RTL8366S_NUM_PORTS;
dev->vlans = RTL8366S_NUM_VIDS;
dev->ops = &rtl8366_ops;
- dev->devname = dev_name(smi->parent);
+ dev->alias = dev_name(smi->parent);
err = register_switch(dev, NULL);
if (err)
diff --git a/target/linux/generic/files/drivers/net/phy/swconfig.c b/target/linux/generic/files/drivers/net/phy/swconfig.c
index 16afea0af..88fa244bc 100644
--- a/target/linux/generic/files/drivers/net/phy/swconfig.c
+++ b/target/linux/generic/files/drivers/net/phy/swconfig.c
@@ -31,6 +31,8 @@
#define DPRINTF(...) do {} while(0)
#endif
+#define SWCONFIG_DEVNAME "switch%d"
+
MODULE_AUTHOR("Felix Fietkau <nbd@openwrt.org>");
MODULE_LICENSE("GPL");
@@ -760,8 +762,9 @@ swconfig_send_switch(struct sk_buff *msg, u32 pid, u32 seq, int flags,
return -1;
NLA_PUT_U32(msg, SWITCH_ATTR_ID, dev->id);
- NLA_PUT_STRING(msg, SWITCH_ATTR_NAME, dev->name);
NLA_PUT_STRING(msg, SWITCH_ATTR_DEV_NAME, dev->devname);
+ NLA_PUT_STRING(msg, SWITCH_ATTR_ALIAS, dev->alias);
+ NLA_PUT_STRING(msg, SWITCH_ATTR_NAME, dev->name);
NLA_PUT_U32(msg, SWITCH_ATTR_VLANS, dev->vlans);
NLA_PUT_U32(msg, SWITCH_ATTR_PORTS, dev->ports);
NLA_PUT_U32(msg, SWITCH_ATTR_CPU_PORT, dev->cpu_port);
@@ -857,13 +860,18 @@ static struct genl_ops swconfig_ops[] = {
int
register_switch(struct switch_dev *dev, struct net_device *netdev)
{
+ struct switch_dev *sdev;
+ const int max_switches = 8 * sizeof(unsigned long);
+ unsigned long in_use = 0;
+ int i;
+
INIT_LIST_HEAD(&dev->dev_list);
if (netdev) {
dev->netdev = netdev;
- if (!dev->devname)
- dev->devname = netdev->name;
+ if (!dev->alias)
+ dev->alias = netdev->name;
}
- BUG_ON(!dev->devname);
+ BUG_ON(!dev->alias);
if (dev->ports > 0) {
dev->portbuf = kzalloc(sizeof(struct switch_port) * dev->ports,
@@ -871,10 +879,27 @@ register_switch(struct switch_dev *dev, struct net_device *netdev)
if (!dev->portbuf)
return -ENOMEM;
}
- dev->id = ++swdev_id;
swconfig_defaults_init(dev);
spin_lock_init(&dev->lock);
swconfig_lock();
+ dev->id = ++swdev_id;
+
+ list_for_each_entry(sdev, &swdevs, dev_list) {
+ if (!sscanf(sdev->devname, SWCONFIG_DEVNAME, &i))
+ continue;
+ if (i < 0 || i > max_switches)
+ continue;
+
+ set_bit(i, &in_use);
+ }
+ i = find_first_zero_bit(&in_use, max_switches);
+
+ if (i == max_switches)
+ return -ENFILE;
+
+ /* fill device name */
+ snprintf(dev->devname, IFNAMSIZ, SWCONFIG_DEVNAME, i);
+
list_add(&dev->dev_list, &swdevs);
swconfig_unlock();