[package] base-files, ppp: fix interface shutdown
[openwrt.git] / target / linux / generic-2.6 / files / drivers / net / phy / swconfig.c
index ade2842..376dec1 100644 (file)
@@ -59,7 +59,7 @@ struct swconfig_callback
 /* defaults */
 
 static int
 /* defaults */
 
 static int
-swconfig_get_vlan_ports(struct switch_dev *dev, struct switch_attr *attr, struct switch_val *val)
+swconfig_get_vlan_ports(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val)
 {
        int ret;
        if (val->port_vlan >= dev->vlans)
 {
        int ret;
        if (val->port_vlan >= dev->vlans)
@@ -69,13 +69,13 @@ swconfig_get_vlan_ports(struct switch_dev *dev, struct switch_attr *attr, struct
                return -EOPNOTSUPP;
 
        ret = dev->get_vlan_ports(dev, val);
                return -EOPNOTSUPP;
 
        ret = dev->get_vlan_ports(dev, val);
-       printk("SET PORTS %d\n", val->len);
        return ret;
 }
 
 static int
        return ret;
 }
 
 static int
-swconfig_set_vlan_ports(struct switch_dev *dev, struct switch_attr *attr, struct switch_val *val)
+swconfig_set_vlan_ports(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val)
 {
 {
+       struct switch_port *ports = val->value.ports;
        int i;
 
        if (val->port_vlan >= dev->vlans)
        int i;
 
        if (val->port_vlan >= dev->vlans)
@@ -85,20 +85,46 @@ swconfig_set_vlan_ports(struct switch_dev *dev, struct switch_attr *attr, struct
        if (val->len > dev->ports)
                return -EINVAL;
 
        if (val->len > dev->ports)
                return -EINVAL;
 
+       if (!dev->set_vlan_ports)
+               return -EOPNOTSUPP;
+
        for (i = 0; i < val->len; i++) {
        for (i = 0; i < val->len; i++) {
-               if (val->value.ports[i].id >= dev->ports)
+               if (ports[i].id >= dev->ports)
                        return -EINVAL;
                        return -EINVAL;
+
+               if (dev->set_port_pvid && !(ports[i].flags & SWITCH_PORT_FLAG_TAGGED))
+                       dev->set_port_pvid(dev, ports[i].id, val->port_vlan);
        }
 
        }
 
-       if (!dev->set_vlan_ports)
+       return dev->set_vlan_ports(dev, val);
+}
+
+static int
+swconfig_set_pvid(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val)
+{
+       if (val->port_vlan >= dev->ports)
+               return -EINVAL;
+
+       if (!dev->set_port_pvid)
                return -EOPNOTSUPP;
 
                return -EOPNOTSUPP;
 
-       printk("SET PORTS %d\n", val->len);
-       return dev->set_vlan_ports(dev, val);
+       return dev->set_port_pvid(dev, val->port_vlan, val->value.i);
+}
+
+static int
+swconfig_get_pvid(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val)
+{
+       if (val->port_vlan >= dev->ports)
+               return -EINVAL;
+
+       if (!dev->get_port_pvid)
+               return -EOPNOTSUPP;
+
+       return dev->get_port_pvid(dev, val->port_vlan, &val->value.i);
 }
 
 static int
 }
 
 static int
-swconfig_apply_config(struct switch_dev *dev, struct switch_attr *attr, struct switch_val *val)
+swconfig_apply_config(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val)
 {
        /* don't complain if not supported by the switch driver */
        if (!dev->apply_config)
 {
        /* don't complain if not supported by the switch driver */
        if (!dev->apply_config)
@@ -107,9 +133,19 @@ swconfig_apply_config(struct switch_dev *dev, struct switch_attr *attr, struct s
        return dev->apply_config(dev);
 }
 
        return dev->apply_config(dev);
 }
 
+static int
+swconfig_reset_switch(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val)
+{
+       /* don't complain if not supported by the switch driver */
+       if (!dev->reset_switch)
+               return 0;
+
+       return dev->reset_switch(dev);
+}
 
 enum global_defaults {
        GLOBAL_APPLY,
 
 enum global_defaults {
        GLOBAL_APPLY,
+       GLOBAL_RESET,
 };
 
 enum vlan_defaults {
 };
 
 enum vlan_defaults {
@@ -117,7 +153,7 @@ enum vlan_defaults {
 };
 
 enum port_defaults {
 };
 
 enum port_defaults {
-       PORT_LINK,
+       PORT_PVID,
 };
 
 static struct switch_attr default_global[] = {
 };
 
 static struct switch_attr default_global[] = {
@@ -126,14 +162,22 @@ static struct switch_attr default_global[] = {
                .name = "apply",
                .description = "Activate changes in the hardware",
                .set = swconfig_apply_config,
                .name = "apply",
                .description = "Activate changes in the hardware",
                .set = swconfig_apply_config,
+       },
+       [GLOBAL_RESET] = {
+               .type = SWITCH_TYPE_NOVAL,
+               .name = "reset",
+               .description = "Reset the switch",
+               .set = swconfig_reset_switch,
        }
 };
 
 static struct switch_attr default_port[] = {
        }
 };
 
 static struct switch_attr default_port[] = {
-       [PORT_LINK] = {
+       [PORT_PVID] = {
                .type = SWITCH_TYPE_INT,
                .type = SWITCH_TYPE_INT,
-               .name = "link",
-               .description = "Current link speed",
+               .name = "pvid",
+               .description = "Primary VLAN ID",
+               .set = swconfig_set_pvid,
+               .get = swconfig_get_pvid,
        }
 };
 
        }
 };
 
@@ -157,8 +201,12 @@ static void swconfig_defaults_init(struct switch_dev *dev)
        if (dev->get_vlan_ports || dev->set_vlan_ports)
                set_bit(VLAN_PORTS, &dev->def_vlan);
 
        if (dev->get_vlan_ports || dev->set_vlan_ports)
                set_bit(VLAN_PORTS, &dev->def_vlan);
 
+       if (dev->get_port_pvid || dev->set_port_pvid)
+               set_bit(PORT_PVID, &dev->def_port);
+
        /* always present, can be no-op */
        set_bit(GLOBAL_APPLY, &dev->def_global);
        /* always present, can be no-op */
        set_bit(GLOBAL_APPLY, &dev->def_global);
+       set_bit(GLOBAL_RESET, &dev->def_global);
 }
 
 
 }
 
 
@@ -352,7 +400,7 @@ swconfig_list_attrs(struct sk_buff *skb, struct genl_info *info)
                if (alist->attr[i].disabled)
                        continue;
                cb.args[0] = i;
                if (alist->attr[i].disabled)
                        continue;
                cb.args[0] = i;
-               err = swconfig_send_multipart(&cb, &alist->attr[i]);
+               err = swconfig_send_multipart(&cb, (void *) &alist->attr[i]);
                if (err < 0)
                        goto error;
        }
                if (err < 0)
                        goto error;
        }
@@ -362,7 +410,7 @@ swconfig_list_attrs(struct sk_buff *skb, struct genl_info *info)
                if (!test_bit(i, def_active))
                        continue;
                cb.args[0] = SWITCH_ATTR_DEFAULTS_OFFSET + i;
                if (!test_bit(i, def_active))
                        continue;
                cb.args[0] = SWITCH_ATTR_DEFAULTS_OFFSET + i;
-               err = swconfig_send_multipart(&cb, &def_list[i]);
+               err = swconfig_send_multipart(&cb, (void *) &def_list[i]);
                if (err < 0)
                        goto error;
        }
                if (err < 0)
                        goto error;
        }
@@ -381,13 +429,13 @@ out:
        return err;
 }
 
        return err;
 }
 
-static struct switch_attr *
+static const struct switch_attr *
 swconfig_lookup_attr(struct switch_dev *dev, struct genl_info *info,
                struct switch_val *val)
 {
        struct genlmsghdr *hdr = nlmsg_data(info->nlhdr);
        const struct switch_attrlist *alist;
 swconfig_lookup_attr(struct switch_dev *dev, struct genl_info *info,
                struct switch_val *val)
 {
        struct genlmsghdr *hdr = nlmsg_data(info->nlhdr);
        const struct switch_attrlist *alist;
-       struct switch_attr *attr = NULL;
+       const struct switch_attr *attr = NULL;
        int attr_id;
 
        /* defaults */
        int attr_id;
 
        /* defaults */
@@ -415,6 +463,8 @@ swconfig_lookup_attr(struct switch_dev *dev, struct genl_info *info,
                if (!info->attrs[SWITCH_ATTR_OP_VLAN])
                        goto done;
                val->port_vlan = nla_get_u32(info->attrs[SWITCH_ATTR_OP_VLAN]);
                if (!info->attrs[SWITCH_ATTR_OP_VLAN])
                        goto done;
                val->port_vlan = nla_get_u32(info->attrs[SWITCH_ATTR_OP_VLAN]);
+               if (val->port_vlan >= dev->vlans)
+                       goto done;
                break;
        case SWITCH_CMD_SET_PORT:
        case SWITCH_CMD_GET_PORT:
                break;
        case SWITCH_CMD_SET_PORT:
        case SWITCH_CMD_GET_PORT:
@@ -425,6 +475,8 @@ swconfig_lookup_attr(struct switch_dev *dev, struct genl_info *info,
                if (!info->attrs[SWITCH_ATTR_OP_PORT])
                        goto done;
                val->port_vlan = nla_get_u32(info->attrs[SWITCH_ATTR_OP_PORT]);
                if (!info->attrs[SWITCH_ATTR_OP_PORT])
                        goto done;
                val->port_vlan = nla_get_u32(info->attrs[SWITCH_ATTR_OP_PORT]);
+               if (val->port_vlan >= dev->ports)
+                       goto done;
                break;
        default:
                WARN_ON(1);
                break;
        default:
                WARN_ON(1);
@@ -492,7 +544,7 @@ swconfig_parse_ports(struct sk_buff *msg, struct nlattr *head,
 static int
 swconfig_set_attr(struct sk_buff *skb, struct genl_info *info)
 {
 static int
 swconfig_set_attr(struct sk_buff *skb, struct genl_info *info)
 {
-       struct switch_attr *attr;
+       const struct switch_attr *attr;
        struct switch_dev *dev;
        struct switch_val val;
        int err = -EINVAL;
        struct switch_dev *dev;
        struct switch_val val;
        int err = -EINVAL;
@@ -622,7 +674,7 @@ static int
 swconfig_get_attr(struct sk_buff *skb, struct genl_info *info)
 {
        struct genlmsghdr *hdr = nlmsg_data(info->nlhdr);
 swconfig_get_attr(struct sk_buff *skb, struct genl_info *info)
 {
        struct genlmsghdr *hdr = nlmsg_data(info->nlhdr);
-       struct switch_attr *attr;
+       const struct switch_attr *attr;
        struct switch_dev *dev;
        struct sk_buff *msg = NULL;
        struct switch_val val;
        struct switch_dev *dev;
        struct sk_buff *msg = NULL;
        struct switch_val val;
@@ -709,6 +761,7 @@ swconfig_send_switch(struct sk_buff *msg, u32 pid, u32 seq, int flags,
        NLA_PUT_STRING(msg, SWITCH_ATTR_DEV_NAME, dev->devname);
        NLA_PUT_U32(msg, SWITCH_ATTR_VLANS, dev->vlans);
        NLA_PUT_U32(msg, SWITCH_ATTR_PORTS, dev->ports);
        NLA_PUT_STRING(msg, SWITCH_ATTR_DEV_NAME, dev->devname);
        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);
 
        return genlmsg_end(msg, hdr);
 nla_put_failure:
 
        return genlmsg_end(msg, hdr);
 nla_put_failure:
This page took 0.027828 seconds and 4 git commands to generate.