2008-10-07 20:45:18 +07:00
|
|
|
/*
|
2009-03-20 16:50:39 +07:00
|
|
|
* net/dsa/mv88e6131.c - Marvell 88e6095/6095f/6131 switch chip support
|
|
|
|
* Copyright (c) 2008-2009 Marvell Semiconductor
|
2008-10-07 20:45:18 +07:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2013-01-08 23:05:54 +07:00
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/jiffies.h>
|
2008-10-07 20:45:18 +07:00
|
|
|
#include <linux/list.h>
|
2012-01-24 17:41:40 +07:00
|
|
|
#include <linux/module.h>
|
2008-10-07 20:45:18 +07:00
|
|
|
#include <linux/netdevice.h>
|
|
|
|
#include <linux/phy.h>
|
2011-11-28 00:06:08 +07:00
|
|
|
#include <net/dsa.h>
|
2008-10-07 20:45:18 +07:00
|
|
|
#include "mv88e6xxx.h"
|
|
|
|
|
2014-09-16 00:00:27 +07:00
|
|
|
static char *mv88e6131_probe(struct device *host_dev, int sw_addr)
|
2008-10-07 20:45:18 +07:00
|
|
|
{
|
2014-09-16 00:00:27 +07:00
|
|
|
struct mii_bus *bus = dsa_host_dev_to_mii_bus(host_dev);
|
2008-10-07 20:45:18 +07:00
|
|
|
int ret;
|
|
|
|
|
2014-09-16 00:00:27 +07:00
|
|
|
if (bus == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2015-04-02 09:06:39 +07:00
|
|
|
ret = __mv88e6xxx_reg_read(bus, sw_addr, REG_PORT(0), PORT_SWITCH_ID);
|
2008-10-07 20:45:18 +07:00
|
|
|
if (ret >= 0) {
|
2014-10-30 00:44:55 +07:00
|
|
|
int ret_masked = ret & 0xfff0;
|
|
|
|
|
2015-04-02 09:06:39 +07:00
|
|
|
if (ret_masked == PORT_SWITCH_ID_6085)
|
2011-04-05 10:03:56 +07:00
|
|
|
return "Marvell 88E6085";
|
2015-04-02 09:06:39 +07:00
|
|
|
if (ret_masked == PORT_SWITCH_ID_6095)
|
2009-03-20 16:50:39 +07:00
|
|
|
return "Marvell 88E6095/88E6095F";
|
2015-04-02 09:06:39 +07:00
|
|
|
if (ret == PORT_SWITCH_ID_6131_B2)
|
2014-10-30 00:44:55 +07:00
|
|
|
return "Marvell 88E6131 (B2)";
|
2015-04-02 09:06:39 +07:00
|
|
|
if (ret_masked == PORT_SWITCH_ID_6131)
|
2008-10-07 20:45:18 +07:00
|
|
|
return "Marvell 88E6131";
|
2015-05-06 06:09:52 +07:00
|
|
|
if (ret_masked == PORT_SWITCH_ID_6185)
|
|
|
|
return "Marvell 88E6185";
|
2008-10-07 20:45:18 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mv88e6131_setup_global(struct dsa_switch *ds)
|
|
|
|
{
|
2015-05-06 06:09:49 +07:00
|
|
|
u32 upstream_port = dsa_upstream_port(ds);
|
2008-10-07 20:45:18 +07:00
|
|
|
int ret;
|
2015-05-06 06:09:49 +07:00
|
|
|
u32 reg;
|
2015-05-06 06:09:47 +07:00
|
|
|
|
|
|
|
ret = mv88e6xxx_setup_global(ds);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2008-10-07 20:45:18 +07:00
|
|
|
|
2013-01-08 23:05:53 +07:00
|
|
|
/* Enable the PHY polling unit, don't discard packets with
|
2008-10-07 20:45:18 +07:00
|
|
|
* excessive collisions, use a weighted fair queueing scheme
|
|
|
|
* to arbitrate between packet queues, set the maximum frame
|
|
|
|
* size to 1632, and mask all interrupt sources.
|
|
|
|
*/
|
2015-05-06 06:09:49 +07:00
|
|
|
REG_WRITE(REG_GLOBAL, GLOBAL_CONTROL,
|
|
|
|
GLOBAL_CONTROL_PPU_ENABLE | GLOBAL_CONTROL_MAX_FRAME_1632);
|
2008-10-07 20:45:18 +07:00
|
|
|
|
2013-01-08 23:05:53 +07:00
|
|
|
/* Set the VLAN ethertype to 0x8100. */
|
2015-05-06 06:09:49 +07:00
|
|
|
REG_WRITE(REG_GLOBAL, GLOBAL_CORE_TAG_TYPE, 0x8100);
|
2008-10-07 20:45:18 +07:00
|
|
|
|
2013-01-08 23:05:53 +07:00
|
|
|
/* Disable ARP mirroring, and configure the upstream port as
|
dsa: add switch chip cascading support
The initial version of the DSA driver only supported a single switch
chip per network interface, while DSA-capable switch chips can be
interconnected to form a tree of switch chips. This patch adds support
for multiple switch chips on a network interface.
An example topology for a 16-port device with an embedded CPU is as
follows:
+-----+ +--------+ +--------+
| |eth0 10| switch |9 10| switch |
| CPU +----------+ +-------+ |
| | | chip 0 | | chip 1 |
+-----+ +---++---+ +---++---+
|| ||
|| ||
||1000baseT ||1000baseT
||ports 1-8 ||ports 9-16
This requires a couple of interdependent changes in the DSA layer:
- The dsa platform driver data needs to be extended: there is still
only one netdevice per DSA driver instance (eth0 in the example
above), but each of the switch chips in the tree needs its own
mii_bus device pointer, MII management bus address, and port name
array. (include/net/dsa.h) The existing in-tree dsa users need
some small changes to deal with this. (arch/arm)
- The DSA and Ethertype DSA tagging modules need to be extended to
use the DSA device ID field on receive and demultiplex the packet
accordingly, and fill in the DSA device ID field on transmit
according to which switch chip the packet is heading to.
(net/dsa/tag_{dsa,edsa}.c)
- The concept of "CPU port", which is the switch chip port that the
CPU is connected to (port 10 on switch chip 0 in the example), needs
to be extended with the concept of "upstream port", which is the
port on the switch chip that will bring us one hop closer to the CPU
(port 10 for both switch chips in the example above).
- The dsa platform data needs to specify which ports on which switch
chips are links to other switch chips, so that we can enable DSA
tagging mode on them. (For inter-switch links, we always use
non-EtherType DSA tagging, since it has lower overhead. The CPU
link uses dsa or edsa tagging depending on what the 'root' switch
chip supports.) This is done by specifying "dsa" for the given
port in the port array.
- The dsa platform data needs to be extended with information on via
which port to reach any given switch chip from any given switch chip.
This info is specified via the per-switch chip data struct ->rtable[]
array, which gives the nexthop ports for each of the other switches
in the tree.
For the example topology above, the dsa platform data would look
something like this:
static struct dsa_chip_data sw[2] = {
{
.mii_bus = &foo,
.sw_addr = 1,
.port_names[0] = "p1",
.port_names[1] = "p2",
.port_names[2] = "p3",
.port_names[3] = "p4",
.port_names[4] = "p5",
.port_names[5] = "p6",
.port_names[6] = "p7",
.port_names[7] = "p8",
.port_names[9] = "dsa",
.port_names[10] = "cpu",
.rtable = (s8 []){ -1, 9, },
}, {
.mii_bus = &foo,
.sw_addr = 2,
.port_names[0] = "p9",
.port_names[1] = "p10",
.port_names[2] = "p11",
.port_names[3] = "p12",
.port_names[4] = "p13",
.port_names[5] = "p14",
.port_names[6] = "p15",
.port_names[7] = "p16",
.port_names[10] = "dsa",
.rtable = (s8 []){ 10, -1, },
},
},
static struct dsa_platform_data pd = {
.netdev = &foo,
.nr_switches = 2,
.sw = sw,
};
Signed-off-by: Lennert Buytenhek <buytenh@marvell.com>
Tested-by: Gary Thomas <gary@mlbassoc.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2009-03-20 16:52:09 +07:00
|
|
|
* the port to which ingress and egress monitor frames are to
|
|
|
|
* be sent.
|
2008-10-07 20:45:18 +07:00
|
|
|
*/
|
2015-05-06 06:09:49 +07:00
|
|
|
reg = upstream_port << GLOBAL_MONITOR_CONTROL_INGRESS_SHIFT |
|
|
|
|
upstream_port << GLOBAL_MONITOR_CONTROL_EGRESS_SHIFT |
|
|
|
|
GLOBAL_MONITOR_CONTROL_ARP_DISABLED;
|
|
|
|
REG_WRITE(REG_GLOBAL, GLOBAL_MONITOR_CONTROL, reg);
|
2008-10-07 20:45:18 +07:00
|
|
|
|
2013-01-08 23:05:53 +07:00
|
|
|
/* Disable cascade port functionality unless this device
|
2011-06-25 02:53:51 +07:00
|
|
|
* is used in a cascade configuration, and set the switch's
|
dsa: add switch chip cascading support
The initial version of the DSA driver only supported a single switch
chip per network interface, while DSA-capable switch chips can be
interconnected to form a tree of switch chips. This patch adds support
for multiple switch chips on a network interface.
An example topology for a 16-port device with an embedded CPU is as
follows:
+-----+ +--------+ +--------+
| |eth0 10| switch |9 10| switch |
| CPU +----------+ +-------+ |
| | | chip 0 | | chip 1 |
+-----+ +---++---+ +---++---+
|| ||
|| ||
||1000baseT ||1000baseT
||ports 1-8 ||ports 9-16
This requires a couple of interdependent changes in the DSA layer:
- The dsa platform driver data needs to be extended: there is still
only one netdevice per DSA driver instance (eth0 in the example
above), but each of the switch chips in the tree needs its own
mii_bus device pointer, MII management bus address, and port name
array. (include/net/dsa.h) The existing in-tree dsa users need
some small changes to deal with this. (arch/arm)
- The DSA and Ethertype DSA tagging modules need to be extended to
use the DSA device ID field on receive and demultiplex the packet
accordingly, and fill in the DSA device ID field on transmit
according to which switch chip the packet is heading to.
(net/dsa/tag_{dsa,edsa}.c)
- The concept of "CPU port", which is the switch chip port that the
CPU is connected to (port 10 on switch chip 0 in the example), needs
to be extended with the concept of "upstream port", which is the
port on the switch chip that will bring us one hop closer to the CPU
(port 10 for both switch chips in the example above).
- The dsa platform data needs to specify which ports on which switch
chips are links to other switch chips, so that we can enable DSA
tagging mode on them. (For inter-switch links, we always use
non-EtherType DSA tagging, since it has lower overhead. The CPU
link uses dsa or edsa tagging depending on what the 'root' switch
chip supports.) This is done by specifying "dsa" for the given
port in the port array.
- The dsa platform data needs to be extended with information on via
which port to reach any given switch chip from any given switch chip.
This info is specified via the per-switch chip data struct ->rtable[]
array, which gives the nexthop ports for each of the other switches
in the tree.
For the example topology above, the dsa platform data would look
something like this:
static struct dsa_chip_data sw[2] = {
{
.mii_bus = &foo,
.sw_addr = 1,
.port_names[0] = "p1",
.port_names[1] = "p2",
.port_names[2] = "p3",
.port_names[3] = "p4",
.port_names[4] = "p5",
.port_names[5] = "p6",
.port_names[6] = "p7",
.port_names[7] = "p8",
.port_names[9] = "dsa",
.port_names[10] = "cpu",
.rtable = (s8 []){ -1, 9, },
}, {
.mii_bus = &foo,
.sw_addr = 2,
.port_names[0] = "p9",
.port_names[1] = "p10",
.port_names[2] = "p11",
.port_names[3] = "p12",
.port_names[4] = "p13",
.port_names[5] = "p14",
.port_names[6] = "p15",
.port_names[7] = "p16",
.port_names[10] = "dsa",
.rtable = (s8 []){ 10, -1, },
},
},
static struct dsa_platform_data pd = {
.netdev = &foo,
.nr_switches = 2,
.sw = sw,
};
Signed-off-by: Lennert Buytenhek <buytenh@marvell.com>
Tested-by: Gary Thomas <gary@mlbassoc.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2009-03-20 16:52:09 +07:00
|
|
|
* DSA device number.
|
2008-10-07 20:45:18 +07:00
|
|
|
*/
|
2011-06-25 02:53:51 +07:00
|
|
|
if (ds->dst->pd->nr_chips > 1)
|
2015-05-06 06:09:49 +07:00
|
|
|
REG_WRITE(REG_GLOBAL, GLOBAL_CONTROL_2,
|
|
|
|
GLOBAL_CONTROL_2_MULTIPLE_CASCADE |
|
|
|
|
(ds->index & 0x1f));
|
2011-06-25 02:53:51 +07:00
|
|
|
else
|
2015-05-06 06:09:49 +07:00
|
|
|
REG_WRITE(REG_GLOBAL, GLOBAL_CONTROL_2,
|
|
|
|
GLOBAL_CONTROL_2_NO_CASCADE |
|
|
|
|
(ds->index & 0x1f));
|
2008-10-07 20:45:18 +07:00
|
|
|
|
2013-01-08 23:05:53 +07:00
|
|
|
/* Force the priority of IGMP/MLD snoop frames and ARP frames
|
2008-10-07 20:45:18 +07:00
|
|
|
* to the highest setting.
|
|
|
|
*/
|
2015-05-06 06:09:49 +07:00
|
|
|
REG_WRITE(REG_GLOBAL2, GLOBAL2_PRIO_OVERRIDE,
|
|
|
|
GLOBAL2_PRIO_OVERRIDE_FORCE_SNOOP |
|
|
|
|
7 << GLOBAL2_PRIO_OVERRIDE_SNOOP_SHIFT |
|
|
|
|
GLOBAL2_PRIO_OVERRIDE_FORCE_ARP |
|
|
|
|
7 << GLOBAL2_PRIO_OVERRIDE_ARP_SHIFT);
|
2008-10-07 20:45:18 +07:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mv88e6131_setup(struct dsa_switch *ds)
|
|
|
|
{
|
2015-04-02 09:06:31 +07:00
|
|
|
struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
|
2008-10-07 20:45:18 +07:00
|
|
|
int ret;
|
|
|
|
|
2015-04-02 09:06:29 +07:00
|
|
|
ret = mv88e6xxx_setup_common(ds);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2008-10-07 20:45:18 +07:00
|
|
|
|
2015-04-02 09:06:29 +07:00
|
|
|
mv88e6xxx_ppu_state_init(ds);
|
2011-04-05 10:03:56 +07:00
|
|
|
|
2015-04-02 09:06:31 +07:00
|
|
|
switch (ps->id) {
|
2015-04-02 09:06:39 +07:00
|
|
|
case PORT_SWITCH_ID_6085:
|
2015-05-06 06:09:52 +07:00
|
|
|
case PORT_SWITCH_ID_6185:
|
2015-04-02 09:06:31 +07:00
|
|
|
ps->num_ports = 10;
|
|
|
|
break;
|
2015-04-02 09:06:39 +07:00
|
|
|
case PORT_SWITCH_ID_6095:
|
2015-04-02 09:06:31 +07:00
|
|
|
ps->num_ports = 11;
|
|
|
|
break;
|
2015-04-02 09:06:39 +07:00
|
|
|
case PORT_SWITCH_ID_6131:
|
|
|
|
case PORT_SWITCH_ID_6131_B2:
|
2015-04-02 09:06:31 +07:00
|
|
|
ps->num_ports = 8;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
2015-04-02 09:06:34 +07:00
|
|
|
ret = mv88e6xxx_switch_reset(ds, false);
|
2008-10-07 20:45:18 +07:00
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
ret = mv88e6131_setup_global(ds);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
2015-05-06 06:09:48 +07:00
|
|
|
return mv88e6xxx_setup_ports(ds);
|
2008-10-07 20:45:18 +07:00
|
|
|
}
|
|
|
|
|
2015-04-02 09:06:31 +07:00
|
|
|
static int mv88e6131_port_to_phy_addr(struct dsa_switch *ds, int port)
|
2008-10-07 20:45:18 +07:00
|
|
|
{
|
2015-04-02 09:06:31 +07:00
|
|
|
struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
|
|
|
|
|
|
|
|
if (port >= 0 && port < ps->num_ports)
|
2008-10-07 20:45:18 +07:00
|
|
|
return port;
|
2015-04-02 09:06:31 +07:00
|
|
|
|
|
|
|
return -EINVAL;
|
2008-10-07 20:45:18 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
mv88e6131_phy_read(struct dsa_switch *ds, int port, int regnum)
|
|
|
|
{
|
2015-04-02 09:06:31 +07:00
|
|
|
int addr = mv88e6131_port_to_phy_addr(ds, port);
|
|
|
|
|
|
|
|
if (addr < 0)
|
|
|
|
return addr;
|
|
|
|
|
2008-10-07 20:45:18 +07:00
|
|
|
return mv88e6xxx_phy_read_ppu(ds, addr, regnum);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
mv88e6131_phy_write(struct dsa_switch *ds,
|
|
|
|
int port, int regnum, u16 val)
|
|
|
|
{
|
2015-04-02 09:06:31 +07:00
|
|
|
int addr = mv88e6131_port_to_phy_addr(ds, port);
|
|
|
|
|
|
|
|
if (addr < 0)
|
|
|
|
return addr;
|
|
|
|
|
2008-10-07 20:45:18 +07:00
|
|
|
return mv88e6xxx_phy_write_ppu(ds, addr, regnum, val);
|
|
|
|
}
|
|
|
|
|
2011-11-25 21:36:19 +07:00
|
|
|
struct dsa_switch_driver mv88e6131_switch_driver = {
|
2014-09-12 11:18:09 +07:00
|
|
|
.tag_protocol = DSA_TAG_PROTO_DSA,
|
2008-10-07 20:45:18 +07:00
|
|
|
.priv_size = sizeof(struct mv88e6xxx_priv_state),
|
|
|
|
.probe = mv88e6131_probe,
|
|
|
|
.setup = mv88e6131_setup,
|
|
|
|
.set_addr = mv88e6xxx_set_addr_direct,
|
|
|
|
.phy_read = mv88e6131_phy_read,
|
|
|
|
.phy_write = mv88e6131_phy_write,
|
|
|
|
.poll_link = mv88e6xxx_poll_link,
|
2015-04-02 09:06:38 +07:00
|
|
|
.get_strings = mv88e6xxx_get_strings,
|
|
|
|
.get_ethtool_stats = mv88e6xxx_get_ethtool_stats,
|
|
|
|
.get_sset_count = mv88e6xxx_get_sset_count,
|
2008-10-07 20:45:18 +07:00
|
|
|
};
|
2011-11-25 21:37:16 +07:00
|
|
|
|
|
|
|
MODULE_ALIAS("platform:mv88e6085");
|
|
|
|
MODULE_ALIAS("platform:mv88e6095");
|
|
|
|
MODULE_ALIAS("platform:mv88e6095f");
|
|
|
|
MODULE_ALIAS("platform:mv88e6131");
|