generic: rtl8366: add is_vlan_valid function to smi_ops

git-svn-id: svn://svn.openwrt.org/openwrt/trunk@22201 3c298f89-4303-0410-b956-a3cf2f4a3e73
master
Gabor Juhos 2010-07-15 13:05:39 +00:00
parent cf551c6259
commit d2d1fc5eb6
3 changed files with 25 additions and 6 deletions

View File

@ -86,6 +86,7 @@ struct rtl8366_smi_ops {
int (*set_mc_index)(struct rtl8366_smi *smi, int port, int index); int (*set_mc_index)(struct rtl8366_smi *smi, int port, int index);
int (*get_mib_counter)(struct rtl8366_smi *smi, int counter, int (*get_mib_counter)(struct rtl8366_smi *smi, int counter,
int port, unsigned long long *val); int port, unsigned long long *val);
int (*is_vlan_valid)(struct rtl8366_smi *smi, unsigned vlan);
}; };
struct rtl8366_smi *rtl8366_smi_alloc(struct device *parent); struct rtl8366_smi *rtl8366_smi_alloc(struct device *parent);

View File

@ -552,6 +552,14 @@ static int rtl8366rb_set_mc_index(struct rtl8366_smi *smi, int port, int index)
RTL8366RB_PORT_VLAN_CTRL_SHIFT(port)); RTL8366RB_PORT_VLAN_CTRL_SHIFT(port));
} }
static int rtl8366rb_is_vlan_valid(struct rtl8366_smi *smi, unsigned vlan)
{
if (vlan == 0 || vlan >= RTL8366RB_NUM_VLANS)
return 0;
return 1;
}
static int rtl8366rb_vlan_set_vlan(struct rtl8366_smi *smi, int enable) static int rtl8366rb_vlan_set_vlan(struct rtl8366_smi *smi, int enable)
{ {
return rtl8366_smi_rmwr(smi, RTL8366RB_SGCR, RTL8366RB_SGCR_EN_VLAN, return rtl8366_smi_rmwr(smi, RTL8366RB_SGCR, RTL8366RB_SGCR_EN_VLAN,
@ -708,7 +716,7 @@ static int rtl8366rb_sw_get_vlan_info(struct switch_dev *dev,
char *buf = smi->buf; char *buf = smi->buf;
int err; int err;
if (val->port_vlan == 0 || val->port_vlan >= RTL8366RB_NUM_VLANS) if (!smi->ops->is_vlan_valid(smi, val->port_vlan))
return -EINVAL; return -EINVAL;
memset(buf, '\0', sizeof(smi->buf)); memset(buf, '\0', sizeof(smi->buf));
@ -800,7 +808,7 @@ static int rtl8366rb_sw_get_vlan_ports(struct switch_dev *dev,
struct rtl8366_vlan_4k vlan4k; struct rtl8366_vlan_4k vlan4k;
int i; int i;
if (val->port_vlan == 0 || val->port_vlan >= RTL8366RB_NUM_VLANS) if (!smi->ops->is_vlan_valid(smi, val->port_vlan))
return -EINVAL; return -EINVAL;
rtl8366rb_get_vlan_4k(smi, val->port_vlan, &vlan4k); rtl8366rb_get_vlan_4k(smi, val->port_vlan, &vlan4k);
@ -829,7 +837,7 @@ static int rtl8366rb_sw_set_vlan_ports(struct switch_dev *dev,
u32 untag = 0; u32 untag = 0;
int i; int i;
if (val->port_vlan == 0 || val->port_vlan >= RTL8366RB_NUM_VLANS) if (!smi->ops->is_vlan_valid(smi, val->port_vlan))
return -EINVAL; return -EINVAL;
port = &val->value.ports[0]; port = &val->value.ports[0];
@ -1071,6 +1079,7 @@ static struct rtl8366_smi_ops rtl8366rb_smi_ops = {
.get_mc_index = rtl8366rb_get_mc_index, .get_mc_index = rtl8366rb_get_mc_index,
.set_mc_index = rtl8366rb_set_mc_index, .set_mc_index = rtl8366rb_set_mc_index,
.get_mib_counter = rtl8366rb_get_mib_counter, .get_mib_counter = rtl8366rb_get_mib_counter,
.is_vlan_valid = rtl8366rb_is_vlan_valid,
}; };
static int __init rtl8366rb_probe(struct platform_device *pdev) static int __init rtl8366rb_probe(struct platform_device *pdev)

View File

@ -591,6 +591,14 @@ static int rtl8366s_vlan_set_4ktable(struct rtl8366_smi *smi, int enable)
1, (enable) ? 1 : 0); 1, (enable) ? 1 : 0);
} }
static int rtl8366s_is_vlan_valid(struct rtl8366_smi *smi, unsigned vlan)
{
if (vlan == 0 || vlan >= RTL8366S_NUM_VLANS)
return 0;
return 1;
}
static int rtl8366s_sw_reset_mibs(struct switch_dev *dev, static int rtl8366s_sw_reset_mibs(struct switch_dev *dev,
const struct switch_attr *attr, const struct switch_attr *attr,
struct switch_val *val) struct switch_val *val)
@ -733,7 +741,7 @@ static int rtl8366s_sw_get_vlan_info(struct switch_dev *dev,
char *buf = smi->buf; char *buf = smi->buf;
int err; int err;
if (val->port_vlan == 0 || val->port_vlan >= RTL8366S_NUM_VLANS) if (!smi->ops->is_vlan_valid(smi, val->port_vlan))
return -EINVAL; return -EINVAL;
memset(buf, '\0', sizeof(smi->buf)); memset(buf, '\0', sizeof(smi->buf));
@ -827,7 +835,7 @@ static int rtl8366s_sw_get_vlan_ports(struct switch_dev *dev,
struct rtl8366_vlan_4k vlan4k; struct rtl8366_vlan_4k vlan4k;
int i; int i;
if (val->port_vlan == 0 || val->port_vlan >= RTL8366S_NUM_VLANS) if (!smi->ops->is_vlan_valid(smi, val->port_vlan))
return -EINVAL; return -EINVAL;
rtl8366s_get_vlan_4k(smi, val->port_vlan, &vlan4k); rtl8366s_get_vlan_4k(smi, val->port_vlan, &vlan4k);
@ -856,7 +864,7 @@ static int rtl8366s_sw_set_vlan_ports(struct switch_dev *dev,
u32 untag = 0; u32 untag = 0;
int i; int i;
if (val->port_vlan == 0 || val->port_vlan >= RTL8366S_NUM_VLANS) if (!smi->ops->is_vlan_valid(smi, val->port_vlan))
return -EINVAL; return -EINVAL;
port = &val->value.ports[0]; port = &val->value.ports[0];
@ -1098,6 +1106,7 @@ static struct rtl8366_smi_ops rtl8366s_smi_ops = {
.get_mc_index = rtl8366s_get_mc_index, .get_mc_index = rtl8366s_get_mc_index,
.set_mc_index = rtl8366s_set_mc_index, .set_mc_index = rtl8366s_set_mc_index,
.get_mib_counter = rtl8366_get_mib_counter, .get_mib_counter = rtl8366_get_mib_counter,
.is_vlan_valid = rtl8366s_is_vlan_valid,
}; };
static int __init rtl8366s_probe(struct platform_device *pdev) static int __init rtl8366s_probe(struct platform_device *pdev)