Guenter Roeck | 3ad50cc | 2014-10-29 10:44:56 -0700 | [diff] [blame] | 1 | /* |
| 2 | * net/dsa/mv88e6352.c - Marvell 88e6352 switch chip support |
| 3 | * |
| 4 | * Copyright (c) 2014 Guenter Roeck |
| 5 | * |
| 6 | * Derived from mv88e6123_61_65.c |
| 7 | * Copyright (c) 2008-2009 Marvell Semiconductor |
| 8 | * |
| 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. |
| 13 | */ |
| 14 | |
| 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> |
| 22 | #include <net/dsa.h> |
| 23 | #include "mv88e6xxx.h" |
| 24 | |
Vivien Didelot | b9b3771 | 2015-10-30 19:39:48 -0400 | [diff] [blame] | 25 | static const struct mv88e6xxx_switch_id mv88e6352_table[] = { |
| 26 | { PORT_SWITCH_ID_6172, "Marvell 88E6172" }, |
| 27 | { PORT_SWITCH_ID_6176, "Marvell 88E6176" }, |
Sascha Hauer | bd16a72 | 2016-02-11 11:44:48 +0100 | [diff] [blame] | 28 | { PORT_SWITCH_ID_6240, "Marvell 88E6240" }, |
Vivien Didelot | b9b3771 | 2015-10-30 19:39:48 -0400 | [diff] [blame] | 29 | { PORT_SWITCH_ID_6320, "Marvell 88E6320" }, |
| 30 | { PORT_SWITCH_ID_6320_A1, "Marvell 88E6320 (A1)" }, |
| 31 | { PORT_SWITCH_ID_6320_A2, "Marvell 88e6320 (A2)" }, |
| 32 | { PORT_SWITCH_ID_6321, "Marvell 88E6321" }, |
| 33 | { PORT_SWITCH_ID_6321_A1, "Marvell 88E6321 (A1)" }, |
| 34 | { PORT_SWITCH_ID_6321_A2, "Marvell 88e6321 (A2)" }, |
| 35 | { PORT_SWITCH_ID_6352, "Marvell 88E6352" }, |
| 36 | { PORT_SWITCH_ID_6352_A0, "Marvell 88E6352 (A0)" }, |
| 37 | { PORT_SWITCH_ID_6352_A1, "Marvell 88E6352 (A1)" }, |
| 38 | }; |
| 39 | |
Vivien Didelot | 0209d14 | 2016-04-17 13:23:55 -0400 | [diff] [blame^] | 40 | static const char *mv88e6352_drv_probe(struct device *dsa_dev, |
| 41 | struct device *host_dev, int sw_addr, |
| 42 | void **priv) |
Guenter Roeck | 3ad50cc | 2014-10-29 10:44:56 -0700 | [diff] [blame] | 43 | { |
Andrew Lunn | a77d43f | 2016-04-13 02:40:42 +0200 | [diff] [blame] | 44 | return mv88e6xxx_drv_probe(dsa_dev, host_dev, sw_addr, priv, |
| 45 | mv88e6352_table, |
| 46 | ARRAY_SIZE(mv88e6352_table)); |
Guenter Roeck | 3ad50cc | 2014-10-29 10:44:56 -0700 | [diff] [blame] | 47 | } |
| 48 | |
Guenter Roeck | 3ad50cc | 2014-10-29 10:44:56 -0700 | [diff] [blame] | 49 | static int mv88e6352_setup_global(struct dsa_switch *ds) |
| 50 | { |
Andrew Lunn | 15966a2 | 2015-05-06 01:09:49 +0200 | [diff] [blame] | 51 | u32 upstream_port = dsa_upstream_port(ds); |
Guenter Roeck | 3ad50cc | 2014-10-29 10:44:56 -0700 | [diff] [blame] | 52 | int ret; |
Andrew Lunn | 15966a2 | 2015-05-06 01:09:49 +0200 | [diff] [blame] | 53 | u32 reg; |
Andrew Lunn | 54d792f | 2015-05-06 01:09:47 +0200 | [diff] [blame] | 54 | |
| 55 | ret = mv88e6xxx_setup_global(ds); |
| 56 | if (ret) |
| 57 | return ret; |
Guenter Roeck | 3ad50cc | 2014-10-29 10:44:56 -0700 | [diff] [blame] | 58 | |
| 59 | /* Discard packets with excessive collisions, |
| 60 | * mask all interrupt sources, enable PPU (bit 14, undocumented). |
| 61 | */ |
Andrew Lunn | 48ace4e | 2016-04-14 23:47:12 +0200 | [diff] [blame] | 62 | ret = mv88e6xxx_reg_write(ds, REG_GLOBAL, GLOBAL_CONTROL, |
| 63 | GLOBAL_CONTROL_PPU_ENABLE | |
| 64 | GLOBAL_CONTROL_DISCARD_EXCESS); |
| 65 | if (ret) |
| 66 | return ret; |
Guenter Roeck | 3ad50cc | 2014-10-29 10:44:56 -0700 | [diff] [blame] | 67 | |
Guenter Roeck | 3ad50cc | 2014-10-29 10:44:56 -0700 | [diff] [blame] | 68 | /* Configure the upstream port, and configure the upstream |
| 69 | * port as the port to which ingress and egress monitor frames |
| 70 | * are to be sent. |
| 71 | */ |
Andrew Lunn | 15966a2 | 2015-05-06 01:09:49 +0200 | [diff] [blame] | 72 | reg = upstream_port << GLOBAL_MONITOR_CONTROL_INGRESS_SHIFT | |
| 73 | upstream_port << GLOBAL_MONITOR_CONTROL_EGRESS_SHIFT | |
| 74 | upstream_port << GLOBAL_MONITOR_CONTROL_ARP_SHIFT; |
Andrew Lunn | 48ace4e | 2016-04-14 23:47:12 +0200 | [diff] [blame] | 75 | ret = mv88e6xxx_reg_write(ds, REG_GLOBAL, GLOBAL_MONITOR_CONTROL, reg); |
| 76 | if (ret) |
| 77 | return ret; |
Guenter Roeck | 3ad50cc | 2014-10-29 10:44:56 -0700 | [diff] [blame] | 78 | |
| 79 | /* Disable remote management for now, and set the switch's |
| 80 | * DSA device number. |
| 81 | */ |
Andrew Lunn | 48ace4e | 2016-04-14 23:47:12 +0200 | [diff] [blame] | 82 | return mv88e6xxx_reg_write(ds, REG_GLOBAL, 0x1c, ds->index & 0x1f); |
Guenter Roeck | 3ad50cc | 2014-10-29 10:44:56 -0700 | [diff] [blame] | 83 | } |
| 84 | |
Guenter Roeck | 3ad50cc | 2014-10-29 10:44:56 -0700 | [diff] [blame] | 85 | static int mv88e6352_setup(struct dsa_switch *ds) |
| 86 | { |
| 87 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
| 88 | int ret; |
Guenter Roeck | 3ad50cc | 2014-10-29 10:44:56 -0700 | [diff] [blame] | 89 | |
Andrew Lunn | 7543a6d | 2016-04-13 02:40:40 +0200 | [diff] [blame] | 90 | ps->ds = ds; |
| 91 | |
Guenter Roeck | acdaffc | 2015-03-26 18:36:28 -0700 | [diff] [blame] | 92 | ret = mv88e6xxx_setup_common(ds); |
| 93 | if (ret < 0) |
| 94 | return ret; |
| 95 | |
Andrew Lunn | 44e50dd | 2015-04-02 04:06:33 +0200 | [diff] [blame] | 96 | ps->num_ports = 7; |
| 97 | |
Guenter Roeck | 33b43df | 2014-10-29 10:45:03 -0700 | [diff] [blame] | 98 | mutex_init(&ps->eeprom_mutex); |
Guenter Roeck | 3ad50cc | 2014-10-29 10:44:56 -0700 | [diff] [blame] | 99 | |
Andrew Lunn | 143a830 | 2015-04-02 04:06:34 +0200 | [diff] [blame] | 100 | ret = mv88e6xxx_switch_reset(ds, true); |
Guenter Roeck | 3ad50cc | 2014-10-29 10:44:56 -0700 | [diff] [blame] | 101 | if (ret < 0) |
| 102 | return ret; |
| 103 | |
Guenter Roeck | 3ad50cc | 2014-10-29 10:44:56 -0700 | [diff] [blame] | 104 | ret = mv88e6352_setup_global(ds); |
| 105 | if (ret < 0) |
| 106 | return ret; |
| 107 | |
Andrew Lunn | dbde9e6 | 2015-05-06 01:09:48 +0200 | [diff] [blame] | 108 | return mv88e6xxx_setup_ports(ds); |
Guenter Roeck | 3ad50cc | 2014-10-29 10:44:56 -0700 | [diff] [blame] | 109 | } |
| 110 | |
Guenter Roeck | 33b43df | 2014-10-29 10:45:03 -0700 | [diff] [blame] | 111 | static int mv88e6352_read_eeprom_word(struct dsa_switch *ds, int addr) |
| 112 | { |
| 113 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
| 114 | int ret; |
| 115 | |
| 116 | mutex_lock(&ps->eeprom_mutex); |
| 117 | |
Andrew Lunn | 966bce3 | 2015-08-08 17:04:50 +0200 | [diff] [blame] | 118 | ret = mv88e6xxx_reg_write(ds, REG_GLOBAL2, GLOBAL2_EEPROM_OP, |
| 119 | GLOBAL2_EEPROM_OP_READ | |
| 120 | (addr & GLOBAL2_EEPROM_OP_ADDR_MASK)); |
Guenter Roeck | 33b43df | 2014-10-29 10:45:03 -0700 | [diff] [blame] | 121 | if (ret < 0) |
| 122 | goto error; |
| 123 | |
Andrew Lunn | f304468 | 2015-02-14 19:17:50 +0100 | [diff] [blame] | 124 | ret = mv88e6xxx_eeprom_busy_wait(ds); |
Guenter Roeck | 33b43df | 2014-10-29 10:45:03 -0700 | [diff] [blame] | 125 | if (ret < 0) |
| 126 | goto error; |
| 127 | |
Andrew Lunn | 966bce3 | 2015-08-08 17:04:50 +0200 | [diff] [blame] | 128 | ret = mv88e6xxx_reg_read(ds, REG_GLOBAL2, GLOBAL2_EEPROM_DATA); |
Guenter Roeck | 33b43df | 2014-10-29 10:45:03 -0700 | [diff] [blame] | 129 | error: |
| 130 | mutex_unlock(&ps->eeprom_mutex); |
| 131 | return ret; |
| 132 | } |
| 133 | |
| 134 | static int mv88e6352_get_eeprom(struct dsa_switch *ds, |
| 135 | struct ethtool_eeprom *eeprom, u8 *data) |
| 136 | { |
| 137 | int offset; |
| 138 | int len; |
| 139 | int ret; |
| 140 | |
| 141 | offset = eeprom->offset; |
| 142 | len = eeprom->len; |
| 143 | eeprom->len = 0; |
| 144 | |
| 145 | eeprom->magic = 0xc3ec4951; |
| 146 | |
Andrew Lunn | f304468 | 2015-02-14 19:17:50 +0100 | [diff] [blame] | 147 | ret = mv88e6xxx_eeprom_load_wait(ds); |
Guenter Roeck | 33b43df | 2014-10-29 10:45:03 -0700 | [diff] [blame] | 148 | if (ret < 0) |
| 149 | return ret; |
| 150 | |
| 151 | if (offset & 1) { |
| 152 | int word; |
| 153 | |
| 154 | word = mv88e6352_read_eeprom_word(ds, offset >> 1); |
| 155 | if (word < 0) |
| 156 | return word; |
| 157 | |
| 158 | *data++ = (word >> 8) & 0xff; |
| 159 | |
| 160 | offset++; |
| 161 | len--; |
| 162 | eeprom->len++; |
| 163 | } |
| 164 | |
| 165 | while (len >= 2) { |
| 166 | int word; |
| 167 | |
| 168 | word = mv88e6352_read_eeprom_word(ds, offset >> 1); |
| 169 | if (word < 0) |
| 170 | return word; |
| 171 | |
| 172 | *data++ = word & 0xff; |
| 173 | *data++ = (word >> 8) & 0xff; |
| 174 | |
| 175 | offset += 2; |
| 176 | len -= 2; |
| 177 | eeprom->len += 2; |
| 178 | } |
| 179 | |
| 180 | if (len) { |
| 181 | int word; |
| 182 | |
| 183 | word = mv88e6352_read_eeprom_word(ds, offset >> 1); |
| 184 | if (word < 0) |
| 185 | return word; |
| 186 | |
| 187 | *data++ = word & 0xff; |
| 188 | |
| 189 | offset++; |
| 190 | len--; |
| 191 | eeprom->len++; |
| 192 | } |
| 193 | |
| 194 | return 0; |
| 195 | } |
| 196 | |
| 197 | static int mv88e6352_eeprom_is_readonly(struct dsa_switch *ds) |
| 198 | { |
| 199 | int ret; |
| 200 | |
Andrew Lunn | 966bce3 | 2015-08-08 17:04:50 +0200 | [diff] [blame] | 201 | ret = mv88e6xxx_reg_read(ds, REG_GLOBAL2, GLOBAL2_EEPROM_OP); |
Guenter Roeck | 33b43df | 2014-10-29 10:45:03 -0700 | [diff] [blame] | 202 | if (ret < 0) |
| 203 | return ret; |
| 204 | |
Andrew Lunn | 966bce3 | 2015-08-08 17:04:50 +0200 | [diff] [blame] | 205 | if (!(ret & GLOBAL2_EEPROM_OP_WRITE_EN)) |
Guenter Roeck | 33b43df | 2014-10-29 10:45:03 -0700 | [diff] [blame] | 206 | return -EROFS; |
| 207 | |
| 208 | return 0; |
| 209 | } |
| 210 | |
| 211 | static int mv88e6352_write_eeprom_word(struct dsa_switch *ds, int addr, |
| 212 | u16 data) |
| 213 | { |
| 214 | struct mv88e6xxx_priv_state *ps = ds_to_priv(ds); |
| 215 | int ret; |
| 216 | |
| 217 | mutex_lock(&ps->eeprom_mutex); |
| 218 | |
Andrew Lunn | 966bce3 | 2015-08-08 17:04:50 +0200 | [diff] [blame] | 219 | ret = mv88e6xxx_reg_write(ds, REG_GLOBAL2, GLOBAL2_EEPROM_DATA, data); |
Guenter Roeck | 33b43df | 2014-10-29 10:45:03 -0700 | [diff] [blame] | 220 | if (ret < 0) |
| 221 | goto error; |
| 222 | |
Andrew Lunn | 966bce3 | 2015-08-08 17:04:50 +0200 | [diff] [blame] | 223 | ret = mv88e6xxx_reg_write(ds, REG_GLOBAL2, GLOBAL2_EEPROM_OP, |
| 224 | GLOBAL2_EEPROM_OP_WRITE | |
| 225 | (addr & GLOBAL2_EEPROM_OP_ADDR_MASK)); |
Guenter Roeck | 33b43df | 2014-10-29 10:45:03 -0700 | [diff] [blame] | 226 | if (ret < 0) |
| 227 | goto error; |
| 228 | |
Andrew Lunn | f304468 | 2015-02-14 19:17:50 +0100 | [diff] [blame] | 229 | ret = mv88e6xxx_eeprom_busy_wait(ds); |
Guenter Roeck | 33b43df | 2014-10-29 10:45:03 -0700 | [diff] [blame] | 230 | error: |
| 231 | mutex_unlock(&ps->eeprom_mutex); |
| 232 | return ret; |
| 233 | } |
| 234 | |
| 235 | static int mv88e6352_set_eeprom(struct dsa_switch *ds, |
| 236 | struct ethtool_eeprom *eeprom, u8 *data) |
| 237 | { |
| 238 | int offset; |
| 239 | int ret; |
| 240 | int len; |
| 241 | |
| 242 | if (eeprom->magic != 0xc3ec4951) |
| 243 | return -EINVAL; |
| 244 | |
| 245 | ret = mv88e6352_eeprom_is_readonly(ds); |
| 246 | if (ret) |
| 247 | return ret; |
| 248 | |
| 249 | offset = eeprom->offset; |
| 250 | len = eeprom->len; |
| 251 | eeprom->len = 0; |
| 252 | |
Andrew Lunn | f304468 | 2015-02-14 19:17:50 +0100 | [diff] [blame] | 253 | ret = mv88e6xxx_eeprom_load_wait(ds); |
Guenter Roeck | 33b43df | 2014-10-29 10:45:03 -0700 | [diff] [blame] | 254 | if (ret < 0) |
| 255 | return ret; |
| 256 | |
| 257 | if (offset & 1) { |
| 258 | int word; |
| 259 | |
| 260 | word = mv88e6352_read_eeprom_word(ds, offset >> 1); |
| 261 | if (word < 0) |
| 262 | return word; |
| 263 | |
| 264 | word = (*data++ << 8) | (word & 0xff); |
| 265 | |
| 266 | ret = mv88e6352_write_eeprom_word(ds, offset >> 1, word); |
| 267 | if (ret < 0) |
| 268 | return ret; |
| 269 | |
| 270 | offset++; |
| 271 | len--; |
| 272 | eeprom->len++; |
| 273 | } |
| 274 | |
| 275 | while (len >= 2) { |
| 276 | int word; |
| 277 | |
| 278 | word = *data++; |
| 279 | word |= *data++ << 8; |
| 280 | |
| 281 | ret = mv88e6352_write_eeprom_word(ds, offset >> 1, word); |
| 282 | if (ret < 0) |
| 283 | return ret; |
| 284 | |
| 285 | offset += 2; |
| 286 | len -= 2; |
| 287 | eeprom->len += 2; |
| 288 | } |
| 289 | |
| 290 | if (len) { |
| 291 | int word; |
| 292 | |
| 293 | word = mv88e6352_read_eeprom_word(ds, offset >> 1); |
| 294 | if (word < 0) |
| 295 | return word; |
| 296 | |
| 297 | word = (word & 0xff00) | *data++; |
| 298 | |
| 299 | ret = mv88e6352_write_eeprom_word(ds, offset >> 1, word); |
| 300 | if (ret < 0) |
| 301 | return ret; |
| 302 | |
| 303 | offset++; |
| 304 | len--; |
| 305 | eeprom->len++; |
| 306 | } |
| 307 | |
| 308 | return 0; |
| 309 | } |
| 310 | |
Guenter Roeck | 3ad50cc | 2014-10-29 10:44:56 -0700 | [diff] [blame] | 311 | struct dsa_switch_driver mv88e6352_switch_driver = { |
| 312 | .tag_protocol = DSA_TAG_PROTO_EDSA, |
Andrew Lunn | e49bad3 | 2016-04-13 02:40:43 +0200 | [diff] [blame] | 313 | .probe = mv88e6352_drv_probe, |
Guenter Roeck | 3ad50cc | 2014-10-29 10:44:56 -0700 | [diff] [blame] | 314 | .setup = mv88e6352_setup, |
| 315 | .set_addr = mv88e6xxx_set_addr_indirect, |
Andrew Lunn | fd3a0ee | 2015-04-02 04:06:36 +0200 | [diff] [blame] | 316 | .phy_read = mv88e6xxx_phy_read_indirect, |
| 317 | .phy_write = mv88e6xxx_phy_write_indirect, |
Andrew Lunn | e413e7e | 2015-04-02 04:06:38 +0200 | [diff] [blame] | 318 | .get_strings = mv88e6xxx_get_strings, |
| 319 | .get_ethtool_stats = mv88e6xxx_get_ethtool_stats, |
| 320 | .get_sset_count = mv88e6xxx_get_sset_count, |
Andrew Lunn | dea8702 | 2015-08-31 15:56:47 +0200 | [diff] [blame] | 321 | .adjust_link = mv88e6xxx_adjust_link, |
Guenter Roeck | 04b0a80 | 2015-03-06 22:23:52 -0800 | [diff] [blame] | 322 | .set_eee = mv88e6xxx_set_eee, |
| 323 | .get_eee = mv88e6xxx_get_eee, |
Guenter Roeck | 276db3b | 2014-10-29 10:44:59 -0700 | [diff] [blame] | 324 | #ifdef CONFIG_NET_DSA_HWMON |
Guenter Roeck | c22995c | 2015-07-25 09:42:28 -0700 | [diff] [blame] | 325 | .get_temp = mv88e6xxx_get_temp, |
| 326 | .get_temp_limit = mv88e6xxx_get_temp_limit, |
| 327 | .set_temp_limit = mv88e6xxx_set_temp_limit, |
| 328 | .get_temp_alarm = mv88e6xxx_get_temp_alarm, |
Guenter Roeck | 276db3b | 2014-10-29 10:44:59 -0700 | [diff] [blame] | 329 | #endif |
Guenter Roeck | 33b43df | 2014-10-29 10:45:03 -0700 | [diff] [blame] | 330 | .get_eeprom = mv88e6352_get_eeprom, |
| 331 | .set_eeprom = mv88e6352_set_eeprom, |
Guenter Roeck | 95d08b5 | 2014-10-29 10:45:06 -0700 | [diff] [blame] | 332 | .get_regs_len = mv88e6xxx_get_regs_len, |
| 333 | .get_regs = mv88e6xxx_get_regs, |
Vivien Didelot | 71327a4 | 2016-03-13 16:21:32 -0400 | [diff] [blame] | 334 | .port_bridge_join = mv88e6xxx_port_bridge_join, |
| 335 | .port_bridge_leave = mv88e6xxx_port_bridge_leave, |
Vivien Didelot | 43c44a9 | 2016-04-06 11:55:03 -0400 | [diff] [blame] | 336 | .port_stp_state_set = mv88e6xxx_port_stp_state_set, |
Vivien Didelot | 214cdb9 | 2016-02-26 13:16:08 -0500 | [diff] [blame] | 337 | .port_vlan_filtering = mv88e6xxx_port_vlan_filtering, |
Vivien Didelot | 76e398a | 2015-11-01 12:33:55 -0500 | [diff] [blame] | 338 | .port_vlan_prepare = mv88e6xxx_port_vlan_prepare, |
Vivien Didelot | 0d3b33e | 2015-08-13 12:52:22 -0400 | [diff] [blame] | 339 | .port_vlan_add = mv88e6xxx_port_vlan_add, |
Vivien Didelot | 7dad08d | 2015-08-13 12:52:21 -0400 | [diff] [blame] | 340 | .port_vlan_del = mv88e6xxx_port_vlan_del, |
Vivien Didelot | ceff5ef | 2016-02-23 12:13:55 -0500 | [diff] [blame] | 341 | .port_vlan_dump = mv88e6xxx_port_vlan_dump, |
Vivien Didelot | 146a320 | 2015-10-08 11:35:12 -0400 | [diff] [blame] | 342 | .port_fdb_prepare = mv88e6xxx_port_fdb_prepare, |
Vivien Didelot | 2a778e1 | 2015-08-10 09:09:49 -0400 | [diff] [blame] | 343 | .port_fdb_add = mv88e6xxx_port_fdb_add, |
| 344 | .port_fdb_del = mv88e6xxx_port_fdb_del, |
Vivien Didelot | f33475b | 2015-10-22 09:34:41 -0400 | [diff] [blame] | 345 | .port_fdb_dump = mv88e6xxx_port_fdb_dump, |
Guenter Roeck | 3ad50cc | 2014-10-29 10:44:56 -0700 | [diff] [blame] | 346 | }; |
| 347 | |
Andrew Lunn | 1636d88 | 2015-05-06 01:09:50 +0200 | [diff] [blame] | 348 | MODULE_ALIAS("platform:mv88e6172"); |
Aleksey S. Kazantsev | 7c3d0d6 | 2015-07-07 20:38:15 -0700 | [diff] [blame] | 349 | MODULE_ALIAS("platform:mv88e6176"); |
| 350 | MODULE_ALIAS("platform:mv88e6320"); |
| 351 | MODULE_ALIAS("platform:mv88e6321"); |
| 352 | MODULE_ALIAS("platform:mv88e6352"); |