merge swconfig (+drivers) improvements from trunk
authorFelix Fietkau <nbd@openwrt.org>
Mon, 16 Aug 2010 19:23:53 +0000 (19:23 +0000)
committerFelix Fietkau <nbd@openwrt.org>
Mon, 16 Aug 2010 19:23:53 +0000 (19:23 +0000)
SVN-Revision: 22677

23 files changed:
target/linux/atheros/config-2.6.30
target/linux/atheros/config-2.6.32
target/linux/generic-2.6/config-2.6.30
target/linux/generic-2.6/config-2.6.32
target/linux/generic-2.6/files/drivers/net/phy/ar8216.c
target/linux/generic-2.6/files/drivers/net/phy/ip175c.c [deleted file]
target/linux/generic-2.6/files/drivers/net/phy/ip17xx.c [new file with mode: 0644]
target/linux/generic-2.6/files/drivers/net/phy/rtl8306.c
target/linux/generic-2.6/files/drivers/net/phy/rtl8366_smi.c
target/linux/generic-2.6/files/drivers/net/phy/rtl8366_smi.h
target/linux/generic-2.6/files/drivers/net/phy/rtl8366rb.c
target/linux/generic-2.6/files/drivers/net/phy/rtl8366s.c
target/linux/generic-2.6/files/drivers/net/phy/swconfig.c
target/linux/generic-2.6/files/include/linux/switch.h
target/linux/generic-2.6/patches-2.6.30/670-phy_ip175c.patch
target/linux/generic-2.6/patches-2.6.30/680-phy_ar8216.patch
target/linux/generic-2.6/patches-2.6.30/690-phy_rtl8306.patch
target/linux/generic-2.6/patches-2.6.30/691-phy_rtl8366.patch
target/linux/generic-2.6/patches-2.6.32/651-swconfig-2.6.32-fix.patch [deleted file]
target/linux/generic-2.6/patches-2.6.32/670-phy_ip175c.patch
target/linux/generic-2.6/patches-2.6.32/680-phy_ar8216.patch
target/linux/generic-2.6/patches-2.6.32/690-phy_rtl8306.patch
target/linux/generic-2.6/patches-2.6.32/691-phy_rtl8366.patch

index 2804447500a677ff5b364259cbe6ea916a2fab9a..32c98146f293f0cb95af4ea1c66dbfd1f4452aa0 100644 (file)
@@ -82,7 +82,7 @@ CONFIG_HAVE_OPROFILE=y
 CONFIG_HW_HAS_PCI=y
 CONFIG_HW_RANDOM=y
 CONFIG_INITRAMFS_SOURCE=""
-CONFIG_IP175C_PHY=y
+CONFIG_IP17XX_PHY=y
 CONFIG_IRQ_CPU=y
 # CONFIG_LEDS_GPIO is not set
 # CONFIG_LEMOTE_FULONG is not set
index 9ccb44977a2128a62f0b152c4c696ba8b8087d24..677a17b8c7a6660242aeb30f76f7f941866e790a 100644 (file)
@@ -84,7 +84,7 @@ CONFIG_HAVE_OPROFILE=y
 CONFIG_HW_HAS_PCI=y
 CONFIG_HW_RANDOM=y
 CONFIG_INITRAMFS_SOURCE=""
-CONFIG_IP175C_PHY=y
+CONFIG_IP17XX_PHY=y
 CONFIG_IRQ_CPU=y
 # CONFIG_LEDS_GPIO is not set
 # CONFIG_MACH_ALCHEMY is not set
index ff553850b8fd59eba96dde1ece1515d1f32d117b..16483b73cd4545f13cac408f94f08877321587fe 100644 (file)
@@ -870,7 +870,7 @@ CONFIG_INPUT_MISC=y
 CONFIG_IOSCHED_DEADLINE=y
 CONFIG_IOSCHED_NOOP=y
 # CONFIG_IP1000 is not set
-# CONFIG_IP175C_PHY is not set
+# CONFIG_IP17XX_PHY is not set
 # CONFIG_IP6_NF_FILTER is not set
 # CONFIG_IP6_NF_IPTABLES is not set
 # CONFIG_IP6_NF_MANGLE is not set
index 522a30acba272b83fe3a5fb3fac4ff0d83ab24cc..771cfb028c695ea438b8f59ff52f33ce7f04bfd4 100644 (file)
@@ -921,7 +921,7 @@ CONFIG_INPUT_MISC=y
 CONFIG_IOSCHED_DEADLINE=y
 CONFIG_IOSCHED_NOOP=y
 # CONFIG_IP1000 is not set
-# CONFIG_IP175C_PHY is not set
+# CONFIG_IP17XX_PHY is not set
 # CONFIG_IP6_NF_FILTER is not set
 # CONFIG_IP6_NF_IPTABLES is not set
 # CONFIG_IP6_NF_MANGLE is not set
index 4ae61da2338ac61ee929f3e9e00b446ad892dd0e..98bfc7eb313c573f4c9bea082372040ac1aad88f 100644 (file)
@@ -52,7 +52,6 @@ struct ar8216_priv {
        u8 vlan_tagged;
        u16 pvid[AR8216_NUM_PORTS];
 };
-static struct switch_dev athdev;
 
 #define to_ar8216(_dev) container_of(_dev, struct ar8216_priv, dev)
 
@@ -631,11 +630,34 @@ ar8216_reset_switch(struct switch_dev *dev)
        return ar8216_hw_apply(dev);
 }
 
+
+static const struct switch_dev_ops ar8216_ops = {
+       .attr_global = {
+               .attr = ar8216_globals,
+               .n_attr = ARRAY_SIZE(ar8216_globals),
+       },
+       .attr_port = {
+               .attr = ar8216_port,
+               .n_attr = ARRAY_SIZE(ar8216_port),
+       },
+       .attr_vlan = {
+               .attr = ar8216_vlan,
+               .n_attr = ARRAY_SIZE(ar8216_vlan),
+       },
+       .get_port_pvid = ar8216_get_pvid,
+       .set_port_pvid = ar8216_set_pvid,
+       .get_vlan_ports = ar8216_get_ports,
+       .set_vlan_ports = ar8216_set_ports,
+       .apply_config = ar8216_hw_apply,
+       .reset_switch = ar8216_reset_switch,
+};
+
 static int
 ar8216_config_init(struct phy_device *pdev)
 {
        struct ar8216_priv *priv;
        struct net_device *dev = pdev->attached_dev;
+       struct switch_dev *swdev;
        int ret;
 
        priv = kzalloc(sizeof(struct ar8216_priv), GFP_KERNEL);
@@ -667,14 +689,22 @@ ar8216_config_init(struct phy_device *pdev)
        mutex_init(&priv->reg_mutex);
        priv->read = ar8216_mii_read;
        priv->write = ar8216_mii_write;
-       memcpy(&priv->dev, &athdev, sizeof(struct switch_dev));
+
        pdev->priv = priv;
 
+       swdev = &priv->dev;
+       swdev->cpu_port = AR8216_PORT_CPU;
+       swdev->ops = &ar8216_ops;
+
        if (priv->chip == AR8316) {
-               priv->dev.name = "Atheros AR8316";
-               priv->dev.vlans = AR8X16_MAX_VLANS;
+               swdev->name = "Atheros AR8316";
+               swdev->vlans = AR8X16_MAX_VLANS;
                /* port 5 connected to the other mac, therefore unusable */
-               priv->dev.ports = (AR8216_NUM_PORTS - 1);
+               swdev->ports = (AR8216_NUM_PORTS - 1);
+       } else {
+               swdev->name = "Atheros AR8216";
+               swdev->vlans = AR8216_NUM_VLANS;
+               swdev->ports = AR8216_NUM_PORTS;
        }
 
        if ((ret = register_switch(&priv->dev, pdev->attached_dev)) < 0) {
@@ -782,32 +812,6 @@ ar8216_remove(struct phy_device *pdev)
        kfree(priv);
 }
 
-/* template */
-static struct switch_dev athdev = {
-       .name = "Atheros AR8216",
-       .cpu_port = AR8216_PORT_CPU,
-       .ports = AR8216_NUM_PORTS,
-       .vlans = AR8216_NUM_VLANS,
-       .attr_global = {
-               .attr = ar8216_globals,
-               .n_attr = ARRAY_SIZE(ar8216_globals),
-       },
-       .attr_port = {
-               .attr = ar8216_port,
-               .n_attr = ARRAY_SIZE(ar8216_port),
-       },
-       .attr_vlan = {
-               .attr = ar8216_vlan,
-               .n_attr = ARRAY_SIZE(ar8216_vlan),
-       },
-       .get_port_pvid = ar8216_get_pvid,
-       .set_port_pvid = ar8216_set_pvid,
-       .get_vlan_ports = ar8216_get_ports,
-       .set_vlan_ports = ar8216_set_ports,
-       .apply_config = ar8216_hw_apply,
-       .reset_switch = ar8216_reset_switch,
-};
-
 static struct phy_driver ar8216_driver = {
        .phy_id         = 0x004d0000,
        .name           = "Atheros AR8216/AR8316",
diff --git a/target/linux/generic-2.6/files/drivers/net/phy/ip175c.c b/target/linux/generic-2.6/files/drivers/net/phy/ip175c.c
deleted file mode 100644 (file)
index 1e83477..0000000
+++ /dev/null
@@ -1,1346 +0,0 @@
-/*
- * swconfig-ip175c.c: Swconfig configuration for IC+ IP175C switch
- *
- * Copyright (C) 2008 Patrick Horn <patrick.horn@gmail.com>
- * Copyright (C) 2008 Martin Mares <mj@ucw.cz>
- * Copyright (C) 2009 Felix Fietkau <nbd@openwrt.org>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.        See the
- * GNU General Public License for more details.
- */
-
-#include <linux/kernel.h>
-#include <linux/module.h>
-#include <linux/init.h>
-#include <linux/list.h>
-#include <linux/skbuff.h>
-#include <linux/mii.h>
-#include <linux/phy.h>
-#include <linux/delay.h>
-#include <linux/switch.h>
-
-#define MAX_VLANS 16
-#define MAX_PORTS 9
-
-typedef struct ip175c_reg {
-       u16 p;                  // phy
-       u16 m;                  // mii
-} reg;
-typedef char bitnum;
-
-#define NOTSUPPORTED {-1,-1}
-
-#define REG_SUPP(x) (((x).m != ((u16)-1)) && ((x).p != (u16)-1))
-
-/*********** CONSTANTS ***********/
-struct register_mappings {
-       char *NAME;
-       u16 MODEL_NO;                   // compare to bits 4-9 of MII register 0,3.
-       bitnum NUM_PORTS;
-       bitnum CPU_PORT;
-
-/* The default VLAN for each port.
-        Default: 0x0001 for Ports 0,1,2,3
-                 0x0002 for Ports 4,5 */
-       reg VLAN_DEFAULT_TAG_REG[MAX_PORTS];
-
-/* These ports are tagged.
-        Default: 0x00 */
-       reg ADD_TAG_REG;
-       reg REMOVE_TAG_REG;
-       bitnum ADD_TAG_BIT[MAX_PORTS];
-/* These ports are untagged.
-        Default: 0x00 (i.e. do not alter any VLAN tags...)
-        Maybe set to 0 if user disables VLANs. */
-       bitnum REMOVE_TAG_BIT[MAX_PORTS];
-
-/* Port M and Port N are on the same VLAN.
-        Default: All ports on all VLANs. */
-// Use register {29, 19+N/2}
-       reg VLAN_LOOKUP_REG;
-// Port 5 uses register {30, 18} but same as odd bits.
-       reg VLAN_LOOKUP_REG_5;          // in a different register on IP175C.
-       bitnum VLAN_LOOKUP_EVEN_BIT[MAX_PORTS];
-       bitnum VLAN_LOOKUP_ODD_BIT[MAX_PORTS];
-
-/* This VLAN corresponds to which ports.
-        Default: 0x2f,0x30,0x3f,0x3f... */
-       reg TAG_VLAN_MASK_REG;
-       bitnum TAG_VLAN_MASK_EVEN_BIT[MAX_PORTS];
-       bitnum TAG_VLAN_MASK_ODD_BIT[MAX_PORTS];
-
-       int RESET_VAL;
-       reg RESET_REG;
-
-       reg MODE_REG;
-       int MODE_VAL;
-
-/* General flags */
-       reg ROUTER_CONTROL_REG;
-       reg VLAN_CONTROL_REG;
-       bitnum TAG_VLAN_BIT;
-       bitnum ROUTER_EN_BIT;
-       bitnum NUMLAN_GROUPS_MAX;
-       bitnum NUMLAN_GROUPS_BIT;
-
-       reg MII_REGISTER_EN;
-       bitnum MII_REGISTER_EN_BIT;
-
-       // set to 1 for 178C, 0 for 175C.
-       bitnum SIMPLE_VLAN_REGISTERS;   // 175C has two vlans per register but 178C has only one.
-};
-
-static const struct register_mappings IP178C = {
-       .NAME = "IP178C",
-       .MODEL_NO = 0x18,
-       .VLAN_DEFAULT_TAG_REG = {
-               {30,3},{30,4},{30,5},{30,6},{30,7},{30,8},
-               {30,9},{30,10},{30,11},
-       },
-
-       .ADD_TAG_REG = {30,12},
-       .ADD_TAG_BIT = {0,1,2,3,4,5,6,7,8},
-       .REMOVE_TAG_REG = {30,13},
-       .REMOVE_TAG_BIT = {4,5,6,7,8,9,10,11,12},
-
-       .SIMPLE_VLAN_REGISTERS = 1,
-
-       .VLAN_LOOKUP_REG = {31,0},// +N
-       .VLAN_LOOKUP_REG_5 = NOTSUPPORTED, // not used with SIMPLE_VLAN_REGISTERS
-       .VLAN_LOOKUP_EVEN_BIT = {0,1,2,3,4,5,6,7,8},
-       .VLAN_LOOKUP_ODD_BIT = {0,1,2,3,4,5,6,7,8},
-
-       .TAG_VLAN_MASK_REG = {30,14}, // +N
-       .TAG_VLAN_MASK_EVEN_BIT = {0,1,2,3,4,5,6,7,8},
-       .TAG_VLAN_MASK_ODD_BIT = {0,1,2,3,4,5,6,7,8},
-
-       .RESET_VAL = 0x55AA,
-       .RESET_REG = {30,0},
-       .MODE_VAL = 0,
-       .MODE_REG = NOTSUPPORTED,
-
-       .ROUTER_CONTROL_REG = {30,30},
-       .ROUTER_EN_BIT = 11,
-       .NUMLAN_GROUPS_MAX = 8,
-       .NUMLAN_GROUPS_BIT = 8, // {0-2}
-
-       .VLAN_CONTROL_REG = {30,13},
-       .TAG_VLAN_BIT = 3,
-
-       .CPU_PORT = 8,
-       .NUM_PORTS = 9,
-
-       .MII_REGISTER_EN = NOTSUPPORTED,
-
-};
-
-static const struct register_mappings IP175C = {
-       .NAME = "IP175C",
-       .MODEL_NO = 0x18,
-       .VLAN_DEFAULT_TAG_REG = {
-               {29,24},{29,25},{29,26},{29,27},{29,28},{29,30},
-               NOTSUPPORTED,NOTSUPPORTED,NOTSUPPORTED
-       },
-
-       .ADD_TAG_REG = {29,23},
-       .REMOVE_TAG_REG = {29,23},
-       .ADD_TAG_BIT = {11,12,13,14,15,1,-1,-1,-1},
-       .REMOVE_TAG_BIT = {6,7,8,9,10,0,-1,-1,-1},
-
-       .SIMPLE_VLAN_REGISTERS = 0,
-
-       .VLAN_LOOKUP_REG = {29,19},// +N/2
-       .VLAN_LOOKUP_REG_5 = {30,18},
-       .VLAN_LOOKUP_EVEN_BIT = {8,9,10,11,12,15,-1,-1,-1},
-       .VLAN_LOOKUP_ODD_BIT = {0,1,2,3,4,7,-1,-1,-1},
-
-       .TAG_VLAN_MASK_REG = {30,1}, // +N/2
-       .TAG_VLAN_MASK_EVEN_BIT = {0,1,2,3,4,5,-1,-1,-1},
-       .TAG_VLAN_MASK_ODD_BIT = {8,9,10,11,12,13,-1,-1,-1},
-
-       .RESET_VAL = 0x175C,
-       .RESET_REG = {30,0},
-       .MODE_VAL = 0x175C,
-       .MODE_REG = {29,31},
-
-       .ROUTER_CONTROL_REG = {30,9},
-       .ROUTER_EN_BIT = 3,
-       .NUMLAN_GROUPS_MAX = 8,
-       .NUMLAN_GROUPS_BIT = 0, // {0-2}
-
-       .VLAN_CONTROL_REG = {30,9},
-       .TAG_VLAN_BIT = 7,
-
-       .NUM_PORTS = 6,
-       .CPU_PORT = 5,
-
-       .MII_REGISTER_EN = NOTSUPPORTED,
-
-};
-
-static const struct register_mappings IP175A = {
-       .NAME = "IP175A",
-       .MODEL_NO = 0x05,
-       .VLAN_DEFAULT_TAG_REG = {
-               {0,24},{0,25},{0,26},{0,27},{0,28},NOTSUPPORTED,
-               NOTSUPPORTED,NOTSUPPORTED,NOTSUPPORTED
-       },
-
-       .ADD_TAG_REG = {0,23},
-       .REMOVE_TAG_REG = {0,23},
-       .ADD_TAG_BIT = {11,12,13,14,15,-1,-1,-1,-1},
-       .REMOVE_TAG_BIT = {6,7,8,9,10,-1,-1,-1,-1},
-
-       .SIMPLE_VLAN_REGISTERS = 0,
-
-       // Register 19-21 documentation is missing/contradictory.
-       // For registers 19-21 ports need to be: even numbers to MSB, odd to LSB.
-       // This contradicts text for ROM registers, but follows logic of CoS bits.
-
-       .VLAN_LOOKUP_REG = {0,19},// +N/2
-       .VLAN_LOOKUP_REG_5 = NOTSUPPORTED,
-       .VLAN_LOOKUP_EVEN_BIT = {8,9,10,11,12,-1,-1,-1,-1},
-       .VLAN_LOOKUP_ODD_BIT = {0,1,2,3,4,-1,-1,-1,-1},
-
-       .TAG_VLAN_MASK_REG = NOTSUPPORTED, // +N/2,
-       .TAG_VLAN_MASK_EVEN_BIT = {-1,-1,-1,-1,-1,-1,-1,-1,-1},
-       .TAG_VLAN_MASK_ODD_BIT = {-1,-1,-1,-1,-1,-1,-1,-1,-1},
-
-       .RESET_VAL = -1,
-       .RESET_REG = NOTSUPPORTED,
-       .MODE_VAL = 0,
-       .MODE_REG = NOTSUPPORTED,
-
-       .ROUTER_CONTROL_REG = NOTSUPPORTED,
-       .VLAN_CONTROL_REG = NOTSUPPORTED,
-       .TAG_VLAN_BIT = -1,
-       .ROUTER_EN_BIT = -1,
-       .NUMLAN_GROUPS_MAX = -1,
-       .NUMLAN_GROUPS_BIT = -1, // {0-2}
-
-       .NUM_PORTS = 5,
-       .CPU_PORT = 4,
-
-       .MII_REGISTER_EN = {0, 18},
-       .MII_REGISTER_EN_BIT = 7,
-};
-
-
-struct ip175c_state {
-       struct switch_dev dev;
-       struct mii_bus *mii_bus;
-       bool registered;
-
-       int router_mode;                // ROUTER_EN
-       int vlan_enabled;               // TAG_VLAN_EN
-       struct port_state {
-               u16 pvid;
-               unsigned int shareports;
-       } ports[MAX_PORTS];
-       unsigned int add_tag;
-       unsigned int remove_tag;
-       int num_vlans;
-       unsigned int vlan_ports[MAX_VLANS];
-       const struct register_mappings *regs;
-       reg proc_mii; /*!< phy/reg for the low level register access via /proc */
-
-       char buf[80];
-};
-
-static int ip_phy_read(struct mii_bus *bus, int port, int reg)
-{
-       int val;
-
-       mutex_lock(&bus->mdio_lock);
-       val = bus->read(bus, port, reg);
-       mutex_unlock(&bus->mdio_lock);
-
-       return val;
-}
-
-
-static int ip_phy_write(struct mii_bus *bus, int port, int reg, u16 val)
-{
-       int err;
-
-       mutex_lock(&bus->mdio_lock);
-       err = bus->write(bus, port, reg, val);
-       mutex_unlock(&bus->mdio_lock);
-
-       return err;
-}
-
-
-static int getPhy (struct ip175c_state *state, reg mii)
-{
-       struct mii_bus *bus = state->mii_bus;
-       int val;
-
-       if (!REG_SUPP(mii))
-               return -EFAULT;
-
-       val = ip_phy_read(bus, mii.p, mii.m);
-       if (val < 0)
-               pr_warning("IP175C: Unable to get MII register %d,%d: error %d\n", mii.p,mii.m,-val);
-
-       return val;
-}
-
-static int setPhy (struct ip175c_state *state, reg mii, u16 value)
-{
-       struct mii_bus *bus = state->mii_bus;
-       int err;
-
-       if (!REG_SUPP(mii))
-               return -EFAULT;
-
-       err = ip_phy_write(bus, mii.p, mii.m, value);
-       if (err < 0) {
-               pr_warning("IP175C: Unable to set MII register %d,%d to %d: error %d\n", mii.p,mii.m,value,-err);
-               return err;
-       }
-       mdelay(2);
-       getPhy(state, mii);
-       return 0;
-}
-
-/**
- * These two macros are to simplify the mapping of logical bits to the bits in hardware.
- * NOTE: these macros will return if there is an error!
- */
-
-#define GET_PORT_BITS(state, bits, addr, bit_lookup)           \
-       do {                                                    \
-               int i, val = getPhy((state), (addr));           \
-               if (val < 0)                                    \
-                       return val;                             \
-               (bits) = 0;                                     \
-               for (i = 0; i < MAX_PORTS; i++) {               \
-                       if ((bit_lookup)[i] == -1) continue;    \
-                       if (val & (1<<(bit_lookup)[i]))         \
-                               (bits) |= (1<<i);               \
-               }                                               \
-       } while (0)
-
-#define SET_PORT_BITS(state, bits, addr, bit_lookup)           \
-       do {                                                    \
-               int i, val = getPhy((state), (addr));           \
-               if (val < 0)                                    \
-                       return val;                             \
-               for (i = 0; i < MAX_PORTS; i++) {               \
-                       unsigned int newmask = ((bits)&(1<<i)); \
-                       if ((bit_lookup)[i] == -1) continue;    \
-                       val &= ~(1<<(bit_lookup)[i]);           \
-                       val |= ((newmask>>i)<<(bit_lookup)[i]); \
-               }                                               \
-               val = setPhy((state), (addr), val);             \
-               if (val < 0)                                    \
-                       return val;                             \
-       } while (0)
-
-static int get_model(struct ip175c_state *state)
-{
-       reg oui_id_reg = {0, 2};
-       int oui_id;
-       reg model_no_reg = {0, 3};
-       int model_no, model_no_orig;
-
-       // 175 and 178 have the same oui ID.
-       reg oui_id_reg_178c = {5, 2}; // returns error on IP175C.
-       int is_178c = 0;
-
-       oui_id = getPhy(state, oui_id_reg);
-       if (oui_id != 0x0243) {
-               // non
-               return -ENODEV; // Not a IC+ chip.
-       }
-       oui_id = getPhy(state, oui_id_reg_178c);
-       if (oui_id == 0x0243) {
-               is_178c = 1;
-       }
-
-       model_no_orig = getPhy(state, model_no_reg);
-       if (model_no_orig < 0) {
-               return -ENODEV;
-       }
-       model_no = model_no_orig >> 4; // shift out revision number.
-       model_no &= 0x3f; // only take the model number (low 6 bits).
-       if (model_no == IP175A.MODEL_NO) {
-               state->regs = &IP175A;
-       } else if (model_no == IP175C.MODEL_NO) {
-               if (is_178c) {
-                       state->regs = &IP178C;
-               } else {
-                       state->regs = &IP175C;
-               }
-       } else {
-               printk(KERN_WARNING "ip175c: Found an unknown IC+ switch with model number %02Xh.\n", model_no_orig);
-               return -EPERM;
-       }
-       return 0;
-}
-
-/** Get only the vlan and router flags on the router **/
-static int get_flags(struct ip175c_state *state)
-{
-       int val;
-
-       state->router_mode = 0;
-       state->vlan_enabled = -1; // hack
-       state->num_vlans = 0;
-
-       if (!REG_SUPP(state->regs->ROUTER_CONTROL_REG)) {
-               return 0; // not an error if it doesn't support enable vlan.
-       }
-
-       val = getPhy(state, state->regs->ROUTER_CONTROL_REG);
-       if (val < 0) {
-               return val;
-       }
-       if (state->regs->ROUTER_EN_BIT >= 0)
-               state->router_mode = ((val>>state->regs->ROUTER_EN_BIT) & 1);
-
-       if (state->regs->NUMLAN_GROUPS_BIT >= 0) {
-               state->num_vlans = (val >> state->regs->NUMLAN_GROUPS_BIT);
-               state->num_vlans &= (state->regs->NUMLAN_GROUPS_MAX-1);
-               state->num_vlans+=1; // does not include WAN.
-       }
-
-
-       val = getPhy(state, state->regs->VLAN_CONTROL_REG);
-       if (val < 0) {
-               return 0;
-       }
-       if (state->regs->TAG_VLAN_BIT >= 0)
-               state->vlan_enabled = ((val>>state->regs->TAG_VLAN_BIT) & 1);
-
-       return  0;
-}
-/** Get all state variables for VLAN mappings and port-based tagging. **/
-static int get_state(struct ip175c_state *state)
-{
-       int i, j;
-       int ret;
-       ret = get_flags(state);
-       if (ret < 0) {
-               return ret;
-       }
-       GET_PORT_BITS(state, state->remove_tag,
-                                 state->regs->REMOVE_TAG_REG, state->regs->REMOVE_TAG_BIT);
-       GET_PORT_BITS(state, state->add_tag,
-                                 state->regs->ADD_TAG_REG, state->regs->ADD_TAG_BIT);
-
-       if (state->vlan_enabled == -1) {
-               // not sure how to get this...
-               state->vlan_enabled = (state->remove_tag || state->add_tag);
-       }
-
-       if (REG_SUPP(state->regs->VLAN_LOOKUP_REG)) {
-       for (j=0; j<MAX_PORTS; j++) {
-               state->ports[j].shareports = 0; // initialize them in case.
-       }
-       for (j=0; j<state->regs->NUM_PORTS; j++) {
-               reg addr;
-               const bitnum *bit_lookup = (j%2==0)?
-                       state->regs->VLAN_LOOKUP_EVEN_BIT:
-                       state->regs->VLAN_LOOKUP_ODD_BIT;
-               addr = state->regs->VLAN_LOOKUP_REG;
-               if (state->regs->SIMPLE_VLAN_REGISTERS) {
-                       addr.m += j;
-               } else {
-                       switch (j) {
-                       case 0:
-                       case 1:
-                               break;
-                       case 2:
-                       case 3:
-                               addr.m+=1;
-                               break;
-                       case 4:
-                               addr.m+=2;
-                               break;
-                       case 5:
-                               addr = state->regs->VLAN_LOOKUP_REG_5;
-                               break;
-                       }
-               }
-
-               if (REG_SUPP(addr)) {
-                       GET_PORT_BITS(state, state->ports[j].shareports, addr, bit_lookup);
-               }
-       }
-       } else {
-               for (j=0; j<MAX_PORTS; j++) {
-                       state->ports[j].shareports = 0xff;
-               }
-       }
-
-       for (i=0; i<MAX_PORTS; i++) {
-               if (REG_SUPP(state->regs->VLAN_DEFAULT_TAG_REG[i])) {
-                       int val = getPhy(state, state->regs->VLAN_DEFAULT_TAG_REG[i]);
-                       if (val < 0) {
-                               return val;
-                       }
-                       state->ports[i].pvid = val;
-               } else {
-                       state->ports[i].pvid = 0;
-               }
-       }
-
-       if (REG_SUPP(state->regs->TAG_VLAN_MASK_REG)) {
-               for (j=0; j<MAX_VLANS; j++) {
-                       reg addr = state->regs->TAG_VLAN_MASK_REG;
-                       const bitnum *bit_lookup = (j%2==0)?
-                               state->regs->TAG_VLAN_MASK_EVEN_BIT:
-                               state->regs->TAG_VLAN_MASK_ODD_BIT;
-                       if (state->regs->SIMPLE_VLAN_REGISTERS) {
-                               addr.m += j;
-                       } else {
-                               addr.m += j/2;
-                       }
-                       GET_PORT_BITS(state, state->vlan_ports[j], addr, bit_lookup);
-               }
-       } else {
-               for (j=0; j<MAX_VLANS; j++) {
-                       state->vlan_ports[j] = 0;
-                       for (i=0; i<state->regs->NUM_PORTS; i++) {
-                               if ((state->ports[i].pvid == j) ||
-                                               (state->ports[i].pvid == 0)) {
-                                       state->vlan_ports[j] |= (1<<i);
-                               }
-                       }
-               }
-       }
-
-       return 0;
-}
-
-
-/** Only update vlan and router flags in the switch **/
-static int update_flags(struct ip175c_state *state)
-{
-       int val;
-
-       if (!REG_SUPP(state->regs->ROUTER_CONTROL_REG)) {
-               return 0;
-       }
-
-       val = getPhy(state, state->regs->ROUTER_CONTROL_REG);
-       if (val < 0) {
-               return val;
-       }
-       if (state->regs->ROUTER_EN_BIT >= 0) {
-               if (state->router_mode) {
-                       val |= (1<<state->regs->ROUTER_EN_BIT);
-               } else {
-                       val &= (~(1<<state->regs->ROUTER_EN_BIT));
-               }
-       }
-       if (state->regs->TAG_VLAN_BIT >= 0) {
-               if (state->vlan_enabled) {
-                       val |= (1<<state->regs->TAG_VLAN_BIT);
-               } else {
-                       val &= (~(1<<state->regs->TAG_VLAN_BIT));
-               }
-       }
-       if (state->regs->NUMLAN_GROUPS_BIT >= 0) {
-               val &= (~((state->regs->NUMLAN_GROUPS_MAX-1)<<state->regs->NUMLAN_GROUPS_BIT));
-               if (state->num_vlans > state->regs->NUMLAN_GROUPS_MAX) {
-                       val |= state->regs->NUMLAN_GROUPS_MAX << state->regs->NUMLAN_GROUPS_BIT;
-               } else if (state->num_vlans >= 1) {
-                       val |= (state->num_vlans-1) << state->regs->NUMLAN_GROUPS_BIT;
-               }
-       }
-       return setPhy(state, state->regs->ROUTER_CONTROL_REG, val);
-}
-
-/** Update all VLAN and port state.  Usually you should call "correct_vlan_state" first. **/
-static int update_state(struct ip175c_state *state)
-{
-       int j;
-       int i;
-       SET_PORT_BITS(state, state->add_tag,
-                                 state->regs->ADD_TAG_REG, state->regs->ADD_TAG_BIT);
-       SET_PORT_BITS(state, state->remove_tag,
-                                 state->regs->REMOVE_TAG_REG, state->regs->REMOVE_TAG_BIT);
-
-       if (REG_SUPP(state->regs->VLAN_LOOKUP_REG)) {
-       for (j=0; j<state->regs->NUM_PORTS; j++) {
-               reg addr;
-               const bitnum *bit_lookup = (j%2==0)?
-                       state->regs->VLAN_LOOKUP_EVEN_BIT:
-                       state->regs->VLAN_LOOKUP_ODD_BIT;
-
-               // duplicate code -- sorry
-               addr = state->regs->VLAN_LOOKUP_REG;
-               if (state->regs->SIMPLE_VLAN_REGISTERS) {
-                       addr.m += j;
-               } else {
-                       switch (j) {
-                       case 0:
-                       case 1:
-                               break;
-                       case 2:
-                       case 3:
-                               addr.m+=1;
-                               break;
-                       case 4:
-                               addr.m+=2;
-                               break;
-                       case 5:
-                               addr = state->regs->VLAN_LOOKUP_REG_5;
-                               break;
-                       default:
-                               addr.m = -1; // shouldn't get here, but...
-                               break;
-                       }
-               }
-               //printf("shareports for %d is %02X\n",j,state->ports[j].shareports);
-               if (REG_SUPP(addr)) {
-                       SET_PORT_BITS(state, state->ports[j].shareports, addr, bit_lookup);
-               }
-       }
-       }
-       if (REG_SUPP(state->regs->TAG_VLAN_MASK_REG)) {
-       for (j=0; j<MAX_VLANS; j++) {
-               reg addr = state->regs->TAG_VLAN_MASK_REG;
-               const bitnum *bit_lookup = (j%2==0)?
-                       state->regs->TAG_VLAN_MASK_EVEN_BIT:
-                       state->regs->TAG_VLAN_MASK_ODD_BIT;
-               unsigned int vlan_mask;
-               if (state->regs->SIMPLE_VLAN_REGISTERS) {
-                       addr.m += j;
-               } else {
-                       addr.m += j/2;
-               }
-               vlan_mask = state->vlan_ports[j];
-               SET_PORT_BITS(state, vlan_mask, addr, bit_lookup);
-       }
-       }
-
-       for (i=0; i<MAX_PORTS; i++) {
-               if (REG_SUPP(state->regs->VLAN_DEFAULT_TAG_REG[i])) {
-                       int err = setPhy(state, state->regs->VLAN_DEFAULT_TAG_REG[i],
-                                       state->ports[i].pvid);
-                       if (err < 0) {
-                               return err;
-                       }
-               }
-       }
-
-       return update_flags(state);
-
-       // software reset: 30.0 = 0x175C
-       // wait 2ms
-       // reset ports 0,1,2,3,4
-}
-
-/*
-  Uses only the VLAN port mask and the add tag mask to generate the other fields:
-  which ports are part of the same VLAN, removing vlan tags, and VLAN tag ids.
- */
-static void correct_vlan_state(struct ip175c_state *state)
-{
-       int i, j;
-       state->num_vlans = 0;
-       for (i=0; i<MAX_VLANS; i++) {
-               if (state->vlan_ports[i] != 0) {
-                       state->num_vlans = i+1; //hack -- we need to store the "set" vlans somewhere...
-               }
-       }
-
-
-
-       for (i=0; i<state->regs->NUM_PORTS; i++) {
-               unsigned int portmask = (1<<i);
-               if (!state->vlan_enabled) {
-                       // share with everybody!
-                       state->ports[i].shareports = (1<<state->regs->NUM_PORTS)-1;
-                       continue;
-               }
-               state->ports[i].shareports = portmask;
-               for (j=0; j<MAX_VLANS; j++) {
-                       if (state->vlan_ports[j] & portmask)
-                               state->ports[i].shareports |= state->vlan_ports[j];
-               }
-       }
-       state->remove_tag = ((~state->add_tag) & ((1<<state->regs->NUM_PORTS)-1));
-}
-
-static int ip175c_get_enable_vlan(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val)
-{
-       struct ip175c_state *state = dev->priv;
-       int err;
-
-       err = get_state(state); // may be set in get_state.
-       if (err < 0)
-               return err;
-       val->value.i = state->vlan_enabled;
-       return 0;
-}
-
-static int ip175c_set_enable_vlan(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val)
-{
-       struct ip175c_state *state = dev->priv;
-       int err;
-       int enable;
-       int i;
-
-       err = get_state(state);
-       if (err < 0)
-               return err;
-       enable = val->value.i;
-
-       if (state->vlan_enabled == enable) {
-               // do not change any state.
-               return 0;
-       }
-       state->vlan_enabled = enable;
-
-       // Otherwise, if we are switching state, set fields to a known default.
-       state->remove_tag = 0x0000;
-       state->add_tag = 0x0000;
-       for (i = 0; i < MAX_PORTS; i++)
-               state->ports[i].shareports = 0xffff;
-
-       for (i = 0; i < MAX_VLANS; i++)
-               state->vlan_ports[i] = 0x0;
-
-       if (state->vlan_enabled) {
-               // updates other fields only based off vlan_ports and add_tag fields.
-               // Note that by default, no ports are in any vlans.
-               correct_vlan_state(state);
-       }
-       // ensure sane defaults?
-       return update_state(state);
-}
-
-static int ip175c_get_ports(struct switch_dev *dev, struct switch_val *val)
-{
-       struct ip175c_state *state = dev->priv;
-       int err;
-       int b;
-       int ind;
-       unsigned int ports;
-
-       if (val->port_vlan >= dev->vlans || val->port_vlan < 0)
-               return -EINVAL;
-
-       err = get_state(state);
-       if (err<0)
-               return err;
-
-       ports = state->vlan_ports[val->port_vlan];
-       b = 0;
-       ind = 0;
-       while (b < MAX_PORTS) {
-               if (ports&1) {
-                       int istagged = ((state->add_tag >> b) & 1);
-                       val->value.ports[ind].id = b;
-                       val->value.ports[ind].flags = (istagged << SWITCH_PORT_FLAG_TAGGED);
-                       ind++;
-               }
-               b++;
-               ports >>= 1;
-       }
-       val->len = ind;
-
-       return 0;
-}
-
-static int ip175c_set_ports(struct switch_dev *dev, struct switch_val *val)
-{
-       struct ip175c_state *state = dev->priv;
-       int i;
-       int err;
-
-       if (val->port_vlan >= dev->vlans || val->port_vlan < 0)
-               return -EINVAL;
-
-       err = get_state(state);
-       if (err < 0)
-               return err;
-
-       state->vlan_ports[val->port_vlan] = 0;
-       for (i = 0; i < val->len; i++) {
-               int bitmask = (1<<val->value.ports[i].id);
-               state->vlan_ports[val->port_vlan] |= bitmask;
-               if (val->value.ports[i].flags & (1<<SWITCH_PORT_FLAG_TAGGED)) {
-                       state->add_tag |= bitmask;
-               } else {
-                       state->add_tag &= (~bitmask);
-               }
-       }
-
-       correct_vlan_state(state);
-       err = update_state(state);
-
-       return err;
-}
-
-static int ip175c_apply(struct switch_dev *dev)
-{
-       struct ip175c_state *state = dev->priv;
-       int err;
-
-       err = get_flags(state);
-       if (err < 0)
-               return err;
-
-       if (REG_SUPP(state->regs->MII_REGISTER_EN)){
-               int val = getPhy(state, state->regs->MII_REGISTER_EN);
-               if (val < 0) {
-                       return val;
-               }
-               val |= (1<<state->regs->MII_REGISTER_EN_BIT);
-               return setPhy(state, state->regs->MII_REGISTER_EN, val);
-       }
-       return 0;
-}
-
-static int ip175c_reset(struct switch_dev *dev)
-{
-       struct ip175c_state *state = dev->priv;
-       int i, err;
-
-       err = get_flags(state);
-       if (err < 0)
-               return err;
-
-       if (REG_SUPP(state->regs->RESET_REG)) {
-               err = setPhy(state, state->regs->RESET_REG, state->regs->RESET_VAL);
-               if (err < 0)
-                       return err;
-               err = getPhy(state, state->regs->RESET_REG);
-
-               /* data sheet specifies reset period is 2 msec
-                  (don't see any mention of the 2ms delay in the IP178C spec, only
-                   in IP175C, but it can't hurt.) */
-               mdelay(2);
-       }
-
-       if (REG_SUPP(state->regs->MODE_REG)) {
-               err = setPhy(state, state->regs->MODE_REG, state->regs->RESET_VAL);
-               if (err < 0)
-                       return err;
-               err = getPhy(state, state->regs->MODE_REG);
-       }
-
-       if (REG_SUPP(state->regs->RESET_REG)) {
-               /* reset external phy ports, except on IP175A */
-               for (i = 0; i < state->regs->NUM_PORTS-1; i++) {
-                       err = state->mii_bus->write(state->mii_bus, i,
-                                                MII_BMCR, BMCR_RESET);
-                       if (err < 0)
-                               return err;
-               }
-       }
-
-       return 0;
-}
-
-/*! get the current register number */
-static int ip175c_get_tagged(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val)
-{
-       struct ip175c_state *state = dev->priv;
-       int err;
-
-       err = get_state(state);
-       if (err < 0)
-               return err;
-
-       if (state->add_tag & (1<<val->port_vlan)) {
-               if (state->remove_tag & (1<<val->port_vlan))
-                       val->value.i = 3; // shouldn't ever happen.
-               else
-                       val->value.i = 1;
-       } else {
-               if (state->remove_tag & (1<<val->port_vlan))
-                       val->value.i = 0;
-               else
-                       val->value.i = 2;
-       }
-       return 0;
-}
-
-/*! set a new register address for low level access to registers */
-static int ip175c_set_tagged(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val)
-{
-       struct ip175c_state *state = dev->priv;
-       int err;
-
-       err = get_state(state);
-       if (err < 0)
-               return err;
-
-       state->add_tag &= ~(1<<val->port_vlan);
-       state->remove_tag &= ~(1<<val->port_vlan);
-
-       if (val->value.i == 0)
-               state->remove_tag |= (1<<val->port_vlan);
-       if (val->value.i == 1)
-               state->add_tag |= (1<<val->port_vlan);
-
-       SET_PORT_BITS(state, state->add_tag,
-                                 state->regs->ADD_TAG_REG, state->regs->ADD_TAG_BIT);
-       SET_PORT_BITS(state, state->remove_tag,
-                                 state->regs->REMOVE_TAG_REG, state->regs->REMOVE_TAG_BIT);
-
-       return err;
-}
-
-
-/* low level /proc procedures */
-
-/*! get the current phy address */
-static int ip175c_get_phy(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val)
-{
-       struct ip175c_state *state = dev->priv;
-
-       val->value.i = state->proc_mii.p;
-       return 0;
-}
-
-/*! set a new phy address for low level access to registers */
-static int ip175c_set_phy(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val)
-{
-       struct ip175c_state *state = dev->priv;
-       int new_reg = val->value.i;
-
-       if (new_reg < 0 || new_reg > 31)
-               state->proc_mii.p = (u16)-1;
-       else
-               state->proc_mii.p = (u16)new_reg;
-       return 0;
-}
-
-/*! get the current register number */
-static int ip175c_get_reg(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val)
-{
-       struct ip175c_state *state = dev->priv;
-
-       val->value.i = state->proc_mii.m;
-       return 0;
-}
-
-/*! set a new register address for low level access to registers */
-static int ip175c_set_reg(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val)
-{
-       struct ip175c_state *state = dev->priv;
-       int new_reg = val->value.i;
-
-       if (new_reg < 0 || new_reg > 31)
-               state->proc_mii.m = (u16)-1;
-       else
-               state->proc_mii.m = (u16)new_reg;
-       return 0;
-}
-
-/*! get the register content of state->proc_mii */
-static int ip175c_get_val(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val)
-{
-       struct ip175c_state *state = dev->priv;
-       int retval = -EINVAL;
-       if (REG_SUPP(state->proc_mii))
-               retval = getPhy(state, state->proc_mii);
-
-       if (retval < 0) {
-               return retval;
-       } else {
-               val->value.i = retval;
-               return 0;
-       }
-}
-
-/*! write a value to the register defined by phy/reg above */
-static int ip175c_set_val(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val)
-{
-       struct ip175c_state *state = dev->priv;
-       int myval, err = 0;
-
-       myval = val->value.i;
-       if (myval <= 0xffff && myval >= 0 && REG_SUPP(state->proc_mii)) {
-               err = setPhy(state, state->proc_mii, (u16)myval);
-       }
-       return err;
-}
-
-static int ip175c_read_name(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val)
-{
-       struct ip175c_state *state = dev->priv;
-       val->value.s = state->regs->NAME; // just a const pointer, won't be freed by swconfig.
-       return 0;
-}
-
-
-static int ip175c_set_port_speed(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val)
-{
-       struct ip175c_state *state = dev->priv;
-       struct mii_bus *bus = state->mii_bus;
-       int nr = val->port_vlan;
-       int ctrl;
-       int autoneg;
-       int speed;
-       if (val->value.i == 100) {
-               speed = 1;
-               autoneg = 0;
-       } else if (val->value.i == 10) {
-               speed = 0;
-               autoneg = 0;
-       } else {
-               autoneg = 1;
-               speed = 1;
-       }
-
-       /* can't set speed for cpu port */
-       if (nr == state->regs->CPU_PORT)
-               return -EINVAL;
-
-       if (nr >= dev->ports || nr < 0)
-               return -EINVAL;
-
-       ctrl = ip_phy_read(bus, nr, 0);
-       if (ctrl < 0)
-               return -EIO;
-
-       ctrl &= (~(1<<12));
-       ctrl &= (~(1<<13));
-       ctrl |= (autoneg<<12);
-       ctrl |= (speed<<13);
-
-       return ip_phy_write(bus, nr, 0, ctrl);
-}
-
-static int ip175c_get_port_speed(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val)
-{
-       struct ip175c_state *state = dev->priv;
-       struct mii_bus *bus = state->mii_bus;
-       int nr = val->port_vlan;
-       int speed, status;
-
-       if (nr == state->regs->CPU_PORT) {
-               val->value.i = 100;
-               return 0;
-       }
-
-       if (nr >= dev->ports || nr < 0)
-               return -EINVAL;
-
-       status = ip_phy_read(bus, nr, 1);
-       speed = ip_phy_read(bus, nr, 18);
-       if (status < 0 || speed < 0)
-               return -EIO;
-
-       if (status & 4)
-               val->value.i = ((speed & (1<<11)) ? 100 : 10);
-       else
-               val->value.i = 0;
-
-       return 0;
-}
-
-
-static int ip175c_get_port_status(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val)
-{
-       struct ip175c_state *state = dev->priv;
-       struct mii_bus *bus = state->mii_bus;
-       int ctrl, speed, status;
-       int nr = val->port_vlan;
-       int len;
-       char *buf = state->buf; // fixed-length at 80.
-
-       if (nr == state->regs->CPU_PORT) {
-               sprintf(buf, "up, 100 Mbps, cpu port");
-               val->value.s = buf;
-               return 0;
-       }
-
-       if (nr >= dev->ports || nr < 0)
-               return -EINVAL;
-
-       ctrl = ip_phy_read(bus, nr, 0);
-       status = ip_phy_read(bus, nr, 1);
-       speed = ip_phy_read(bus, nr, 18);
-       if (ctrl < 0 || status < 0 || speed < 0)
-               return -EIO;
-
-       if (status & 4)
-               len = sprintf(buf, "up, %d Mbps, %s duplex",
-                       ((speed & (1<<11)) ? 100 : 10),
-                       ((speed & (1<<10)) ? "full" : "half"));
-       else
-               len = sprintf(buf, "down");
-
-       if (ctrl & (1<<12)) {
-               len += sprintf(buf+len, ", auto-negotiate");
-               if (!(status & (1<<5)))
-                       len += sprintf(buf+len, " (in progress)");
-       } else {
-               len += sprintf(buf+len, ", fixed speed (%d)",
-                       ((ctrl & (1<<13)) ? 100 : 10));
-       }
-
-       buf[len] = '\0';
-       val->value.s = buf;
-       return 0;
-}
-
-static int ip175c_get_pvid(struct switch_dev *dev, int port, int *val)
-{
-       struct ip175c_state *state = dev->priv;
-
-       *val = state->ports[port].pvid;
-       return 0;
-}
-
-static int ip175c_set_pvid(struct switch_dev *dev, int port, int val)
-{
-       struct ip175c_state *state = dev->priv;
-
-       state->ports[port].pvid = val;
-
-       if (!REG_SUPP(state->regs->VLAN_DEFAULT_TAG_REG[port]))
-               return 0;
-
-       return setPhy(state, state->regs->VLAN_DEFAULT_TAG_REG[port], val);
-}
-
-
-enum Ports {
-       IP175C_PORT_STATUS,
-       IP175C_PORT_LINK,
-       IP175C_PORT_TAGGED,
-       IP175C_PORT_PVID,
-};
-
-enum Globals {
-       IP175C_ENABLE_VLAN,
-       IP175C_GET_NAME,
-       IP175C_REGISTER_PHY,
-       IP175C_REGISTER_MII,
-       IP175C_REGISTER_VALUE,
-       IP175C_REGISTER_ERRNO,
-};
-
-static const struct switch_attr ip175c_global[] = {
-       [IP175C_ENABLE_VLAN] = {
-               .id = IP175C_ENABLE_VLAN,
-               .type = SWITCH_TYPE_INT,
-               .name  = "enable_vlan",
-               .description = "Flag to enable or disable VLANs and tagging",
-               .get  = ip175c_get_enable_vlan,
-               .set = ip175c_set_enable_vlan,
-       },
-       [IP175C_GET_NAME] = {
-               .id = IP175C_GET_NAME,
-               .type = SWITCH_TYPE_STRING,
-               .description = "Returns the type of IC+ chip.",
-               .name  = "name",
-               .get  = ip175c_read_name,
-               .set = NULL,
-       },
-       /* jal: added for low level debugging etc. */
-       [IP175C_REGISTER_PHY] = {
-               .id = IP175C_REGISTER_PHY,
-               .type = SWITCH_TYPE_INT,
-               .description = "Direct register access: set phy (0-4, or 29,30,31)",
-               .name  = "phy",
-               .get  = ip175c_get_phy,
-               .set = ip175c_set_phy,
-       },
-       [IP175C_REGISTER_MII] = {
-               .id = IP175C_REGISTER_MII,
-               .type = SWITCH_TYPE_INT,
-               .description = "Direct register access: set mii number (0-31)",
-               .name  = "reg",
-               .get  = ip175c_get_reg,
-               .set = ip175c_set_reg,
-       },
-       [IP175C_REGISTER_VALUE] = {
-               .id = IP175C_REGISTER_VALUE,
-               .type = SWITCH_TYPE_INT,
-               .description = "Direct register access: read/write to register (0-65535)",
-               .name  = "val",
-               .get  = ip175c_get_val,
-               .set = ip175c_set_val,
-       },
-};
-
-static const struct switch_attr ip175c_vlan[] = {
-};
-
-static const struct switch_attr ip175c_port[] = {
-       [IP175C_PORT_STATUS] = {
-               .id = IP175C_PORT_STATUS,
-               .type = SWITCH_TYPE_STRING,
-               .description = "Returns Detailed port status",
-               .name  = "status",
-               .get  = ip175c_get_port_status,
-               .set = NULL,
-       },
-       [IP175C_PORT_LINK] = {
-               .id = IP175C_PORT_LINK,
-               .type = SWITCH_TYPE_INT,
-               .description = "Link speed. Can write 0 for auto-negotiate, or 10 or 100",
-               .name  = "link",
-               .get  = ip175c_get_port_speed,
-               .set = ip175c_set_port_speed,
-       },
-       [IP175C_PORT_TAGGED] = {
-               .id = IP175C_PORT_LINK,
-               .type = SWITCH_TYPE_INT,
-               .description = "0 = untag, 1 = add tags, 2 = do not alter (This value is reset if vlans are altered)",
-               .name  = "tagged",
-               .get  = ip175c_get_tagged,
-               .set = ip175c_set_tagged,
-       },
-};
-
-static int ip175c_probe(struct phy_device *pdev)
-{
-       struct ip175c_state *state;
-       struct switch_dev *dev;
-       int err;
-
-       /* we only attach to PHY 0, but use all available PHYs */
-       if (pdev->addr != 0)
-               return -ENODEV;
-
-       state = kzalloc(sizeof(*state), GFP_KERNEL);
-       if (!state)
-               return -ENOMEM;
-
-       dev = &state->dev;
-       dev->attr_global.attr = ip175c_global;
-       dev->attr_global.n_attr = ARRAY_SIZE(ip175c_global);
-       dev->attr_port.attr = ip175c_port;
-       dev->attr_port.n_attr = ARRAY_SIZE(ip175c_port);
-       dev->attr_vlan.attr = ip175c_vlan;
-       dev->attr_vlan.n_attr = ARRAY_SIZE(ip175c_vlan);
-
-       dev->get_port_pvid = ip175c_get_pvid;
-       dev->set_port_pvid = ip175c_set_pvid;
-       dev->get_vlan_ports = ip175c_get_ports;
-       dev->set_vlan_ports = ip175c_set_ports;
-       dev->apply_config = ip175c_apply;
-       dev->reset_switch = ip175c_reset;
-
-       dev->priv = state;
-       pdev->priv = state;
-       state->mii_bus = pdev->bus;
-
-       err = get_model(state);
-       if (err < 0)
-               goto error;
-
-       dev->vlans = MAX_VLANS;
-       dev->cpu_port = state->regs->CPU_PORT;
-       dev->ports = state->regs->NUM_PORTS;
-       dev->name = state->regs->NAME;
-
-       return 0;
-
-error:
-       kfree(state);
-       return err;
-}
-
-static int ip175c_config_init(struct phy_device *pdev)
-{
-       struct ip175c_state *state = pdev->priv;
-       struct net_device *dev = pdev->attached_dev;
-       int err;
-
-       pdev->irq = PHY_IGNORE_INTERRUPT;
-       err = register_switch(&state->dev, dev);
-       if (err < 0)
-               return err;
-
-       ip175c_reset(&state->dev);
-
-       state->registered = true;
-       netif_carrier_on(pdev->attached_dev);
-
-       return 0;
-}
-
-static void ip175c_remove(struct phy_device *pdev)
-{
-       struct ip175c_state *state = pdev->priv;
-
-       if (state->registered)
-               unregister_switch(&state->dev);
-       kfree(state);
-}
-
-static int ip175c_config_aneg(struct phy_device *pdev)
-{
-       return 0;
-}
-
-static int ip175c_read_status(struct phy_device *pdev)
-{
-       pdev->speed = SPEED_100;
-       pdev->duplex = DUPLEX_FULL;
-       pdev->pause = pdev->asym_pause = 0;
-       return 0;
-}
-
-static struct phy_driver ip175c_driver = {
-       .name           = "IC+ IP175C",
-       .phy_id         = 0x02430d80,
-       .phy_id_mask    = 0x0ffffff0,
-       .features       = PHY_BASIC_FEATURES,
-       .probe          = ip175c_probe,
-       .remove         = ip175c_remove,
-       .config_init    = ip175c_config_init,
-       .config_aneg    = ip175c_config_aneg,
-       .read_status    = ip175c_read_status,
-       .driver         = { .owner = THIS_MODULE },
-};
-
-static struct phy_driver ip175a_driver = {
-       .name           = "IC+ IP175A",
-       .phy_id         = 0x02430c50,
-       .phy_id_mask    = 0x0ffffff0,
-       .features       = PHY_BASIC_FEATURES,
-       .probe          = ip175c_probe,
-       .remove         = ip175c_remove,
-       .config_init    = ip175c_config_init,
-       .config_aneg    = ip175c_config_aneg,
-       .read_status    = ip175c_read_status,
-       .driver         = { .owner = THIS_MODULE },
-};
-
-
-int __init ip175c_init(void)
-{
-       int ret;
-
-       ret = phy_driver_register(&ip175a_driver);
-       if (ret < 0)
-               return ret;
-
-       return phy_driver_register(&ip175c_driver);
-}
-
-void __exit ip175c_exit(void)
-{
-       phy_driver_unregister(&ip175c_driver);
-       phy_driver_unregister(&ip175a_driver);
-}
-
-MODULE_AUTHOR("Patrick Horn <patrick.horn@gmail.com>");
-MODULE_AUTHOR("Felix Fietkau <nbd@openwrt.org>");
-MODULE_LICENSE("GPL");
-
-module_init(ip175c_init);
-module_exit(ip175c_exit);
-
diff --git a/target/linux/generic-2.6/files/drivers/net/phy/ip17xx.c b/target/linux/generic-2.6/files/drivers/net/phy/ip17xx.c
new file mode 100644 (file)
index 0000000..49b3ece
--- /dev/null
@@ -0,0 +1,1395 @@
+/*
+ * ip17xx.c: Swconfig configuration for IC+ IP17xx switch family
+ *
+ * Copyright (C) 2008 Patrick Horn <patrick.horn@gmail.com>
+ * Copyright (C) 2008, 2010 Martin Mares <mj@ucw.cz>
+ * Copyright (C) 2009 Felix Fietkau <nbd@openwrt.org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.        See the
+ * GNU General Public License for more details.
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/list.h>
+#include <linux/skbuff.h>
+#include <linux/mii.h>
+#include <linux/phy.h>
+#include <linux/delay.h>
+#include <linux/switch.h>
+#include <linux/device.h>
+
+#define MAX_VLANS 16
+#define MAX_PORTS 9
+#undef DUMP_MII_IO
+
+typedef struct ip17xx_reg {
+       u16 p;                  // phy
+       u16 m;                  // mii
+} reg;
+typedef char bitnum;
+
+#define NOTSUPPORTED {-1,-1}
+
+#define REG_SUPP(x) (((x).m != ((u16)-1)) && ((x).p != (u16)-1))
+
+struct ip17xx_state;
+
+/*********** CONSTANTS ***********/
+struct register_mappings {
+       char *NAME;
+       u16 MODEL_NO;                   // Compare to bits 4-9 of MII register 0,3.
+       bitnum NUM_PORTS;
+       bitnum CPU_PORT;
+
+/* The default VLAN for each port.
+        Default: 0x0001 for Ports 0,1,2,3
+                 0x0002 for Ports 4,5 */
+       reg VLAN_DEFAULT_TAG_REG[MAX_PORTS];
+
+/* These ports are tagged.
+        Default: 0x00 */
+       reg ADD_TAG_REG;
+       reg REMOVE_TAG_REG;
+       bitnum ADD_TAG_BIT[MAX_PORTS];
+/* These ports are untagged.
+        Default: 0x00 (i.e. do not alter any VLAN tags...)
+        Maybe set to 0 if user disables VLANs. */
+       bitnum REMOVE_TAG_BIT[MAX_PORTS];
+
+/* Port M and Port N are on the same VLAN.
+        Default: All ports on all VLANs. */
+// Use register {29, 19+N/2}
+       reg VLAN_LOOKUP_REG;
+// Port 5 uses register {30, 18} but same as odd bits.
+       reg VLAN_LOOKUP_REG_5;          // in a different register on IP175C.
+       bitnum VLAN_LOOKUP_EVEN_BIT[MAX_PORTS];
+       bitnum VLAN_LOOKUP_ODD_BIT[MAX_PORTS];
+
+/* This VLAN corresponds to which ports.
+        Default: 0x2f,0x30,0x3f,0x3f... */
+       reg TAG_VLAN_MASK_REG;
+       bitnum TAG_VLAN_MASK_EVEN_BIT[MAX_PORTS];
+       bitnum TAG_VLAN_MASK_ODD_BIT[MAX_PORTS];
+
+       int RESET_VAL;
+       reg RESET_REG;
+
+       reg MODE_REG;
+       int MODE_VAL;
+
+/* General flags */
+       reg ROUTER_CONTROL_REG;
+       reg VLAN_CONTROL_REG;
+       bitnum TAG_VLAN_BIT;
+       bitnum ROUTER_EN_BIT;
+       bitnum NUMLAN_GROUPS_MAX;
+       bitnum NUMLAN_GROUPS_BIT;
+
+       reg MII_REGISTER_EN;
+       bitnum MII_REGISTER_EN_BIT;
+
+       // set to 1 for 178C, 0 for 175C.
+       bitnum SIMPLE_VLAN_REGISTERS;   // 175C has two vlans per register but 178C has only one.
+
+       // Pointers to functions which manipulate hardware state
+       int (*update_state)(struct ip17xx_state *state);
+       int (*set_vlan_mode)(struct ip17xx_state *state);
+       int (*reset)(struct ip17xx_state *state);
+};
+
+static int ip175c_update_state(struct ip17xx_state *state);
+static int ip175c_set_vlan_mode(struct ip17xx_state *state);
+static int ip175c_reset(struct ip17xx_state *state);
+
+static const struct register_mappings IP178C = {
+       .NAME = "IP178C",
+       .MODEL_NO = 0x18,
+       .VLAN_DEFAULT_TAG_REG = {
+               {30,3},{30,4},{30,5},{30,6},{30,7},{30,8},
+               {30,9},{30,10},{30,11},
+       },
+
+       .ADD_TAG_REG = {30,12},
+       .ADD_TAG_BIT = {0,1,2,3,4,5,6,7,8},
+       .REMOVE_TAG_REG = {30,13},
+       .REMOVE_TAG_BIT = {4,5,6,7,8,9,10,11,12},
+
+       .SIMPLE_VLAN_REGISTERS = 1,
+
+       .VLAN_LOOKUP_REG = {31,0},// +N
+       .VLAN_LOOKUP_REG_5 = NOTSUPPORTED, // not used with SIMPLE_VLAN_REGISTERS
+       .VLAN_LOOKUP_EVEN_BIT = {0,1,2,3,4,5,6,7,8},
+       .VLAN_LOOKUP_ODD_BIT = {0,1,2,3,4,5,6,7,8},
+
+       .TAG_VLAN_MASK_REG = {30,14}, // +N
+       .TAG_VLAN_MASK_EVEN_BIT = {0,1,2,3,4,5,6,7,8},
+       .TAG_VLAN_MASK_ODD_BIT = {0,1,2,3,4,5,6,7,8},
+
+       .RESET_VAL = 0x55AA,
+       .RESET_REG = {30,0},
+       .MODE_VAL = 0,
+       .MODE_REG = NOTSUPPORTED,
+
+       .ROUTER_CONTROL_REG = {30,30},
+       .ROUTER_EN_BIT = 11,
+       .NUMLAN_GROUPS_MAX = 8,
+       .NUMLAN_GROUPS_BIT = 8, // {0-2}
+
+       .VLAN_CONTROL_REG = {30,13},
+       .TAG_VLAN_BIT = 3,
+
+       .CPU_PORT = 8,
+       .NUM_PORTS = 9,
+
+       .MII_REGISTER_EN = NOTSUPPORTED,
+
+       .update_state = ip175c_update_state,
+       .set_vlan_mode = ip175c_set_vlan_mode,
+       .reset = ip175c_reset,
+};
+
+static const struct register_mappings IP175C = {
+       .NAME = "IP175C",
+       .MODEL_NO = 0x18,
+       .VLAN_DEFAULT_TAG_REG = {
+               {29,24},{29,25},{29,26},{29,27},{29,28},{29,30},
+               NOTSUPPORTED,NOTSUPPORTED,NOTSUPPORTED
+       },
+
+       .ADD_TAG_REG = {29,23},
+       .REMOVE_TAG_REG = {29,23},
+       .ADD_TAG_BIT = {11,12,13,14,15,1,-1,-1,-1},
+       .REMOVE_TAG_BIT = {6,7,8,9,10,0,-1,-1,-1},
+
+       .SIMPLE_VLAN_REGISTERS = 0,
+
+       .VLAN_LOOKUP_REG = {29,19},// +N/2
+       .VLAN_LOOKUP_REG_5 = {30,18},
+       .VLAN_LOOKUP_EVEN_BIT = {8,9,10,11,12,15,-1,-1,-1},
+       .VLAN_LOOKUP_ODD_BIT = {0,1,2,3,4,7,-1,-1,-1},
+
+       .TAG_VLAN_MASK_REG = {30,1}, // +N/2
+       .TAG_VLAN_MASK_EVEN_BIT = {0,1,2,3,4,5,-1,-1,-1},
+       .TAG_VLAN_MASK_ODD_BIT = {8,9,10,11,12,13,-1,-1,-1},
+
+       .RESET_VAL = 0x175C,
+       .RESET_REG = {30,0},
+       .MODE_VAL = 0x175C,
+       .MODE_REG = {29,31},
+
+       .ROUTER_CONTROL_REG = {30,9},
+       .ROUTER_EN_BIT = 3,
+       .NUMLAN_GROUPS_MAX = 8,
+       .NUMLAN_GROUPS_BIT = 0, // {0-2}
+
+       .VLAN_CONTROL_REG = {30,9},
+       .TAG_VLAN_BIT = 7,
+
+       .NUM_PORTS = 6,
+       .CPU_PORT = 5,
+
+       .MII_REGISTER_EN = NOTSUPPORTED,
+
+       .update_state = ip175c_update_state,
+       .set_vlan_mode = ip175c_set_vlan_mode,
+       .reset = ip175c_reset,
+};
+
+static const struct register_mappings IP175A = {
+       .NAME = "IP175A",
+       .MODEL_NO = 0x05,
+       .VLAN_DEFAULT_TAG_REG = {
+               {0,24},{0,25},{0,26},{0,27},{0,28},NOTSUPPORTED,
+               NOTSUPPORTED,NOTSUPPORTED,NOTSUPPORTED
+       },
+
+       .ADD_TAG_REG = {0,23},
+       .REMOVE_TAG_REG = {0,23},
+       .ADD_TAG_BIT = {11,12,13,14,15,-1,-1,-1,-1},
+       .REMOVE_TAG_BIT = {6,7,8,9,10,-1,-1,-1,-1},
+
+       .SIMPLE_VLAN_REGISTERS = 0,
+
+       // Only programmable via EEPROM
+       .VLAN_LOOKUP_REG = NOTSUPPORTED,// +N/2
+       .VLAN_LOOKUP_REG_5 = NOTSUPPORTED,
+       .VLAN_LOOKUP_EVEN_BIT = {8,9,10,11,12,-1,-1,-1,-1},
+       .VLAN_LOOKUP_ODD_BIT = {0,1,2,3,4,-1,-1,-1,-1},
+
+       .TAG_VLAN_MASK_REG = NOTSUPPORTED, // +N/2,
+       .TAG_VLAN_MASK_EVEN_BIT = {-1,-1,-1,-1,-1,-1,-1,-1,-1},
+       .TAG_VLAN_MASK_ODD_BIT = {-1,-1,-1,-1,-1,-1,-1,-1,-1},
+
+       .RESET_VAL = -1,
+       .RESET_REG = NOTSUPPORTED,
+       .MODE_VAL = 0,
+       .MODE_REG = NOTSUPPORTED,
+
+       .ROUTER_CONTROL_REG = NOTSUPPORTED,
+       .VLAN_CONTROL_REG = NOTSUPPORTED,
+       .TAG_VLAN_BIT = -1,
+       .ROUTER_EN_BIT = -1,
+       .NUMLAN_GROUPS_MAX = -1,
+       .NUMLAN_GROUPS_BIT = -1, // {0-2}
+
+       .NUM_PORTS = 5,
+       .CPU_PORT = 4,
+
+       .MII_REGISTER_EN = {0, 18},
+       .MII_REGISTER_EN_BIT = 7,
+
+       .update_state = ip175c_update_state,
+       .set_vlan_mode = ip175c_set_vlan_mode,
+       .reset = ip175c_reset,
+};
+
+
+static int ip175d_update_state(struct ip17xx_state *state);
+static int ip175d_set_vlan_mode(struct ip17xx_state *state);
+static int ip175d_reset(struct ip17xx_state *state);
+
+static const struct register_mappings IP175D = {
+       .NAME = "IP175D",
+       .MODEL_NO = 0x18,
+
+       // The IP175D has a completely different interface, so we leave most
+       // of the registers undefined and switch to different code paths.
+
+       .VLAN_DEFAULT_TAG_REG = {
+               NOTSUPPORTED,NOTSUPPORTED,NOTSUPPORTED,NOTSUPPORTED,
+               NOTSUPPORTED,NOTSUPPORTED,NOTSUPPORTED,NOTSUPPORTED,
+       },
+
+       .ADD_TAG_REG = NOTSUPPORTED,
+       .REMOVE_TAG_REG = NOTSUPPORTED,
+
+       .SIMPLE_VLAN_REGISTERS = 0,
+
+       .VLAN_LOOKUP_REG = NOTSUPPORTED,
+       .VLAN_LOOKUP_REG_5 = NOTSUPPORTED,
+       .TAG_VLAN_MASK_REG = NOTSUPPORTED,
+
+       .RESET_VAL = 0x175D,
+       .RESET_REG = {20,2},
+       .MODE_REG = NOTSUPPORTED,
+
+       .ROUTER_CONTROL_REG = NOTSUPPORTED,
+       .ROUTER_EN_BIT = -1,
+       .NUMLAN_GROUPS_BIT = -1,
+
+       .VLAN_CONTROL_REG = NOTSUPPORTED,
+       .TAG_VLAN_BIT = -1,
+
+       .NUM_PORTS = 6,
+       .CPU_PORT = 5,
+
+       .MII_REGISTER_EN = NOTSUPPORTED,
+
+       .update_state = ip175d_update_state,
+       .set_vlan_mode = ip175d_set_vlan_mode,
+       .reset = ip175d_reset,
+};
+
+struct ip17xx_state {
+       struct switch_dev dev;
+       struct mii_bus *mii_bus;
+       bool registered;
+
+       int router_mode;                // ROUTER_EN
+       int vlan_enabled;               // TAG_VLAN_EN
+       struct port_state {
+               u16 pvid;
+               unsigned int shareports;
+       } ports[MAX_PORTS];
+       unsigned int add_tag;
+       unsigned int remove_tag;
+       int num_vlans;
+       struct vlan_state {
+               unsigned int ports;
+               unsigned int tag;       // VLAN tag (IP175D only)
+       } vlans[MAX_VLANS];
+       const struct register_mappings *regs;
+       reg proc_mii;   // phy/reg for the low level register access via swconfig
+
+       char buf[80];
+};
+
+#define get_state(_dev) container_of((_dev), struct ip17xx_state, dev)
+
+static int ip_phy_read(struct ip17xx_state *state, int port, int reg)
+{
+       int val = mdiobus_read(state->mii_bus, port, reg);
+       if (val < 0)
+               pr_warning("IP17xx: Unable to get MII register %d,%d: error %d\n", port, reg, -val);
+#ifdef DUMP_MII_IO
+       else
+               pr_debug("IP17xx: Read MII(%d,%d) -> %04x\n", port, reg, val);
+#endif
+       return val;
+}
+
+static int ip_phy_write(struct ip17xx_state *state, int port, int reg, u16 val)
+{
+       int err;
+
+#ifdef DUMP_MII_IO
+       pr_debug("IP17xx: Write MII(%d,%d) <- %04x\n", port, reg, val);
+#endif
+       err = mdiobus_write(state->mii_bus, port, reg, val);
+       if (err < 0)
+               pr_warning("IP17xx: Unable to write MII register %d,%d: error %d\n", port, reg, -err);
+       return err;
+}
+
+static int ip_phy_write_masked(struct ip17xx_state *state, int port, int reg, unsigned int mask, unsigned int data)
+{
+       int val = ip_phy_read(state, port, reg);
+       if (val < 0)
+               return 0;
+       return ip_phy_write(state, port, reg, (val & ~mask) | data);
+}
+
+static int getPhy(struct ip17xx_state *state, reg mii)
+{
+       if (!REG_SUPP(mii))
+               return -EFAULT;
+       return ip_phy_read(state, mii.p, mii.m);
+}
+
+static int setPhy(struct ip17xx_state *state, reg mii, u16 value)
+{
+       int err;
+
+       if (!REG_SUPP(mii))
+               return -EFAULT;
+       err = ip_phy_write(state, mii.p, mii.m, value);
+       if (err < 0)
+               return err;
+       mdelay(2);
+       getPhy(state, mii);
+       return 0;
+}
+
+
+/**
+ * These two macros are to simplify the mapping of logical bits to the bits in hardware.
+ * NOTE: these macros will return if there is an error!
+ */
+
+#define GET_PORT_BITS(state, bits, addr, bit_lookup)           \
+       do {                                                    \
+               int i, val = getPhy((state), (addr));           \
+               if (val < 0)                                    \
+                       return val;                             \
+               (bits) = 0;                                     \
+               for (i = 0; i < MAX_PORTS; i++) {               \
+                       if ((bit_lookup)[i] == -1) continue;    \
+                       if (val & (1<<(bit_lookup)[i]))         \
+                               (bits) |= (1<<i);               \
+               }                                               \
+       } while (0)
+
+#define SET_PORT_BITS(state, bits, addr, bit_lookup)           \
+       do {                                                    \
+               int i, val = getPhy((state), (addr));           \
+               if (val < 0)                                    \
+                       return val;                             \
+               for (i = 0; i < MAX_PORTS; i++) {               \
+                       unsigned int newmask = ((bits)&(1<<i)); \
+                       if ((bit_lookup)[i] == -1) continue;    \
+                       val &= ~(1<<(bit_lookup)[i]);           \
+                       val |= ((newmask>>i)<<(bit_lookup)[i]); \
+               }                                               \
+               val = setPhy((state), (addr), val);             \
+               if (val < 0)                                    \
+                       return val;                             \
+       } while (0)
+
+
+static int get_model(struct ip17xx_state *state)
+{
+       int id1, id2;
+       int oui_id, model_no, rev_no, chip_no;
+
+       id1 = ip_phy_read(state, 0, 2);
+       id2 = ip_phy_read(state, 0, 3);
+       oui_id = (id1 << 6) | ((id2 >> 10) & 0x3f);
+       model_no = (id2 >> 4) & 0x3f;
+       rev_no = id2 & 0xf;
+       pr_debug("IP17xx: Identified oui=%06x model=%02x rev=%X\n", oui_id, model_no, rev_no);
+
+       if (oui_id != 0x0090c3)  // No other oui_id should have reached us anyway
+               return -ENODEV;
+
+       if (model_no == IP175A.MODEL_NO) {
+               state->regs = &IP175A;
+       } else if (model_no == IP175C.MODEL_NO) {
+               /*
+                *  Several models share the same model_no:
+                *  178C has more PHYs, so we try whether the device responds to a read from PHY5
+                *  175D has a new chip ID register
+                *  175C has neither
+                */
+               if (ip_phy_read(state, 5, 2) == 0x0243) {
+                       state->regs = &IP178C;
+               } else {
+                       chip_no = ip_phy_read(state, 20, 0);
+                       pr_debug("IP17xx: Chip ID register reads %04x\n", chip_no);
+                       if (chip_no == 0x175d) {
+                               state->regs = &IP175D;
+                       } else {
+                               state->regs = &IP175C;
+                       }
+               }
+       } else {
+               pr_warning("IP17xx: Found an unknown IC+ switch with model number %02x, revision %X.\n", model_no, rev_no);
+               return -EPERM;
+       }
+       return 0;
+}
+
+/*** Low-level functions for the older models ***/
+
+/** Only set vlan and router flags in the switch **/
+static int ip175c_set_flags(struct ip17xx_state *state)
+{
+       int val;
+
+       if (!REG_SUPP(state->regs->ROUTER_CONTROL_REG)) {
+               return 0;
+       }
+
+       val = getPhy(state, state->regs->ROUTER_CONTROL_REG);
+       if (val < 0) {
+               return val;
+       }
+       if (state->regs->ROUTER_EN_BIT >= 0) {
+               if (state->router_mode) {
+                       val |= (1<<state->regs->ROUTER_EN_BIT);
+               } else {
+                       val &= (~(1<<state->regs->ROUTER_EN_BIT));
+               }
+       }
+       if (state->regs->TAG_VLAN_BIT >= 0) {
+               if (state->vlan_enabled) {
+                       val |= (1<<state->regs->TAG_VLAN_BIT);
+               } else {
+                       val &= (~(1<<state->regs->TAG_VLAN_BIT));
+               }
+       }
+       if (state->regs->NUMLAN_GROUPS_BIT >= 0) {
+               val &= (~((state->regs->NUMLAN_GROUPS_MAX-1)<<state->regs->NUMLAN_GROUPS_BIT));
+               if (state->num_vlans > state->regs->NUMLAN_GROUPS_MAX) {
+                       val |= state->regs->NUMLAN_GROUPS_MAX << state->regs->NUMLAN_GROUPS_BIT;
+               } else if (state->num_vlans >= 1) {
+                       val |= (state->num_vlans-1) << state->regs->NUMLAN_GROUPS_BIT;
+               }
+       }
+       return setPhy(state, state->regs->ROUTER_CONTROL_REG, val);
+}
+
+/** Set all VLAN and port state.  Usually you should call "correct_vlan_state" first. **/
+static int ip175c_set_state(struct ip17xx_state *state)
+{
+       int j;
+       int i;
+       SET_PORT_BITS(state, state->add_tag,
+                                 state->regs->ADD_TAG_REG, state->regs->ADD_TAG_BIT);
+       SET_PORT_BITS(state, state->remove_tag,
+                                 state->regs->REMOVE_TAG_REG, state->regs->REMOVE_TAG_BIT);
+
+       if (REG_SUPP(state->regs->VLAN_LOOKUP_REG)) {
+               for (j=0; j<state->regs->NUM_PORTS; j++) {
+                       reg addr;
+                       const bitnum *bit_lookup = (j%2==0)?
+                               state->regs->VLAN_LOOKUP_EVEN_BIT:
+                               state->regs->VLAN_LOOKUP_ODD_BIT;
+
+                       addr = state->regs->VLAN_LOOKUP_REG;
+                       if (state->regs->SIMPLE_VLAN_REGISTERS) {
+                               addr.m += j;
+                       } else {
+                               switch (j) {
+                               case 0:
+                               case 1:
+                                       break;
+                               case 2:
+                               case 3:
+                                       addr.m+=1;
+                                       break;
+                               case 4:
+                                       addr.m+=2;
+                                       break;
+                               case 5:
+                                       addr = state->regs->VLAN_LOOKUP_REG_5;
+                                       break;
+                               default:
+                                       addr.m = -1; // shouldn't get here, but...
+                                       break;
+                               }
+                       }
+                       //printf("shareports for %d is %02X\n",j,state->ports[j].shareports);
+                       if (REG_SUPP(addr)) {
+                               SET_PORT_BITS(state, state->ports[j].shareports, addr, bit_lookup);
+                       }
+               }
+       }
+       if (REG_SUPP(state->regs->TAG_VLAN_MASK_REG)) {
+               for (j=0; j<MAX_VLANS; j++) {
+                       reg addr = state->regs->TAG_VLAN_MASK_REG;
+                       const bitnum *bit_lookup = (j%2==0)?
+                               state->regs->TAG_VLAN_MASK_EVEN_BIT:
+                               state->regs->TAG_VLAN_MASK_ODD_BIT;
+                       unsigned int vlan_mask;
+                       if (state->regs->SIMPLE_VLAN_REGISTERS) {
+                               addr.m += j;
+                       } else {
+                               addr.m += j/2;
+                       }
+                       vlan_mask = state->vlans[j].ports;
+                       SET_PORT_BITS(state, vlan_mask, addr, bit_lookup);
+               }
+       }
+
+       for (i=0; i<MAX_PORTS; i++) {
+               if (REG_SUPP(state->regs->VLAN_DEFAULT_TAG_REG[i])) {
+                       int err = setPhy(state, state->regs->VLAN_DEFAULT_TAG_REG[i],
+                                       state->ports[i].pvid);
+                       if (err < 0) {
+                               return err;
+                       }
+               }
+       }
+
+       return ip175c_set_flags(state);
+}
+
+/**
+ *  Uses only the VLAN port mask and the add tag mask to generate the other fields:
+ *  which ports are part of the same VLAN, removing vlan tags, and VLAN tag ids.
+ */
+static void ip175c_correct_vlan_state(struct ip17xx_state *state)
+{
+       int i, j;
+       state->num_vlans = 0;
+       for (i=0; i<MAX_VLANS; i++) {
+               if (state->vlans[i].ports != 0) {
+                       state->num_vlans = i+1; // Hack -- we need to store the "set" vlans somewhere...
+               }
+       }
+
+       for (i=0; i<state->regs->NUM_PORTS; i++) {
+               unsigned int portmask = (1<<i);
+               if (!state->vlan_enabled) {
+                       // Share with everybody!
+                       state->ports[i].shareports = (1<<state->regs->NUM_PORTS)-1;
+                       continue;
+               }
+               state->ports[i].shareports = portmask;
+               for (j=0; j<MAX_VLANS; j++) {
+                       if (state->vlans[j].ports & portmask)
+                               state->ports[i].shareports |= state->vlans[j].ports;
+               }
+       }
+}
+
+static int ip175c_update_state(struct ip17xx_state *state)
+{
+       ip175c_correct_vlan_state(state);
+       return ip175c_set_state(state);
+}
+
+static int ip175c_set_vlan_mode(struct ip17xx_state *state)
+{
+       return ip175c_update_state(state);
+}
+
+static int ip175c_reset(struct ip17xx_state *state)
+{
+       int err;
+
+       if (REG_SUPP(state->regs->MODE_REG)) {
+               err = setPhy(state, state->regs->MODE_REG, state->regs->MODE_VAL);
+               if (err < 0)
+                       return err;
+               err = getPhy(state, state->regs->MODE_REG);
+               if (err < 0)
+                       return err;
+       }
+
+       return ip175c_update_state(state);
+}
+
+/*** Low-level functions for IP175D ***/
+
+static int ip175d_update_state(struct ip17xx_state *state)
+{
+       unsigned int filter_mask = 0;
+       unsigned int ports[16], add[16], rem[16];
+       int i, j;
+       int err = 0;
+
+       for (i = 0; i < 16; i++) {
+               ports[i] = 0;
+               add[i] = 0;
+               rem[i] = 0;
+               if (!state->vlan_enabled) {
+                       err |= ip_phy_write(state, 22, 14+i, i+1);      // default tags
+                       ports[i] = 0x3f;
+                       continue;
+               }
+               if (!state->vlans[i].tag) {
+                       // Reset the filter
+                       err |= ip_phy_write(state, 22, 14+i, 0);        // tag
+                       continue;
+               }
+               filter_mask |= 1 << i;
+               err |= ip_phy_write(state, 22, 14+i, state->vlans[i].tag);
+               ports[i] = state->vlans[i].ports;
+               for (j = 0; j < 6; j++) {
+                       if (ports[i] & (1 << j)) {
+                               if (state->add_tag & (1 << j))
+                                       add[i] |= 1 << j;
+                               if (state->remove_tag & (1 << j))
+                                       rem[i] |= 1 << j;
+                       }
+               }
+       }
+
+       // Port masks, tag adds and removals
+       for (i = 0; i < 8; i++) {
+               err |= ip_phy_write(state, 23, i, ports[2*i] | (ports[2*i+1] << 8));
+               err |= ip_phy_write(state, 23, 8+i, add[2*i] | (add[2*i+1] << 8));
+               err |= ip_phy_write(state, 23, 16+i, rem[2*i] | (rem[2*i+1] << 8));
+       }
+       err |= ip_phy_write(state, 22, 10, filter_mask);
+
+       // Default VLAN tag for each port
+       for (i = 0; i < 6; i++)
+               err |= ip_phy_write(state, 22, 4+i, state->vlans[state->ports[i].pvid].tag);
+
+       return (err ? -EIO : 0);
+}
+
+static int ip175d_set_vlan_mode(struct ip17xx_state *state)
+{
+       int i;
+       int err = 0;
+
+       if (state->vlan_enabled) {
+               // VLAN classification rules: tag-based VLANs, use VID to classify,
+               // drop packets that cannot be classified.
+               err |= ip_phy_write_masked(state, 22, 0, 0x3fff, 0x003f);
+
+               // Ingress rules: CFI=1 dropped, null VID is untagged, VID=1 passed,
+               // VID=0xfff discarded, admin both tagged and untagged, ingress
+               // filters enabled.
+               err |= ip_phy_write_masked(state, 22, 1, 0x0fff, 0x0c3f);
+
+               // Egress rules: IGMP processing off, keep VLAN header off
+               err |= ip_phy_write_masked(state, 22, 2, 0x0fff, 0x0000);
+       } else {
+               // VLAN classification rules: everything off & clear table
+               err |= ip_phy_write_masked(state, 22, 0, 0xbfff, 0x8000);
+
+               // Ingress and egress rules: set to defaults
+               err |= ip_phy_write_masked(state, 22, 1, 0x0fff, 0x0c3f);
+               err |= ip_phy_write_masked(state, 22, 2, 0x0fff, 0x0000);
+       }
+
+       // Reset default VLAN for each port to 0
+       for (i = 0; i < 6; i++)
+               state->ports[i].pvid = 0;
+
+       err |= ip175d_update_state(state);
+
+       return (err ? -EIO : 0);
+}
+
+static int ip175d_reset(struct ip17xx_state *state)
+{
+       int err = 0;
+
+       // Disable the special tagging mode
+       err |= ip_phy_write_masked(state, 21, 22, 0x0003, 0x0000);
+
+       // Set 802.1q protocol type
+       err |= ip_phy_write(state, 22, 3, 0x8100);
+
+       state->vlan_enabled = 0;
+       err |= ip175d_set_vlan_mode(state);
+
+       return (err ? -EIO : 0);
+}
+
+/*** High-level functions ***/
+
+static int ip17xx_get_enable_vlan(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val)
+{
+       struct ip17xx_state *state = get_state(dev);
+
+       val->value.i = state->vlan_enabled;
+       return 0;
+}
+
+static void ip17xx_reset_vlan_config(struct ip17xx_state *state)
+{
+       int i;
+
+       state->remove_tag = (state->vlan_enabled ? ((1<<state->regs->NUM_PORTS)-1) : 0x0000);
+       state->add_tag = 0x0000;
+       for (i = 0; i < MAX_VLANS; i++) {
+               state->vlans[i].ports = 0x0000;
+               state->vlans[i].tag = (i ? i : 16);
+       }
+       for (i = 0; i < MAX_PORTS; i++)
+               state->ports[i].pvid = 0;
+}
+
+static int ip17xx_set_enable_vlan(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val)
+{
+       struct ip17xx_state *state = get_state(dev);
+       int enable;
+
+       enable = val->value.i;
+       if (state->vlan_enabled == enable) {
+               // Do not change any state.
+               return 0;
+       }
+       state->vlan_enabled = enable;
+
+       // Otherwise, if we are switching state, set fields to a known default.
+       ip17xx_reset_vlan_config(state);
+
+       return state->regs->set_vlan_mode(state);
+}
+
+static int ip17xx_get_ports(struct switch_dev *dev, struct switch_val *val)
+{
+       struct ip17xx_state *state = get_state(dev);
+       int b;
+       int ind;
+       unsigned int ports;
+
+       if (val->port_vlan >= dev->vlans || val->port_vlan < 0)
+               return -EINVAL;
+
+       ports = state->vlans[val->port_vlan].ports;
+       b = 0;
+       ind = 0;
+       while (b < MAX_PORTS) {
+               if (ports&1) {
+                       int istagged = ((state->add_tag >> b) & 1);
+                       val->value.ports[ind].id = b;
+                       val->value.ports[ind].flags = (istagged << SWITCH_PORT_FLAG_TAGGED);
+                       ind++;
+               }
+               b++;
+               ports >>= 1;
+       }
+       val->len = ind;
+
+       return 0;
+}
+
+static int ip17xx_set_ports(struct switch_dev *dev, struct switch_val *val)
+{
+       struct ip17xx_state *state = get_state(dev);
+       int i;
+
+       if (val->port_vlan >= dev->vlans || val->port_vlan < 0)
+               return -EINVAL;
+
+       state->vlans[val->port_vlan].ports = 0;
+       for (i = 0; i < val->len; i++) {
+               unsigned int bitmask = (1<<val->value.ports[i].id);
+               state->vlans[val->port_vlan].ports |= bitmask;
+               if (val->value.ports[i].flags & (1<<SWITCH_PORT_FLAG_TAGGED)) {
+                       state->add_tag |= bitmask;
+                       state->remove_tag &= (~bitmask);
+               } else {
+                       state->add_tag &= (~bitmask);
+                       state->remove_tag |= bitmask;
+               }
+       }
+
+       return state->regs->update_state(state);
+}
+
+static int ip17xx_apply(struct switch_dev *dev)
+{
+       struct ip17xx_state *state = get_state(dev);
+
+       if (REG_SUPP(state->regs->MII_REGISTER_EN)) {
+               int val = getPhy(state, state->regs->MII_REGISTER_EN);
+               if (val < 0) {
+                       return val;
+               }
+               val |= (1<<state->regs->MII_REGISTER_EN_BIT);
+               return setPhy(state, state->regs->MII_REGISTER_EN, val);
+       }
+       return 0;
+}
+
+static int ip17xx_reset(struct switch_dev *dev)
+{
+       struct ip17xx_state *state = get_state(dev);
+       int i, err;
+
+       if (REG_SUPP(state->regs->RESET_REG)) {
+               err = setPhy(state, state->regs->RESET_REG, state->regs->RESET_VAL);
+               if (err < 0)
+                       return err;
+               err = getPhy(state, state->regs->RESET_REG);
+
+               /*
+                *  Data sheet specifies reset period to be 2 msec.
+                *  (I don't see any mention of the 2ms delay in the IP178C spec, only
+                *  in IP175C, but it can't hurt.)
+                */
+               mdelay(2);
+       }
+
+       /* reset switch ports */
+       for (i = 0; i < state->regs->NUM_PORTS-1; i++) {
+               err = ip_phy_write(state, i, MII_BMCR, BMCR_RESET);
+               if (err < 0)
+                       return err;
+       }
+
+       state->router_mode = 0;
+       state->vlan_enabled = 0;
+       ip17xx_reset_vlan_config(state);
+
+       return state->regs->reset(state);
+}
+
+static int ip17xx_get_tagged(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val)
+{
+       struct ip17xx_state *state = get_state(dev);
+
+       if (state->add_tag & (1<<val->port_vlan)) {
+               if (state->remove_tag & (1<<val->port_vlan))
+                       val->value.i = 3; // shouldn't ever happen.
+               else
+                       val->value.i = 1;
+       } else {
+               if (state->remove_tag & (1<<val->port_vlan))
+                       val->value.i = 0;
+               else
+                       val->value.i = 2;
+       }
+       return 0;
+}
+
+static int ip17xx_set_tagged(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val)
+{
+       struct ip17xx_state *state = get_state(dev);
+
+       state->add_tag &= ~(1<<val->port_vlan);
+       state->remove_tag &= ~(1<<val->port_vlan);
+
+       if (val->value.i == 0)
+               state->remove_tag |= (1<<val->port_vlan);
+       if (val->value.i == 1)
+               state->add_tag |= (1<<val->port_vlan);
+
+       return state->regs->update_state(state);
+}
+
+/** Get the current phy address */
+static int ip17xx_get_phy(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val)
+{
+       struct ip17xx_state *state = get_state(dev);
+
+       val->value.i = state->proc_mii.p;
+       return 0;
+}
+
+/** Set a new phy address for low level access to registers */
+static int ip17xx_set_phy(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val)
+{
+       struct ip17xx_state *state = get_state(dev);
+       int new_reg = val->value.i;
+
+       if (new_reg < 0 || new_reg > 31)
+               state->proc_mii.p = (u16)-1;
+       else
+               state->proc_mii.p = (u16)new_reg;
+       return 0;
+}
+
+/** Get the current register number */
+static int ip17xx_get_reg(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val)
+{
+       struct ip17xx_state *state = get_state(dev);
+
+       val->value.i = state->proc_mii.m;
+       return 0;
+}
+
+/** Set a new register address for low level access to registers */
+static int ip17xx_set_reg(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val)
+{
+       struct ip17xx_state *state = get_state(dev);
+       int new_reg = val->value.i;
+
+       if (new_reg < 0 || new_reg > 31)
+               state->proc_mii.m = (u16)-1;
+       else
+               state->proc_mii.m = (u16)new_reg;
+       return 0;
+}
+
+/** Get the register content of state->proc_mii */
+static int ip17xx_get_val(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val)
+{
+       struct ip17xx_state *state = get_state(dev);
+       int retval = -EINVAL;
+       if (REG_SUPP(state->proc_mii))
+               retval = getPhy(state, state->proc_mii);
+
+       if (retval < 0) {
+               return retval;
+       } else {
+               val->value.i = retval;
+               return 0;
+       }
+}
+
+/** Write a value to the register defined by phy/reg above */
+static int ip17xx_set_val(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val)
+{
+       struct ip17xx_state *state = get_state(dev);
+       int myval, err = -EINVAL;
+
+       myval = val->value.i;
+       if (myval <= 0xffff && myval >= 0 && REG_SUPP(state->proc_mii)) {
+               err = setPhy(state, state->proc_mii, (u16)myval);
+       }
+       return err;
+}
+
+static int ip17xx_read_name(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val)
+{
+       struct ip17xx_state *state = get_state(dev);
+       val->value.s = state->regs->NAME; // Just a const pointer, won't be freed by swconfig.
+       return 0;
+}
+
+static int ip17xx_get_tag(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val)
+{
+       struct ip17xx_state *state = get_state(dev);
+       int vlan = val->port_vlan;
+
+       if (vlan < 0 || vlan >= MAX_VLANS)
+               return -EINVAL;
+
+       val->value.i = state->vlans[vlan].tag;
+       return 0;
+}
+
+static int ip17xx_set_tag(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val)
+{
+       struct ip17xx_state *state = get_state(dev);
+       int vlan = val->port_vlan;
+       int tag = val->value.i;
+
+       if (vlan < 0 || vlan >= MAX_VLANS)
+               return -EINVAL;
+
+       if (tag < 0 || tag > 4095)
+               return -EINVAL;
+
+       state->vlans[vlan].tag = tag;
+       return state->regs->update_state(state);
+}
+
+static int ip17xx_set_port_speed(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val)
+{
+       struct ip17xx_state *state = get_state(dev);
+       int nr = val->port_vlan;
+       int ctrl;
+       int autoneg;
+       int speed;
+       if (val->value.i == 100) {
+               speed = 1;
+               autoneg = 0;
+       } else if (val->value.i == 10) {
+               speed = 0;
+               autoneg = 0;
+       } else {
+               autoneg = 1;
+               speed = 1;
+       }
+
+       /* Can't set speed for cpu port */
+       if (nr == state->regs->CPU_PORT)
+               return -EINVAL;
+
+       if (nr >= dev->ports || nr < 0)
+               return -EINVAL;
+
+       ctrl = ip_phy_read(state, nr, 0);
+       if (ctrl < 0)
+               return -EIO;
+
+       ctrl &= (~(1<<12));
+       ctrl &= (~(1<<13));
+       ctrl |= (autoneg<<12);
+       ctrl |= (speed<<13);
+
+       return ip_phy_write(state, nr, 0, ctrl);
+}
+
+static int ip17xx_get_port_speed(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val)
+{
+       struct ip17xx_state *state = get_state(dev);
+       int nr = val->port_vlan;
+       int speed, status;
+
+       if (nr == state->regs->CPU_PORT) {
+               val->value.i = 100;
+               return 0;
+       }
+
+       if (nr >= dev->ports || nr < 0)
+               return -EINVAL;
+
+       status = ip_phy_read(state, nr, 1);
+       speed = ip_phy_read(state, nr, 18);
+       if (status < 0 || speed < 0)
+               return -EIO;
+
+       if (status & 4)
+               val->value.i = ((speed & (1<<11)) ? 100 : 10);
+       else
+               val->value.i = 0;
+
+       return 0;
+}
+
+static int ip17xx_get_port_status(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val)
+{
+       struct ip17xx_state *state = get_state(dev);
+       int ctrl, speed, status;
+       int nr = val->port_vlan;
+       int len;
+       char *buf = state->buf; // fixed-length at 80.
+
+       if (nr == state->regs->CPU_PORT) {
+               sprintf(buf, "up, 100 Mbps, cpu port");
+               val->value.s = buf;
+               return 0;
+       }
+
+       if (nr >= dev->ports || nr < 0)
+               return -EINVAL;
+
+       ctrl = ip_phy_read(state, nr, 0);
+       status = ip_phy_read(state, nr, 1);
+       speed = ip_phy_read(state, nr, 18);
+       if (ctrl < 0 || status < 0 || speed < 0)
+               return -EIO;
+
+       if (status & 4)
+               len = sprintf(buf, "up, %d Mbps, %s duplex",
+                       ((speed & (1<<11)) ? 100 : 10),
+                       ((speed & (1<<10)) ? "full" : "half"));
+       else
+               len = sprintf(buf, "down");
+
+       if (ctrl & (1<<12)) {
+               len += sprintf(buf+len, ", auto-negotiate");
+               if (!(status & (1<<5)))
+                       len += sprintf(buf+len, " (in progress)");
+       } else {
+               len += sprintf(buf+len, ", fixed speed (%d)",
+                       ((ctrl & (1<<13)) ? 100 : 10));
+       }
+
+       buf[len] = '\0';
+       val->value.s = buf;
+       return 0;
+}
+
+static int ip17xx_get_pvid(struct switch_dev *dev, int port, int *val)
+{
+       struct ip17xx_state *state = get_state(dev);
+
+       *val = state->ports[port].pvid;
+       return 0;
+}
+
+static int ip17xx_set_pvid(struct switch_dev *dev, int port, int val)
+{
+       struct ip17xx_state *state = get_state(dev);
+
+       if (val < 0 || val >= MAX_VLANS)
+               return -EINVAL;
+
+       state->ports[port].pvid = val;
+       return state->regs->update_state(state);
+}
+
+
+enum Ports {
+       IP17XX_PORT_STATUS,
+       IP17XX_PORT_LINK,
+       IP17XX_PORT_TAGGED,
+       IP17XX_PORT_PVID,
+};
+
+enum Globals {
+       IP17XX_ENABLE_VLAN,
+       IP17XX_GET_NAME,
+       IP17XX_REGISTER_PHY,
+       IP17XX_REGISTER_MII,
+       IP17XX_REGISTER_VALUE,
+       IP17XX_REGISTER_ERRNO,
+};
+
+enum Vlans {
+       IP17XX_VLAN_TAG,
+};
+
+static const struct switch_attr ip17xx_global[] = {
+       [IP17XX_ENABLE_VLAN] = {
+               .id = IP17XX_ENABLE_VLAN,
+               .type = SWITCH_TYPE_INT,
+               .name  = "enable_vlan",
+               .description = "Flag to enable or disable VLANs and tagging",
+               .get  = ip17xx_get_enable_vlan,
+               .set = ip17xx_set_enable_vlan,
+       },
+       [IP17XX_GET_NAME] = {
+               .id = IP17XX_GET_NAME,
+               .type = SWITCH_TYPE_STRING,
+               .description = "Returns the type of IC+ chip.",
+               .name  = "name",
+               .get  = ip17xx_read_name,
+               .set = NULL,
+       },
+       /* jal: added for low level debugging etc. */
+       [IP17XX_REGISTER_PHY] = {
+               .id = IP17XX_REGISTER_PHY,
+               .type = SWITCH_TYPE_INT,
+               .description = "Direct register access: set PHY (0-4, or 29,30,31)",
+               .name  = "phy",
+               .get  = ip17xx_get_phy,
+               .set = ip17xx_set_phy,
+       },
+       [IP17XX_REGISTER_MII] = {
+               .id = IP17XX_REGISTER_MII,
+               .type = SWITCH_TYPE_INT,
+               .description = "Direct register access: set MII register number (0-31)",
+               .name  = "reg",
+               .get  = ip17xx_get_reg,
+               .set = ip17xx_set_reg,
+       },
+       [IP17XX_REGISTER_VALUE] = {
+               .id = IP17XX_REGISTER_VALUE,
+               .type = SWITCH_TYPE_INT,
+               .description = "Direct register access: read/write to register (0-65535)",
+               .name  = "val",
+               .get  = ip17xx_get_val,
+               .set = ip17xx_set_val,
+       },
+};
+
+static const struct switch_attr ip17xx_vlan[] = {
+       [IP17XX_VLAN_TAG] = {
+               .id = IP17XX_VLAN_TAG,
+               .type = SWITCH_TYPE_INT,
+               .description = "VLAN tag (0-4095) [IP175D only]",
+               .name = "tag",
+               .get = ip17xx_get_tag,
+               .set = ip17xx_set_tag,
+       }
+};
+
+static const struct switch_attr ip17xx_port[] = {
+       [IP17XX_PORT_STATUS] = {
+               .id = IP17XX_PORT_STATUS,
+               .type = SWITCH_TYPE_STRING,
+               .description = "Returns Detailed port status",
+               .name  = "status",
+               .get  = ip17xx_get_port_status,
+               .set = NULL,
+       },
+       [IP17XX_PORT_LINK] = {
+               .id = IP17XX_PORT_LINK,
+               .type = SWITCH_TYPE_INT,
+               .description = "Link speed. Can write 0 for auto-negotiate, or 10 or 100",
+               .name  = "link",
+               .get  = ip17xx_get_port_speed,
+               .set = ip17xx_set_port_speed,
+       },
+       [IP17XX_PORT_TAGGED] = {
+               .id = IP17XX_PORT_LINK,
+               .type = SWITCH_TYPE_INT,
+               .description = "0 = untag, 1 = add tags, 2 = do not alter (This value is reset if vlans are altered)",
+               .name  = "tagged",
+               .get  = ip17xx_get_tagged,
+               .set = ip17xx_set_tagged,
+       },
+};
+
+static const struct switch_dev_ops ip17xx_ops = {
+       .attr_global = {
+               .attr = ip17xx_global,
+               .n_attr = ARRAY_SIZE(ip17xx_global),
+       },
+       .attr_port = {
+               .attr = ip17xx_port,
+               .n_attr = ARRAY_SIZE(ip17xx_port),
+       },
+       .attr_vlan = {
+               .attr = ip17xx_vlan,
+               .n_attr = ARRAY_SIZE(ip17xx_vlan),
+       },
+
+       .get_port_pvid = ip17xx_get_pvid,
+       .set_port_pvid = ip17xx_set_pvid,
+       .get_vlan_ports = ip17xx_get_ports,
+       .set_vlan_ports = ip17xx_set_ports,
+       .apply_config = ip17xx_apply,
+       .reset_switch = ip17xx_reset,
+};
+
+static int ip17xx_probe(struct phy_device *pdev)
+{
+       struct ip17xx_state *state;
+       struct switch_dev *dev;
+       int err;
+
+       /* We only attach to PHY 0, but use all available PHYs */
+       if (pdev->addr != 0)
+               return -ENODEV;
+
+       state = kzalloc(sizeof(*state), GFP_KERNEL);
+       if (!state)
+               return -ENOMEM;
+
+       dev = &state->dev;
+
+       pdev->priv = state;
+       state->mii_bus = pdev->bus;
+
+       err = get_model(state);
+       if (err < 0)
+               goto error;
+
+       dev->vlans = MAX_VLANS;
+       dev->cpu_port = state->regs->CPU_PORT;
+       dev->ports = state->regs->NUM_PORTS;
+       dev->name = state->regs->NAME;
+       dev->ops = &ip17xx_ops;
+
+       pr_info("IP17xx: Found %s at %s\n", dev->name, dev_name(&pdev->dev));
+       return 0;
+
+error:
+       kfree(state);
+       return err;
+}
+
+static int ip17xx_config_init(struct phy_device *pdev)
+{
+       struct ip17xx_state *state = pdev->priv;
+       struct net_device *dev = pdev->attached_dev;
+       int err;
+
+       err = register_switch(&state->dev, dev);
+       if (err < 0)
+               return err;
+
+       state->registered = true;
+       ip17xx_reset(&state->dev);
+       return 0;
+}
+
+static void ip17xx_remove(struct phy_device *pdev)
+{
+       struct ip17xx_state *state = pdev->priv;
+
+       if (state->registered)
+               unregister_switch(&state->dev);
+       kfree(state);
+}
+
+static int ip17xx_config_aneg(struct phy_device *pdev)
+{
+       return 0;
+}
+
+static int ip17xx_read_status(struct phy_device *pdev)
+{
+       pdev->speed = SPEED_100;
+       pdev->duplex = DUPLEX_FULL;
+       pdev->pause = pdev->asym_pause = 0;
+       pdev->link = 1;
+
+       return 0;
+}
+
+static struct phy_driver ip17xx_driver = {
+       .name           = "IC+ IP17xx",
+       .phy_id         = 0x02430c00,
+       .phy_id_mask    = 0x0ffffc00,
+       .features       = PHY_BASIC_FEATURES,
+       .probe          = ip17xx_probe,
+       .remove         = ip17xx_remove,
+       .config_init    = ip17xx_config_init,
+       .config_aneg    = ip17xx_config_aneg,
+       .read_status    = ip17xx_read_status,
+       .driver         = { .owner = THIS_MODULE },
+};
+
+static struct phy_driver ip175a_driver = {
+       .name           = "IC+ IP175A",
+       .phy_id         = 0x02430c50,
+       .phy_id_mask    = 0x0ffffff0,
+       .features       = PHY_BASIC_FEATURES,
+       .probe          = ip17xx_probe,
+       .remove         = ip17xx_remove,
+       .config_init    = ip17xx_config_init,
+       .config_aneg    = ip17xx_config_aneg,
+       .read_status    = ip17xx_read_status,
+       .driver         = { .owner = THIS_MODULE },
+};
+
+
+int __init ip17xx_init(void)
+{
+       int ret;
+
+       ret = phy_driver_register(&ip175a_driver);
+       if (ret < 0)
+               return ret;
+
+       return phy_driver_register(&ip17xx_driver);
+}
+
+void __exit ip17xx_exit(void)
+{
+       phy_driver_unregister(&ip17xx_driver);
+       phy_driver_unregister(&ip175a_driver);
+}
+
+MODULE_AUTHOR("Patrick Horn <patrick.horn@gmail.com>");
+MODULE_AUTHOR("Felix Fietkau <nbd@openwrt.org>");
+MODULE_AUTHOR("Martin Mares <mj@ucw.cz>");
+MODULE_LICENSE("GPL");
+
+module_init(ip17xx_init);
+module_exit(ip17xx_exit);
index 901b5b2f83ef578b011de83189c2c7a82207dcfb..87c661a77a3b1b3310cb2039e5743723febfcaef 100644 (file)
@@ -250,11 +250,6 @@ static const struct rtl_reg rtl_regs[] = {
 };
 
 
-/* IFXMIPS compat stuff - remove after PHY layer migration */
-static struct switch_dev rtldev;
-/* END IFXMIPS compat stuff */
-
-
 static inline void
 rtl_set_page(struct rtl_priv *priv, unsigned int page)
 {
@@ -706,64 +701,6 @@ rtl_set_ports(struct switch_dev *dev, struct switch_val *val)
        return 0;
 }
 
-static int
-rtl8306_config_init(struct phy_device *pdev)
-{
-       struct net_device *netdev = pdev->attached_dev;
-       struct rtl_priv *priv = pdev->priv;
-       struct switch_dev *dev = &priv->dev;
-       struct switch_val val;
-       unsigned int chipid, chipver, chiptype;
-       int err;
-
-       /* Only init the switch for the primary PHY */
-       if (pdev->addr != 0)
-               return 0;
-
-       val.value.i = 1;
-       memcpy(&priv->dev, &rtldev, sizeof(struct switch_dev));
-       priv->do_cpu = 0;
-       priv->page = -1;
-       priv->bus = pdev->bus;
-
-       dev->priv = priv;
-
-       chipid = rtl_get(dev, RTL_REG_CHIPID);
-       chipver = rtl_get(dev, RTL_REG_CHIPVER);
-       chiptype = rtl_get(dev, RTL_REG_CHIPTYPE);
-       switch(chiptype) {
-       case 0:
-       case 2:
-               strncpy(priv->hwname, RTL_NAME_S, sizeof(priv->hwname));
-               priv->type = RTL_TYPE_S;
-               break;
-       case 1:
-               strncpy(priv->hwname, RTL_NAME_SD, sizeof(priv->hwname));
-               priv->type = RTL_TYPE_SD;
-               break;
-       case 3:
-               strncpy(priv->hwname, RTL_NAME_SDM, sizeof(priv->hwname));
-               priv->type = RTL_TYPE_SDM;
-               break;
-       default:
-               strncpy(priv->hwname, RTL_NAME_UNKNOWN, sizeof(priv->hwname));
-               break;
-       }
-
-       dev->name = priv->hwname;
-       rtl_hw_init(dev);
-
-       printk(KERN_INFO "Registering %s switch with Chip ID: 0x%04x, version: 0x%04x\n", priv->hwname, chipid, chipver);
-
-       err = register_switch(dev, netdev);
-       if (err < 0) {
-               kfree(priv);
-               return err;
-       }
-
-       return 0;
-}
-
 static struct switch_attr rtl_globals[] = {
        {
                .type = SWITCH_TYPE_INT,
@@ -897,11 +834,7 @@ static struct switch_attr rtl_vlan[] = {
        },
 };
 
-/* template */
-static struct switch_dev rtldev = {
-       .cpu_port = RTL8306_PORT_CPU,
-       .ports = RTL8306_NUM_PORTS,
-       .vlans = RTL8306_NUM_VLANS,
+static const struct switch_dev_ops rtl8306_ops = {
        .attr_global = {
                .attr = rtl_globals,
                .n_attr = ARRAY_SIZE(rtl_globals),
@@ -920,6 +853,65 @@ static struct switch_dev rtldev = {
        .apply_config = rtl_hw_apply,
 };
 
+static int
+rtl8306_config_init(struct phy_device *pdev)
+{
+       struct net_device *netdev = pdev->attached_dev;
+       struct rtl_priv *priv = pdev->priv;
+       struct switch_dev *dev = &priv->dev;
+       struct switch_val val;
+       unsigned int chipid, chipver, chiptype;
+       int err;
+
+       /* Only init the switch for the primary PHY */
+       if (pdev->addr != 0)
+               return 0;
+
+       val.value.i = 1;
+       priv->dev.cpu_port = RTL8306_PORT_CPU;
+       priv->dev.ports = RTL8306_NUM_PORTS;
+       priv->dev.vlans = RTL8306_NUM_VLANS;
+       priv->dev.ops = &rtl8306_ops;
+       priv->do_cpu = 0;
+       priv->page = -1;
+       priv->bus = pdev->bus;
+
+       chipid = rtl_get(dev, RTL_REG_CHIPID);
+       chipver = rtl_get(dev, RTL_REG_CHIPVER);
+       chiptype = rtl_get(dev, RTL_REG_CHIPTYPE);
+       switch(chiptype) {
+       case 0:
+       case 2:
+               strncpy(priv->hwname, RTL_NAME_S, sizeof(priv->hwname));
+               priv->type = RTL_TYPE_S;
+               break;
+       case 1:
+               strncpy(priv->hwname, RTL_NAME_SD, sizeof(priv->hwname));
+               priv->type = RTL_TYPE_SD;
+               break;
+       case 3:
+               strncpy(priv->hwname, RTL_NAME_SDM, sizeof(priv->hwname));
+               priv->type = RTL_TYPE_SDM;
+               break;
+       default:
+               strncpy(priv->hwname, RTL_NAME_UNKNOWN, sizeof(priv->hwname));
+               break;
+       }
+
+       dev->name = priv->hwname;
+       rtl_hw_init(dev);
+
+       printk(KERN_INFO "Registering %s switch with Chip ID: 0x%04x, version: 0x%04x\n", priv->hwname, chipid, chipver);
+
+       err = register_switch(dev, netdev);
+       if (err < 0) {
+               kfree(priv);
+               return err;
+       }
+
+       return 0;
+}
+
 
 static int
 rtl8306_fixup(struct phy_device *pdev)
index d0b3680562938c2ac84e9f2b23ba986b66380014..c827cd20eeab6ca5eda426ca7a452bd6bc87ca04 100644 (file)
@@ -307,8 +307,8 @@ static int rtl8366_mc_is_used(struct rtl8366_smi *smi, int mc_index, int *used)
        return 0;
 }
 
-int rtl8366_set_vlan(struct rtl8366_smi *smi, int vid, u32 member, u32 untag,
-                    u32 fid)
+static int rtl8366_set_vlan(struct rtl8366_smi *smi, int vid, u32 member,
+                           u32 untag, u32 fid)
 {
        struct rtl8366_vlan_4k vlan4k;
        int err;
@@ -347,47 +347,8 @@ int rtl8366_set_vlan(struct rtl8366_smi *smi, int vid, u32 member, u32 untag,
 
        return err;
 }
-EXPORT_SYMBOL_GPL(rtl8366_set_vlan);
 
-int rtl8366_reset_vlan(struct rtl8366_smi *smi)
-{
-       struct rtl8366_vlan_mc vlanmc;
-       int err;
-       int i;
-
-       /* clear VLAN member configurations */
-       vlanmc.vid = 0;
-       vlanmc.priority = 0;
-       vlanmc.member = 0;
-       vlanmc.untag = 0;
-       vlanmc.fid = 0;
-       for (i = 0; i < smi->num_vlan_mc; i++) {
-               err = smi->ops->set_vlan_mc(smi, i, &vlanmc);
-               if (err)
-                       return err;
-       }
-
-       for (i = 0; i < smi->num_ports; i++) {
-               if (i == smi->cpu_port)
-                       continue;
-
-               err = rtl8366_set_vlan(smi, (i + 1),
-                                       (1 << i) | (1 << smi->cpu_port),
-                                       (1 << i) | (1 << smi->cpu_port),
-                                       0);
-               if (err)
-                       return err;
-
-               err = rtl8366_set_pvid(smi, i, (i + 1));
-               if (err)
-                       return err;
-       }
-
-       return 0;
-}
-EXPORT_SYMBOL_GPL(rtl8366_reset_vlan);
-
-int rtl8366_get_pvid(struct rtl8366_smi *smi, int port, int *val)
+static int rtl8366_get_pvid(struct rtl8366_smi *smi, int port, int *val)
 {
        struct rtl8366_vlan_mc vlanmc;
        int err;
@@ -404,9 +365,9 @@ int rtl8366_get_pvid(struct rtl8366_smi *smi, int port, int *val)
        *val = vlanmc.vid;
        return 0;
 }
-EXPORT_SYMBOL_GPL(rtl8366_get_pvid);
 
-int rtl8366_set_pvid(struct rtl8366_smi *smi, unsigned port, unsigned vid)
+static int rtl8366_set_pvid(struct rtl8366_smi *smi, unsigned port,
+                           unsigned vid)
 {
        struct rtl8366_vlan_mc vlanmc;
        struct rtl8366_vlan_4k vlan4k;
@@ -486,7 +447,44 @@ int rtl8366_set_pvid(struct rtl8366_smi *smi, unsigned port, unsigned vid)
 
        return -ENOSPC;
 }
-EXPORT_SYMBOL_GPL(rtl8366_set_pvid);
+
+int rtl8366_reset_vlan(struct rtl8366_smi *smi)
+{
+       struct rtl8366_vlan_mc vlanmc;
+       int err;
+       int i;
+
+       /* clear VLAN member configurations */
+       vlanmc.vid = 0;
+       vlanmc.priority = 0;
+       vlanmc.member = 0;
+       vlanmc.untag = 0;
+       vlanmc.fid = 0;
+       for (i = 0; i < smi->num_vlan_mc; i++) {
+               err = smi->ops->set_vlan_mc(smi, i, &vlanmc);
+               if (err)
+                       return err;
+       }
+
+       for (i = 0; i < smi->num_ports; i++) {
+               if (i == smi->cpu_port)
+                       continue;
+
+               err = rtl8366_set_vlan(smi, (i + 1),
+                                       (1 << i) | (1 << smi->cpu_port),
+                                       (1 << i) | (1 << smi->cpu_port),
+                                       0);
+               if (err)
+                       return err;
+
+               err = rtl8366_set_pvid(smi, i, (i + 1));
+               if (err)
+                       return err;
+       }
+
+       return 0;
+}
+EXPORT_SYMBOL_GPL(rtl8366_reset_vlan);
 
 #ifdef CONFIG_RTL8366S_PHY_DEBUG_FS
 int rtl8366_debugfs_open(struct inode *inode, struct file *file)
@@ -522,6 +520,34 @@ static ssize_t rtl8366_read_debugfs_vlan_mc(struct file *file,
        return simple_read_from_buffer(user_buf, count, ppos, buf, len);
 }
 
+static ssize_t rtl8366_read_debugfs_pvid(struct file *file,
+                                        char __user *user_buf,
+                                        size_t count, loff_t *ppos)
+{
+       struct rtl8366_smi *smi = (struct rtl8366_smi *)file->private_data;
+       char *buf = smi->buf;
+       int len = 0;
+       int i;
+
+       len += snprintf(buf + len, sizeof(smi->buf) - len, "%4s %4s\n",
+                       "port", "pvid");
+
+       for (i = 0; i < smi->num_ports; i++) {
+               int pvid;
+               int err;
+
+               err = rtl8366_get_pvid(smi, i, &pvid);
+               if (err)
+                       len += snprintf(buf + len, sizeof(smi->buf) - len,
+                               "%4d error\n", i);
+               else
+                       len += snprintf(buf + len, sizeof(smi->buf) - len,
+                               "%4d %4d\n", i, pvid);
+       }
+
+       return simple_read_from_buffer(user_buf, count, ppos, buf, len);
+}
+
 static ssize_t rtl8366_read_debugfs_reg(struct file *file,
                                         char __user *user_buf,
                                         size_t count, loff_t *ppos)
@@ -636,6 +662,12 @@ static const struct file_operations fops_rtl8366_vlan_mc = {
        .owner  = THIS_MODULE
 };
 
+static const struct file_operations fops_rtl8366_pvid = {
+       .read   = rtl8366_read_debugfs_pvid,
+       .open   = rtl8366_debugfs_open,
+       .owner  = THIS_MODULE
+};
+
 static const struct file_operations fops_rtl8366_mibs = {
        .read = rtl8366_read_debugfs_mibs,
        .open = rtl8366_debugfs_open,
@@ -681,6 +713,14 @@ static void rtl8366_debugfs_init(struct rtl8366_smi *smi)
                return;
        }
 
+       node = debugfs_create_file("pvid", S_IRUSR, root, smi,
+                                  &fops_rtl8366_pvid);
+       if (!node) {
+               dev_err(smi->parent, "Creating debugfs file '%s' failed\n",
+                       "pvid");
+               return;
+       }
+
        node = debugfs_create_file("mibs", S_IRUSR, smi->debugfs_root, smi,
                                   &fops_rtl8366_mibs);
        if (!node)
@@ -741,13 +781,168 @@ static void rtl8366_smi_mii_cleanup(struct rtl8366_smi *smi)
        mdiobus_free(smi->mii_bus);
 }
 
-int rtl8366_smi_init(struct rtl8366_smi *smi)
+int rtl8366_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);
+}
+EXPORT_SYMBOL_GPL(rtl8366_sw_get_port_pvid);
+
+int rtl8366_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);
+}
+EXPORT_SYMBOL_GPL(rtl8366_sw_set_port_pvid);
+
+int rtl8366_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 >= smi->num_ports)
+               return -EINVAL;
+
+       len += snprintf(buf + len, sizeof(smi->buf) - len,
+                       "Port %d MIB counters\n",
+                       val->port_vlan);
+
+       for (i = 0; i < smi->num_mib_counters; ++i) {
+               len += snprintf(buf + len, sizeof(smi->buf) - len,
+                               "%-36s: ", smi->mib_counters[i].name);
+               if (!smi->ops->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;
+}
+EXPORT_SYMBOL_GPL(rtl8366_sw_get_port_mib);
+
+int rtl8366_sw_get_vlan_info(struct switch_dev *dev,
+                            const struct switch_attr *attr,
+                            struct switch_val *val)
 {
+       int i;
+       u32 len = 0;
+       struct rtl8366_vlan_4k vlan4k;
+       struct rtl8366_smi *smi = sw_to_rtl8366_smi(dev);
+       char *buf = smi->buf;
        int err;
 
-       if (!smi->parent)
+       if (!smi->ops->is_vlan_valid(smi, val->port_vlan))
                return -EINVAL;
 
+       memset(buf, '\0', sizeof(smi->buf));
+
+       err = smi->ops->get_vlan_4k(smi, val->port_vlan, &vlan4k);
+       if (err)
+               return err;
+
+       len += snprintf(buf + len, sizeof(smi->buf) - len,
+                       "VLAN %d: Ports: '", vlan4k.vid);
+
+       for (i = 0; i < smi->num_ports; i++) {
+               if (!(vlan4k.member & (1 << i)))
+                       continue;
+
+               len += snprintf(buf + len, sizeof(smi->buf) - len, "%d%s", i,
+                               (vlan4k.untag & (1 << i)) ? "" : "t");
+       }
+
+       len += snprintf(buf + len, sizeof(smi->buf) - len,
+                       "', members=%04x, untag=%04x, fid=%u",
+                       vlan4k.member, vlan4k.untag, vlan4k.fid);
+
+       val->value.s = buf;
+       val->len = len;
+
+       return 0;
+}
+EXPORT_SYMBOL_GPL(rtl8366_sw_get_vlan_info);
+
+int rtl8366_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 (!smi->ops->is_vlan_valid(smi, val->port_vlan))
+               return -EINVAL;
+
+       smi->ops->get_vlan_4k(smi, val->port_vlan, &vlan4k);
+
+       port = &val->value.ports[0];
+       val->len = 0;
+       for (i = 0; i < smi->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;
+}
+EXPORT_SYMBOL_GPL(rtl8366_sw_get_vlan_ports);
+
+int rtl8366_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 (!smi->ops->is_vlan_valid(smi, val->port_vlan))
+               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);
+}
+EXPORT_SYMBOL_GPL(rtl8366_sw_set_vlan_ports);
+
+struct rtl8366_smi *rtl8366_smi_alloc(struct device *parent)
+{
+       struct rtl8366_smi *smi;
+
+       BUG_ON(!parent);
+
+       smi = kzalloc(sizeof(*smi), GFP_KERNEL);
+       if (!smi) {
+               dev_err(parent, "no memory for private data\n");
+               return NULL;
+       }
+
+       smi->parent = parent;
+       return smi;
+}
+EXPORT_SYMBOL_GPL(rtl8366_smi_alloc);
+
+int rtl8366_smi_init(struct rtl8366_smi *smi)
+{
+       int err;
+
        if (!smi->ops)
                return -EINVAL;
 
@@ -776,6 +971,12 @@ int rtl8366_smi_init(struct rtl8366_smi *smi)
                goto err_free_sck;
        }
 
+       err = smi->ops->setup(smi);
+       if (err) {
+               dev_err(smi->parent, "chip setup failed, err=%d\n", err);
+               goto err_free_sck;
+       }
+
        err = rtl8366_smi_mii_init(smi);
        if (err)
                goto err_free_sck;
index 3b639f2b691fd8268a187ca06b68a765e02d09cc..2cd4a8ff44d1bc795eaedd5ed267f738f892e19e 100644 (file)
@@ -12,6 +12,7 @@
 #define _RTL8366_SMI_H
 
 #include <linux/phy.h>
+#include <linux/switch.h>
 
 struct rtl8366_smi_ops;
 struct rtl8366_vlan_ops;
@@ -34,6 +35,7 @@ struct rtl8366_smi {
        spinlock_t              lock;
        struct mii_bus          *mii_bus;
        int                     mii_irq[PHY_MAX_ADDR];
+       struct switch_dev       sw_dev;
 
        unsigned int            cpu_port;
        unsigned int            num_ports;
@@ -67,6 +69,7 @@ struct rtl8366_vlan_4k {
 
 struct rtl8366_smi_ops {
        int     (*detect)(struct rtl8366_smi *smi);
+       int     (*setup)(struct rtl8366_smi *smi);
 
        int     (*mii_read)(struct mii_bus *bus, int addr, int reg);
        int     (*mii_write)(struct mii_bus *bus, int addr, int reg, u16 val);
@@ -83,22 +86,36 @@ struct rtl8366_smi_ops {
        int     (*set_mc_index)(struct rtl8366_smi *smi, int port, int index);
        int     (*get_mib_counter)(struct rtl8366_smi *smi, int counter,
                                   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);
 int rtl8366_smi_init(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_read_reg(struct rtl8366_smi *smi, u32 addr, u32 *data);
 int rtl8366_smi_rmwr(struct rtl8366_smi *smi, u32 addr, u32 mask, u32 data);
 
-int rtl8366_set_vlan(struct rtl8366_smi *smi, int vid, u32 member, u32 untag,
-                    u32 fid);
 int rtl8366_reset_vlan(struct rtl8366_smi *smi);
-int rtl8366_get_pvid(struct rtl8366_smi *smi, int port, int *val);
-int rtl8366_set_pvid(struct rtl8366_smi *smi, unsigned port, unsigned vid);
 
 #ifdef CONFIG_RTL8366S_PHY_DEBUG_FS
 int rtl8366_debugfs_open(struct inode *inode, struct file *file);
 #endif
 
+static inline struct rtl8366_smi *sw_to_rtl8366_smi(struct switch_dev *sw)
+{
+       return container_of(sw, struct rtl8366_smi, sw_dev);
+}
+
+int rtl8366_sw_get_port_pvid(struct switch_dev *dev, int port, int *val);
+int rtl8366_sw_set_port_pvid(struct switch_dev *dev, int port, int val);
+int rtl8366_sw_get_port_mib(struct switch_dev *dev,
+                           const struct switch_attr *attr,
+                           struct switch_val *val);
+int rtl8366_sw_get_vlan_info(struct switch_dev *dev,
+                            const struct switch_attr *attr,
+                            struct switch_val *val);
+int rtl8366_sw_get_vlan_ports(struct switch_dev *dev, struct switch_val *val);
+int rtl8366_sw_set_vlan_ports(struct switch_dev *dev, struct switch_val *val);
+
 #endif /*  _RTL8366_SMI_H */
index 7eba6c40a03602eb852a2db6c7fb460e23c0708b..d442d2feb8d4147334661849ba079158ecf42152 100644 (file)
@@ -15,7 +15,6 @@
 #include <linux/platform_device.h>
 #include <linux/delay.h>
 #include <linux/skbuff.h>
-#include <linux/switch.h>
 #include <linux/rtl8366rb.h>
 
 #include "rtl8366_smi.h"
 #define RTL8366RB_TABLE_VLAN_READ_CTRL         0x0E01
 #define RTL8366RB_TABLE_VLAN_WRITE_CTRL                0x0F01
 
-#define RTL8366RB_VLAN_MEMCONF_BASE            0x0020
+#define RTL8366RB_VLAN_MC_BASE(_x)             (0x0020 + (_x) * 3)
 
 
 #define RTL8366RB_PORT_LINK_STATUS_BASE                0x0014
 
 #define RTL8366RB_PORT_ALL_INTERNAL     RTL8366RB_PORT_CPU
 
-struct rtl8366rb {
-       struct device           *parent;
-       struct rtl8366_smi      smi;
-       struct switch_dev       dev;
-};
-
-struct rtl8366rb_vlan_mc {
-       u16     reserved2:1;
-       u16     priority:3;
-       u16     vid:12;
-       u16     untag:8;
-       u16     member:8;
-       u16     stag_mbr:8;
-       u16     stag_idx:3;
-       u16     reserved1:2;
-       u16     fid:3;
-};
-
-struct rtl8366rb_vlan_4k {
-       u16     reserved1:4;
-       u16     vid:12;
-       u16     untag:8;
-       u16     member:8;
-       u16     reserved2:13;
-       u16     fid:3;
-};
+#define RTL8366RB_VLAN_VID_MASK                0xfff
+#define RTL8366RB_VLAN_PRIORITY_SHIFT  12
+#define RTL8366RB_VLAN_PRIORITY_MASK   0x7
+#define RTL8366RB_VLAN_UNTAG_SHIFT     8
+#define RTL8366RB_VLAN_UNTAG_MASK      0xff
+#define RTL8366RB_VLAN_MEMBER_MASK     0xff
+#define RTL8366RB_VLAN_FID_MASK                0x7
 
 static struct rtl8366_mib_counter rtl8366rb_mib_counters[] = {
        { 0,  0, 4, "IfInOctets"                                },
@@ -233,22 +213,6 @@ static struct rtl8366_mib_counter rtl8366rb_mib_counters[] = {
                        return err;                                     \
        } while (0)
 
-static inline struct rtl8366rb *smi_to_rtl8366rb(struct rtl8366_smi *smi)
-{
-       return container_of(smi, struct rtl8366rb, smi);
-}
-
-static inline struct rtl8366rb *sw_to_rtl8366rb(struct switch_dev *sw)
-{
-       return container_of(sw, struct rtl8366rb, dev);
-}
-
-static inline struct rtl8366_smi *sw_to_rtl8366_smi(struct switch_dev *sw)
-{
-       struct rtl8366rb *rtl = sw_to_rtl8366rb(sw);
-       return &rtl->smi;
-}
-
 static int rtl8366rb_reset_chip(struct rtl8366_smi *smi)
 {
        int timeout = 10;
@@ -419,22 +383,18 @@ static int rtl8366rb_get_mib_counter(struct rtl8366_smi *smi, int counter,
 static int rtl8366rb_get_vlan_4k(struct rtl8366_smi *smi, u32 vid,
                                 struct rtl8366_vlan_4k *vlan4k)
 {
-       struct rtl8366rb_vlan_4k vlan4k_priv;
+       u32 data[3];
        int err;
-       u32 data;
-       u16 *tableaddr;
+       int i;
 
        memset(vlan4k, '\0', sizeof(struct rtl8366_vlan_4k));
-       vlan4k_priv.vid = vid;
 
        if (vid >= RTL8366RB_NUM_VIDS)
                return -EINVAL;
 
-       tableaddr = (u16 *)&vlan4k_priv;
-
        /* write VID */
-       data = *tableaddr;
-       err = rtl8366_smi_write_reg(smi, RTL8366RB_VLAN_TABLE_WRITE_BASE, data);
+       err = rtl8366_smi_write_reg(smi, RTL8366RB_VLAN_TABLE_WRITE_BASE,
+                                   vid & RTL8366RB_VLAN_VID_MASK);
        if (err)
                return err;
 
@@ -444,31 +404,19 @@ static int rtl8366rb_get_vlan_4k(struct rtl8366_smi *smi, u32 vid,
        if (err)
                return err;
 
-       err = rtl8366_smi_read_reg(smi, RTL8366RB_VLAN_TABLE_READ_BASE, &data);
-       if (err)
-               return err;
-
-       *tableaddr = data;
-       tableaddr++;
-
-       err = rtl8366_smi_read_reg(smi, RTL8366RB_VLAN_TABLE_READ_BASE + 1,
-                                  &data);
-       if (err)
-               return err;
-
-       *tableaddr = data;
-       tableaddr++;
-
-       err = rtl8366_smi_read_reg(smi, RTL8366RB_VLAN_TABLE_READ_BASE + 2,
-                                  &data);
-       if (err)
-               return err;
-       *tableaddr = data;
+       for (i = 0; i < 3; i++) {
+               err = rtl8366_smi_read_reg(smi,
+                                          RTL8366RB_VLAN_TABLE_READ_BASE + i,
+                                          &data[i]);
+               if (err)
+                       return err;
+       }
 
        vlan4k->vid = vid;
-       vlan4k->untag = vlan4k_priv.untag;
-       vlan4k->member = vlan4k_priv.member;
-       vlan4k->fid = vlan4k_priv.fid;
+       vlan4k->untag = (data[1] >> RTL8366RB_VLAN_UNTAG_SHIFT) &
+                       RTL8366RB_VLAN_UNTAG_MASK;
+       vlan4k->member = data[1] & RTL8366RB_VLAN_MEMBER_MASK;
+       vlan4k->fid = data[2] & RTL8366RB_VLAN_FID_MASK;
 
        return 0;
 }
@@ -476,10 +424,9 @@ static int rtl8366rb_get_vlan_4k(struct rtl8366_smi *smi, u32 vid,
 static int rtl8366rb_set_vlan_4k(struct rtl8366_smi *smi,
                                 const struct rtl8366_vlan_4k *vlan4k)
 {
-       struct rtl8366rb_vlan_4k vlan4k_priv;
+       u32 data[3];
        int err;
-       u32 data;
-       u16 *tableaddr;
+       int i;
 
        if (vlan4k->vid >= RTL8366RB_NUM_VIDS ||
            vlan4k->member > RTL8366RB_PORT_ALL ||
@@ -487,36 +434,19 @@ static int rtl8366rb_set_vlan_4k(struct rtl8366_smi *smi,
            vlan4k->fid > RTL8366RB_FIDMAX)
                return -EINVAL;
 
-       vlan4k_priv.vid = vlan4k->vid;
-       vlan4k_priv.untag = vlan4k->untag;
-       vlan4k_priv.member = vlan4k->member;
-       vlan4k_priv.fid = vlan4k->fid;
-
-       tableaddr = (u16 *)&vlan4k_priv;
-
-       data = *tableaddr;
-
-       err = rtl8366_smi_write_reg(smi, RTL8366RB_VLAN_TABLE_WRITE_BASE, data);
-       if (err)
-               return err;
-
-       tableaddr++;
-
-       data = *tableaddr;
-
-       err = rtl8366_smi_write_reg(smi, RTL8366RB_VLAN_TABLE_WRITE_BASE + 1,
-                                   data);
-       if (err)
-               return err;
-
-       tableaddr++;
+       data[0] = vlan4k->vid & RTL8366RB_VLAN_VID_MASK;
+       data[1] = (vlan4k->member & RTL8366RB_VLAN_MEMBER_MASK) |
+                 ((vlan4k->untag & RTL8366RB_VLAN_UNTAG_MASK) <<
+                       RTL8366RB_VLAN_UNTAG_SHIFT);
+       data[2] = vlan4k->fid & RTL8366RB_VLAN_FID_MASK;
 
-       data = *tableaddr;
-
-       err = rtl8366_smi_write_reg(smi, RTL8366RB_VLAN_TABLE_WRITE_BASE + 2,
-                                   data);
-       if (err)
-               return err;
+       for (i = 0; i < 3; i++) {
+               err = rtl8366_smi_write_reg(smi,
+                                           RTL8366RB_VLAN_TABLE_WRITE_BASE + i,
+                                           data[i]);
+               if (err)
+                       return err;
+       }
 
        /* write table access control word */
        err = rtl8366_smi_write_reg(smi, RTL8366RB_TABLE_ACCESS_CTRL_REG,
@@ -528,47 +458,30 @@ static int rtl8366rb_set_vlan_4k(struct rtl8366_smi *smi,
 static int rtl8366rb_get_vlan_mc(struct rtl8366_smi *smi, u32 index,
                                 struct rtl8366_vlan_mc *vlanmc)
 {
-       struct rtl8366rb_vlan_mc vlanmc_priv;
+       u32 data[3];
        int err;
-       u32 addr;
-       u32 data;
-       u16 *tableaddr;
+       int i;
 
        memset(vlanmc, '\0', sizeof(struct rtl8366_vlan_mc));
 
        if (index >= RTL8366RB_NUM_VLANS)
                return -EINVAL;
 
-       tableaddr = (u16 *)&vlanmc_priv;
-
-       addr = RTL8366RB_VLAN_MEMCONF_BASE + (index * 3);
-       err = rtl8366_smi_read_reg(smi, addr, &data);
-       if (err)
-               return err;
-
-       *tableaddr = data;
-       tableaddr++;
-
-       addr = RTL8366RB_VLAN_MEMCONF_BASE + 1 + (index * 3);
-       err = rtl8366_smi_read_reg(smi, addr, &data);
-       if (err)
-               return err;
-
-       *tableaddr = data;
-       tableaddr++;
-
-       addr = RTL8366RB_VLAN_MEMCONF_BASE + 2 + (index * 3);
-       err = rtl8366_smi_read_reg(smi, addr, &data);
-       if (err)
-               return err;
-
-       *tableaddr = data;
+       for (i = 0; i < 3; i++) {
+               err = rtl8366_smi_read_reg(smi,
+                                          RTL8366RB_VLAN_MC_BASE(index) + i,
+                                          &data[i]);
+               if (err)
+                       return err;
+       }
 
-       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;
+       vlanmc->vid = data[0] & RTL8366RB_VLAN_VID_MASK;
+       vlanmc->priority = (data[0] >> RTL8366RB_VLAN_PRIORITY_SHIFT) &
+                          RTL8366RB_VLAN_PRIORITY_MASK;
+       vlanmc->untag = (data[1] >> RTL8366RB_VLAN_UNTAG_SHIFT) &
+                       RTL8366RB_VLAN_UNTAG_MASK;
+       vlanmc->member = data[1] & RTL8366RB_VLAN_MEMBER_MASK;
+       vlanmc->fid = data[2] & RTL8366RB_VLAN_FID_MASK;
 
        return 0;
 }
@@ -576,11 +489,9 @@ static int rtl8366rb_get_vlan_mc(struct rtl8366_smi *smi, u32 index,
 static int rtl8366rb_set_vlan_mc(struct rtl8366_smi *smi, u32 index,
                                 const struct rtl8366_vlan_mc *vlanmc)
 {
-       struct rtl8366rb_vlan_mc vlanmc_priv;
+       u32 data[3];
        int err;
-       u32 addr;
-       u32 data;
-       u16 *tableaddr;
+       int i;
 
        if (index >= RTL8366RB_NUM_VLANS ||
            vlanmc->vid >= RTL8366RB_NUM_VIDS ||
@@ -590,40 +501,22 @@ static int rtl8366rb_set_vlan_mc(struct rtl8366_smi *smi, u32 index,
            vlanmc->fid > RTL8366RB_FIDMAX)
                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 = RTL8366RB_VLAN_MEMCONF_BASE + (index * 3);
-
-       tableaddr = (u16 *)&vlanmc_priv;
-       data = *tableaddr;
-
-       err = rtl8366_smi_write_reg(smi, addr, data);
-       if (err)
-               return err;
-
-       addr = RTL8366RB_VLAN_MEMCONF_BASE + 1 + (index * 3);
-
-       tableaddr++;
-       data = *tableaddr;
-
-       err = rtl8366_smi_write_reg(smi, addr, data);
-       if (err)
-               return err;
-
-       addr = RTL8366RB_VLAN_MEMCONF_BASE + 2 + (index * 3);
-
-       tableaddr++;
-       data = *tableaddr;
+       data[0] = (vlanmc->vid & RTL8366RB_VLAN_VID_MASK) |
+                 ((vlanmc->priority & RTL8366RB_VLAN_PRIORITY_MASK) <<
+                       RTL8366RB_VLAN_PRIORITY_SHIFT);
+       data[1] = (vlanmc->member & RTL8366RB_VLAN_MEMBER_MASK) |
+                 ((vlanmc->untag & RTL8366RB_VLAN_UNTAG_MASK) <<
+                       RTL8366RB_VLAN_UNTAG_SHIFT);
+       data[2] = vlanmc->fid & RTL8366RB_VLAN_FID_MASK;
+
+       for (i = 0; i < 3; i++) {
+               err = rtl8366_smi_write_reg(smi,
+                                           RTL8366RB_VLAN_MC_BASE(index) + i,
+                                           data[i]);
+               if (err)
+                       return err;
+       }
 
-       err = rtl8366_smi_write_reg(smi, addr, data);
-       if (err)
-               return err;
        return 0;
 }
 
@@ -659,6 +552,14 @@ static int rtl8366rb_set_mc_index(struct rtl8366_smi *smi, int port, int index)
                                        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)
 {
        return rtl8366_smi_rmwr(smi, RTL8366RB_SGCR, RTL8366RB_SGCR_EN_VLAN,
@@ -677,13 +578,9 @@ static int rtl8366rb_sw_reset_mibs(struct switch_dev *dev,
                                  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, RTL8366RB_MIB_CTRL_REG, 0,
-                                      RTL8366RB_MIB_CTRL_GLOBAL_RESET);
-
-       return err;
+       return rtl8366_smi_rmwr(smi, RTL8366RB_MIB_CTRL_REG, 0,
+                               RTL8366RB_MIB_CTRL_GLOBAL_RESET);
 }
 
 static int rtl8366rb_sw_get_vlan_enable(struct switch_dev *dev,
@@ -843,47 +740,6 @@ static int rtl8366rb_sw_get_port_link(struct switch_dev *dev,
        return 0;
 }
 
-static int rtl8366rb_sw_get_vlan_info(struct switch_dev *dev,
-                                    const struct switch_attr *attr,
-                                    struct switch_val *val)
-{
-       int i;
-       u32 len = 0;
-       struct rtl8366_vlan_4k vlan4k;
-       struct rtl8366_smi *smi = sw_to_rtl8366_smi(dev);
-       char *buf = smi->buf;
-       int err;
-
-       if (val->port_vlan == 0 || val->port_vlan >= RTL8366RB_NUM_VLANS)
-               return -EINVAL;
-
-       memset(buf, '\0', sizeof(smi->buf));
-
-       err = rtl8366rb_get_vlan_4k(smi, val->port_vlan, &vlan4k);
-       if (err)
-               return err;
-
-       len += snprintf(buf + len, sizeof(smi->buf) - len,
-                       "VLAN %d: Ports: '", vlan4k.vid);
-
-       for (i = 0; i < RTL8366RB_NUM_PORTS; i++) {
-               if (!(vlan4k.member & (1 << i)))
-                       continue;
-
-               len += snprintf(buf + len, sizeof(smi->buf) - len, "%d%s", i,
-                               (vlan4k.untag & (1 << i)) ? "" : "t");
-       }
-
-       len += snprintf(buf + len, sizeof(smi->buf) - len,
-                       "', members=%04x, untag=%04x, fid=%u",
-                       vlan4k.member, vlan4k.untag, vlan4k.fid);
-
-       val->value.s = buf;
-       val->len = len;
-
-       return 0;
-}
-
 static int rtl8366rb_sw_set_port_led(struct switch_dev *dev,
                                    const struct switch_attr *attr,
                                    struct switch_val *val)
@@ -938,101 +794,6 @@ static int rtl8366rb_sw_reset_port_mibs(struct switch_dev *dev,
                                RTL8366RB_MIB_CTRL_PORT_RESET(val->port_vlan));
 }
 
-static int rtl8366rb_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 >= RTL8366RB_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(rtl8366rb_mib_counters); ++i) {
-               len += snprintf(buf + len, sizeof(smi->buf) - len,
-                               "%-36s: ", rtl8366rb_mib_counters[i].name);
-               if (!rtl8366rb_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 rtl8366rb_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 >= RTL8366RB_NUM_VLANS)
-               return -EINVAL;
-
-       rtl8366rb_get_vlan_4k(smi, val->port_vlan, &vlan4k);
-
-       port = &val->value.ports[0];
-       val->len = 0;
-       for (i = 0; i < RTL8366RB_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 rtl8366rb_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 >= RTL8366RB_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 rtl8366rb_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 rtl8366rb_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);
-}
-
 static int rtl8366rb_sw_reset_switch(struct switch_dev *dev)
 {
        struct rtl8366_smi *smi = sw_to_rtl8366_smi(dev);
@@ -1074,12 +835,10 @@ static struct switch_attr rtl8366rb_globals[] = {
                .max = 1,
                .ofs = 2
        }, {
-               .type = SWITCH_TYPE_INT,
+               .type = SWITCH_TYPE_NOVAL,
                .name = "reset_mibs",
                .description = "Reset all MIB counters",
                .set = rtl8366rb_sw_reset_mibs,
-               .get = NULL,
-               .max = 1
        }, {
                .type = SWITCH_TYPE_INT,
                .name = "blinkrate",
@@ -1100,19 +859,17 @@ static struct switch_attr rtl8366rb_port[] = {
                .set = NULL,
                .get = rtl8366rb_sw_get_port_link,
        }, {
-               .type = SWITCH_TYPE_INT,
+               .type = SWITCH_TYPE_NOVAL,
                .name = "reset_mib",
                .description = "Reset single port MIB counters",
-               .max = 1,
                .set = rtl8366rb_sw_reset_port_mibs,
-               .get = NULL,
        }, {
                .type = SWITCH_TYPE_STRING,
                .name = "mib",
                .description = "Get MIB counters for port",
                .max = 33,
                .set = NULL,
-               .get = rtl8366rb_sw_get_port_mib,
+               .get = rtl8366_sw_get_port_mib,
        }, {
                .type = SWITCH_TYPE_INT,
                .name = "led",
@@ -1130,16 +887,11 @@ static struct switch_attr rtl8366rb_vlan[] = {
                .description = "Get vlan information",
                .max = 1,
                .set = NULL,
-               .get = rtl8366rb_sw_get_vlan_info,
+               .get = rtl8366_sw_get_vlan_info,
        },
 };
 
-/* template */
-static struct switch_dev rtl8366_switch_dev = {
-       .name = "RTL8366S",
-       .cpu_port = RTL8366RB_PORT_NUM_CPU,
-       .ports = RTL8366RB_NUM_PORTS,
-       .vlans = RTL8366RB_NUM_VLANS,
+static const struct switch_dev_ops rtl8366_ops = {
        .attr_global = {
                .attr = rtl8366rb_globals,
                .n_attr = ARRAY_SIZE(rtl8366rb_globals),
@@ -1153,32 +905,35 @@ static struct switch_dev rtl8366_switch_dev = {
                .n_attr = ARRAY_SIZE(rtl8366rb_vlan),
        },
 
-       .get_vlan_ports = rtl8366rb_sw_get_vlan_ports,
-       .set_vlan_ports = rtl8366rb_sw_set_vlan_ports,
-       .get_port_pvid = rtl8366rb_sw_get_port_pvid,
-       .set_port_pvid = rtl8366rb_sw_set_port_pvid,
+       .get_vlan_ports = rtl8366_sw_get_vlan_ports,
+       .set_vlan_ports = rtl8366_sw_set_vlan_ports,
+       .get_port_pvid = rtl8366_sw_get_port_pvid,
+       .set_port_pvid = rtl8366_sw_set_port_pvid,
        .reset_switch = rtl8366rb_sw_reset_switch,
 };
 
-static int rtl8366rb_switch_init(struct rtl8366rb *rtl)
+static int rtl8366rb_switch_init(struct rtl8366_smi *smi)
 {
-       struct switch_dev *dev = &rtl->dev;
+       struct switch_dev *dev = &smi->sw_dev;
        int err;
 
-       memcpy(dev, &rtl8366_switch_dev, sizeof(struct switch_dev));
-       dev->priv = rtl;
-       dev->devname = dev_name(rtl->parent);
+       dev->name = "RTL8366RB";
+       dev->cpu_port = RTL8366RB_PORT_NUM_CPU;
+       dev->ports = RTL8366RB_NUM_PORTS;
+       dev->vlans = RTL8366RB_NUM_VLANS;
+       dev->ops = &rtl8366_ops;
+       dev->devname = dev_name(smi->parent);
 
        err = register_switch(dev, NULL);
        if (err)
-               dev_err(rtl->parent, "switch registration failed\n");
+               dev_err(smi->parent, "switch registration failed\n");
 
        return err;
 }
 
-static void rtl8366rb_switch_cleanup(struct rtl8366rb *rtl)
+static void rtl8366rb_switch_cleanup(struct rtl8366_smi *smi)
 {
-       unregister_switch(&rtl->dev);
+       unregister_switch(&smi->sw_dev);
 }
 
 static int rtl8366rb_mii_read(struct mii_bus *bus, int addr, int reg)
@@ -1213,9 +968,8 @@ static int rtl8366rb_mii_bus_match(struct mii_bus *bus)
                bus->write == rtl8366rb_mii_write);
 }
 
-static int rtl8366rb_setup(struct rtl8366rb *rtl)
+static int rtl8366rb_setup(struct rtl8366_smi *smi)
 {
-       struct rtl8366_smi *smi = &rtl->smi;
        int ret;
 
        ret = rtl8366rb_reset_chip(smi);
@@ -1261,6 +1015,8 @@ static int rtl8366rb_detect(struct rtl8366_smi *smi)
 
 static struct rtl8366_smi_ops rtl8366rb_smi_ops = {
        .detect         = rtl8366rb_detect,
+       .setup          = rtl8366rb_setup,
+
        .mii_read       = rtl8366rb_mii_read,
        .mii_write      = rtl8366rb_mii_write,
 
@@ -1271,13 +1027,13 @@ static struct rtl8366_smi_ops rtl8366rb_smi_ops = {
        .get_mc_index   = rtl8366rb_get_mc_index,
        .set_mc_index   = rtl8366rb_set_mc_index,
        .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 rtl8366_smi_version_printed;
        struct rtl8366rb_platform_data *pdata;
-       struct rtl8366rb *rtl;
        struct rtl8366_smi *smi;
        int err;
 
@@ -1292,17 +1048,12 @@ static int __init rtl8366rb_probe(struct platform_device *pdev)
                goto err_out;
        }
 
-       rtl = kzalloc(sizeof(*rtl), GFP_KERNEL);
-       if (!rtl) {
-               dev_err(&pdev->dev, "no memory for private data\n");
+       smi = rtl8366_smi_alloc(&pdev->dev);
+       if (!smi) {
                err = -ENOMEM;
                goto err_out;
        }
 
-       rtl->parent = &pdev->dev;
-
-       smi = &rtl->smi;
-       smi->parent = &pdev->dev;
        smi->gpio_sda = pdata->gpio_sda;
        smi->gpio_sck = pdata->gpio_sck;
        smi->ops = &rtl8366rb_smi_ops;
@@ -1314,15 +1065,11 @@ static int __init rtl8366rb_probe(struct platform_device *pdev)
 
        err = rtl8366_smi_init(smi);
        if (err)
-               goto err_free_rtl;
-
-       platform_set_drvdata(pdev, rtl);
+               goto err_free_smi;
 
-       err = rtl8366rb_setup(rtl);
-       if (err)
-               goto err_clear_drvdata;
+       platform_set_drvdata(pdev, smi);
 
-       err = rtl8366rb_switch_init(rtl);
+       err = rtl8366rb_switch_init(smi);
        if (err)
                goto err_clear_drvdata;
 
@@ -1331,8 +1078,8 @@ static int __init rtl8366rb_probe(struct platform_device *pdev)
  err_clear_drvdata:
        platform_set_drvdata(pdev, NULL);
        rtl8366_smi_cleanup(smi);
- err_free_rtl:
-       kfree(rtl);
+ err_free_smi:
+       kfree(smi);
  err_out:
        return err;
 }
@@ -1365,13 +1112,13 @@ static struct phy_driver rtl8366rb_phy_driver = {
 
 static int __devexit rtl8366rb_remove(struct platform_device *pdev)
 {
-       struct rtl8366rb *rtl = platform_get_drvdata(pdev);
+       struct rtl8366_smi *smi = platform_get_drvdata(pdev);
 
-       if (rtl) {
-               rtl8366rb_switch_cleanup(rtl);
+       if (smi) {
+               rtl8366rb_switch_cleanup(smi);
                platform_set_drvdata(pdev, NULL);
-               rtl8366_smi_cleanup(&rtl->smi);
-               kfree(rtl);
+               rtl8366_smi_cleanup(smi);
+               kfree(smi);
        }
 
        return 0;
index 615f930936c7c5ae9f0f6dff51635a30b6b3c3fc..ad631ef728b084c40cf356070cac26bd7928feac 100644 (file)
@@ -15,7 +15,6 @@
 #include <linux/platform_device.h>
 #include <linux/delay.h>
 #include <linux/skbuff.h>
-#include <linux/switch.h>
 #include <linux/rtl8366s.h>
 
 #include "rtl8366_smi.h"
 #define RTL8366S_TABLE_VLAN_READ_CTRL          0x0E01
 #define RTL8366S_TABLE_VLAN_WRITE_CTRL         0x0F01
 
-#define RTL8366S_VLAN_MEMCONF_BASE             0x0016
+#define RTL8366S_VLAN_MC_BASE(_x)              (0x0016 + (_x) * 2)
 
 #define RTL8366S_VLAN_MEMBERINGRESS_REG                0x0379
 
 #define RTL8366S_PORT_ALL_INTERNAL     (RTL8366S_PORT_UNKNOWN | \
                                         RTL8366S_PORT_CPU)
 
-struct rtl8366s {
-       struct device           *parent;
-       struct rtl8366_smi      smi;
-       struct switch_dev       dev;
-};
-
-struct rtl8366s_vlan_mc {
-       u16     reserved2:1;
-       u16     priority:3;
-       u16     vid:12;
-
-       u16     reserved1:1;
-       u16     fid:3;
-       u16     untag:6;
-       u16     member:6;
-};
-
-struct rtl8366s_vlan_4k {
-       u16     reserved1:4;
-       u16     vid:12;
-
-       u16     reserved2:1;
-       u16     fid:3;
-       u16     untag:6;
-       u16     member:6;
-};
+#define RTL8366S_VLAN_VID_MASK         0xfff
+#define RTL8366S_VLAN_PRIORITY_SHIFT   12
+#define RTL8366S_VLAN_PRIORITY_MASK    0x7
+#define RTL8366S_VLAN_MEMBER_MASK      0x3f
+#define RTL8366S_VLAN_UNTAG_SHIFT      6
+#define RTL8366S_VLAN_UNTAG_MASK       0x3f
+#define RTL8366S_VLAN_FID_SHIFT                12
+#define RTL8366S_VLAN_FID_MASK         0x7
 
 static struct rtl8366_mib_counter rtl8366s_mib_counters[] = {
        { 0,  0, 4, "IfInOctets"                                },
@@ -243,22 +224,6 @@ static struct rtl8366_mib_counter rtl8366s_mib_counters[] = {
                        return err;                                     \
        } while (0)
 
-static inline struct rtl8366s *smi_to_rtl8366s(struct rtl8366_smi *smi)
-{
-       return container_of(smi, struct rtl8366s, smi);
-}
-
-static inline struct rtl8366s *sw_to_rtl8366s(struct switch_dev *sw)
-{
-       return container_of(sw, struct rtl8366s, dev);
-}
-
-static inline struct rtl8366_smi *sw_to_rtl8366_smi(struct switch_dev *sw)
-{
-       struct rtl8366s *rtl = sw_to_rtl8366s(sw);
-       return &rtl->smi;
-}
-
 static int rtl8366s_reset_chip(struct rtl8366_smi *smi)
 {
        int timeout = 10;
@@ -442,22 +407,18 @@ static int rtl8366_get_mib_counter(struct rtl8366_smi *smi, int counter,
 static int rtl8366s_get_vlan_4k(struct rtl8366_smi *smi, u32 vid,
                                struct rtl8366_vlan_4k *vlan4k)
 {
-       struct rtl8366s_vlan_4k vlan4k_priv;
+       u32 data[2];
        int err;
-       u32 data;
-       u16 *tableaddr;
+       int i;
 
        memset(vlan4k, '\0', sizeof(struct rtl8366_vlan_4k));
-       vlan4k_priv.vid = vid;
 
        if (vid >= RTL8366S_NUM_VIDS)
                return -EINVAL;
 
-       tableaddr = (u16 *)&vlan4k_priv;
-
        /* write VID */
-       data = *tableaddr;
-       err = rtl8366_smi_write_reg(smi, RTL8366S_VLAN_TABLE_WRITE_BASE, data);
+       err = rtl8366_smi_write_reg(smi, RTL8366S_VLAN_TABLE_WRITE_BASE,
+                                   vid & RTL8366S_VLAN_VID_MASK);
        if (err)
                return err;
 
@@ -467,24 +428,20 @@ static int rtl8366s_get_vlan_4k(struct rtl8366_smi *smi, u32 vid,
        if (err)
                return err;
 
-       err = rtl8366_smi_read_reg(smi, RTL8366S_VLAN_TABLE_READ_BASE, &data);
-       if (err)
-               return err;
-
-       *tableaddr = data;
-       tableaddr++;
-
-       err = rtl8366_smi_read_reg(smi, RTL8366S_VLAN_TABLE_READ_BASE + 1,
-                                  &data);
-       if (err)
-               return err;
-
-       *tableaddr = data;
+       for (i = 0; i < 2; i++) {
+               err = rtl8366_smi_read_reg(smi,
+                                          RTL8366S_VLAN_TABLE_READ_BASE + i,
+                                          &data[i]);
+               if (err)
+                       return err;
+       }
 
        vlan4k->vid = vid;
-       vlan4k->untag = vlan4k_priv.untag;
-       vlan4k->member = vlan4k_priv.member;
-       vlan4k->fid = vlan4k_priv.fid;
+       vlan4k->untag = (data[1] >> RTL8366S_VLAN_UNTAG_SHIFT) &
+                       RTL8366S_VLAN_UNTAG_MASK;
+       vlan4k->member = data[1] & RTL8366S_VLAN_MEMBER_MASK;
+       vlan4k->fid = (data[1] >> RTL8366S_VLAN_FID_SHIFT) &
+                       RTL8366S_VLAN_FID_MASK;
 
        return 0;
 }
@@ -492,10 +449,9 @@ static int rtl8366s_get_vlan_4k(struct rtl8366_smi *smi, u32 vid,
 static int rtl8366s_set_vlan_4k(struct rtl8366_smi *smi,
                                const struct rtl8366_vlan_4k *vlan4k)
 {
-       struct rtl8366s_vlan_4k vlan4k_priv;
+       u32 data[2];
        int err;
-       u32 data;
-       u16 *tableaddr;
+       int i;
 
        if (vlan4k->vid >= RTL8366S_NUM_VIDS ||
            vlan4k->member > RTL8366S_PORT_ALL ||
@@ -503,27 +459,20 @@ static int rtl8366s_set_vlan_4k(struct rtl8366_smi *smi,
            vlan4k->fid > RTL8366S_FIDMAX)
                return -EINVAL;
 
-       vlan4k_priv.vid = vlan4k->vid;
-       vlan4k_priv.untag = vlan4k->untag;
-       vlan4k_priv.member = vlan4k->member;
-       vlan4k_priv.fid = vlan4k->fid;
-
-       tableaddr = (u16 *)&vlan4k_priv;
-
-       data = *tableaddr;
-
-       err = rtl8366_smi_write_reg(smi, RTL8366S_VLAN_TABLE_WRITE_BASE, data);
-       if (err)
-               return err;
-
-       tableaddr++;
-
-       data = *tableaddr;
-
-       err = rtl8366_smi_write_reg(smi, RTL8366S_VLAN_TABLE_WRITE_BASE + 1,
-                                   data);
-       if (err)
-               return err;
+       data[0] = vlan4k->vid & RTL8366S_VLAN_VID_MASK;
+       data[1] = (vlan4k->member & RTL8366S_VLAN_MEMBER_MASK) |
+                 ((vlan4k->untag & RTL8366S_VLAN_UNTAG_MASK) <<
+                       RTL8366S_VLAN_UNTAG_SHIFT) |
+                 ((vlan4k->fid & RTL8366S_VLAN_FID_MASK) <<
+                       RTL8366S_VLAN_FID_SHIFT);
+
+       for (i = 0; i < 2; i++) {
+               err = rtl8366_smi_write_reg(smi,
+                                           RTL8366S_VLAN_TABLE_WRITE_BASE + i,
+                                           data[i]);
+               if (err)
+                       return err;
+       }
 
        /* write table access control word */
        err = rtl8366_smi_write_reg(smi, RTL8366S_TABLE_ACCESS_CTRL_REG,
@@ -535,39 +484,31 @@ static int rtl8366s_set_vlan_4k(struct rtl8366_smi *smi,
 static int rtl8366s_get_vlan_mc(struct rtl8366_smi *smi, u32 index,
                                struct rtl8366_vlan_mc *vlanmc)
 {
-       struct rtl8366s_vlan_mc vlanmc_priv;
+       u32 data[2];
        int err;
-       u32 addr;
-       u32 data;
-       u16 *tableaddr;
+       int i;
 
        memset(vlanmc, '\0', sizeof(struct rtl8366_vlan_mc));
 
        if (index >= RTL8366S_NUM_VLANS)
                return -EINVAL;
 
-       tableaddr = (u16 *)&vlanmc_priv;
-
-       addr = RTL8366S_VLAN_MEMCONF_BASE + (index << 1);
-       err = rtl8366_smi_read_reg(smi, addr, &data);
-       if (err)
-               return err;
-
-       *tableaddr = data;
-       tableaddr++;
-
-       addr = RTL8366S_VLAN_MEMCONF_BASE + 1 + (index << 1);
-       err = rtl8366_smi_read_reg(smi, addr, &data);
-       if (err)
-               return err;
-
-       *tableaddr = data;
+       for (i = 0; i < 2; i++) {
+               err = rtl8366_smi_read_reg(smi,
+                                          RTL8366S_VLAN_MC_BASE(index) + i,
+                                          &data[i]);
+               if (err)
+                       return err;
+       }
 
-       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;
+       vlanmc->vid = data[0] & RTL8366S_VLAN_VID_MASK;
+       vlanmc->priority = (data[0] >> RTL8366S_VLAN_PRIORITY_SHIFT) &
+                          RTL8366S_VLAN_PRIORITY_MASK;
+       vlanmc->untag = (data[1] >> RTL8366S_VLAN_UNTAG_SHIFT) &
+                       RTL8366S_VLAN_UNTAG_MASK;
+       vlanmc->member = data[1] & RTL8366S_VLAN_MEMBER_MASK;
+       vlanmc->fid = (data[1] >> RTL8366S_VLAN_FID_SHIFT) &
+                     RTL8366S_VLAN_FID_MASK;
 
        return 0;
 }
@@ -575,11 +516,9 @@ static int rtl8366s_get_vlan_mc(struct rtl8366_smi *smi, u32 index,
 static int rtl8366s_set_vlan_mc(struct rtl8366_smi *smi, u32 index,
                                const struct rtl8366_vlan_mc *vlanmc)
 {
-       struct rtl8366s_vlan_mc vlanmc_priv;
+       u32 data[2];
        int err;
-       u32 addr;
-       u32 data;
-       u16 *tableaddr;
+       int i;
 
        if (index >= RTL8366S_NUM_VLANS ||
            vlanmc->vid >= RTL8366S_NUM_VIDS ||
@@ -589,29 +528,22 @@ static int rtl8366s_set_vlan_mc(struct rtl8366_smi *smi, u32 index,
            vlanmc->fid > RTL8366S_FIDMAX)
                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);
-
-       tableaddr = (u16 *)&vlanmc_priv;
-       data = *tableaddr;
-
-       err = rtl8366_smi_write_reg(smi, addr, data);
-       if (err)
-               return err;
-
-       addr = RTL8366S_VLAN_MEMCONF_BASE + 1 + (index << 1);
-
-       tableaddr++;
-       data = *tableaddr;
-
-       err = rtl8366_smi_write_reg(smi, addr, data);
-       if (err)
-               return err;
+       data[0] = (vlanmc->vid & RTL8366S_VLAN_VID_MASK) |
+                 ((vlanmc->priority & RTL8366S_VLAN_PRIORITY_MASK) <<
+                       RTL8366S_VLAN_PRIORITY_SHIFT);
+       data[1] = (vlanmc->member & RTL8366S_VLAN_MEMBER_MASK) |
+                 ((vlanmc->untag & RTL8366S_VLAN_UNTAG_MASK) <<
+                       RTL8366S_VLAN_UNTAG_SHIFT) |
+                 ((vlanmc->fid & RTL8366S_VLAN_FID_MASK) <<
+                       RTL8366S_VLAN_FID_SHIFT);
+
+       for (i = 0; i < 2; i++) {
+               err = rtl8366_smi_write_reg(smi,
+                                           RTL8366S_VLAN_MC_BASE(index) + i,
+                                           data[i]);
+               if (err)
+                       return err;
+       }
 
        return 0;
 }
@@ -659,17 +591,21 @@ static int rtl8366s_vlan_set_4ktable(struct rtl8366_smi *smi, int enable)
                                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,
                                  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,
@@ -829,47 +765,6 @@ static int rtl8366s_sw_get_port_link(struct switch_dev *dev,
        return 0;
 }
 
-static int rtl8366s_sw_get_vlan_info(struct switch_dev *dev,
-                                    const struct switch_attr *attr,
-                                    struct switch_val *val)
-{
-       int i;
-       u32 len = 0;
-       struct rtl8366_vlan_4k vlan4k;
-       struct rtl8366_smi *smi = sw_to_rtl8366_smi(dev);
-       char *buf = smi->buf;
-       int err;
-
-       if (val->port_vlan == 0 || val->port_vlan >= RTL8366S_NUM_VLANS)
-               return -EINVAL;
-
-       memset(buf, '\0', sizeof(smi->buf));
-
-       err = rtl8366s_get_vlan_4k(smi, val->port_vlan, &vlan4k);
-       if (err)
-               return err;
-
-       len += snprintf(buf + len, sizeof(smi->buf) - len,
-                       "VLAN %d: Ports: '", vlan4k.vid);
-
-       for (i = 0; i < RTL8366S_NUM_PORTS; i++) {
-               if (!(vlan4k.member & (1 << i)))
-                       continue;
-
-               len += snprintf(buf + len, sizeof(smi->buf) - len, "%d%s", i,
-                               (vlan4k.untag & (1 << i)) ? "" : "t");
-       }
-
-       len += snprintf(buf + len, sizeof(smi->buf) - len,
-                       "', members=%04x, untag=%04x, fid=%u",
-                       vlan4k.member, vlan4k.untag, vlan4k.fid);
-
-       val->value.s = buf;
-       val->len = len;
-
-       return 0;
-}
-
 static int rtl8366s_sw_set_port_led(struct switch_dev *dev,
                                    const struct switch_attr *attr,
                                    struct switch_val *val)
@@ -926,101 +821,6 @@ static int rtl8366s_sw_reset_port_mibs(struct switch_dev *dev,
                                0, (1 << (val->port_vlan + 3)));
 }
 
-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);
-}
-
 static int rtl8366s_sw_reset_switch(struct switch_dev *dev)
 {
        struct rtl8366_smi *smi = sw_to_rtl8366_smi(dev);
@@ -1062,12 +862,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",
@@ -1088,19 +886,17 @@ 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",
                .description = "Get MIB counters for port",
                .max = 33,
                .set = NULL,
-               .get = rtl8366s_sw_get_port_mib,
+               .get = rtl8366_sw_get_port_mib,
        }, {
                .type = SWITCH_TYPE_INT,
                .name = "led",
@@ -1118,16 +914,11 @@ static struct switch_attr rtl8366s_vlan[] = {
                .description = "Get vlan information",
                .max = 1,
                .set = NULL,
-               .get = rtl8366s_sw_get_vlan_info,
+               .get = rtl8366_sw_get_vlan_info,
        },
 };
 
-/* template */
-static struct switch_dev rtl8366_switch_dev = {
-       .name = "RTL8366S",
-       .cpu_port = RTL8366S_PORT_NUM_CPU,
-       .ports = RTL8366S_NUM_PORTS,
-       .vlans = RTL8366S_NUM_VLANS,
+static const struct switch_dev_ops rtl8366_ops = {
        .attr_global = {
                .attr = rtl8366s_globals,
                .n_attr = ARRAY_SIZE(rtl8366s_globals),
@@ -1141,32 +932,35 @@ static struct switch_dev rtl8366_switch_dev = {
                .n_attr = ARRAY_SIZE(rtl8366s_vlan),
        },
 
-       .get_vlan_ports = rtl8366s_sw_get_vlan_ports,
-       .set_vlan_ports = rtl8366s_sw_set_vlan_ports,
-       .get_port_pvid = rtl8366s_sw_get_port_pvid,
-       .set_port_pvid = rtl8366s_sw_set_port_pvid,
+       .get_vlan_ports = rtl8366_sw_get_vlan_ports,
+       .set_vlan_ports = rtl8366_sw_set_vlan_ports,
+       .get_port_pvid = rtl8366_sw_get_port_pvid,
+       .set_port_pvid = rtl8366_sw_set_port_pvid,
        .reset_switch = rtl8366s_sw_reset_switch,
 };
 
-static int rtl8366s_switch_init(struct rtl8366s *rtl)
+static int rtl8366s_switch_init(struct rtl8366_smi *smi)
 {
-       struct switch_dev *dev = &rtl->dev;
+       struct switch_dev *dev = &smi->sw_dev;
        int err;
 
-       memcpy(dev, &rtl8366_switch_dev, sizeof(struct switch_dev));
-       dev->priv = rtl;
-       dev->devname = dev_name(rtl->parent);
+       dev->name = "RTL8366S";
+       dev->cpu_port = RTL8366S_PORT_NUM_CPU;
+       dev->ports = RTL8366S_NUM_PORTS;
+       dev->vlans = RTL8366S_NUM_VLANS;
+       dev->ops = &rtl8366_ops;
+       dev->devname = dev_name(smi->parent);
 
        err = register_switch(dev, NULL);
        if (err)
-               dev_err(rtl->parent, "switch registration failed\n");
+               dev_err(smi->parent, "switch registration failed\n");
 
        return err;
 }
 
-static void rtl8366s_switch_cleanup(struct rtl8366s *rtl)
+static void rtl8366s_switch_cleanup(struct rtl8366_smi *smi)
 {
-       unregister_switch(&rtl->dev);
+       unregister_switch(&smi->sw_dev);
 }
 
 static int rtl8366s_mii_read(struct mii_bus *bus, int addr, int reg)
@@ -1201,9 +995,8 @@ static int rtl8366s_mii_bus_match(struct mii_bus *bus)
                bus->write == rtl8366s_mii_write);
 }
 
-static int rtl8366s_setup(struct rtl8366s *rtl)
+static int rtl8366s_setup(struct rtl8366_smi *smi)
 {
-       struct rtl8366_smi *smi = &rtl->smi;
        int ret;
 
        ret = rtl8366s_reset_chip(smi);
@@ -1249,6 +1042,8 @@ static int rtl8366s_detect(struct rtl8366_smi *smi)
 
 static struct rtl8366_smi_ops rtl8366s_smi_ops = {
        .detect         = rtl8366s_detect,
+       .setup          = rtl8366s_setup,
+
        .mii_read       = rtl8366s_mii_read,
        .mii_write      = rtl8366s_mii_write,
 
@@ -1259,13 +1054,13 @@ static struct rtl8366_smi_ops rtl8366s_smi_ops = {
        .get_mc_index   = rtl8366s_get_mc_index,
        .set_mc_index   = rtl8366s_set_mc_index,
        .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 rtl8366_smi_version_printed;
        struct rtl8366s_platform_data *pdata;
-       struct rtl8366s *rtl;
        struct rtl8366_smi *smi;
        int err;
 
@@ -1280,17 +1075,12 @@ static int __init rtl8366s_probe(struct platform_device *pdev)
                goto err_out;
        }
 
-       rtl = kzalloc(sizeof(*rtl), GFP_KERNEL);
-       if (!rtl) {
-               dev_err(&pdev->dev, "no memory for private data\n");
+       smi = rtl8366_smi_alloc(&pdev->dev);
+       if (!smi) {
                err = -ENOMEM;
                goto err_out;
        }
 
-       rtl->parent = &pdev->dev;
-
-       smi = &rtl->smi;
-       smi->parent = &pdev->dev;
        smi->gpio_sda = pdata->gpio_sda;
        smi->gpio_sck = pdata->gpio_sck;
        smi->ops = &rtl8366s_smi_ops;
@@ -1302,15 +1092,11 @@ static int __init rtl8366s_probe(struct platform_device *pdev)
 
        err = rtl8366_smi_init(smi);
        if (err)
-               goto err_free_rtl;
-
-       platform_set_drvdata(pdev, rtl);
+               goto err_free_smi;
 
-       err = rtl8366s_setup(rtl);
-       if (err)
-               goto err_clear_drvdata;
+       platform_set_drvdata(pdev, smi);
 
-       err = rtl8366s_switch_init(rtl);
+       err = rtl8366s_switch_init(smi);
        if (err)
                goto err_clear_drvdata;
 
@@ -1319,8 +1105,8 @@ static int __init rtl8366s_probe(struct platform_device *pdev)
  err_clear_drvdata:
        platform_set_drvdata(pdev, NULL);
        rtl8366_smi_cleanup(smi);
- err_free_rtl:
-       kfree(rtl);
+ err_free_smi:
+       kfree(smi);
  err_out:
        return err;
 }
@@ -1353,13 +1139,13 @@ static struct phy_driver rtl8366s_phy_driver = {
 
 static int __devexit rtl8366s_remove(struct platform_device *pdev)
 {
-       struct rtl8366s *rtl = platform_get_drvdata(pdev);
+       struct rtl8366_smi *smi = platform_get_drvdata(pdev);
 
-       if (rtl) {
-               rtl8366s_switch_cleanup(rtl);
+       if (smi) {
+               rtl8366s_switch_cleanup(smi);
                platform_set_drvdata(pdev, NULL);
-               rtl8366_smi_cleanup(&rtl->smi);
-               kfree(rtl);
+               rtl8366_smi_cleanup(smi);
+               kfree(smi);
        }
 
        return 0;
index dea8e78b79b4fd61da2a32427d92811c77648206..799fc29d17560f86618cfcba08eacca9e53013ae 100644 (file)
@@ -65,10 +65,10 @@ swconfig_get_vlan_ports(struct switch_dev *dev, const struct switch_attr *attr,
        if (val->port_vlan >= dev->vlans)
                return -EINVAL;
 
-       if (!dev->get_vlan_ports)
+       if (!dev->ops->get_vlan_ports)
                return -EOPNOTSUPP;
 
-       ret = dev->get_vlan_ports(dev, val);
+       ret = dev->ops->get_vlan_ports(dev, val);
        return ret;
 }
 
@@ -76,6 +76,7 @@ static int
 swconfig_set_vlan_ports(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val)
 {
        struct switch_port *ports = val->value.ports;
+       const struct switch_dev_ops *ops = dev->ops;
        int i;
 
        if (val->port_vlan >= dev->vlans)
@@ -85,18 +86,19 @@ swconfig_set_vlan_ports(struct switch_dev *dev, const struct switch_attr *attr,
        if (val->len > dev->ports)
                return -EINVAL;
 
-       if (!dev->set_vlan_ports)
+       if (!ops->set_vlan_ports)
                return -EOPNOTSUPP;
 
        for (i = 0; i < val->len; i++) {
                if (ports[i].id >= dev->ports)
                        return -EINVAL;
 
-               if (dev->set_port_pvid && !(ports[i].flags & (1 << SWITCH_PORT_FLAG_TAGGED)))
-                       dev->set_port_pvid(dev, ports[i].id, val->port_vlan);
+               if (ops->set_port_pvid &&
+                   !(ports[i].flags & (1 << SWITCH_PORT_FLAG_TAGGED)))
+                       ops->set_port_pvid(dev, ports[i].id, val->port_vlan);
        }
 
-       return dev->set_vlan_ports(dev, val);
+       return ops->set_vlan_ports(dev, val);
 }
 
 static int
@@ -105,10 +107,10 @@ swconfig_set_pvid(struct switch_dev *dev, const struct switch_attr *attr, struct
        if (val->port_vlan >= dev->ports)
                return -EINVAL;
 
-       if (!dev->set_port_pvid)
+       if (!dev->ops->set_port_pvid)
                return -EOPNOTSUPP;
 
-       return dev->set_port_pvid(dev, val->port_vlan, val->value.i);
+       return dev->ops->set_port_pvid(dev, val->port_vlan, val->value.i);
 }
 
 static int
@@ -117,30 +119,30 @@ swconfig_get_pvid(struct switch_dev *dev, const struct switch_attr *attr, struct
        if (val->port_vlan >= dev->ports)
                return -EINVAL;
 
-       if (!dev->get_port_pvid)
+       if (!dev->ops->get_port_pvid)
                return -EOPNOTSUPP;
 
-       return dev->get_port_pvid(dev, val->port_vlan, &val->value.i);
+       return dev->ops->get_port_pvid(dev, val->port_vlan, &val->value.i);
 }
 
 static int
 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)
+       if (!dev->ops->apply_config)
                return 0;
 
-       return dev->apply_config(dev);
+       return dev->ops->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)
+       if (!dev->ops->reset_switch)
                return 0;
 
-       return dev->reset_switch(dev);
+       return dev->ops->reset_switch(dev);
 }
 
 enum global_defaults {
@@ -194,14 +196,16 @@ static struct switch_attr default_vlan[] = {
 
 static void swconfig_defaults_init(struct switch_dev *dev)
 {
+       const struct switch_dev_ops *ops = dev->ops;
+
        dev->def_global = 0;
        dev->def_vlan = 0;
        dev->def_port = 0;
 
-       if (dev->get_vlan_ports || dev->set_vlan_ports)
+       if (ops->get_vlan_ports || ops->set_vlan_ports)
                set_bit(VLAN_PORTS, &dev->def_vlan);
 
-       if (dev->get_port_pvid || dev->set_port_pvid)
+       if (ops->get_port_pvid || ops->set_port_pvid)
                set_bit(PORT_PVID, &dev->def_port);
 
        /* always present, can be no-op */
@@ -335,7 +339,7 @@ swconfig_send_multipart(struct swconfig_callback *cb, void *arg)
                        if (cb->close(cb, arg) < 0)
                                goto error;
                }
-               err = genlmsg_unicast(cb->msg, info->snd_pid);
+               err = genlmsg_reply(cb->msg, info);
                cb->msg = NULL;
                if (err < 0)
                        goto error;
@@ -371,19 +375,19 @@ swconfig_list_attrs(struct sk_buff *skb, struct genl_info *info)
 
        switch(hdr->cmd) {
        case SWITCH_CMD_LIST_GLOBAL:
-               alist = &dev->attr_global;
+               alist = &dev->ops->attr_global;
                def_list = default_global;
                def_active = &dev->def_global;
                n_def = ARRAY_SIZE(default_global);
                break;
        case SWITCH_CMD_LIST_VLAN:
-               alist = &dev->attr_vlan;
+               alist = &dev->ops->attr_vlan;
                def_list = default_vlan;
                def_active = &dev->def_vlan;
                n_def = ARRAY_SIZE(default_vlan);
                break;
        case SWITCH_CMD_LIST_PORT:
-               alist = &dev->attr_port;
+               alist = &dev->ops->attr_port;
                def_list = default_port;
                def_active = &dev->def_port;
                n_def = ARRAY_SIZE(default_port);
@@ -419,7 +423,7 @@ swconfig_list_attrs(struct sk_buff *skb, struct genl_info *info)
        if (!cb.msg)
                return 0;
 
-       return genlmsg_unicast(cb.msg, info->snd_pid);
+       return genlmsg_reply(cb.msg, info);
 
 error:
        if (cb.msg)
@@ -449,14 +453,14 @@ swconfig_lookup_attr(struct switch_dev *dev, struct genl_info *info,
        switch(hdr->cmd) {
        case SWITCH_CMD_SET_GLOBAL:
        case SWITCH_CMD_GET_GLOBAL:
-               alist = &dev->attr_global;
+               alist = &dev->ops->attr_global;
                def_list = default_global;
                def_active = &dev->def_global;
                n_def = ARRAY_SIZE(default_global);
                break;
        case SWITCH_CMD_SET_VLAN:
        case SWITCH_CMD_GET_VLAN:
-               alist = &dev->attr_vlan;
+               alist = &dev->ops->attr_vlan;
                def_list = default_vlan;
                def_active = &dev->def_vlan;
                n_def = ARRAY_SIZE(default_vlan);
@@ -468,7 +472,7 @@ swconfig_lookup_attr(struct switch_dev *dev, struct genl_info *info,
                break;
        case SWITCH_CMD_SET_PORT:
        case SWITCH_CMD_GET_PORT:
-               alist = &dev->attr_port;
+               alist = &dev->ops->attr_port;
                def_list = default_port;
                def_active = &dev->def_port;
                n_def = ARRAY_SIZE(default_port);
@@ -732,7 +736,7 @@ swconfig_get_attr(struct sk_buff *skb, struct genl_info *info)
                goto nla_put_failure;
 
        swconfig_put_dev(dev);
-       return genlmsg_unicast(msg, info->snd_pid);
+       return genlmsg_reply(msg, info);
 
 nla_put_failure:
        if (msg)
index 25aedb83b07420ade5c1b3097eebf17ae3d3e01a..ef2dc3ad9fe1de38a66346ab39025ba97d41aa51 100644 (file)
@@ -102,16 +102,50 @@ struct switch_attrlist;
 int register_switch(struct switch_dev *dev, struct net_device *netdev);
 void unregister_switch(struct switch_dev *dev);
 
+/**
+ * struct switch_attrlist - attribute list
+ *
+ * @n_attr: number of attributes
+ * @attr: pointer to the attributes array
+ */
 struct switch_attrlist {
-       /* filled in by the driver */
        int n_attr;
        const struct switch_attr *attr;
 };
 
+/**
+ * struct switch_dev_ops - switch driver operations
+ *
+ * @attr_global: global switch attribute list
+ * @attr_port: port attribute list
+ * @attr_vlan: vlan attribute list
+ *
+ * Callbacks:
+ *
+ * @get_vlan_ports: read the port list of a VLAN
+ * @set_vlan_ports: set the port list of a VLAN
+ *
+ * @get_port_pvid: get the primary VLAN ID of a port
+ * @set_port_pvid: set the primary VLAN ID of a port
+ *
+ * @apply_config: apply all changed settings to the switch
+ * @reset_switch: resetting the switch
+ */
+struct switch_dev_ops {
+       struct switch_attrlist attr_global, attr_port, attr_vlan;
+
+       int (*get_vlan_ports)(struct switch_dev *dev, struct switch_val *val);
+       int (*set_vlan_ports)(struct switch_dev *dev, struct switch_val *val);
+
+       int (*get_port_pvid)(struct switch_dev *dev, int port, int *val);
+       int (*set_port_pvid)(struct switch_dev *dev, int port, int val);
+
+       int (*apply_config)(struct switch_dev *dev);
+       int (*reset_switch)(struct switch_dev *dev);
+};
 
 struct switch_dev {
-       int id;
-       void *priv;
+       const struct switch_dev_ops *ops;
        const char *name;
 
        /* NB: either devname or netdev must be set */
@@ -121,19 +155,14 @@ struct switch_dev {
        int ports;
        int vlans;
        int cpu_port;
-       struct switch_attrlist attr_global, attr_port, attr_vlan;
 
-       spinlock_t lock;
-       struct switch_port *portbuf;
+       /* the following fields are internal for swconfig */
+       int id;
        struct list_head dev_list;
        unsigned long def_global, def_port, def_vlan;
 
-       int (*get_vlan_ports)(struct switch_dev *dev, struct switch_val *val);
-       int (*set_vlan_ports)(struct switch_dev *dev, struct switch_val *val);
-       int (*get_port_pvid)(struct switch_dev *dev, int port, int *val);
-       int (*set_port_pvid)(struct switch_dev *dev, int port, int val);
-       int (*apply_config)(struct switch_dev *dev);
-       int (*reset_switch)(struct switch_dev *dev);
+       spinlock_t lock;
+       struct switch_port *portbuf;
 };
 
 struct switch_port {
index 461df5046557f0b717534e4dbac78f0354870004..50341751dc73ab343f111a4e3dab2dc6bd01cd0c 100644 (file)
@@ -4,7 +4,7 @@
  config MVSWITCH_PHY
        tristate "Driver for Marvell 88E6060 switches"
  
-+config IP175C_PHY
++config IP17XX_PHY
 +      tristate "Driver for IC+ IP175C/IP178C switches"
 +      select SWCONFIG
 +
@@ -17,7 +17,7 @@
  obj-$(CONFIG_ICPLUS_PHY)      += icplus.o
  obj-$(CONFIG_ADM6996_PHY)     += adm6996.o
  obj-$(CONFIG_MVSWITCH_PHY)    += mvswitch.o
-+obj-$(CONFIG_IP175C_PHY)      += ip175c.o
++obj-$(CONFIG_IP17XX_PHY)      += ip17xx.o
  obj-$(CONFIG_REALTEK_PHY)     += realtek.o
  obj-$(CONFIG_LSI_ET1011C_PHY) += et1011c.o
  obj-$(CONFIG_FIXED_PHY)               += fixed.o
index d9d3ce7721ff626ada2ad8e1770ff57da8061c51..aac645389ebbdf28168ab0cf8c6f1a1facfe4860 100644 (file)
@@ -1,6 +1,6 @@
 --- a/drivers/net/phy/Kconfig
 +++ b/drivers/net/phy/Kconfig
-@@ -100,6 +100,10 @@ config IP175C_PHY
+@@ -100,6 +100,10 @@ config IP17XX_PHY
        tristate "Driver for IC+ IP175C/IP178C switches"
        select SWCONFIG
  
@@ -15,7 +15,7 @@
 +++ b/drivers/net/phy/Makefile
 @@ -17,6 +17,7 @@ obj-$(CONFIG_ADM6996_PHY)    += adm6996.o
  obj-$(CONFIG_MVSWITCH_PHY)    += mvswitch.o
- obj-$(CONFIG_IP175C_PHY)      += ip175c.o
+ obj-$(CONFIG_IP17XX_PHY)      += ip17xx.o
  obj-$(CONFIG_REALTEK_PHY)     += realtek.o
 +obj-$(CONFIG_AR8216_PHY)      += ar8216.o
  obj-$(CONFIG_LSI_ET1011C_PHY) += et1011c.o
index bfebbcff5176f63bc9fcbc73a9905fd5b43cad24..259f7ec6e675ff8dec668a8e66a072eed25d3ed4 100644 (file)
@@ -14,7 +14,7 @@
 --- a/drivers/net/phy/Makefile
 +++ b/drivers/net/phy/Makefile
 @@ -18,6 +18,7 @@ obj-$(CONFIG_MVSWITCH_PHY)   += mvswitch.o
- obj-$(CONFIG_IP175C_PHY)      += ip175c.o
+ obj-$(CONFIG_IP17XX_PHY)      += ip17xx.o
  obj-$(CONFIG_REALTEK_PHY)     += realtek.o
  obj-$(CONFIG_AR8216_PHY)      += ar8216.o
 +obj-$(CONFIG_RTL8306_PHY)     += rtl8306.o
index 4ce0520b11a8f6bfcca9a0c820b7a43b9d8a1e96..62a6430b867b2d92badc8bf2f8f537b82bfe5f24 100644 (file)
@@ -32,7 +32,7 @@
  endif # PHYLIB
 --- a/drivers/net/phy/Makefile
 +++ b/drivers/net/phy/Makefile
-@@ -19,6 +19,9 @@ obj-$(CONFIG_IP175C_PHY)     += ip175c.o
+@@ -19,6 +19,9 @@ obj-$(CONFIG_IP17XX_PHY)     += ip17xx.o
  obj-$(CONFIG_REALTEK_PHY)     += realtek.o
  obj-$(CONFIG_AR8216_PHY)      += ar8216.o
  obj-$(CONFIG_RTL8306_PHY)     += rtl8306.o
diff --git a/target/linux/generic-2.6/patches-2.6.32/651-swconfig-2.6.32-fix.patch b/target/linux/generic-2.6/patches-2.6.32/651-swconfig-2.6.32-fix.patch
deleted file mode 100644 (file)
index bc8f8fc..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
---- a/drivers/net/phy/swconfig.c
-+++ b/drivers/net/phy/swconfig.c
-@@ -335,7 +335,7 @@ swconfig_send_multipart(struct swconfig_
-                       if (cb->close(cb, arg) < 0)
-                               goto error;
-               }
--              err = genlmsg_unicast(cb->msg, info->snd_pid);
-+              err = genlmsg_reply(cb->msg, info);
-               cb->msg = NULL;
-               if (err < 0)
-                       goto error;
-@@ -419,7 +419,7 @@ swconfig_list_attrs(struct sk_buff *skb,
-       if (!cb.msg)
-               return 0;
--      return genlmsg_unicast(cb.msg, info->snd_pid);
-+      return genlmsg_reply(cb.msg, info);
- error:
-       if (cb.msg)
-@@ -728,7 +728,7 @@ swconfig_get_attr(struct sk_buff *skb, s
-               goto nla_put_failure;
-       swconfig_put_dev(dev);
--      return genlmsg_unicast(msg, info->snd_pid);
-+      return genlmsg_reply(msg, info);
- nla_put_failure:
-       if (msg)
index 862868c8d17a423d54c8fd513a907d1ca903445c..7cf63331619ee66b847f68bf81d745baf5b9f46a 100644 (file)
@@ -4,7 +4,7 @@
  config MVSWITCH_PHY
        tristate "Driver for Marvell 88E6060 switches"
  
-+config IP175C_PHY
++config IP17XX_PHY
 +      tristate "Driver for IC+ IP175C/IP178C switches"
 +      select SWCONFIG
 +
@@ -17,7 +17,7 @@
  obj-$(CONFIG_ICPLUS_PHY)      += icplus.o
  obj-$(CONFIG_ADM6996_PHY)     += adm6996.o
  obj-$(CONFIG_MVSWITCH_PHY)    += mvswitch.o
-+obj-$(CONFIG_IP175C_PHY)      += ip175c.o
++obj-$(CONFIG_IP17XX_PHY)      += ip17xx.o
  obj-$(CONFIG_REALTEK_PHY)     += realtek.o
  obj-$(CONFIG_LSI_ET1011C_PHY) += et1011c.o
  obj-$(CONFIG_FIXED_PHY)               += fixed.o
index 00372aae0e11689eac851b7776ec055217450fba..2460586420d7c1a5e9b9204637efe3bd7902b376 100644 (file)
@@ -1,6 +1,6 @@
 --- a/drivers/net/phy/Kconfig
 +++ b/drivers/net/phy/Kconfig
-@@ -106,6 +106,10 @@ config IP175C_PHY
+@@ -106,6 +106,10 @@ config IP17XX_PHY
        tristate "Driver for IC+ IP175C/IP178C switches"
        select SWCONFIG
  
@@ -15,7 +15,7 @@
 +++ b/drivers/net/phy/Makefile
 @@ -18,6 +18,7 @@ obj-$(CONFIG_ADM6996_PHY)    += adm6996.o
  obj-$(CONFIG_MVSWITCH_PHY)    += mvswitch.o
- obj-$(CONFIG_IP175C_PHY)      += ip175c.o
+ obj-$(CONFIG_IP17XX_PHY)      += ip17xx.o
  obj-$(CONFIG_REALTEK_PHY)     += realtek.o
 +obj-$(CONFIG_AR8216_PHY)      += ar8216.o
  obj-$(CONFIG_LSI_ET1011C_PHY) += et1011c.o
index a4793cb63b6fceea853cc7835eb75d4fccd83bdb..a8c1cb59f2e264aad9eb8840bfb39c69cccff288 100644 (file)
@@ -14,7 +14,7 @@
 --- a/drivers/net/phy/Makefile
 +++ b/drivers/net/phy/Makefile
 @@ -19,6 +19,7 @@ obj-$(CONFIG_MVSWITCH_PHY)   += mvswitch.o
- obj-$(CONFIG_IP175C_PHY)      += ip175c.o
+ obj-$(CONFIG_IP17XX)  += ip17xx.o
  obj-$(CONFIG_REALTEK_PHY)     += realtek.o
  obj-$(CONFIG_AR8216_PHY)      += ar8216.o
 +obj-$(CONFIG_RTL8306_PHY)     += rtl8306.o
index db29760c5bf10ea9e6ef4a3334a58c22d49ad240..56050912c10f0ef1a99587a6cc65a01eae3e276b 100644 (file)
@@ -32,7 +32,7 @@
  endif # PHYLIB
 --- a/drivers/net/phy/Makefile
 +++ b/drivers/net/phy/Makefile
-@@ -20,6 +20,9 @@ obj-$(CONFIG_IP175C_PHY)     += ip175c.o
+@@ -20,6 +20,9 @@ obj-$(CONFIG_IP17XX_PHY)     += ip17xx.o
  obj-$(CONFIG_REALTEK_PHY)     += realtek.o
  obj-$(CONFIG_AR8216_PHY)      += ar8216.o
  obj-$(CONFIG_RTL8306_PHY)     += rtl8306.o