Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net
[cascardo/linux.git] / drivers / net / dsa / mv88e6171.c
1 /* net/dsa/mv88e6171.c - Marvell 88e6171 switch chip support
2  * Copyright (c) 2008-2009 Marvell Semiconductor
3  * Copyright (c) 2014 Claudio Leite <leitec@staticky.com>
4  *
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
11 #include <linux/delay.h>
12 #include <linux/jiffies.h>
13 #include <linux/list.h>
14 #include <linux/module.h>
15 #include <linux/netdevice.h>
16 #include <linux/phy.h>
17 #include <net/dsa.h>
18 #include "mv88e6xxx.h"
19
20 static const struct mv88e6xxx_info mv88e6171_table[] = {
21         {
22                 .prod_num = PORT_SWITCH_ID_PROD_NUM_6171,
23                 .family = MV88E6XXX_FAMILY_6351,
24                 .name = "Marvell 88E6171",
25                 .num_databases = 4096,
26                 .num_ports = 7,
27         }, {
28                 .prod_num = PORT_SWITCH_ID_PROD_NUM_6175,
29                 .family = MV88E6XXX_FAMILY_6351,
30                 .name = "Marvell 88E6175",
31                 .num_databases = 4096,
32                 .num_ports = 7,
33         }, {
34                 .prod_num = PORT_SWITCH_ID_PROD_NUM_6350,
35                 .family = MV88E6XXX_FAMILY_6351,
36                 .name = "Marvell 88E6350",
37                 .num_databases = 4096,
38                 .num_ports = 7,
39         }, {
40                 .prod_num = PORT_SWITCH_ID_PROD_NUM_6351,
41                 .family = MV88E6XXX_FAMILY_6351,
42                 .name = "Marvell 88E6351",
43                 .num_databases = 4096,
44                 .num_ports = 7,
45         }
46 };
47
48 static const char *mv88e6171_drv_probe(struct device *dsa_dev,
49                                        struct device *host_dev, int sw_addr,
50                                        void **priv)
51 {
52         return mv88e6xxx_drv_probe(dsa_dev, host_dev, sw_addr, priv,
53                                    mv88e6171_table,
54                                    ARRAY_SIZE(mv88e6171_table));
55 }
56
57 static int mv88e6171_setup_global(struct dsa_switch *ds)
58 {
59         u32 upstream_port = dsa_upstream_port(ds);
60         int ret;
61         u32 reg;
62
63         ret = mv88e6xxx_setup_global(ds);
64         if (ret)
65                 return ret;
66
67         /* Discard packets with excessive collisions, mask all
68          * interrupt sources, enable PPU.
69          */
70         ret = mv88e6xxx_reg_write(ds, REG_GLOBAL, GLOBAL_CONTROL,
71                                   GLOBAL_CONTROL_PPU_ENABLE |
72                                   GLOBAL_CONTROL_DISCARD_EXCESS);
73         if (ret)
74                 return ret;
75
76         /* Configure the upstream port, and configure the upstream
77          * port as the port to which ingress and egress monitor frames
78          * are to be sent.
79          */
80         reg = upstream_port << GLOBAL_MONITOR_CONTROL_INGRESS_SHIFT |
81                 upstream_port << GLOBAL_MONITOR_CONTROL_EGRESS_SHIFT |
82                 upstream_port << GLOBAL_MONITOR_CONTROL_ARP_SHIFT |
83                 upstream_port << GLOBAL_MONITOR_CONTROL_MIRROR_SHIFT;
84         ret = mv88e6xxx_reg_write(ds, REG_GLOBAL, GLOBAL_MONITOR_CONTROL, reg);
85         if (ret)
86                 return ret;
87
88         /* Disable remote management for now, and set the switch's
89          * DSA device number.
90          */
91         return mv88e6xxx_reg_write(ds, REG_GLOBAL, GLOBAL_CONTROL_2,
92                                    ds->index & 0x1f);
93 }
94
95 static int mv88e6171_setup(struct dsa_switch *ds)
96 {
97         int ret;
98
99         ret = mv88e6xxx_setup_common(ds);
100         if (ret < 0)
101                 return ret;
102
103         ret = mv88e6xxx_switch_reset(ds, true);
104         if (ret < 0)
105                 return ret;
106
107         ret = mv88e6171_setup_global(ds);
108         if (ret < 0)
109                 return ret;
110
111         return mv88e6xxx_setup_ports(ds);
112 }
113
114 struct dsa_switch_driver mv88e6171_switch_driver = {
115         .tag_protocol           = DSA_TAG_PROTO_EDSA,
116         .probe                  = mv88e6171_drv_probe,
117         .setup                  = mv88e6171_setup,
118         .set_addr               = mv88e6xxx_set_addr_indirect,
119         .phy_read               = mv88e6xxx_phy_read_indirect,
120         .phy_write              = mv88e6xxx_phy_write_indirect,
121         .get_strings            = mv88e6xxx_get_strings,
122         .get_ethtool_stats      = mv88e6xxx_get_ethtool_stats,
123         .get_sset_count         = mv88e6xxx_get_sset_count,
124         .adjust_link            = mv88e6xxx_adjust_link,
125 #ifdef CONFIG_NET_DSA_HWMON
126         .get_temp               = mv88e6xxx_get_temp,
127 #endif
128         .get_regs_len           = mv88e6xxx_get_regs_len,
129         .get_regs               = mv88e6xxx_get_regs,
130         .port_bridge_join       = mv88e6xxx_port_bridge_join,
131         .port_bridge_leave      = mv88e6xxx_port_bridge_leave,
132         .port_stp_state_set     = mv88e6xxx_port_stp_state_set,
133         .port_vlan_filtering    = mv88e6xxx_port_vlan_filtering,
134         .port_vlan_prepare      = mv88e6xxx_port_vlan_prepare,
135         .port_vlan_add          = mv88e6xxx_port_vlan_add,
136         .port_vlan_del          = mv88e6xxx_port_vlan_del,
137         .port_vlan_dump         = mv88e6xxx_port_vlan_dump,
138         .port_fdb_prepare       = mv88e6xxx_port_fdb_prepare,
139         .port_fdb_add           = mv88e6xxx_port_fdb_add,
140         .port_fdb_del           = mv88e6xxx_port_fdb_del,
141         .port_fdb_dump          = mv88e6xxx_port_fdb_dump,
142 };
143
144 MODULE_ALIAS("platform:mv88e6171");
145 MODULE_ALIAS("platform:mv88e6175");
146 MODULE_ALIAS("platform:mv88e6350");
147 MODULE_ALIAS("platform:mv88e6351");