-static int rtl8366s_sw_get_port_mib(struct switch_dev *dev,
- const struct switch_attr *attr,
- struct switch_val *val)
-{
- struct rtl8366_smi *smi = sw_to_rtl8366_smi(dev);
- int i, len = 0;
- unsigned long long counter = 0;
- char *buf = smi->buf;
-
- if (val->port_vlan >= RTL8366S_NUM_PORTS)
- return -EINVAL;
-
- len += snprintf(buf + len, sizeof(smi->buf) - len,
- "Port %d MIB counters\n",
- val->port_vlan);
-
- for (i = 0; i < ARRAY_SIZE(rtl8366s_mib_counters); ++i) {
- len += snprintf(buf + len, sizeof(smi->buf) - len,
- "%-36s: ", rtl8366s_mib_counters[i].name);
- if (!rtl8366_get_mib_counter(smi, i, val->port_vlan, &counter))
- len += snprintf(buf + len, sizeof(smi->buf) - len,
- "%llu\n", counter);
- else
- len += snprintf(buf + len, sizeof(smi->buf) - len,
- "%s\n", "error");
- }
-
- val->value.s = buf;
- val->len = len;
- return 0;
-}
-
-static int rtl8366s_sw_get_vlan_ports(struct switch_dev *dev,
- struct switch_val *val)
-{
- struct rtl8366_smi *smi = sw_to_rtl8366_smi(dev);
- struct switch_port *port;
- struct rtl8366_vlan_4k vlan4k;
- int i;
-
- if (val->port_vlan == 0 || val->port_vlan >= RTL8366S_NUM_VLANS)
- return -EINVAL;
-
- rtl8366s_get_vlan_4k(smi, val->port_vlan, &vlan4k);
-
- port = &val->value.ports[0];
- val->len = 0;
- for (i = 0; i < RTL8366S_NUM_PORTS; i++) {
- if (!(vlan4k.member & BIT(i)))
- continue;
-
- port->id = i;
- port->flags = (vlan4k.untag & BIT(i)) ?
- 0 : BIT(SWITCH_PORT_FLAG_TAGGED);
- val->len++;
- port++;
- }
- return 0;
-}
-
-static int rtl8366s_sw_set_vlan_ports(struct switch_dev *dev,
- struct switch_val *val)
-{
- struct rtl8366_smi *smi = sw_to_rtl8366_smi(dev);
- struct switch_port *port;
- u32 member = 0;
- u32 untag = 0;
- int i;
-
- if (val->port_vlan == 0 || val->port_vlan >= RTL8366S_NUM_VLANS)
- return -EINVAL;
-
- port = &val->value.ports[0];
- for (i = 0; i < val->len; i++, port++) {
- member |= BIT(port->id);
-
- if (!(port->flags & BIT(SWITCH_PORT_FLAG_TAGGED)))
- untag |= BIT(port->id);
- }
-
- return rtl8366_set_vlan(smi, val->port_vlan, member, untag, 0);
-}
-
-static int rtl8366s_sw_get_port_pvid(struct switch_dev *dev, int port, int *val)
-{
- struct rtl8366_smi *smi = sw_to_rtl8366_smi(dev);
- return rtl8366_get_pvid(smi, port, val);
-}
-
-static int rtl8366s_sw_set_port_pvid(struct switch_dev *dev, int port, int val)
-{
- struct rtl8366_smi *smi = sw_to_rtl8366_smi(dev);
- return rtl8366_set_pvid(smi, port, val);
-}
-