da5aa9c0a4716b08d1c04ced03351a02e59df265
[cascardo/linux.git] / drivers / net / dsa / mv88e6123.c
1 /*
2  * net/dsa/mv88e6123_61_65.c - Marvell 88e6123/6161/6165 switch chip support
3  * Copyright (c) 2008-2009 Marvell Semiconductor
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 mv88e6123_table[] = {
21         {
22                 .prod_num = PORT_SWITCH_ID_PROD_NUM_6123,
23                 .family = MV88E6XXX_FAMILY_6165,
24                 .name = "Marvell 88E6123",
25                 .num_databases = 4096,
26                 .num_ports = 3,
27                 .flags = MV88E6XXX_FLAGS_FAMILY_6165,
28         }, {
29                 .prod_num = PORT_SWITCH_ID_PROD_NUM_6161,
30                 .family = MV88E6XXX_FAMILY_6165,
31                 .name = "Marvell 88E6161",
32                 .num_databases = 4096,
33                 .num_ports = 6,
34                 .flags = MV88E6XXX_FLAGS_FAMILY_6165,
35         }, {
36                 .prod_num = PORT_SWITCH_ID_PROD_NUM_6165,
37                 .family = MV88E6XXX_FAMILY_6165,
38                 .name = "Marvell 88E6165",
39                 .num_databases = 4096,
40                 .num_ports = 6,
41                 .flags = MV88E6XXX_FLAGS_FAMILY_6165,
42         }
43 };
44
45 static const char *mv88e6123_drv_probe(struct device *dsa_dev,
46                                        struct device *host_dev, int sw_addr,
47                                        void **priv)
48 {
49         return mv88e6xxx_drv_probe(dsa_dev, host_dev, sw_addr, priv,
50                                    mv88e6123_table,
51                                    ARRAY_SIZE(mv88e6123_table));
52 }
53
54 static int mv88e6123_setup_global(struct dsa_switch *ds)
55 {
56         struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
57         u32 upstream_port = dsa_upstream_port(ds);
58         int ret;
59         u32 reg;
60
61         ret = mv88e6xxx_setup_global(ds);
62         if (ret)
63                 return ret;
64
65         /* Disable the PHY polling unit (since there won't be any
66          * external PHYs to poll), don't discard packets with
67          * excessive collisions, and mask all interrupt sources.
68          */
69         ret = mv88e6xxx_reg_write(ps, REG_GLOBAL, GLOBAL_CONTROL, 0x0000);
70         if (ret)
71                 return ret;
72
73         /* Configure the upstream port, and configure the upstream
74          * port as the port to which ingress and egress monitor frames
75          * are to be sent.
76          */
77         reg = upstream_port << GLOBAL_MONITOR_CONTROL_INGRESS_SHIFT |
78                 upstream_port << GLOBAL_MONITOR_CONTROL_EGRESS_SHIFT |
79                 upstream_port << GLOBAL_MONITOR_CONTROL_ARP_SHIFT;
80         ret = mv88e6xxx_reg_write(ps, REG_GLOBAL, GLOBAL_MONITOR_CONTROL, reg);
81         if (ret)
82                 return ret;
83
84         /* Disable remote management for now, and set the switch's
85          * DSA device number.
86          */
87         return mv88e6xxx_reg_write(ps, REG_GLOBAL, GLOBAL_CONTROL_2,
88                                    ds->index & 0x1f);
89 }
90
91 static int mv88e6123_setup(struct dsa_switch *ds)
92 {
93         struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
94         int ret;
95
96         ps->ds = ds;
97
98         ret = mv88e6xxx_setup_common(ps);
99         if (ret < 0)
100                 return ret;
101
102         ret = mv88e6xxx_switch_reset(ps, false);
103         if (ret < 0)
104                 return ret;
105
106         ret = mv88e6123_setup_global(ds);
107         if (ret < 0)
108                 return ret;
109
110         return mv88e6xxx_setup_ports(ds);
111 }
112
113 struct dsa_switch_driver mv88e6123_switch_driver = {
114         .tag_protocol           = DSA_TAG_PROTO_EDSA,
115         .probe                  = mv88e6123_drv_probe,
116         .setup                  = mv88e6123_setup,
117         .set_addr               = mv88e6xxx_set_addr,
118         .phy_read               = mv88e6xxx_phy_read,
119         .phy_write              = mv88e6xxx_phy_write,
120         .set_eee                = mv88e6xxx_set_eee,
121         .get_eee                = mv88e6xxx_get_eee,
122         .get_strings            = mv88e6xxx_get_strings,
123         .get_ethtool_stats      = mv88e6xxx_get_ethtool_stats,
124         .get_sset_count         = mv88e6xxx_get_sset_count,
125         .adjust_link            = mv88e6xxx_adjust_link,
126 #ifdef CONFIG_NET_DSA_HWMON
127         .get_temp               = mv88e6xxx_get_temp,
128         .get_temp_limit         = mv88e6xxx_get_temp_limit,
129         .set_temp_limit         = mv88e6xxx_set_temp_limit,
130         .get_temp_alarm         = mv88e6xxx_get_temp_alarm,
131 #endif
132         .get_eeprom             = mv88e6xxx_get_eeprom,
133         .set_eeprom             = mv88e6xxx_set_eeprom,
134         .get_regs_len           = mv88e6xxx_get_regs_len,
135         .get_regs               = mv88e6xxx_get_regs,
136         .port_bridge_join       = mv88e6xxx_port_bridge_join,
137         .port_bridge_leave      = mv88e6xxx_port_bridge_leave,
138         .port_stp_state_set     = mv88e6xxx_port_stp_state_set,
139         .port_vlan_filtering    = mv88e6xxx_port_vlan_filtering,
140         .port_vlan_prepare      = mv88e6xxx_port_vlan_prepare,
141         .port_vlan_add          = mv88e6xxx_port_vlan_add,
142         .port_vlan_del          = mv88e6xxx_port_vlan_del,
143         .port_vlan_dump         = mv88e6xxx_port_vlan_dump,
144 };
145
146 MODULE_ALIAS("platform:mv88e6123");
147 MODULE_ALIAS("platform:mv88e6161");
148 MODULE_ALIAS("platform:mv88e6165");