blob: 34d297b650400f83545e00f4139426ad239ed09b [file] [log] [blame]
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +00001/*
Lennert Buytenhek076d3e12009-03-20 09:50:39 +00002 * net/dsa/mv88e6131.c - Marvell 88e6095/6095f/6131 switch chip support
3 * Copyright (c) 2008-2009 Marvell Semiconductor
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +00004 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 */
10
Barry Grussling19b2f972013-01-08 16:05:54 +000011#include <linux/delay.h>
12#include <linux/jiffies.h>
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +000013#include <linux/list.h>
Paul Gortmaker2bbba272012-01-24 10:41:40 +000014#include <linux/module.h>
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +000015#include <linux/netdevice.h>
16#include <linux/phy.h>
Ben Hutchingsc8f0b862011-11-27 17:06:08 +000017#include <net/dsa.h>
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +000018#include "mv88e6xxx.h"
19
Vivien Didelotb9b37712015-10-30 19:39:48 -040020static const struct mv88e6xxx_switch_id mv88e6131_table[] = {
21 { PORT_SWITCH_ID_6085, "Marvell 88E6085" },
22 { PORT_SWITCH_ID_6095, "Marvell 88E6095/88E6095F" },
23 { PORT_SWITCH_ID_6131, "Marvell 88E6131" },
24 { PORT_SWITCH_ID_6131_B2, "Marvell 88E6131 (B2)" },
25 { PORT_SWITCH_ID_6185, "Marvell 88E6185" },
26};
27
Andrew Lunne49bad32016-04-13 02:40:43 +020028static char *mv88e6131_drv_probe(struct device *dsa_dev,
29 struct device *host_dev,
30 int sw_addr, void **priv)
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +000031{
Andrew Lunna77d43f2016-04-13 02:40:42 +020032 return mv88e6xxx_drv_probe(dsa_dev, host_dev, sw_addr, priv,
33 mv88e6131_table,
34 ARRAY_SIZE(mv88e6131_table));
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +000035}
36
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +000037static int mv88e6131_setup_global(struct dsa_switch *ds)
38{
Andrew Lunn15966a22015-05-06 01:09:49 +020039 u32 upstream_port = dsa_upstream_port(ds);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +000040 int ret;
Andrew Lunn15966a22015-05-06 01:09:49 +020041 u32 reg;
Andrew Lunn54d792f2015-05-06 01:09:47 +020042
43 ret = mv88e6xxx_setup_global(ds);
44 if (ret)
45 return ret;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +000046
Barry Grussling3675c8d2013-01-08 16:05:53 +000047 /* Enable the PHY polling unit, don't discard packets with
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +000048 * excessive collisions, use a weighted fair queueing scheme
49 * to arbitrate between packet queues, set the maximum frame
50 * size to 1632, and mask all interrupt sources.
51 */
Andrew Lunn48ace4e2016-04-14 23:47:12 +020052 ret = mv88e6xxx_reg_write(ds, REG_GLOBAL, GLOBAL_CONTROL,
53 GLOBAL_CONTROL_PPU_ENABLE |
54 GLOBAL_CONTROL_MAX_FRAME_1632);
55 if (ret)
56 return ret;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +000057
Barry Grussling3675c8d2013-01-08 16:05:53 +000058 /* Set the VLAN ethertype to 0x8100. */
Andrew Lunn48ace4e2016-04-14 23:47:12 +020059 ret = mv88e6xxx_reg_write(ds, REG_GLOBAL, GLOBAL_CORE_TAG_TYPE, 0x8100);
60 if (ret)
61 return ret;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +000062
Barry Grussling3675c8d2013-01-08 16:05:53 +000063 /* Disable ARP mirroring, and configure the upstream port as
Lennert Buytenheke84665c2009-03-20 09:52:09 +000064 * the port to which ingress and egress monitor frames are to
65 * be sent.
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +000066 */
Andrew Lunn15966a22015-05-06 01:09:49 +020067 reg = upstream_port << GLOBAL_MONITOR_CONTROL_INGRESS_SHIFT |
68 upstream_port << GLOBAL_MONITOR_CONTROL_EGRESS_SHIFT |
69 GLOBAL_MONITOR_CONTROL_ARP_DISABLED;
Andrew Lunn48ace4e2016-04-14 23:47:12 +020070 ret = mv88e6xxx_reg_write(ds, REG_GLOBAL, GLOBAL_MONITOR_CONTROL, reg);
71 if (ret)
72 return ret;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +000073
Barry Grussling3675c8d2013-01-08 16:05:53 +000074 /* Disable cascade port functionality unless this device
Barry Grussling81399ec2011-06-24 19:53:51 +000075 * is used in a cascade configuration, and set the switch's
Lennert Buytenheke84665c2009-03-20 09:52:09 +000076 * DSA device number.
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +000077 */
Barry Grussling81399ec2011-06-24 19:53:51 +000078 if (ds->dst->pd->nr_chips > 1)
Andrew Lunn48ace4e2016-04-14 23:47:12 +020079 ret = mv88e6xxx_reg_write(ds, REG_GLOBAL, GLOBAL_CONTROL_2,
80 GLOBAL_CONTROL_2_MULTIPLE_CASCADE |
81 (ds->index & 0x1f));
Barry Grussling81399ec2011-06-24 19:53:51 +000082 else
Andrew Lunn48ace4e2016-04-14 23:47:12 +020083 ret = mv88e6xxx_reg_write(ds, REG_GLOBAL, GLOBAL_CONTROL_2,
84 GLOBAL_CONTROL_2_NO_CASCADE |
85 (ds->index & 0x1f));
86 if (ret)
87 return ret;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +000088
Barry Grussling3675c8d2013-01-08 16:05:53 +000089 /* Force the priority of IGMP/MLD snoop frames and ARP frames
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +000090 * to the highest setting.
91 */
Andrew Lunn48ace4e2016-04-14 23:47:12 +020092 return mv88e6xxx_reg_write(ds, REG_GLOBAL2, GLOBAL2_PRIO_OVERRIDE,
93 GLOBAL2_PRIO_OVERRIDE_FORCE_SNOOP |
94 7 << GLOBAL2_PRIO_OVERRIDE_SNOOP_SHIFT |
95 GLOBAL2_PRIO_OVERRIDE_FORCE_ARP |
96 7 << GLOBAL2_PRIO_OVERRIDE_ARP_SHIFT);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +000097}
98
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +000099static int mv88e6131_setup(struct dsa_switch *ds)
100{
Guenter Roeckd1988932015-04-02 04:06:31 +0200101 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000102 int ret;
103
Andrew Lunn7543a6d2016-04-13 02:40:40 +0200104 ps->ds = ds;
105
Guenter Roeck0d65da42015-04-02 04:06:29 +0200106 ret = mv88e6xxx_setup_common(ds);
107 if (ret < 0)
108 return ret;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000109
Guenter Roeck0d65da42015-04-02 04:06:29 +0200110 mv88e6xxx_ppu_state_init(ds);
Peter Korsgaardec80bfc2011-04-05 03:03:56 +0000111
Guenter Roeckd1988932015-04-02 04:06:31 +0200112 switch (ps->id) {
Andrew Lunncca8b132015-04-02 04:06:39 +0200113 case PORT_SWITCH_ID_6085:
Andrew Lunn1441f4e2015-05-06 01:09:52 +0200114 case PORT_SWITCH_ID_6185:
Guenter Roeckd1988932015-04-02 04:06:31 +0200115 ps->num_ports = 10;
116 break;
Andrew Lunncca8b132015-04-02 04:06:39 +0200117 case PORT_SWITCH_ID_6095:
Guenter Roeckd1988932015-04-02 04:06:31 +0200118 ps->num_ports = 11;
119 break;
Andrew Lunncca8b132015-04-02 04:06:39 +0200120 case PORT_SWITCH_ID_6131:
121 case PORT_SWITCH_ID_6131_B2:
Guenter Roeckd1988932015-04-02 04:06:31 +0200122 ps->num_ports = 8;
123 break;
124 default:
125 return -ENODEV;
126 }
127
Andrew Lunn143a8302015-04-02 04:06:34 +0200128 ret = mv88e6xxx_switch_reset(ds, false);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000129 if (ret < 0)
130 return ret;
131
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000132 ret = mv88e6131_setup_global(ds);
133 if (ret < 0)
134 return ret;
135
Andrew Lunndbde9e62015-05-06 01:09:48 +0200136 return mv88e6xxx_setup_ports(ds);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000137}
138
Guenter Roeckd1988932015-04-02 04:06:31 +0200139static int mv88e6131_port_to_phy_addr(struct dsa_switch *ds, int port)
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000140{
Guenter Roeckd1988932015-04-02 04:06:31 +0200141 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
142
143 if (port >= 0 && port < ps->num_ports)
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000144 return port;
Guenter Roeckd1988932015-04-02 04:06:31 +0200145
146 return -EINVAL;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000147}
148
149static int
150mv88e6131_phy_read(struct dsa_switch *ds, int port, int regnum)
151{
Guenter Roeckd1988932015-04-02 04:06:31 +0200152 int addr = mv88e6131_port_to_phy_addr(ds, port);
153
154 if (addr < 0)
155 return addr;
156
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000157 return mv88e6xxx_phy_read_ppu(ds, addr, regnum);
158}
159
160static int
161mv88e6131_phy_write(struct dsa_switch *ds,
162 int port, int regnum, u16 val)
163{
Guenter Roeckd1988932015-04-02 04:06:31 +0200164 int addr = mv88e6131_port_to_phy_addr(ds, port);
165
166 if (addr < 0)
167 return addr;
168
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000169 return mv88e6xxx_phy_write_ppu(ds, addr, regnum, val);
170}
171
Ben Hutchings98e67302011-11-25 14:36:19 +0000172struct dsa_switch_driver mv88e6131_switch_driver = {
Florian Fainelliac7a04c2014-09-11 21:18:09 -0700173 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunne49bad32016-04-13 02:40:43 +0200174 .probe = mv88e6131_drv_probe,
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000175 .setup = mv88e6131_setup,
176 .set_addr = mv88e6xxx_set_addr_direct,
177 .phy_read = mv88e6131_phy_read,
178 .phy_write = mv88e6131_phy_write,
Andrew Lunne413e7e2015-04-02 04:06:38 +0200179 .get_strings = mv88e6xxx_get_strings,
180 .get_ethtool_stats = mv88e6xxx_get_ethtool_stats,
181 .get_sset_count = mv88e6xxx_get_sset_count,
Andrew Lunndea87022015-08-31 15:56:47 +0200182 .adjust_link = mv88e6xxx_adjust_link,
Vivien Didelot26892ff2016-03-31 16:53:46 -0400183 .port_bridge_join = mv88e6xxx_port_bridge_join,
184 .port_bridge_leave = mv88e6xxx_port_bridge_leave,
185 .port_vlan_filtering = mv88e6xxx_port_vlan_filtering,
186 .port_vlan_prepare = mv88e6xxx_port_vlan_prepare,
187 .port_vlan_add = mv88e6xxx_port_vlan_add,
188 .port_vlan_del = mv88e6xxx_port_vlan_del,
189 .port_vlan_dump = mv88e6xxx_port_vlan_dump,
190 .port_fdb_prepare = mv88e6xxx_port_fdb_prepare,
191 .port_fdb_add = mv88e6xxx_port_fdb_add,
192 .port_fdb_del = mv88e6xxx_port_fdb_del,
193 .port_fdb_dump = mv88e6xxx_port_fdb_dump,
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000194};
Ben Hutchings3d825ed2011-11-25 14:37:16 +0000195
196MODULE_ALIAS("platform:mv88e6085");
197MODULE_ALIAS("platform:mv88e6095");
198MODULE_ALIAS("platform:mv88e6095f");
199MODULE_ALIAS("platform:mv88e6131");