generic: rtl8366: use SWITCH_TYPE_NOVAL for reset_mib attributes
[openwrt.git] / target / linux / generic / files / drivers / net / phy / rtl8366s.c
index ebba2bb..5672c42 100644 (file)
 
 #include "rtl8366_smi.h"
 
-#ifdef CONFIG_RTL8366S_PHY_DEBUG_FS
-#include <linux/debugfs.h>
-#endif
-
 #define RTL8366S_DRIVER_DESC   "Realtek RTL8366S ethernet switch driver"
 #define RTL8366S_DRIVER_VER    "0.2.2"
 
@@ -31,9 +27,6 @@
 #define RTL8366S_PHY_PAGE_MAX  7
 #define RTL8366S_PHY_ADDR_MAX  31
 
-#define RTL8366S_CHIP_GLOBAL_CTRL_REG          0x0000
-#define RTL8366S_CHIP_CTRL_VLAN                        (1 << 13)
-
 /* Switch Global Configuration register */
 #define RTL8366S_SGCR                          0x0000
 #define RTL8366S_SGCR_EN_BC_STORM_CTRL         BIT(0)
@@ -43,6 +36,7 @@
 #define RTL8366S_SGCR_MAX_LENGTH_1536          RTL8366S_SGCR_MAX_LENGTH(0x1)
 #define RTL8366S_SGCR_MAX_LENGTH_1552          RTL8366S_SGCR_MAX_LENGTH(0x2)
 #define RTL8366S_SGCR_MAX_LENGTH_16000         RTL8366S_SGCR_MAX_LENGTH(0x3)
+#define RTL8366S_SGCR_EN_VLAN                  BIT(13)
 
 /* Port Enable Control register */
 #define RTL8366S_PECR                          0x0001
 
 #define RTL8366S_VLAN_MEMCONF_BASE             0x0016
 
+#define RTL8366S_VLAN_MEMBERINGRESS_REG                0x0379
 
 #define RTL8366S_PORT_LINK_STATUS_BASE         0x0060
 #define RTL8366S_PORT_STATUS_SPEED_MASK                0x0003
@@ -305,6 +300,12 @@ static int rtl8366s_hw_init(struct rtl8366_smi *smi)
        /* disable auto ageing for all ports */
        REG_WR(smi, RTL8366S_SSCR1, RTL8366S_PORT_ALL);
 
+       /*
+        * discard VLAN tagged packets if the port is not a member of
+        * the VLAN with which the packets is associated.
+        */
+       REG_WR(smi, RTL8366S_VLAN_MEMBERINGRESS_REG, RTL8366S_PORT_ALL);
+
        /* don't drop packets whose DA has not been learned */
        REG_RMW(smi, RTL8366S_SSCR2, RTL8366S_SSCR2_DROP_UNKNOWN_DA, 0);
 
@@ -648,9 +649,8 @@ static int rtl8366s_set_mc_index(struct rtl8366_smi *smi, int port, int index)
 
 static int rtl8366s_vlan_set_vlan(struct rtl8366_smi *smi, int enable)
 {
-       return rtl8366_smi_rmwr(smi, RTL8366S_CHIP_GLOBAL_CTRL_REG,
-                               RTL8366S_CHIP_CTRL_VLAN,
-                               (enable) ? RTL8366S_CHIP_CTRL_VLAN : 0);
+       return rtl8366_smi_rmwr(smi, RTL8366S_SGCR, RTL8366S_SGCR_EN_VLAN,
+                               (enable) ? RTL8366S_SGCR_EN_VLAN : 0);
 }
 
 static int rtl8366s_vlan_set_4ktable(struct rtl8366_smi *smi, int enable)
@@ -659,82 +659,13 @@ static int rtl8366s_vlan_set_4ktable(struct rtl8366_smi *smi, int enable)
                                1, (enable) ? 1 : 0);
 }
 
-#ifdef CONFIG_RTL8366S_PHY_DEBUG_FS
-static ssize_t rtl8366s_read_debugfs_mibs(struct file *file,
-                                         char __user *user_buf,
-                                         size_t count, loff_t *ppos)
-{
-       struct rtl8366_smi *smi = file->private_data;
-       int i, j, len = 0;
-       char *buf = smi->buf;
-
-       len += snprintf(buf + len, sizeof(smi->buf) - len, "%-36s",
-                       "Counter");
-
-       for (i = 0; i < smi->num_ports; i++) {
-               char port_buf[10];
-
-               snprintf(port_buf, sizeof(port_buf), "Port %d", i);
-               len += snprintf(buf + len, sizeof(smi->buf) - len, " %12s",
-                               port_buf);
-       }
-       len += snprintf(buf + len, sizeof(smi->buf) - len, "\n");
-
-       for (i = 0; i < smi->num_mib_counters; i++) {
-               len += snprintf(buf + len, sizeof(smi->buf) - len, "%-36s ",
-                               smi->mib_counters[i].name);
-               for (j = 0; j < smi->num_ports; j++) {
-                       unsigned long long counter = 0;
-
-                       if (!smi->ops->get_mib_counter(smi, i, j, &counter))
-                               len += snprintf(buf + len,
-                                               sizeof(smi->buf) - len,
-                                               "%12llu ", counter);
-                       else
-                               len += snprintf(buf + len,
-                                               sizeof(smi->buf) - len,
-                                               "%12s ", "error");
-               }
-               len += snprintf(buf + len, sizeof(smi->buf) - len, "\n");
-       }
-
-       return simple_read_from_buffer(user_buf, count, ppos, buf, len);
-}
-
-static const struct file_operations fops_rtl8366s_mibs = {
-       .read = rtl8366s_read_debugfs_mibs,
-       .open = rtl8366_debugfs_open,
-       .owner = THIS_MODULE
-};
-
-static void rtl8366s_debugfs_init(struct rtl8366_smi *smi)
-{
-       struct dentry *node;
-
-       if (!smi->debugfs_root)
-               return;
-
-       node = debugfs_create_file("mibs", S_IRUSR, smi->debugfs_root, smi,
-                                  &fops_rtl8366s_mibs);
-       if (!node)
-               dev_err(smi->parent, "Creating debugfs file '%s' failed\n",
-                       "mibs");
-}
-#else
-static inline void rtl8366s_debugfs_init(struct rtl8366_smi *smi) {}
-#endif /* CONFIG_RTL8366S_PHY_DEBUG_FS */
-
 static int rtl8366s_sw_reset_mibs(struct switch_dev *dev,
                                  const struct switch_attr *attr,
                                  struct switch_val *val)
 {
        struct rtl8366_smi *smi = sw_to_rtl8366_smi(dev);
-       int err = 0;
-
-       if (val->value.i == 1)
-               err = rtl8366_smi_rmwr(smi, RTL8366S_MIB_CTRL_REG, 0, (1 << 2));
 
-       return err;
+       return rtl8366_smi_rmwr(smi, RTL8366S_MIB_CTRL_REG, 0, (1 << 2));
 }
 
 static int rtl8366s_sw_get_vlan_enable(struct switch_dev *dev,
@@ -745,9 +676,9 @@ static int rtl8366s_sw_get_vlan_enable(struct switch_dev *dev,
        u32 data;
 
        if (attr->ofs == 1) {
-               rtl8366_smi_read_reg(smi, RTL8366S_CHIP_GLOBAL_CTRL_REG, &data);
+               rtl8366_smi_read_reg(smi, RTL8366S_SGCR, &data);
 
-               if (data & RTL8366S_CHIP_CTRL_VLAN)
+               if (data & RTL8366S_SGCR_EN_VLAN)
                        val->value.i = 1;
                else
                        val->value.i = 0;
@@ -1085,12 +1016,10 @@ static struct switch_attr rtl8366s_globals[] = {
                .max = 1,
                .ofs = 2
        }, {
-               .type = SWITCH_TYPE_INT,
+               .type = SWITCH_TYPE_NOVAL,
                .name = "reset_mibs",
                .description = "Reset all MIB counters",
                .set = rtl8366s_sw_reset_mibs,
-               .get = NULL,
-               .max = 1
        }, {
                .type = SWITCH_TYPE_INT,
                .name = "blinkrate",
@@ -1111,12 +1040,10 @@ static struct switch_attr rtl8366s_port[] = {
                .set = NULL,
                .get = rtl8366s_sw_get_port_link,
        }, {
-               .type = SWITCH_TYPE_INT,
+               .type = SWITCH_TYPE_NOVAL,
                .name = "reset_mib",
                .description = "Reset single port MIB counters",
-               .max = 1,
                .set = rtl8366s_sw_reset_port_mibs,
-               .get = NULL,
        }, {
                .type = SWITCH_TYPE_STRING,
                .name = "mib",
@@ -1229,8 +1156,6 @@ static int rtl8366s_setup(struct rtl8366s *rtl)
        struct rtl8366_smi *smi = &rtl->smi;
        int ret;
 
-       rtl8366s_debugfs_init(smi);
-
        ret = rtl8366s_reset_chip(smi);
        if (ret)
                return ret;
This page took 0.030259 seconds and 4 git commands to generate.