generic: rtl8366: add common vlan_mc structure

git-svn-id: svn://svn.openwrt.org/openwrt/trunk@21914 3c298f89-4303-0410-b956-a3cf2f4a3e73
master
Gabor Juhos 2010-06-26 19:16:16 +00:00
parent d33784922b
commit adf1d15f9c
3 changed files with 62 additions and 24 deletions

View File

@ -34,6 +34,14 @@ struct rtl8366_smi_ops {
int (*mii_write)(struct mii_bus *bus, int addr, int reg, u16 val); int (*mii_write)(struct mii_bus *bus, int addr, int reg, u16 val);
}; };
struct rtl8366_vlan_mc {
u16 vid;
u8 priority;
u8 untag;
u8 member;
u8 fid;
};
int rtl8366_smi_init(struct rtl8366_smi *smi); int rtl8366_smi_init(struct rtl8366_smi *smi);
void rtl8366_smi_cleanup(struct rtl8366_smi *smi); void rtl8366_smi_cleanup(struct rtl8366_smi *smi);
int rtl8366_smi_write_reg(struct rtl8366_smi *smi, u32 addr, u32 data); int rtl8366_smi_write_reg(struct rtl8366_smi *smi, u32 addr, u32 data);

View File

@ -472,20 +472,21 @@ static int rtl8366rb_set_vlan_4k(struct rtl8366rb *rtl,
} }
static int rtl8366rb_get_vlan_mc(struct rtl8366rb *rtl, u32 index, static int rtl8366rb_get_vlan_mc(struct rtl8366rb *rtl, u32 index,
struct rtl8366rb_vlan_mc *vlanmc) struct rtl8366_vlan_mc *vlanmc)
{ {
struct rtl8366_smi *smi = &rtl->smi; struct rtl8366_smi *smi = &rtl->smi;
struct rtl8366rb_vlan_mc vlanmc_priv;
int err; int err;
u32 addr; u32 addr;
u32 data; u32 data;
u16 *tableaddr; u16 *tableaddr;
memset(vlanmc, '\0', sizeof(struct rtl8366rb_vlan_mc)); memset(vlanmc, '\0', sizeof(struct rtl8366_vlan_mc));
if (index >= RTL8366_NUM_VLANS) if (index >= RTL8366_NUM_VLANS)
return -EINVAL; return -EINVAL;
tableaddr = (u16 *)vlanmc; tableaddr = (u16 *)&vlanmc_priv;
addr = RTL8366S_VLAN_MEMCONF_BASE + (index * 3); addr = RTL8366S_VLAN_MEMCONF_BASE + (index * 3);
err = rtl8366_smi_read_reg(smi, addr, &data); err = rtl8366_smi_read_reg(smi, addr, &data);
@ -510,13 +511,20 @@ static int rtl8366rb_get_vlan_mc(struct rtl8366rb *rtl, u32 index,
*tableaddr = data; *tableaddr = data;
vlanmc->vid = vlanmc_priv.vid;
vlanmc->priority = vlanmc_priv.priority;
vlanmc->untag = vlanmc_priv.untag;
vlanmc->member = vlanmc_priv.member;
vlanmc->fid = vlanmc_priv.fid;
return 0; return 0;
} }
static int rtl8366rb_set_vlan_mc(struct rtl8366rb *rtl, u32 index, static int rtl8366rb_set_vlan_mc(struct rtl8366rb *rtl, u32 index,
const struct rtl8366rb_vlan_mc *vlanmc) const struct rtl8366_vlan_mc *vlanmc)
{ {
struct rtl8366_smi *smi = &rtl->smi; struct rtl8366_smi *smi = &rtl->smi;
struct rtl8366rb_vlan_mc vlanmc_priv;
int err; int err;
u32 addr; u32 addr;
u32 data; u32 data;
@ -530,9 +538,17 @@ static int rtl8366rb_set_vlan_mc(struct rtl8366rb *rtl, u32 index,
vlanmc->fid > RTL8366S_FIDMAX) vlanmc->fid > RTL8366S_FIDMAX)
return -EINVAL; return -EINVAL;
vlanmc_priv.vid = vlanmc->vid;
vlanmc_priv.priority = vlanmc->priority;
vlanmc_priv.untag = vlanmc->untag;
vlanmc_priv.member = vlanmc->member;
vlanmc_priv.stag_mbr = 0;
vlanmc_priv.stag_idx = 0;
vlanmc_priv.fid = vlanmc->fid;
addr = RTL8366S_VLAN_MEMCONF_BASE + (index * 3); addr = RTL8366S_VLAN_MEMCONF_BASE + (index * 3);
tableaddr = (u16 *)vlanmc; tableaddr = (u16 *)&vlanmc_priv;
data = *tableaddr; data = *tableaddr;
err = rtl8366_smi_write_reg(smi, addr, data); err = rtl8366_smi_write_reg(smi, addr, data);
@ -584,7 +600,7 @@ static int rtl8366rb_get_port_vlan_index(struct rtl8366rb *rtl, int port,
static int rtl8366rb_get_vlan_port_pvid(struct rtl8366rb *rtl, int port, static int rtl8366rb_get_vlan_port_pvid(struct rtl8366rb *rtl, int port,
int *val) int *val)
{ {
struct rtl8366rb_vlan_mc vlanmc; struct rtl8366_vlan_mc vlanmc;
int err; int err;
int index; int index;
@ -628,7 +644,7 @@ static int rtl8366rb_set_port_vlan_index(struct rtl8366rb *rtl, int port,
static int rtl8366rb_set_vlan_port_pvid(struct rtl8366rb *rtl, int port, int val) static int rtl8366rb_set_vlan_port_pvid(struct rtl8366rb *rtl, int port, int val)
{ {
int i; int i;
struct rtl8366rb_vlan_mc vlanmc; struct rtl8366_vlan_mc vlanmc;
struct rtl8366rb_vlan_4k vlan4k; struct rtl8366rb_vlan_4k vlan4k;
if (port >= RTL8366_NUM_PORTS || val >= RTL8366_NUM_VIDS) if (port >= RTL8366_NUM_PORTS || val >= RTL8366_NUM_VIDS)
@ -726,7 +742,7 @@ static int rtl8366rb_vlan_set_4ktable(struct rtl8366rb *rtl, int enable)
static int rtl8366rb_reset_vlan(struct rtl8366rb *rtl) static int rtl8366rb_reset_vlan(struct rtl8366rb *rtl)
{ {
struct rtl8366rb_vlan_4k vlan4k; struct rtl8366rb_vlan_4k vlan4k;
struct rtl8366rb_vlan_mc vlanmc; struct rtl8366_vlan_mc vlanmc;
int err; int err;
int i; int i;
@ -831,7 +847,7 @@ static ssize_t rtl8366rb_read_debugfs_vlan(struct file *file,
"\tports\n"); "\tports\n");
for (i = 0; i < RTL8366_NUM_VLANS; ++i) { for (i = 0; i < RTL8366_NUM_VLANS; ++i) {
struct rtl8366rb_vlan_mc vlanmc; struct rtl8366_vlan_mc vlanmc;
rtl8366rb_get_vlan_mc(rtl, i, &vlanmc); rtl8366rb_get_vlan_mc(rtl, i, &vlanmc);
@ -1150,7 +1166,7 @@ static int rtl8366rb_sw_get_vlan_info(struct switch_dev *dev,
{ {
int i; int i;
u32 len = 0; u32 len = 0;
struct rtl8366rb_vlan_mc vlanmc; struct rtl8366_vlan_mc vlanmc;
struct rtl8366rb_vlan_4k vlan4k; struct rtl8366rb_vlan_4k vlan4k;
struct rtl8366rb *rtl = sw_to_rtl8366rb(dev); struct rtl8366rb *rtl = sw_to_rtl8366rb(dev);
char *buf = rtl->buf; char *buf = rtl->buf;
@ -1288,7 +1304,7 @@ static int rtl8366rb_sw_get_port_mib(struct switch_dev *dev,
static int rtl8366rb_sw_get_vlan_ports(struct switch_dev *dev, static int rtl8366rb_sw_get_vlan_ports(struct switch_dev *dev,
struct switch_val *val) struct switch_val *val)
{ {
struct rtl8366rb_vlan_mc vlanmc; struct rtl8366_vlan_mc vlanmc;
struct rtl8366rb *rtl = sw_to_rtl8366rb(dev); struct rtl8366rb *rtl = sw_to_rtl8366rb(dev);
struct switch_port *port; struct switch_port *port;
int i; int i;
@ -1316,7 +1332,7 @@ static int rtl8366rb_sw_get_vlan_ports(struct switch_dev *dev,
static int rtl8366rb_sw_set_vlan_ports(struct switch_dev *dev, static int rtl8366rb_sw_set_vlan_ports(struct switch_dev *dev,
struct switch_val *val) struct switch_val *val)
{ {
struct rtl8366rb_vlan_mc vlanmc; struct rtl8366_vlan_mc vlanmc;
struct rtl8366rb_vlan_4k vlan4k; struct rtl8366rb_vlan_4k vlan4k;
struct rtl8366rb *rtl = sw_to_rtl8366rb(dev); struct rtl8366rb *rtl = sw_to_rtl8366rb(dev);
struct switch_port *port; struct switch_port *port;

View File

@ -457,20 +457,21 @@ static int rtl8366s_set_vlan_4k(struct rtl8366s *rtl,
} }
static int rtl8366s_get_vlan_mc(struct rtl8366s *rtl, u32 index, static int rtl8366s_get_vlan_mc(struct rtl8366s *rtl, u32 index,
struct rtl8366s_vlan_mc *vlanmc) struct rtl8366_vlan_mc *vlanmc)
{ {
struct rtl8366_smi *smi = &rtl->smi; struct rtl8366_smi *smi = &rtl->smi;
struct rtl8366s_vlan_mc vlanmc_priv;
int err; int err;
u32 addr; u32 addr;
u32 data; u32 data;
u16 *tableaddr; u16 *tableaddr;
memset(vlanmc, '\0', sizeof(struct rtl8366s_vlan_mc)); memset(vlanmc, '\0', sizeof(struct rtl8366_vlan_mc));
if (index >= RTL8366_NUM_VLANS) if (index >= RTL8366_NUM_VLANS)
return -EINVAL; return -EINVAL;
tableaddr = (u16 *)vlanmc; tableaddr = (u16 *)&vlanmc_priv;
addr = RTL8366S_VLAN_MEMCONF_BASE + (index << 1); addr = RTL8366S_VLAN_MEMCONF_BASE + (index << 1);
err = rtl8366_smi_read_reg(smi, addr, &data); err = rtl8366_smi_read_reg(smi, addr, &data);
@ -487,13 +488,20 @@ static int rtl8366s_get_vlan_mc(struct rtl8366s *rtl, u32 index,
*tableaddr = data; *tableaddr = data;
vlanmc->vid = vlanmc_priv.vid;
vlanmc->priority = vlanmc_priv.priority;
vlanmc->untag = vlanmc_priv.untag;
vlanmc->member = vlanmc_priv.member;
vlanmc->fid = vlanmc_priv.fid;
return 0; return 0;
} }
static int rtl8366s_set_vlan_mc(struct rtl8366s *rtl, u32 index, static int rtl8366s_set_vlan_mc(struct rtl8366s *rtl, u32 index,
const struct rtl8366s_vlan_mc *vlanmc) const struct rtl8366_vlan_mc *vlanmc)
{ {
struct rtl8366_smi *smi = &rtl->smi; struct rtl8366_smi *smi = &rtl->smi;
struct rtl8366s_vlan_mc vlanmc_priv;
int err; int err;
u32 addr; u32 addr;
u32 data; u32 data;
@ -507,9 +515,15 @@ static int rtl8366s_set_vlan_mc(struct rtl8366s *rtl, u32 index,
vlanmc->fid > RTL8366S_FIDMAX) vlanmc->fid > RTL8366S_FIDMAX)
return -EINVAL; return -EINVAL;
vlanmc_priv.vid = vlanmc->vid;
vlanmc_priv.priority = vlanmc->priority;
vlanmc_priv.untag = vlanmc->untag;
vlanmc_priv.member = vlanmc->member;
vlanmc_priv.fid = vlanmc->fid;
addr = RTL8366S_VLAN_MEMCONF_BASE + (index << 1); addr = RTL8366S_VLAN_MEMCONF_BASE + (index << 1);
tableaddr = (u16 *)vlanmc; tableaddr = (u16 *)&vlanmc_priv;
data = *tableaddr; data = *tableaddr;
err = rtl8366_smi_write_reg(smi, addr, data); err = rtl8366_smi_write_reg(smi, addr, data);
@ -553,7 +567,7 @@ static int rtl8366s_get_port_vlan_index(struct rtl8366s *rtl, int port,
static int rtl8366s_get_vlan_port_pvid(struct rtl8366s *rtl, int port, static int rtl8366s_get_vlan_port_pvid(struct rtl8366s *rtl, int port,
int *val) int *val)
{ {
struct rtl8366s_vlan_mc vlanmc; struct rtl8366_vlan_mc vlanmc;
int err; int err;
int index; int index;
@ -597,7 +611,7 @@ static int rtl8366s_set_port_vlan_index(struct rtl8366s *rtl, int port,
static int rtl8366s_set_vlan_port_pvid(struct rtl8366s *rtl, int port, int val) static int rtl8366s_set_vlan_port_pvid(struct rtl8366s *rtl, int port, int val)
{ {
int i; int i;
struct rtl8366s_vlan_mc vlanmc; struct rtl8366_vlan_mc vlanmc;
struct rtl8366s_vlan_4k vlan4k; struct rtl8366s_vlan_4k vlan4k;
if (port >= RTL8366_NUM_PORTS || val >= RTL8366_NUM_VIDS) if (port >= RTL8366_NUM_PORTS || val >= RTL8366_NUM_VIDS)
@ -695,7 +709,7 @@ static int rtl8366s_vlan_set_4ktable(struct rtl8366s *rtl, int enable)
static int rtl8366s_reset_vlan(struct rtl8366s *rtl) static int rtl8366s_reset_vlan(struct rtl8366s *rtl)
{ {
struct rtl8366s_vlan_4k vlan4k; struct rtl8366s_vlan_4k vlan4k;
struct rtl8366s_vlan_mc vlanmc; struct rtl8366_vlan_mc vlanmc;
int err; int err;
int i; int i;
@ -800,7 +814,7 @@ static ssize_t rtl8366s_read_debugfs_vlan(struct file *file,
"\tports\n"); "\tports\n");
for (i = 0; i < RTL8366_NUM_VLANS; ++i) { for (i = 0; i < RTL8366_NUM_VLANS; ++i) {
struct rtl8366s_vlan_mc vlanmc; struct rtl8366_vlan_mc vlanmc;
rtl8366s_get_vlan_mc(rtl, i, &vlanmc); rtl8366s_get_vlan_mc(rtl, i, &vlanmc);
@ -1119,7 +1133,7 @@ static int rtl8366s_sw_get_vlan_info(struct switch_dev *dev,
{ {
int i; int i;
u32 len = 0; u32 len = 0;
struct rtl8366s_vlan_mc vlanmc; struct rtl8366_vlan_mc vlanmc;
struct rtl8366s_vlan_4k vlan4k; struct rtl8366s_vlan_4k vlan4k;
struct rtl8366s *rtl = sw_to_rtl8366s(dev); struct rtl8366s *rtl = sw_to_rtl8366s(dev);
char *buf = rtl->buf; char *buf = rtl->buf;
@ -1258,7 +1272,7 @@ static int rtl8366s_sw_get_port_mib(struct switch_dev *dev,
static int rtl8366s_sw_get_vlan_ports(struct switch_dev *dev, static int rtl8366s_sw_get_vlan_ports(struct switch_dev *dev,
struct switch_val *val) struct switch_val *val)
{ {
struct rtl8366s_vlan_mc vlanmc; struct rtl8366_vlan_mc vlanmc;
struct rtl8366s *rtl = sw_to_rtl8366s(dev); struct rtl8366s *rtl = sw_to_rtl8366s(dev);
struct switch_port *port; struct switch_port *port;
int i; int i;
@ -1286,7 +1300,7 @@ static int rtl8366s_sw_get_vlan_ports(struct switch_dev *dev,
static int rtl8366s_sw_set_vlan_ports(struct switch_dev *dev, static int rtl8366s_sw_set_vlan_ports(struct switch_dev *dev,
struct switch_val *val) struct switch_val *val)
{ {
struct rtl8366s_vlan_mc vlanmc; struct rtl8366_vlan_mc vlanmc;
struct rtl8366s_vlan_4k vlan4k; struct rtl8366s_vlan_4k vlan4k;
struct rtl8366s *rtl = sw_to_rtl8366s(dev); struct rtl8366s *rtl = sw_to_rtl8366s(dev);
struct switch_port *port; struct switch_port *port;