hwmon: (it87) Fix label group removal
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / net / dsa / mv88e6131.c
blob45f7411e90baf02fbed1642676f6448b74d024cb
1 /*
2 * net/dsa/mv88e6131.c - Marvell 88e6095/6095f/6131 switch chip support
3 * Copyright (c) 2008-2009 Marvell Semiconductor
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 */
11 #include <linux/list.h>
12 #include <linux/netdevice.h>
13 #include <linux/phy.h>
14 #include "dsa_priv.h"
15 #include "mv88e6xxx.h"
18 * Switch product IDs
20 #define ID_6085 0x04a0
21 #define ID_6095 0x0950
22 #define ID_6131 0x1060
24 static char *mv88e6131_probe(struct mii_bus *bus, int sw_addr)
26 int ret;
28 ret = __mv88e6xxx_reg_read(bus, sw_addr, REG_PORT(0), 0x03);
29 if (ret >= 0) {
30 ret &= 0xfff0;
31 if (ret == ID_6085)
32 return "Marvell 88E6085";
33 if (ret == ID_6095)
34 return "Marvell 88E6095/88E6095F";
35 if (ret == ID_6131)
36 return "Marvell 88E6131";
39 return NULL;
42 static int mv88e6131_switch_reset(struct dsa_switch *ds)
44 int i;
45 int ret;
48 * Set all ports to the disabled state.
50 for (i = 0; i < 11; i++) {
51 ret = REG_READ(REG_PORT(i), 0x04);
52 REG_WRITE(REG_PORT(i), 0x04, ret & 0xfffc);
56 * Wait for transmit queues to drain.
58 msleep(2);
61 * Reset the switch.
63 REG_WRITE(REG_GLOBAL, 0x04, 0xc400);
66 * Wait up to one second for reset to complete.
68 for (i = 0; i < 1000; i++) {
69 ret = REG_READ(REG_GLOBAL, 0x00);
70 if ((ret & 0xc800) == 0xc800)
71 break;
73 msleep(1);
75 if (i == 1000)
76 return -ETIMEDOUT;
78 return 0;
81 static int mv88e6131_setup_global(struct dsa_switch *ds)
83 int ret;
84 int i;
87 * Enable the PHY polling unit, don't discard packets with
88 * excessive collisions, use a weighted fair queueing scheme
89 * to arbitrate between packet queues, set the maximum frame
90 * size to 1632, and mask all interrupt sources.
92 REG_WRITE(REG_GLOBAL, 0x04, 0x4400);
95 * Set the default address aging time to 5 minutes, and
96 * enable address learn messages to be sent to all message
97 * ports.
99 REG_WRITE(REG_GLOBAL, 0x0a, 0x0148);
102 * Configure the priority mapping registers.
104 ret = mv88e6xxx_config_prio(ds);
105 if (ret < 0)
106 return ret;
109 * Set the VLAN ethertype to 0x8100.
111 REG_WRITE(REG_GLOBAL, 0x19, 0x8100);
114 * Disable ARP mirroring, and configure the upstream port as
115 * the port to which ingress and egress monitor frames are to
116 * be sent.
118 REG_WRITE(REG_GLOBAL, 0x1a, (dsa_upstream_port(ds) * 0x1100) | 0x00f0);
121 * Disable cascade port functionality, and set the switch's
122 * DSA device number.
124 REG_WRITE(REG_GLOBAL, 0x1c, 0xe000 | (ds->index & 0x1f));
127 * Send all frames with destination addresses matching
128 * 01:80:c2:00:00:0x to the CPU port.
130 REG_WRITE(REG_GLOBAL2, 0x03, 0xffff);
133 * Ignore removed tag data on doubly tagged packets, disable
134 * flow control messages, force flow control priority to the
135 * highest, and send all special multicast frames to the CPU
136 * port at the highest priority.
138 REG_WRITE(REG_GLOBAL2, 0x05, 0x00ff);
141 * Program the DSA routing table.
143 for (i = 0; i < 32; i++) {
144 int nexthop;
146 nexthop = 0x1f;
147 if (i != ds->index && i < ds->dst->pd->nr_chips)
148 nexthop = ds->pd->rtable[i] & 0x1f;
150 REG_WRITE(REG_GLOBAL2, 0x06, 0x8000 | (i << 8) | nexthop);
154 * Clear all trunk masks.
156 for (i = 0; i < 8; i++)
157 REG_WRITE(REG_GLOBAL2, 0x07, 0x8000 | (i << 12) | 0x7ff);
160 * Clear all trunk mappings.
162 for (i = 0; i < 16; i++)
163 REG_WRITE(REG_GLOBAL2, 0x08, 0x8000 | (i << 11));
166 * Force the priority of IGMP/MLD snoop frames and ARP frames
167 * to the highest setting.
169 REG_WRITE(REG_GLOBAL2, 0x0f, 0x00ff);
171 return 0;
174 static int mv88e6131_setup_port(struct dsa_switch *ds, int p)
176 struct mv88e6xxx_priv_state *ps = (void *)(ds + 1);
177 int addr = REG_PORT(p);
178 u16 val;
181 * MAC Forcing register: don't force link, speed, duplex
182 * or flow control state to any particular values on physical
183 * ports, but force the CPU port and all DSA ports to 1000 Mb/s
184 * (100 Mb/s on 6085) full duplex.
186 if (dsa_is_cpu_port(ds, p) || ds->dsa_port_mask & (1 << p))
187 if (ps->id == ID_6085)
188 REG_WRITE(addr, 0x01, 0x003d); /* 100 Mb/s */
189 else
190 REG_WRITE(addr, 0x01, 0x003e); /* 1000 Mb/s */
191 else
192 REG_WRITE(addr, 0x01, 0x0003);
195 * Port Control: disable Core Tag, disable Drop-on-Lock,
196 * transmit frames unmodified, disable Header mode,
197 * enable IGMP/MLD snoop, disable DoubleTag, disable VLAN
198 * tunneling, determine priority by looking at 802.1p and
199 * IP priority fields (IP prio has precedence), and set STP
200 * state to Forwarding.
202 * If this is the upstream port for this switch, enable
203 * forwarding of unknown unicasts, and enable DSA tagging
204 * mode.
206 * If this is the link to another switch, use DSA tagging
207 * mode, but do not enable forwarding of unknown unicasts.
209 val = 0x0433;
210 if (p == dsa_upstream_port(ds)) {
211 val |= 0x0104;
213 * On 6085, unknown multicast forward is controlled
214 * here rather than in Port Control 2 register.
216 if (ps->id == ID_6085)
217 val |= 0x0008;
219 if (ds->dsa_port_mask & (1 << p))
220 val |= 0x0100;
221 REG_WRITE(addr, 0x04, val);
224 * Port Control 1: disable trunking. Also, if this is the
225 * CPU port, enable learn messages to be sent to this port.
227 REG_WRITE(addr, 0x05, dsa_is_cpu_port(ds, p) ? 0x8000 : 0x0000);
230 * Port based VLAN map: give each port its own address
231 * database, allow the CPU port to talk to each of the 'real'
232 * ports, and allow each of the 'real' ports to only talk to
233 * the upstream port.
235 val = (p & 0xf) << 12;
236 if (dsa_is_cpu_port(ds, p))
237 val |= ds->phys_port_mask;
238 else
239 val |= 1 << dsa_upstream_port(ds);
240 REG_WRITE(addr, 0x06, val);
243 * Default VLAN ID and priority: don't set a default VLAN
244 * ID, and set the default packet priority to zero.
246 REG_WRITE(addr, 0x07, 0x0000);
249 * Port Control 2: don't force a good FCS, don't use
250 * VLAN-based, source address-based or destination
251 * address-based priority overrides, don't let the switch
252 * add or strip 802.1q tags, don't discard tagged or
253 * untagged frames on this port, do a destination address
254 * lookup on received packets as usual, don't send a copy
255 * of all transmitted/received frames on this port to the
256 * CPU, and configure the upstream port number.
258 * If this is the upstream port for this switch, enable
259 * forwarding of unknown multicast addresses.
261 if (ps->id == ID_6085)
263 * on 6085, bits 3:0 are reserved, bit 6 control ARP
264 * mirroring, and multicast forward is handled in
265 * Port Control register.
267 REG_WRITE(addr, 0x08, 0x0080);
268 else {
269 val = 0x0080 | dsa_upstream_port(ds);
270 if (p == dsa_upstream_port(ds))
271 val |= 0x0040;
272 REG_WRITE(addr, 0x08, val);
276 * Rate Control: disable ingress rate limiting.
278 REG_WRITE(addr, 0x09, 0x0000);
281 * Rate Control 2: disable egress rate limiting.
283 REG_WRITE(addr, 0x0a, 0x0000);
286 * Port Association Vector: when learning source addresses
287 * of packets, add the address to the address database using
288 * a port bitmap that has only the bit for this port set and
289 * the other bits clear.
291 REG_WRITE(addr, 0x0b, 1 << p);
294 * Tag Remap: use an identity 802.1p prio -> switch prio
295 * mapping.
297 REG_WRITE(addr, 0x18, 0x3210);
300 * Tag Remap 2: use an identity 802.1p prio -> switch prio
301 * mapping.
303 REG_WRITE(addr, 0x19, 0x7654);
305 return 0;
308 static int mv88e6131_setup(struct dsa_switch *ds)
310 struct mv88e6xxx_priv_state *ps = (void *)(ds + 1);
311 int i;
312 int ret;
314 mutex_init(&ps->smi_mutex);
315 mv88e6xxx_ppu_state_init(ds);
316 mutex_init(&ps->stats_mutex);
318 ps->id = REG_READ(REG_PORT(0), 0x03) & 0xfff0;
320 ret = mv88e6131_switch_reset(ds);
321 if (ret < 0)
322 return ret;
324 /* @@@ initialise vtu and atu */
326 ret = mv88e6131_setup_global(ds);
327 if (ret < 0)
328 return ret;
330 for (i = 0; i < 11; i++) {
331 ret = mv88e6131_setup_port(ds, i);
332 if (ret < 0)
333 return ret;
336 return 0;
339 static int mv88e6131_port_to_phy_addr(int port)
341 if (port >= 0 && port <= 11)
342 return port;
343 return -1;
346 static int
347 mv88e6131_phy_read(struct dsa_switch *ds, int port, int regnum)
349 int addr = mv88e6131_port_to_phy_addr(port);
350 return mv88e6xxx_phy_read_ppu(ds, addr, regnum);
353 static int
354 mv88e6131_phy_write(struct dsa_switch *ds,
355 int port, int regnum, u16 val)
357 int addr = mv88e6131_port_to_phy_addr(port);
358 return mv88e6xxx_phy_write_ppu(ds, addr, regnum, val);
361 static struct mv88e6xxx_hw_stat mv88e6131_hw_stats[] = {
362 { "in_good_octets", 8, 0x00, },
363 { "in_bad_octets", 4, 0x02, },
364 { "in_unicast", 4, 0x04, },
365 { "in_broadcasts", 4, 0x06, },
366 { "in_multicasts", 4, 0x07, },
367 { "in_pause", 4, 0x16, },
368 { "in_undersize", 4, 0x18, },
369 { "in_fragments", 4, 0x19, },
370 { "in_oversize", 4, 0x1a, },
371 { "in_jabber", 4, 0x1b, },
372 { "in_rx_error", 4, 0x1c, },
373 { "in_fcs_error", 4, 0x1d, },
374 { "out_octets", 8, 0x0e, },
375 { "out_unicast", 4, 0x10, },
376 { "out_broadcasts", 4, 0x13, },
377 { "out_multicasts", 4, 0x12, },
378 { "out_pause", 4, 0x15, },
379 { "excessive", 4, 0x11, },
380 { "collisions", 4, 0x1e, },
381 { "deferred", 4, 0x05, },
382 { "single", 4, 0x14, },
383 { "multiple", 4, 0x17, },
384 { "out_fcs_error", 4, 0x03, },
385 { "late", 4, 0x1f, },
386 { "hist_64bytes", 4, 0x08, },
387 { "hist_65_127bytes", 4, 0x09, },
388 { "hist_128_255bytes", 4, 0x0a, },
389 { "hist_256_511bytes", 4, 0x0b, },
390 { "hist_512_1023bytes", 4, 0x0c, },
391 { "hist_1024_max_bytes", 4, 0x0d, },
394 static void
395 mv88e6131_get_strings(struct dsa_switch *ds, int port, uint8_t *data)
397 mv88e6xxx_get_strings(ds, ARRAY_SIZE(mv88e6131_hw_stats),
398 mv88e6131_hw_stats, port, data);
401 static void
402 mv88e6131_get_ethtool_stats(struct dsa_switch *ds,
403 int port, uint64_t *data)
405 mv88e6xxx_get_ethtool_stats(ds, ARRAY_SIZE(mv88e6131_hw_stats),
406 mv88e6131_hw_stats, port, data);
409 static int mv88e6131_get_sset_count(struct dsa_switch *ds)
411 return ARRAY_SIZE(mv88e6131_hw_stats);
414 static struct dsa_switch_driver mv88e6131_switch_driver = {
415 .tag_protocol = cpu_to_be16(ETH_P_DSA),
416 .priv_size = sizeof(struct mv88e6xxx_priv_state),
417 .probe = mv88e6131_probe,
418 .setup = mv88e6131_setup,
419 .set_addr = mv88e6xxx_set_addr_direct,
420 .phy_read = mv88e6131_phy_read,
421 .phy_write = mv88e6131_phy_write,
422 .poll_link = mv88e6xxx_poll_link,
423 .get_strings = mv88e6131_get_strings,
424 .get_ethtool_stats = mv88e6131_get_ethtool_stats,
425 .get_sset_count = mv88e6131_get_sset_count,
428 static int __init mv88e6131_init(void)
430 register_switch_driver(&mv88e6131_switch_driver);
431 return 0;
433 module_init(mv88e6131_init);
435 static void __exit mv88e6131_cleanup(void)
437 unregister_switch_driver(&mv88e6131_switch_driver);
439 module_exit(mv88e6131_cleanup);