Changeset 27815


Ignore:
Timestamp:
2011-07-28T14:20:25+02:00 (7 years ago)
Author:
jogo
Message:

[backfire] swconfig: Add generic switch identifiers

Backport of r27880.

Location:
branches/backfire
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • branches/backfire/package/swconfig/Makefile

    r24992 r27815  
    99 
    1010PKG_NAME:=swconfig 
    11 PKG_RELEASE:=7 
     11PKG_RELEASE:=8 
    1212 
    1313include $(INCLUDE_DIR)/package.mk 
  • branches/backfire/package/swconfig/src/cli.c

    r20948 r27815  
    7575list_attributes(struct switch_dev *dev) 
    7676{ 
    77         printf("Switch %d: %s(%s), ports: %d (cpu @ %d), vlans: %d\n", dev->id, dev->dev_name, dev->name, dev->ports, dev->cpu_port, dev->vlans); 
     77        printf("%s: %s(%s), ports: %d (cpu @ %d), vlans: %d\n", dev->dev_name, dev->alias, dev->name, dev->ports, dev->cpu_port, dev->vlans); 
    7878        printf("     --switch\n"); 
    7979        print_attrs(dev->ops); 
  • branches/backfire/package/swconfig/src/swlib.c

    r27626 r27815  
    581581        struct switch_dev *dev; 
    582582        const char *name; 
     583        const char *alias; 
    583584 
    584585        if (nla_parse(tb, SWITCH_ATTR_MAX, genlmsg_attrdata(gnlh, 0), genlmsg_attrlen(gnlh, 0), NULL) < 0) 
     
    589590 
    590591        name = nla_get_string(tb[SWITCH_ATTR_DEV_NAME]); 
    591         if (sa->name && (strcmp(name, sa->name) != 0)) 
     592        alias = nla_get_string(tb[SWITCH_ATTR_ALIAS]); 
     593 
     594        if (sa->name && (strcmp(name, sa->name) != 0) && (strcmp(alias, sa->name) != 0)) 
    592595                goto done; 
    593596 
     
    596599                goto done; 
    597600 
    598         dev->dev_name = strdup(name); 
     601        strncpy(dev->dev_name, name, IFNAMSIZ - 1); 
     602        dev->alias = strdup(alias); 
    599603        if (tb[SWITCH_ATTR_ID]) 
    600604                dev->id = nla_get_u32(tb[SWITCH_ATTR_ID]); 
  • branches/backfire/package/swconfig/src/swlib.h

    r20948 r27815  
    115115struct switch_dev { 
    116116        int id; 
     117        char dev_name[IFNAMSIZ]; 
    117118        const char *name; 
    118         const char *dev_name; 
     119        const char *alias; 
    119120        int ports; 
    120121        int vlans; 
  • branches/backfire/target/linux/generic-2.6/files/drivers/net/phy/rtl8366rb.c

    r27785 r27815  
    11181118        dev->vlans = RTL8366RB_NUM_VIDS; 
    11191119        dev->ops = &rtl8366_ops; 
    1120         dev->devname = dev_name(smi->parent); 
     1120        dev->alias = dev_name(smi->parent); 
    11211121 
    11221122        err = register_switch(dev, NULL); 
  • branches/backfire/target/linux/generic-2.6/files/drivers/net/phy/rtl8366s.c

    r27785 r27815  
    947947        dev->vlans = RTL8366S_NUM_VIDS; 
    948948        dev->ops = &rtl8366_ops; 
    949         dev->devname = dev_name(smi->parent); 
     949        dev->alias = dev_name(smi->parent); 
    950950 
    951951        err = register_switch(dev, NULL); 
  • branches/backfire/target/linux/generic-2.6/files/drivers/net/phy/swconfig.c

    r22677 r27815  
    3232#endif 
    3333 
     34#define SWCONFIG_DEVNAME        "switch%d" 
     35 
    3436MODULE_AUTHOR("Felix Fietkau <nbd@openwrt.org>"); 
    3537MODULE_LICENSE("GPL"); 
     
    761763 
    762764        NLA_PUT_U32(msg, SWITCH_ATTR_ID, dev->id); 
     765        NLA_PUT_STRING(msg, SWITCH_ATTR_DEV_NAME, dev->devname); 
     766        NLA_PUT_STRING(msg, SWITCH_ATTR_ALIAS, dev->alias); 
    763767        NLA_PUT_STRING(msg, SWITCH_ATTR_NAME, dev->name); 
    764         NLA_PUT_STRING(msg, SWITCH_ATTR_DEV_NAME, dev->devname); 
    765768        NLA_PUT_U32(msg, SWITCH_ATTR_VLANS, dev->vlans); 
    766769        NLA_PUT_U32(msg, SWITCH_ATTR_PORTS, dev->ports); 
     
    858861register_switch(struct switch_dev *dev, struct net_device *netdev) 
    859862{ 
     863        struct switch_dev *sdev; 
     864        const int max_switches = 8 * sizeof(unsigned long); 
     865        unsigned long in_use = 0; 
     866        int i; 
     867 
    860868        INIT_LIST_HEAD(&dev->dev_list); 
    861869        if (netdev) { 
    862870                dev->netdev = netdev; 
    863                 if (!dev->devname) 
    864                         dev->devname = netdev->name; 
    865         } 
    866         BUG_ON(!dev->devname); 
     871                if (!dev->alias) 
     872                        dev->alias = netdev->name; 
     873        } 
     874        BUG_ON(!dev->alias); 
    867875 
    868876        if (dev->ports > 0) { 
     
    872880                        return -ENOMEM; 
    873881        } 
    874         dev->id = ++swdev_id; 
    875882        swconfig_defaults_init(dev); 
    876883        spin_lock_init(&dev->lock); 
    877884        swconfig_lock(); 
     885        dev->id = ++swdev_id; 
     886 
     887        list_for_each_entry(sdev, &swdevs, dev_list) { 
     888                if (!sscanf(sdev->devname, SWCONFIG_DEVNAME, &i)) 
     889                        continue; 
     890                if (i < 0 || i > max_switches) 
     891                        continue; 
     892 
     893                set_bit(i, &in_use); 
     894        } 
     895        i = find_first_zero_bit(&in_use, max_switches); 
     896 
     897        if (i == max_switches) 
     898                return -ENFILE; 
     899 
     900        /* fill device name */ 
     901        snprintf(dev->devname, IFNAMSIZ, SWCONFIG_DEVNAME, i); 
     902 
    878903        list_add(&dev->dev_list, &swdevs); 
    879904        swconfig_unlock(); 
  • branches/backfire/target/linux/generic-2.6/files/include/linux/switch.h

    r22677 r27815  
    3737        /* device */ 
    3838        SWITCH_ATTR_ID, 
     39        SWITCH_ATTR_DEV_NAME, 
     40        SWITCH_ATTR_ALIAS, 
    3941        SWITCH_ATTR_NAME, 
    40         SWITCH_ATTR_DEV_NAME, 
    4142        SWITCH_ATTR_VLANS, 
    4243        SWITCH_ATTR_PORTS, 
     
    147148struct switch_dev { 
    148149        const struct switch_dev_ops *ops; 
     150        /* will be automatically filled */ 
     151        char devname[IFNAMSIZ]; 
     152 
    149153        const char *name; 
    150  
    151         /* NB: either devname or netdev must be set */ 
    152         const char *devname; 
     154        /* NB: either alias or netdev must be set */ 
     155        const char *alias; 
    153156        struct net_device *netdev; 
    154157 
Note: See TracChangeset for help on using the changeset viewer.