net: dsa: mv88e6xxx: factorize GLOBAL_CONTROL setup
[deliverable/linux.git] / drivers / net / dsa / mv88e6131.c
1 /*
2 * net/dsa/mv88e6131.c - Marvell 88e6095/6095f/6131 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 mv88e6131_table[] = {
21 {
22 .prod_num = PORT_SWITCH_ID_PROD_NUM_6095,
23 .family = MV88E6XXX_FAMILY_6095,
24 .name = "Marvell 88E6095/88E6095F",
25 .num_databases = 256,
26 .num_ports = 11,
27 .flags = MV88E6XXX_FLAGS_FAMILY_6095,
28 }, {
29 .prod_num = PORT_SWITCH_ID_PROD_NUM_6085,
30 .family = MV88E6XXX_FAMILY_6097,
31 .name = "Marvell 88E6085",
32 .num_databases = 4096,
33 .num_ports = 10,
34 .flags = MV88E6XXX_FLAGS_FAMILY_6097,
35 }, {
36 .prod_num = PORT_SWITCH_ID_PROD_NUM_6131,
37 .family = MV88E6XXX_FAMILY_6185,
38 .name = "Marvell 88E6131",
39 .num_databases = 256,
40 .num_ports = 8,
41 .flags = MV88E6XXX_FLAGS_FAMILY_6185,
42 }, {
43 .prod_num = PORT_SWITCH_ID_PROD_NUM_6185,
44 .family = MV88E6XXX_FAMILY_6185,
45 .name = "Marvell 88E6185",
46 .num_databases = 256,
47 .num_ports = 10,
48 .flags = MV88E6XXX_FLAGS_FAMILY_6185,
49 }
50 };
51
52 static const char *mv88e6131_drv_probe(struct device *dsa_dev,
53 struct device *host_dev, int sw_addr,
54 void **priv)
55 {
56 return mv88e6xxx_drv_probe(dsa_dev, host_dev, sw_addr, priv,
57 mv88e6131_table,
58 ARRAY_SIZE(mv88e6131_table));
59 }
60
61 static int mv88e6131_setup_global(struct dsa_switch *ds)
62 {
63 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
64 u32 upstream_port = dsa_upstream_port(ds);
65 int ret;
66 u32 reg;
67
68 /* Set the VLAN ethertype to 0x8100. */
69 ret = mv88e6xxx_reg_write(ps, REG_GLOBAL, GLOBAL_CORE_TAG_TYPE, 0x8100);
70 if (ret)
71 return ret;
72
73 /* Disable ARP mirroring, and configure the upstream port as
74 * the port to which ingress and egress monitor frames are to
75 * be sent.
76 */
77 reg = upstream_port << GLOBAL_MONITOR_CONTROL_INGRESS_SHIFT |
78 upstream_port << GLOBAL_MONITOR_CONTROL_EGRESS_SHIFT |
79 GLOBAL_MONITOR_CONTROL_ARP_DISABLED;
80 ret = mv88e6xxx_reg_write(ps, REG_GLOBAL, GLOBAL_MONITOR_CONTROL, reg);
81 if (ret)
82 return ret;
83
84 /* Disable cascade port functionality unless this device
85 * is used in a cascade configuration, and set the switch's
86 * DSA device number.
87 */
88 if (ds->dst->pd->nr_chips > 1)
89 ret = mv88e6xxx_reg_write(ps, REG_GLOBAL, GLOBAL_CONTROL_2,
90 GLOBAL_CONTROL_2_MULTIPLE_CASCADE |
91 (ds->index & 0x1f));
92 else
93 ret = mv88e6xxx_reg_write(ps, REG_GLOBAL, GLOBAL_CONTROL_2,
94 GLOBAL_CONTROL_2_NO_CASCADE |
95 (ds->index & 0x1f));
96 if (ret)
97 return ret;
98
99 /* Force the priority of IGMP/MLD snoop frames and ARP frames
100 * to the highest setting.
101 */
102 return mv88e6xxx_reg_write(ps, REG_GLOBAL2, GLOBAL2_PRIO_OVERRIDE,
103 GLOBAL2_PRIO_OVERRIDE_FORCE_SNOOP |
104 7 << GLOBAL2_PRIO_OVERRIDE_SNOOP_SHIFT |
105 GLOBAL2_PRIO_OVERRIDE_FORCE_ARP |
106 7 << GLOBAL2_PRIO_OVERRIDE_ARP_SHIFT);
107 }
108
109 static int mv88e6131_setup(struct dsa_switch *ds)
110 {
111 struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
112 int ret;
113
114 ps->ds = ds;
115
116 ret = mv88e6xxx_setup_common(ps);
117 if (ret < 0)
118 return ret;
119
120 ret = mv88e6131_setup_global(ds);
121 if (ret < 0)
122 return ret;
123
124 return mv88e6xxx_setup_ports(ds);
125 }
126
127 struct dsa_switch_driver mv88e6131_switch_driver = {
128 .tag_protocol = DSA_TAG_PROTO_DSA,
129 .probe = mv88e6131_drv_probe,
130 .setup = mv88e6131_setup,
131 .set_addr = mv88e6xxx_set_addr,
132 .phy_read = mv88e6xxx_phy_read,
133 .phy_write = mv88e6xxx_phy_write,
134 .set_eee = mv88e6xxx_set_eee,
135 .get_eee = mv88e6xxx_get_eee,
136 .get_strings = mv88e6xxx_get_strings,
137 .get_ethtool_stats = mv88e6xxx_get_ethtool_stats,
138 .get_sset_count = mv88e6xxx_get_sset_count,
139 .get_eeprom = mv88e6xxx_get_eeprom,
140 .set_eeprom = mv88e6xxx_set_eeprom,
141 .get_regs_len = mv88e6xxx_get_regs_len,
142 .get_regs = mv88e6xxx_get_regs,
143 #ifdef CONFIG_NET_DSA_HWMON
144 .get_temp = mv88e6xxx_get_temp,
145 .get_temp_limit = mv88e6xxx_get_temp_limit,
146 .set_temp_limit = mv88e6xxx_set_temp_limit,
147 .get_temp_alarm = mv88e6xxx_get_temp_alarm,
148 #endif
149 .adjust_link = mv88e6xxx_adjust_link,
150 .port_bridge_join = mv88e6xxx_port_bridge_join,
151 .port_bridge_leave = mv88e6xxx_port_bridge_leave,
152 .port_stp_state_set = mv88e6xxx_port_stp_state_set,
153 .port_vlan_filtering = mv88e6xxx_port_vlan_filtering,
154 .port_vlan_prepare = mv88e6xxx_port_vlan_prepare,
155 .port_vlan_add = mv88e6xxx_port_vlan_add,
156 .port_vlan_del = mv88e6xxx_port_vlan_del,
157 .port_vlan_dump = mv88e6xxx_port_vlan_dump,
158 .port_fdb_prepare = mv88e6xxx_port_fdb_prepare,
159 .port_fdb_add = mv88e6xxx_port_fdb_add,
160 .port_fdb_del = mv88e6xxx_port_fdb_del,
161 .port_fdb_dump = mv88e6xxx_port_fdb_dump,
162 };
163
164 MODULE_ALIAS("platform:mv88e6085");
165 MODULE_ALIAS("platform:mv88e6095");
166 MODULE_ALIAS("platform:mv88e6095f");
167 MODULE_ALIAS("platform:mv88e6131");
This page took 0.036503 seconds and 5 git commands to generate.