2 * net/dsa/mv88e6352.c - Marvell 88e6352 switch chip support
4 * Copyright (c) 2014 Guenter Roeck
6 * Derived from mv88e6123_61_65.c
7 * Copyright (c) 2008-2009 Marvell Semiconductor
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
15 #include <linux/delay.h>
16 #include <linux/jiffies.h>
17 #include <linux/list.h>
18 #include <linux/module.h>
19 #include <linux/netdevice.h>
20 #include <linux/platform_device.h>
21 #include <linux/phy.h>
23 #include "mv88e6xxx.h"
25 static char *mv88e6352_probe(struct device
*host_dev
, int sw_addr
)
27 struct mii_bus
*bus
= dsa_host_dev_to_mii_bus(host_dev
);
33 ret
= __mv88e6xxx_reg_read(bus
, sw_addr
, REG_PORT(0), PORT_SWITCH_ID
);
35 if ((ret
& 0xfff0) == PORT_SWITCH_ID_6176
)
36 return "Marvell 88E6176";
37 if (ret
== PORT_SWITCH_ID_6352_A0
)
38 return "Marvell 88E6352 (A0)";
39 if (ret
== PORT_SWITCH_ID_6352_A1
)
40 return "Marvell 88E6352 (A1)";
41 if ((ret
& 0xfff0) == PORT_SWITCH_ID_6352
)
42 return "Marvell 88E6352";
48 static int mv88e6352_setup_global(struct dsa_switch
*ds
)
50 struct mv88e6xxx_priv_state
*ps
= ds_to_priv(ds
);
54 /* Discard packets with excessive collisions,
55 * mask all interrupt sources, enable PPU (bit 14, undocumented).
57 REG_WRITE(REG_GLOBAL
, 0x04, 0x6000);
59 /* Set the default address aging time to 5 minutes, and
60 * enable address learn messages to be sent to all message
63 REG_WRITE(REG_GLOBAL
, 0x0a, 0x0148);
65 /* Configure the priority mapping registers. */
66 ret
= mv88e6xxx_config_prio(ds
);
70 /* Configure the upstream port, and configure the upstream
71 * port as the port to which ingress and egress monitor frames
74 REG_WRITE(REG_GLOBAL
, 0x1a, (dsa_upstream_port(ds
) * 0x1110));
76 /* Disable remote management for now, and set the switch's
79 REG_WRITE(REG_GLOBAL
, 0x1c, ds
->index
& 0x1f);
81 /* Send all frames with destination addresses matching
82 * 01:80:c2:00:00:2x to the CPU port.
84 REG_WRITE(REG_GLOBAL2
, 0x02, 0xffff);
86 /* Send all frames with destination addresses matching
87 * 01:80:c2:00:00:0x to the CPU port.
89 REG_WRITE(REG_GLOBAL2
, 0x03, 0xffff);
91 /* Disable the loopback filter, disable flow control
92 * messages, disable flood broadcast override, disable
93 * removing of provider tags, disable ATU age violation
94 * interrupts, disable tag flow control, force flow
95 * control priority to the highest, and send all special
96 * multicast frames to the CPU at the highest priority.
98 REG_WRITE(REG_GLOBAL2
, 0x05, 0x00ff);
100 /* Program the DSA routing table. */
101 for (i
= 0; i
< 32; i
++) {
104 if (i
!= ds
->index
&& i
< ds
->dst
->pd
->nr_chips
)
105 nexthop
= ds
->pd
->rtable
[i
] & 0x1f;
107 REG_WRITE(REG_GLOBAL2
, 0x06, 0x8000 | (i
<< 8) | nexthop
);
110 /* Clear all trunk masks. */
111 for (i
= 0; i
< 8; i
++)
112 REG_WRITE(REG_GLOBAL2
, 0x07, 0x8000 | (i
<< 12) | 0x7f);
114 /* Clear all trunk mappings. */
115 for (i
= 0; i
< 16; i
++)
116 REG_WRITE(REG_GLOBAL2
, 0x08, 0x8000 | (i
<< 11));
118 /* Disable ingress rate limiting by resetting all ingress
119 * rate limit registers to their initial state.
121 for (i
= 0; i
< ps
->num_ports
; i
++)
122 REG_WRITE(REG_GLOBAL2
, 0x09, 0x9000 | (i
<< 8));
124 /* Initialise cross-chip port VLAN table to reset defaults. */
125 REG_WRITE(REG_GLOBAL2
, 0x0b, 0x9000);
127 /* Clear the priority override table. */
128 for (i
= 0; i
< 16; i
++)
129 REG_WRITE(REG_GLOBAL2
, 0x0f, 0x8000 | (i
<< 8));
131 /* @@@ initialise AVB (22/23) watchdog (27) sdet (29) registers */
136 static int mv88e6352_setup_port(struct dsa_switch
*ds
, int p
)
138 int addr
= REG_PORT(p
);
141 /* MAC Forcing register: don't force link, speed, duplex
142 * or flow control state to any particular values on physical
143 * ports, but force the CPU port and all DSA ports to 1000 Mb/s
146 if (dsa_is_cpu_port(ds
, p
) || ds
->dsa_port_mask
& (1 << p
))
147 REG_WRITE(addr
, 0x01, 0x003e);
149 REG_WRITE(addr
, 0x01, 0x0003);
151 /* Do not limit the period of time that this port can be
152 * paused for by the remote end or the period of time that
153 * this port can pause the remote end.
155 REG_WRITE(addr
, 0x02, 0x0000);
157 /* Port Control: disable Drop-on-Unlock, disable Drop-on-Lock,
158 * disable Header mode, enable IGMP/MLD snooping, disable VLAN
159 * tunneling, determine priority by looking at 802.1p and IP
160 * priority fields (IP prio has precedence), and set STP state
163 * If this is the CPU link, use DSA or EDSA tagging depending
164 * on which tagging mode was configured.
166 * If this is a link to another switch, use DSA tagging mode.
168 * If this is the upstream port for this switch, enable
169 * forwarding of unknown unicasts and multicasts.
172 if (dsa_is_cpu_port(ds
, p
)) {
173 if (ds
->dst
->tag_protocol
== DSA_TAG_PROTO_EDSA
)
178 if (ds
->dsa_port_mask
& (1 << p
))
180 if (p
== dsa_upstream_port(ds
))
182 REG_WRITE(addr
, 0x04, val
);
184 /* Port Control 2: don't force a good FCS, set the maximum
185 * frame size to 10240 bytes, don't let the switch add or
186 * strip 802.1q tags, don't discard tagged or untagged frames
187 * on this port, do a destination address lookup on all
188 * received packets as usual, disable ARP mirroring and don't
189 * send a copy of all transmitted/received frames on this port
192 REG_WRITE(addr
, 0x08, 0x2080);
194 /* Egress rate control: disable egress rate control. */
195 REG_WRITE(addr
, 0x09, 0x0001);
197 /* Egress rate control 2: disable egress rate control. */
198 REG_WRITE(addr
, 0x0a, 0x0000);
200 /* Port Association Vector: when learning source addresses
201 * of packets, add the address to the address database using
202 * a port bitmap that has only the bit for this port set and
203 * the other bits clear.
205 REG_WRITE(addr
, 0x0b, 1 << p
);
207 /* Port ATU control: disable limiting the number of address
208 * database entries that this port is allowed to use.
210 REG_WRITE(addr
, 0x0c, 0x0000);
212 /* Priority Override: disable DA, SA and VTU priority override. */
213 REG_WRITE(addr
, 0x0d, 0x0000);
215 /* Port Ethertype: use the Ethertype DSA Ethertype value. */
216 REG_WRITE(addr
, 0x0f, ETH_P_EDSA
);
218 /* Tag Remap: use an identity 802.1p prio -> switch prio
221 REG_WRITE(addr
, 0x18, 0x3210);
223 /* Tag Remap 2: use an identity 802.1p prio -> switch prio
226 REG_WRITE(addr
, 0x19, 0x7654);
228 return mv88e6xxx_setup_port_common(ds
, p
);
231 #ifdef CONFIG_NET_DSA_HWMON
233 static int mv88e6352_get_temp(struct dsa_switch
*ds
, int *temp
)
239 ret
= mv88e6xxx_phy_page_read(ds
, 0, 6, 27);
243 *temp
= (ret
& 0xff) - 25;
248 static int mv88e6352_get_temp_limit(struct dsa_switch
*ds
, int *temp
)
254 ret
= mv88e6xxx_phy_page_read(ds
, 0, 6, 26);
258 *temp
= (((ret
>> 8) & 0x1f) * 5) - 25;
263 static int mv88e6352_set_temp_limit(struct dsa_switch
*ds
, int temp
)
267 ret
= mv88e6xxx_phy_page_read(ds
, 0, 6, 26);
270 temp
= clamp_val(DIV_ROUND_CLOSEST(temp
, 5) + 5, 0, 0x1f);
271 return mv88e6xxx_phy_page_write(ds
, 0, 6, 26,
272 (ret
& 0xe0ff) | (temp
<< 8));
275 static int mv88e6352_get_temp_alarm(struct dsa_switch
*ds
, bool *alarm
)
281 ret
= mv88e6xxx_phy_page_read(ds
, 0, 6, 26);
285 *alarm
= !!(ret
& 0x40);
289 #endif /* CONFIG_NET_DSA_HWMON */
291 static int mv88e6352_setup(struct dsa_switch
*ds
)
293 struct mv88e6xxx_priv_state
*ps
= ds_to_priv(ds
);
297 ret
= mv88e6xxx_setup_common(ds
);
303 mutex_init(&ps
->eeprom_mutex
);
305 ret
= mv88e6xxx_switch_reset(ds
, true);
309 /* @@@ initialise vtu and atu */
311 ret
= mv88e6352_setup_global(ds
);
315 for (i
= 0; i
< ps
->num_ports
; i
++) {
316 ret
= mv88e6352_setup_port(ds
, i
);
324 static int mv88e6352_read_eeprom_word(struct dsa_switch
*ds
, int addr
)
326 struct mv88e6xxx_priv_state
*ps
= ds_to_priv(ds
);
329 mutex_lock(&ps
->eeprom_mutex
);
331 ret
= mv88e6xxx_reg_write(ds
, REG_GLOBAL2
, 0x14,
332 0xc000 | (addr
& 0xff));
336 ret
= mv88e6xxx_eeprom_busy_wait(ds
);
340 ret
= mv88e6xxx_reg_read(ds
, REG_GLOBAL2
, 0x15);
342 mutex_unlock(&ps
->eeprom_mutex
);
346 static int mv88e6352_get_eeprom(struct dsa_switch
*ds
,
347 struct ethtool_eeprom
*eeprom
, u8
*data
)
353 offset
= eeprom
->offset
;
357 eeprom
->magic
= 0xc3ec4951;
359 ret
= mv88e6xxx_eeprom_load_wait(ds
);
366 word
= mv88e6352_read_eeprom_word(ds
, offset
>> 1);
370 *data
++ = (word
>> 8) & 0xff;
380 word
= mv88e6352_read_eeprom_word(ds
, offset
>> 1);
384 *data
++ = word
& 0xff;
385 *data
++ = (word
>> 8) & 0xff;
395 word
= mv88e6352_read_eeprom_word(ds
, offset
>> 1);
399 *data
++ = word
& 0xff;
409 static int mv88e6352_eeprom_is_readonly(struct dsa_switch
*ds
)
413 ret
= mv88e6xxx_reg_read(ds
, REG_GLOBAL2
, 0x14);
423 static int mv88e6352_write_eeprom_word(struct dsa_switch
*ds
, int addr
,
426 struct mv88e6xxx_priv_state
*ps
= ds_to_priv(ds
);
429 mutex_lock(&ps
->eeprom_mutex
);
431 ret
= mv88e6xxx_reg_write(ds
, REG_GLOBAL2
, 0x15, data
);
435 ret
= mv88e6xxx_reg_write(ds
, REG_GLOBAL2
, 0x14,
436 0xb000 | (addr
& 0xff));
440 ret
= mv88e6xxx_eeprom_busy_wait(ds
);
442 mutex_unlock(&ps
->eeprom_mutex
);
446 static int mv88e6352_set_eeprom(struct dsa_switch
*ds
,
447 struct ethtool_eeprom
*eeprom
, u8
*data
)
453 if (eeprom
->magic
!= 0xc3ec4951)
456 ret
= mv88e6352_eeprom_is_readonly(ds
);
460 offset
= eeprom
->offset
;
464 ret
= mv88e6xxx_eeprom_load_wait(ds
);
471 word
= mv88e6352_read_eeprom_word(ds
, offset
>> 1);
475 word
= (*data
++ << 8) | (word
& 0xff);
477 ret
= mv88e6352_write_eeprom_word(ds
, offset
>> 1, word
);
490 word
|= *data
++ << 8;
492 ret
= mv88e6352_write_eeprom_word(ds
, offset
>> 1, word
);
504 word
= mv88e6352_read_eeprom_word(ds
, offset
>> 1);
508 word
= (word
& 0xff00) | *data
++;
510 ret
= mv88e6352_write_eeprom_word(ds
, offset
>> 1, word
);
522 struct dsa_switch_driver mv88e6352_switch_driver
= {
523 .tag_protocol
= DSA_TAG_PROTO_EDSA
,
524 .priv_size
= sizeof(struct mv88e6xxx_priv_state
),
525 .probe
= mv88e6352_probe
,
526 .setup
= mv88e6352_setup
,
527 .set_addr
= mv88e6xxx_set_addr_indirect
,
528 .phy_read
= mv88e6xxx_phy_read_indirect
,
529 .phy_write
= mv88e6xxx_phy_write_indirect
,
530 .poll_link
= mv88e6xxx_poll_link
,
531 .get_strings
= mv88e6xxx_get_strings
,
532 .get_ethtool_stats
= mv88e6xxx_get_ethtool_stats
,
533 .get_sset_count
= mv88e6xxx_get_sset_count
,
534 .set_eee
= mv88e6xxx_set_eee
,
535 .get_eee
= mv88e6xxx_get_eee
,
536 #ifdef CONFIG_NET_DSA_HWMON
537 .get_temp
= mv88e6352_get_temp
,
538 .get_temp_limit
= mv88e6352_get_temp_limit
,
539 .set_temp_limit
= mv88e6352_set_temp_limit
,
540 .get_temp_alarm
= mv88e6352_get_temp_alarm
,
542 .get_eeprom
= mv88e6352_get_eeprom
,
543 .set_eeprom
= mv88e6352_set_eeprom
,
544 .get_regs_len
= mv88e6xxx_get_regs_len
,
545 .get_regs
= mv88e6xxx_get_regs
,
546 .port_join_bridge
= mv88e6xxx_join_bridge
,
547 .port_leave_bridge
= mv88e6xxx_leave_bridge
,
548 .port_stp_update
= mv88e6xxx_port_stp_update
,
549 .fdb_add
= mv88e6xxx_port_fdb_add
,
550 .fdb_del
= mv88e6xxx_port_fdb_del
,
551 .fdb_getnext
= mv88e6xxx_port_fdb_getnext
,
554 MODULE_ALIAS("platform:mv88e6352");