Merge branch 'misc.namei' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs
[linux-2.6-microblaze.git] / drivers / net / dsa / b53 / b53_common.c
index bd1417a..604f541 100644 (file)
@@ -1144,7 +1144,7 @@ static void b53_force_link(struct b53_device *dev, int port, int link)
        u8 reg, val, off;
 
        /* Override the port settings */
-       if (port == dev->cpu_port) {
+       if (port == dev->imp_port) {
                off = B53_PORT_OVERRIDE_CTRL;
                val = PORT_OVERRIDE_EN;
        } else {
@@ -1168,7 +1168,7 @@ static void b53_force_port_config(struct b53_device *dev, int port,
        u8 reg, val, off;
 
        /* Override the port settings */
-       if (port == dev->cpu_port) {
+       if (port == dev->imp_port) {
                off = B53_PORT_OVERRIDE_CTRL;
                val = PORT_OVERRIDE_EN;
        } else {
@@ -1236,7 +1236,7 @@ static void b53_adjust_link(struct dsa_switch *ds, int port,
        b53_force_link(dev, port, phydev->link);
 
        if (is531x5(dev) && phy_interface_is_rgmii(phydev)) {
-               if (port == 8)
+               if (port == dev->imp_port)
                        off = B53_RGMII_CTRL_IMP;
                else
                        off = B53_RGMII_CTRL_P(port);
@@ -2280,6 +2280,7 @@ struct b53_chip_data {
        const char *dev_name;
        u16 vlans;
        u16 enabled_ports;
+       u8 imp_port;
        u8 cpu_port;
        u8 vta_regs[3];
        u8 arl_bins;
@@ -2304,6 +2305,7 @@ static const struct b53_chip_data b53_switch_chips[] = {
                .enabled_ports = 0x1f,
                .arl_bins = 2,
                .arl_buckets = 1024,
+               .imp_port = 5,
                .cpu_port = B53_CPU_PORT_25,
                .duplex_reg = B53_DUPLEX_STAT_FE,
        },
@@ -2314,6 +2316,7 @@ static const struct b53_chip_data b53_switch_chips[] = {
                .enabled_ports = 0x1f,
                .arl_bins = 2,
                .arl_buckets = 1024,
+               .imp_port = 5,
                .cpu_port = B53_CPU_PORT_25,
                .duplex_reg = B53_DUPLEX_STAT_FE,
        },
@@ -2324,6 +2327,7 @@ static const struct b53_chip_data b53_switch_chips[] = {
                .enabled_ports = 0x1f,
                .arl_bins = 4,
                .arl_buckets = 1024,
+               .imp_port = 8,
                .cpu_port = B53_CPU_PORT,
                .vta_regs = B53_VTA_REGS,
                .duplex_reg = B53_DUPLEX_STAT_GE,
@@ -2337,6 +2341,7 @@ static const struct b53_chip_data b53_switch_chips[] = {
                .enabled_ports = 0x1f,
                .arl_bins = 4,
                .arl_buckets = 1024,
+               .imp_port = 8,
                .cpu_port = B53_CPU_PORT,
                .vta_regs = B53_VTA_REGS,
                .duplex_reg = B53_DUPLEX_STAT_GE,
@@ -2350,6 +2355,7 @@ static const struct b53_chip_data b53_switch_chips[] = {
                .enabled_ports = 0x1f,
                .arl_bins = 4,
                .arl_buckets = 1024,
+               .imp_port = 8,
                .cpu_port = B53_CPU_PORT,
                .vta_regs = B53_VTA_REGS_9798,
                .duplex_reg = B53_DUPLEX_STAT_GE,
@@ -2363,6 +2369,7 @@ static const struct b53_chip_data b53_switch_chips[] = {
                .enabled_ports = 0x7f,
                .arl_bins = 4,
                .arl_buckets = 1024,
+               .imp_port = 8,
                .cpu_port = B53_CPU_PORT,
                .vta_regs = B53_VTA_REGS_9798,
                .duplex_reg = B53_DUPLEX_STAT_GE,
@@ -2377,6 +2384,7 @@ static const struct b53_chip_data b53_switch_chips[] = {
                .arl_bins = 4,
                .arl_buckets = 1024,
                .vta_regs = B53_VTA_REGS,
+               .imp_port = 8,
                .cpu_port = B53_CPU_PORT,
                .duplex_reg = B53_DUPLEX_STAT_GE,
                .jumbo_pm_reg = B53_JUMBO_PORT_MASK,
@@ -2389,6 +2397,7 @@ static const struct b53_chip_data b53_switch_chips[] = {
                .enabled_ports = 0xff,
                .arl_bins = 4,
                .arl_buckets = 1024,
+               .imp_port = 8,
                .cpu_port = B53_CPU_PORT,
                .vta_regs = B53_VTA_REGS,
                .duplex_reg = B53_DUPLEX_STAT_GE,
@@ -2402,6 +2411,7 @@ static const struct b53_chip_data b53_switch_chips[] = {
                .enabled_ports = 0x1ff,
                .arl_bins = 4,
                .arl_buckets = 1024,
+               .imp_port = 8,
                .cpu_port = B53_CPU_PORT,
                .vta_regs = B53_VTA_REGS,
                .duplex_reg = B53_DUPLEX_STAT_GE,
@@ -2415,6 +2425,7 @@ static const struct b53_chip_data b53_switch_chips[] = {
                .enabled_ports = 0, /* pdata must provide them */
                .arl_bins = 4,
                .arl_buckets = 1024,
+               .imp_port = 8,
                .cpu_port = B53_CPU_PORT,
                .vta_regs = B53_VTA_REGS_63XX,
                .duplex_reg = B53_DUPLEX_STAT_63XX,
@@ -2428,6 +2439,7 @@ static const struct b53_chip_data b53_switch_chips[] = {
                .enabled_ports = 0x1f,
                .arl_bins = 4,
                .arl_buckets = 1024,
+               .imp_port = 8,
                .cpu_port = B53_CPU_PORT_25, /* TODO: auto detect */
                .vta_regs = B53_VTA_REGS,
                .duplex_reg = B53_DUPLEX_STAT_GE,
@@ -2441,6 +2453,7 @@ static const struct b53_chip_data b53_switch_chips[] = {
                .enabled_ports = 0x1bf,
                .arl_bins = 4,
                .arl_buckets = 1024,
+               .imp_port = 8,
                .cpu_port = B53_CPU_PORT_25, /* TODO: auto detect */
                .vta_regs = B53_VTA_REGS,
                .duplex_reg = B53_DUPLEX_STAT_GE,
@@ -2454,6 +2467,7 @@ static const struct b53_chip_data b53_switch_chips[] = {
                .enabled_ports = 0x1bf,
                .arl_bins = 4,
                .arl_buckets = 1024,
+               .imp_port = 8,
                .cpu_port = B53_CPU_PORT_25, /* TODO: auto detect */
                .vta_regs = B53_VTA_REGS,
                .duplex_reg = B53_DUPLEX_STAT_GE,
@@ -2467,6 +2481,7 @@ static const struct b53_chip_data b53_switch_chips[] = {
                .enabled_ports = 0x1f,
                .arl_bins = 4,
                .arl_buckets = 1024,
+               .imp_port = 8,
                .cpu_port = B53_CPU_PORT_25, /* TODO: auto detect */
                .vta_regs = B53_VTA_REGS,
                .duplex_reg = B53_DUPLEX_STAT_GE,
@@ -2480,6 +2495,7 @@ static const struct b53_chip_data b53_switch_chips[] = {
                .enabled_ports = 0x1f,
                .arl_bins = 4,
                .arl_buckets = 1024,
+               .imp_port = 8,
                .cpu_port = B53_CPU_PORT_25, /* TODO: auto detect */
                .vta_regs = B53_VTA_REGS,
                .duplex_reg = B53_DUPLEX_STAT_GE,
@@ -2493,6 +2509,7 @@ static const struct b53_chip_data b53_switch_chips[] = {
                .enabled_ports = 0x1ff,
                .arl_bins = 4,
                .arl_buckets = 1024,
+               .imp_port = 8,
                .cpu_port = B53_CPU_PORT,
                .vta_regs = B53_VTA_REGS,
                .duplex_reg = B53_DUPLEX_STAT_GE,
@@ -2506,6 +2523,7 @@ static const struct b53_chip_data b53_switch_chips[] = {
                .enabled_ports = 0x103,
                .arl_bins = 4,
                .arl_buckets = 1024,
+               .imp_port = 8,
                .cpu_port = B53_CPU_PORT,
                .vta_regs = B53_VTA_REGS,
                .duplex_reg = B53_DUPLEX_STAT_GE,
@@ -2520,6 +2538,7 @@ static const struct b53_chip_data b53_switch_chips[] = {
                .enabled_ports = 0x1bf,
                .arl_bins = 4,
                .arl_buckets = 256,
+               .imp_port = 8,
                .cpu_port = 8, /* TODO: ports 4, 5, 8 */
                .vta_regs = B53_VTA_REGS,
                .duplex_reg = B53_DUPLEX_STAT_GE,
@@ -2533,6 +2552,7 @@ static const struct b53_chip_data b53_switch_chips[] = {
                .enabled_ports = 0x1ff,
                .arl_bins = 4,
                .arl_buckets = 1024,
+               .imp_port = 8,
                .cpu_port = B53_CPU_PORT,
                .vta_regs = B53_VTA_REGS,
                .duplex_reg = B53_DUPLEX_STAT_GE,
@@ -2546,6 +2566,7 @@ static const struct b53_chip_data b53_switch_chips[] = {
                .enabled_ports = 0x1ff,
                .arl_bins = 4,
                .arl_buckets = 256,
+               .imp_port = 8,
                .cpu_port = B53_CPU_PORT,
                .vta_regs = B53_VTA_REGS,
                .duplex_reg = B53_DUPLEX_STAT_GE,
@@ -2571,6 +2592,7 @@ static int b53_switch_init(struct b53_device *dev)
                        dev->vta_regs[1] = chip->vta_regs[1];
                        dev->vta_regs[2] = chip->vta_regs[2];
                        dev->jumbo_pm_reg = chip->jumbo_pm_reg;
+                       dev->imp_port = chip->imp_port;
                        dev->cpu_port = chip->cpu_port;
                        dev->num_vlans = chip->vlans;
                        dev->num_arl_bins = chip->arl_bins;
@@ -2612,9 +2634,10 @@ static int b53_switch_init(struct b53_device *dev)
                        dev->cpu_port = 5;
        }
 
-       /* cpu port is always last */
-       dev->num_ports = dev->cpu_port + 1;
        dev->enabled_ports |= BIT(dev->cpu_port);
+       dev->num_ports = fls(dev->enabled_ports);
+
+       dev->ds->num_ports = min_t(unsigned int, dev->num_ports, DSA_MAX_PORTS);
 
        /* Include non standard CPU port built-in PHYs to be probed */
        if (is539x(dev) || is531x5(dev)) {
@@ -2660,7 +2683,6 @@ struct b53_device *b53_switch_alloc(struct device *base,
                return NULL;
 
        ds->dev = base;
-       ds->num_ports = DSA_MAX_PORTS;
 
        dev = devm_kzalloc(base, sizeof(*dev), GFP_KERNEL);
        if (!dev)