blob: 357ab794d72083cb0db76d87d3cd8e2af2bd75d0 [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 Didelotf6271e62016-04-17 13:23:59 -040020static const struct mv88e6xxx_info mv88e6131_table[] = {
21 {
22 .prod_num = PORT_SWITCH_ID_PROD_NUM_6095,
Vivien Didelot22356472016-04-17 13:24:00 -040023 .family = MV88E6XXX_FAMILY_6095,
Vivien Didelotf6271e62016-04-17 13:23:59 -040024 .name = "Marvell 88E6095/88E6095F",
Vivien Didelotcd5a2c82016-04-17 13:24:02 -040025 .num_databases = 256,
Vivien Didelot009a2b92016-04-17 13:24:01 -040026 .num_ports = 11,
Vivien Didelotf6271e62016-04-17 13:23:59 -040027 }, {
28 .prod_num = PORT_SWITCH_ID_PROD_NUM_6085,
Vivien Didelot22356472016-04-17 13:24:00 -040029 .family = MV88E6XXX_FAMILY_6097,
Vivien Didelotf6271e62016-04-17 13:23:59 -040030 .name = "Marvell 88E6085",
Vivien Didelotcd5a2c82016-04-17 13:24:02 -040031 .num_databases = 4096,
Vivien Didelot009a2b92016-04-17 13:24:01 -040032 .num_ports = 10,
Vivien Didelotf6271e62016-04-17 13:23:59 -040033 }, {
34 .prod_num = PORT_SWITCH_ID_PROD_NUM_6131,
Vivien Didelot22356472016-04-17 13:24:00 -040035 .family = MV88E6XXX_FAMILY_6185,
Vivien Didelotf6271e62016-04-17 13:23:59 -040036 .name = "Marvell 88E6131",
Vivien Didelotcd5a2c82016-04-17 13:24:02 -040037 .num_databases = 256,
Vivien Didelot009a2b92016-04-17 13:24:01 -040038 .num_ports = 8,
Vivien Didelotf6271e62016-04-17 13:23:59 -040039 }, {
40 .prod_num = PORT_SWITCH_ID_PROD_NUM_6185,
Vivien Didelot22356472016-04-17 13:24:00 -040041 .family = MV88E6XXX_FAMILY_6185,
Vivien Didelotf6271e62016-04-17 13:23:59 -040042 .name = "Marvell 88E6185",
Vivien Didelotcd5a2c82016-04-17 13:24:02 -040043 .num_databases = 256,
Vivien Didelot009a2b92016-04-17 13:24:01 -040044 .num_ports = 10,
Vivien Didelotf6271e62016-04-17 13:23:59 -040045 }
Vivien Didelotb9b37712015-10-30 19:39:48 -040046};
47
Vivien Didelot0209d142016-04-17 13:23:55 -040048static const char *mv88e6131_drv_probe(struct device *dsa_dev,
49 struct device *host_dev, int sw_addr,
50 void **priv)
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +000051{
Andrew Lunna77d43f2016-04-13 02:40:42 +020052 return mv88e6xxx_drv_probe(dsa_dev, host_dev, sw_addr, priv,
53 mv88e6131_table,
54 ARRAY_SIZE(mv88e6131_table));
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +000055}
56
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +000057static int mv88e6131_setup_global(struct dsa_switch *ds)
58{
Andrew Lunn158bc062016-04-28 21:24:06 -040059 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
Andrew Lunn15966a22015-05-06 01:09:49 +020060 u32 upstream_port = dsa_upstream_port(ds);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +000061 int ret;
Andrew Lunn15966a22015-05-06 01:09:49 +020062 u32 reg;
Andrew Lunn54d792f2015-05-06 01:09:47 +020063
64 ret = mv88e6xxx_setup_global(ds);
65 if (ret)
66 return ret;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +000067
Barry Grussling3675c8d2013-01-08 16:05:53 +000068 /* Enable the PHY polling unit, don't discard packets with
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +000069 * excessive collisions, use a weighted fair queueing scheme
70 * to arbitrate between packet queues, set the maximum frame
71 * size to 1632, and mask all interrupt sources.
72 */
Andrew Lunn158bc062016-04-28 21:24:06 -040073 ret = mv88e6xxx_reg_write(ps, REG_GLOBAL, GLOBAL_CONTROL,
Andrew Lunn48ace4e2016-04-14 23:47:12 +020074 GLOBAL_CONTROL_PPU_ENABLE |
75 GLOBAL_CONTROL_MAX_FRAME_1632);
76 if (ret)
77 return ret;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +000078
Barry Grussling3675c8d2013-01-08 16:05:53 +000079 /* Set the VLAN ethertype to 0x8100. */
Andrew Lunn158bc062016-04-28 21:24:06 -040080 ret = mv88e6xxx_reg_write(ps, REG_GLOBAL, GLOBAL_CORE_TAG_TYPE, 0x8100);
Andrew Lunn48ace4e2016-04-14 23:47:12 +020081 if (ret)
82 return ret;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +000083
Barry Grussling3675c8d2013-01-08 16:05:53 +000084 /* Disable ARP mirroring, and configure the upstream port as
Lennert Buytenheke84665c2009-03-20 09:52:09 +000085 * the port to which ingress and egress monitor frames are to
86 * be sent.
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +000087 */
Andrew Lunn15966a22015-05-06 01:09:49 +020088 reg = upstream_port << GLOBAL_MONITOR_CONTROL_INGRESS_SHIFT |
89 upstream_port << GLOBAL_MONITOR_CONTROL_EGRESS_SHIFT |
90 GLOBAL_MONITOR_CONTROL_ARP_DISABLED;
Andrew Lunn158bc062016-04-28 21:24:06 -040091 ret = mv88e6xxx_reg_write(ps, REG_GLOBAL, GLOBAL_MONITOR_CONTROL, reg);
Andrew Lunn48ace4e2016-04-14 23:47:12 +020092 if (ret)
93 return ret;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +000094
Barry Grussling3675c8d2013-01-08 16:05:53 +000095 /* Disable cascade port functionality unless this device
Barry Grussling81399ec2011-06-24 19:53:51 +000096 * is used in a cascade configuration, and set the switch's
Lennert Buytenheke84665c2009-03-20 09:52:09 +000097 * DSA device number.
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +000098 */
Barry Grussling81399ec2011-06-24 19:53:51 +000099 if (ds->dst->pd->nr_chips > 1)
Andrew Lunn158bc062016-04-28 21:24:06 -0400100 ret = mv88e6xxx_reg_write(ps, REG_GLOBAL, GLOBAL_CONTROL_2,
Andrew Lunn48ace4e2016-04-14 23:47:12 +0200101 GLOBAL_CONTROL_2_MULTIPLE_CASCADE |
102 (ds->index & 0x1f));
Barry Grussling81399ec2011-06-24 19:53:51 +0000103 else
Andrew Lunn158bc062016-04-28 21:24:06 -0400104 ret = mv88e6xxx_reg_write(ps, REG_GLOBAL, GLOBAL_CONTROL_2,
Andrew Lunn48ace4e2016-04-14 23:47:12 +0200105 GLOBAL_CONTROL_2_NO_CASCADE |
106 (ds->index & 0x1f));
107 if (ret)
108 return ret;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000109
Barry Grussling3675c8d2013-01-08 16:05:53 +0000110 /* Force the priority of IGMP/MLD snoop frames and ARP frames
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000111 * to the highest setting.
112 */
Andrew Lunn158bc062016-04-28 21:24:06 -0400113 return mv88e6xxx_reg_write(ps, REG_GLOBAL2, GLOBAL2_PRIO_OVERRIDE,
Andrew Lunn48ace4e2016-04-14 23:47:12 +0200114 GLOBAL2_PRIO_OVERRIDE_FORCE_SNOOP |
115 7 << GLOBAL2_PRIO_OVERRIDE_SNOOP_SHIFT |
116 GLOBAL2_PRIO_OVERRIDE_FORCE_ARP |
117 7 << GLOBAL2_PRIO_OVERRIDE_ARP_SHIFT);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000118}
119
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000120static int mv88e6131_setup(struct dsa_switch *ds)
121{
Andrew Lunn158bc062016-04-28 21:24:06 -0400122 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000123 int ret;
124
Andrew Lunn158bc062016-04-28 21:24:06 -0400125 ps->ds = ds;
126
127 ret = mv88e6xxx_setup_common(ps);
Guenter Roeck0d65da42015-04-02 04:06:29 +0200128 if (ret < 0)
129 return ret;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000130
Andrew Lunn158bc062016-04-28 21:24:06 -0400131 mv88e6xxx_ppu_state_init(ps);
Peter Korsgaardec80bfc2011-04-05 03:03:56 +0000132
Andrew Lunn158bc062016-04-28 21:24:06 -0400133 ret = mv88e6xxx_switch_reset(ps, false);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000134 if (ret < 0)
135 return ret;
136
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000137 ret = mv88e6131_setup_global(ds);
138 if (ret < 0)
139 return ret;
140
Andrew Lunndbde9e62015-05-06 01:09:48 +0200141 return mv88e6xxx_setup_ports(ds);
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000142}
143
Guenter Roeckd1988932015-04-02 04:06:31 +0200144static int mv88e6131_port_to_phy_addr(struct dsa_switch *ds, int port)
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000145{
Guenter Roeckd1988932015-04-02 04:06:31 +0200146 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
147
Vivien Didelot009a2b92016-04-17 13:24:01 -0400148 if (port >= 0 && port < ps->info->num_ports)
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000149 return port;
Guenter Roeckd1988932015-04-02 04:06:31 +0200150
151 return -EINVAL;
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000152}
153
154static int
155mv88e6131_phy_read(struct dsa_switch *ds, int port, int regnum)
156{
Guenter Roeckd1988932015-04-02 04:06:31 +0200157 int addr = mv88e6131_port_to_phy_addr(ds, port);
158
159 if (addr < 0)
160 return addr;
161
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000162 return mv88e6xxx_phy_read_ppu(ds, addr, regnum);
163}
164
165static int
166mv88e6131_phy_write(struct dsa_switch *ds,
167 int port, int regnum, u16 val)
168{
Guenter Roeckd1988932015-04-02 04:06:31 +0200169 int addr = mv88e6131_port_to_phy_addr(ds, port);
170
171 if (addr < 0)
172 return addr;
173
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000174 return mv88e6xxx_phy_write_ppu(ds, addr, regnum, val);
175}
176
Ben Hutchings98e67302011-11-25 14:36:19 +0000177struct dsa_switch_driver mv88e6131_switch_driver = {
Florian Fainelliac7a04c2014-09-11 21:18:09 -0700178 .tag_protocol = DSA_TAG_PROTO_DSA,
Andrew Lunne49bad32016-04-13 02:40:43 +0200179 .probe = mv88e6131_drv_probe,
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000180 .setup = mv88e6131_setup,
181 .set_addr = mv88e6xxx_set_addr_direct,
182 .phy_read = mv88e6131_phy_read,
183 .phy_write = mv88e6131_phy_write,
Andrew Lunne413e7e2015-04-02 04:06:38 +0200184 .get_strings = mv88e6xxx_get_strings,
185 .get_ethtool_stats = mv88e6xxx_get_ethtool_stats,
186 .get_sset_count = mv88e6xxx_get_sset_count,
Andrew Lunndea87022015-08-31 15:56:47 +0200187 .adjust_link = mv88e6xxx_adjust_link,
Vivien Didelot26892ff2016-03-31 16:53:46 -0400188 .port_bridge_join = mv88e6xxx_port_bridge_join,
189 .port_bridge_leave = mv88e6xxx_port_bridge_leave,
190 .port_vlan_filtering = mv88e6xxx_port_vlan_filtering,
191 .port_vlan_prepare = mv88e6xxx_port_vlan_prepare,
192 .port_vlan_add = mv88e6xxx_port_vlan_add,
193 .port_vlan_del = mv88e6xxx_port_vlan_del,
194 .port_vlan_dump = mv88e6xxx_port_vlan_dump,
195 .port_fdb_prepare = mv88e6xxx_port_fdb_prepare,
196 .port_fdb_add = mv88e6xxx_port_fdb_add,
197 .port_fdb_del = mv88e6xxx_port_fdb_del,
198 .port_fdb_dump = mv88e6xxx_port_fdb_dump,
Lennert Buytenhek2e5f0322008-10-07 13:45:18 +0000199};
Ben Hutchings3d825ed2011-11-25 14:37:16 +0000200
201MODULE_ALIAS("platform:mv88e6085");
202MODULE_ALIAS("platform:mv88e6095");
203MODULE_ALIAS("platform:mv88e6095f");
204MODULE_ALIAS("platform:mv88e6131");