X-Git-Url: http://git.rohieb.name/openwrt.git/blobdiff_plain/f093fbf8a31d704c1a92f5ca1db8b01eda292e8b..044f0f9c5a1b53dcb4189886ab4ad2992c1be39e:/target/linux/generic/files/drivers/net/phy/swconfig.c diff --git a/target/linux/generic/files/drivers/net/phy/swconfig.c b/target/linux/generic/files/drivers/net/phy/swconfig.c index 799fc29d1..1f4491ac5 100644 --- a/target/linux/generic/files/drivers/net/phy/swconfig.c +++ b/target/linux/generic/files/drivers/net/phy/swconfig.c @@ -31,12 +31,16 @@ #define DPRINTF(...) do {} while(0) #endif +#define SWCONFIG_DEVNAME "switch%d" + +#include "swconfig_leds.c" + MODULE_AUTHOR("Felix Fietkau "); MODULE_LICENSE("GPL"); static int swdev_id = 0; static struct list_head swdevs; -static spinlock_t swdevs_lock = SPIN_LOCK_UNLOCKED; +static DEFINE_SPINLOCK(swdevs_lock); struct swconfig_callback; struct swconfig_callback @@ -760,8 +764,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 +862,19 @@ 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 err; + 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,13 +882,36 @@ 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) { + swconfig_unlock(); + return -ENFILE; + } + + /* fill device name */ + snprintf(dev->devname, IFNAMSIZ, SWCONFIG_DEVNAME, i); + list_add(&dev->dev_list, &swdevs); swconfig_unlock(); + err = swconfig_create_led_trigger(dev); + if (err) + return err; + return 0; } EXPORT_SYMBOL_GPL(register_switch); @@ -885,6 +919,7 @@ EXPORT_SYMBOL_GPL(register_switch); void unregister_switch(struct switch_dev *dev) { + swconfig_destroy_led_trigger(dev); kfree(dev->portbuf); spin_lock(&dev->lock); swconfig_lock();