Florian Fainelli | 246d7f7 | 2014-08-27 17:04:56 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Broadcom Starfighter 2 DSA switch driver |
| 3 | * |
| 4 | * Copyright (C) 2014, Broadcom Corporation |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | */ |
| 11 | |
| 12 | #include <linux/list.h> |
| 13 | #include <linux/module.h> |
| 14 | #include <linux/netdevice.h> |
| 15 | #include <linux/interrupt.h> |
| 16 | #include <linux/platform_device.h> |
| 17 | #include <linux/of.h> |
| 18 | #include <linux/phy.h> |
| 19 | #include <linux/phy_fixed.h> |
| 20 | #include <linux/mii.h> |
| 21 | #include <linux/of.h> |
| 22 | #include <linux/of_irq.h> |
| 23 | #include <linux/of_address.h> |
Florian Fainelli | 8b7c94e | 2015-10-23 12:11:08 -0700 | [diff] [blame] | 24 | #include <linux/of_net.h> |
Florian Fainelli | 461cd1b0 | 2016-06-07 16:32:43 -0700 | [diff] [blame] | 25 | #include <linux/of_mdio.h> |
Florian Fainelli | 246d7f7 | 2014-08-27 17:04:56 -0700 | [diff] [blame] | 26 | #include <net/dsa.h> |
Florian Fainelli | 96e65d7 | 2014-09-18 17:31:25 -0700 | [diff] [blame] | 27 | #include <linux/ethtool.h> |
Florian Fainelli | 12f460f | 2015-02-24 13:15:34 -0800 | [diff] [blame] | 28 | #include <linux/if_bridge.h> |
Florian Fainelli | aafc66f | 2015-06-10 18:08:01 -0700 | [diff] [blame] | 29 | #include <linux/brcmphy.h> |
Florian Fainelli | 680060d | 2015-10-23 11:38:07 -0700 | [diff] [blame] | 30 | #include <linux/etherdevice.h> |
Florian Fainelli | f458995 | 2016-08-26 12:18:33 -0700 | [diff] [blame] | 31 | #include <linux/platform_data/b53.h> |
Florian Fainelli | 246d7f7 | 2014-08-27 17:04:56 -0700 | [diff] [blame] | 32 | |
| 33 | #include "bcm_sf2.h" |
| 34 | #include "bcm_sf2_regs.h" |
Florian Fainelli | f458995 | 2016-08-26 12:18:33 -0700 | [diff] [blame] | 35 | #include "b53/b53_priv.h" |
| 36 | #include "b53/b53_regs.h" |
Florian Fainelli | 246d7f7 | 2014-08-27 17:04:56 -0700 | [diff] [blame] | 37 | |
Andrew Lunn | 7b31436 | 2016-08-22 16:01:01 +0200 | [diff] [blame] | 38 | static enum dsa_tag_protocol bcm_sf2_sw_get_tag_protocol(struct dsa_switch *ds) |
| 39 | { |
| 40 | return DSA_TAG_PROTO_BRCM; |
| 41 | } |
| 42 | |
Florian Fainelli | ebb2ac4 | 2017-01-20 12:36:31 -0800 | [diff] [blame] | 43 | static void bcm_sf2_imp_setup(struct dsa_switch *ds, int port) |
| 44 | { |
| 45 | struct bcm_sf2_priv *priv = bcm_sf2_to_priv(ds); |
Florian Fainelli | c837fc8 | 2017-09-03 20:27:03 -0700 | [diff] [blame] | 46 | unsigned int i; |
Florian Fainelli | ebb2ac4 | 2017-01-20 12:36:31 -0800 | [diff] [blame] | 47 | u32 reg, offset; |
| 48 | |
| 49 | if (priv->type == BCM7445_DEVICE_ID) |
| 50 | offset = CORE_STS_OVERRIDE_IMP; |
| 51 | else |
| 52 | offset = CORE_STS_OVERRIDE_IMP2; |
| 53 | |
| 54 | /* Enable the port memories */ |
| 55 | reg = core_readl(priv, CORE_MEM_PSM_VDD_CTRL); |
| 56 | reg &= ~P_TXQ_PSM_VDD(port); |
| 57 | core_writel(priv, reg, CORE_MEM_PSM_VDD_CTRL); |
| 58 | |
| 59 | /* Enable Broadcast, Multicast, Unicast forwarding to IMP port */ |
| 60 | reg = core_readl(priv, CORE_IMP_CTL); |
| 61 | reg |= (RX_BCST_EN | RX_MCST_EN | RX_UCST_EN); |
| 62 | reg &= ~(RX_DIS | TX_DIS); |
| 63 | core_writel(priv, reg, CORE_IMP_CTL); |
| 64 | |
| 65 | /* Enable forwarding */ |
| 66 | core_writel(priv, SW_FWDG_EN, CORE_SWMODE); |
| 67 | |
| 68 | /* Enable IMP port in dumb mode */ |
| 69 | reg = core_readl(priv, CORE_SWITCH_CTRL); |
| 70 | reg |= MII_DUMB_FWDG_EN; |
| 71 | core_writel(priv, reg, CORE_SWITCH_CTRL); |
| 72 | |
Florian Fainelli | c837fc8 | 2017-09-03 20:27:03 -0700 | [diff] [blame] | 73 | /* Configure Traffic Class to QoS mapping, allow each priority to map |
| 74 | * to a different queue number |
| 75 | */ |
| 76 | reg = core_readl(priv, CORE_PORT_TC2_QOS_MAP_PORT(port)); |
| 77 | for (i = 0; i < SF2_NUM_EGRESS_QUEUES; i++) |
| 78 | reg |= i << (PRT_TO_QID_SHIFT * i); |
| 79 | core_writel(priv, reg, CORE_PORT_TC2_QOS_MAP_PORT(port)); |
| 80 | |
Florian Fainelli | b409a9e | 2017-09-19 10:46:48 -0700 | [diff] [blame] | 81 | b53_brcm_hdr_setup(ds, port); |
Florian Fainelli | 246d7f7 | 2014-08-27 17:04:56 -0700 | [diff] [blame] | 82 | |
| 83 | /* Force link status for IMP port */ |
Florian Fainelli | 0fe9933 | 2017-01-20 12:36:30 -0800 | [diff] [blame] | 84 | reg = core_readl(priv, offset); |
Florian Fainelli | 246d7f7 | 2014-08-27 17:04:56 -0700 | [diff] [blame] | 85 | reg |= (MII_SW_OR | LINK_STS); |
Florian Fainelli | 0fe9933 | 2017-01-20 12:36:30 -0800 | [diff] [blame] | 86 | core_writel(priv, reg, offset); |
Florian Fainelli | 246d7f7 | 2014-08-27 17:04:56 -0700 | [diff] [blame] | 87 | } |
| 88 | |
Florian Fainelli | b083668 | 2015-02-05 11:40:41 -0800 | [diff] [blame] | 89 | static void bcm_sf2_gphy_enable_set(struct dsa_switch *ds, bool enable) |
| 90 | { |
Florian Fainelli | f458995 | 2016-08-26 12:18:33 -0700 | [diff] [blame] | 91 | struct bcm_sf2_priv *priv = bcm_sf2_to_priv(ds); |
Florian Fainelli | b083668 | 2015-02-05 11:40:41 -0800 | [diff] [blame] | 92 | u32 reg; |
| 93 | |
Florian Fainelli | 9af197a | 2015-02-05 11:40:42 -0800 | [diff] [blame] | 94 | reg = reg_readl(priv, REG_SPHY_CNTRL); |
| 95 | if (enable) { |
| 96 | reg |= PHY_RESET; |
| 97 | reg &= ~(EXT_PWR_DOWN | IDDQ_BIAS | CK25_DIS); |
| 98 | reg_writel(priv, reg, REG_SPHY_CNTRL); |
| 99 | udelay(21); |
| 100 | reg = reg_readl(priv, REG_SPHY_CNTRL); |
| 101 | reg &= ~PHY_RESET; |
| 102 | } else { |
| 103 | reg |= EXT_PWR_DOWN | IDDQ_BIAS | PHY_RESET; |
| 104 | reg_writel(priv, reg, REG_SPHY_CNTRL); |
| 105 | mdelay(1); |
| 106 | reg |= CK25_DIS; |
| 107 | } |
| 108 | reg_writel(priv, reg, REG_SPHY_CNTRL); |
Florian Fainelli | b083668 | 2015-02-05 11:40:41 -0800 | [diff] [blame] | 109 | |
Florian Fainelli | 9af197a | 2015-02-05 11:40:42 -0800 | [diff] [blame] | 110 | /* Use PHY-driven LED signaling */ |
| 111 | if (!enable) { |
| 112 | reg = reg_readl(priv, REG_LED_CNTRL(0)); |
| 113 | reg |= SPDLNK_SRC_SEL; |
| 114 | reg_writel(priv, reg, REG_LED_CNTRL(0)); |
| 115 | } |
Florian Fainelli | b083668 | 2015-02-05 11:40:41 -0800 | [diff] [blame] | 116 | } |
| 117 | |
Florian Fainelli | 8b7c94e | 2015-10-23 12:11:08 -0700 | [diff] [blame] | 118 | static inline void bcm_sf2_port_intr_enable(struct bcm_sf2_priv *priv, |
| 119 | int port) |
| 120 | { |
| 121 | unsigned int off; |
| 122 | |
| 123 | switch (port) { |
| 124 | case 7: |
| 125 | off = P7_IRQ_OFF; |
| 126 | break; |
| 127 | case 0: |
| 128 | /* Port 0 interrupts are located on the first bank */ |
| 129 | intrl2_0_mask_clear(priv, P_IRQ_MASK(P0_IRQ_OFF)); |
| 130 | return; |
| 131 | default: |
| 132 | off = P_IRQ_OFF(port); |
| 133 | break; |
| 134 | } |
| 135 | |
| 136 | intrl2_1_mask_clear(priv, P_IRQ_MASK(off)); |
| 137 | } |
| 138 | |
| 139 | static inline void bcm_sf2_port_intr_disable(struct bcm_sf2_priv *priv, |
| 140 | int port) |
| 141 | { |
| 142 | unsigned int off; |
| 143 | |
| 144 | switch (port) { |
| 145 | case 7: |
| 146 | off = P7_IRQ_OFF; |
| 147 | break; |
| 148 | case 0: |
| 149 | /* Port 0 interrupts are located on the first bank */ |
| 150 | intrl2_0_mask_set(priv, P_IRQ_MASK(P0_IRQ_OFF)); |
| 151 | intrl2_0_writel(priv, P_IRQ_MASK(P0_IRQ_OFF), INTRL2_CPU_CLEAR); |
| 152 | return; |
| 153 | default: |
| 154 | off = P_IRQ_OFF(port); |
| 155 | break; |
| 156 | } |
| 157 | |
| 158 | intrl2_1_mask_set(priv, P_IRQ_MASK(off)); |
| 159 | intrl2_1_writel(priv, P_IRQ_MASK(off), INTRL2_CPU_CLEAR); |
| 160 | } |
| 161 | |
Florian Fainelli | b6d045d | 2014-09-24 17:05:20 -0700 | [diff] [blame] | 162 | static int bcm_sf2_port_setup(struct dsa_switch *ds, int port, |
| 163 | struct phy_device *phy) |
Florian Fainelli | 246d7f7 | 2014-08-27 17:04:56 -0700 | [diff] [blame] | 164 | { |
Florian Fainelli | f458995 | 2016-08-26 12:18:33 -0700 | [diff] [blame] | 165 | struct bcm_sf2_priv *priv = bcm_sf2_to_priv(ds); |
Florian Fainelli | e1b9147 | 2017-01-30 09:48:41 -0800 | [diff] [blame] | 166 | unsigned int i; |
Florian Fainelli | 246d7f7 | 2014-08-27 17:04:56 -0700 | [diff] [blame] | 167 | u32 reg; |
| 168 | |
| 169 | /* Clear the memory power down */ |
| 170 | reg = core_readl(priv, CORE_MEM_PSM_VDD_CTRL); |
| 171 | reg &= ~P_TXQ_PSM_VDD(port); |
| 172 | core_writel(priv, reg, CORE_MEM_PSM_VDD_CTRL); |
| 173 | |
Florian Fainelli | 64ff2ae | 2017-01-20 12:36:32 -0800 | [diff] [blame] | 174 | /* Enable Broadcom tags for that port if requested */ |
| 175 | if (priv->brcm_tag_mask & BIT(port)) |
Florian Fainelli | b409a9e | 2017-09-19 10:46:48 -0700 | [diff] [blame] | 176 | b53_brcm_hdr_setup(ds, port); |
Florian Fainelli | 64ff2ae | 2017-01-20 12:36:32 -0800 | [diff] [blame] | 177 | |
Florian Fainelli | e1b9147 | 2017-01-30 09:48:41 -0800 | [diff] [blame] | 178 | /* Configure Traffic Class to QoS mapping, allow each priority to map |
| 179 | * to a different queue number |
| 180 | */ |
| 181 | reg = core_readl(priv, CORE_PORT_TC2_QOS_MAP_PORT(port)); |
Florian Fainelli | 18118377 | 2017-09-03 20:27:02 -0700 | [diff] [blame] | 182 | for (i = 0; i < SF2_NUM_EGRESS_QUEUES; i++) |
Florian Fainelli | e1b9147 | 2017-01-30 09:48:41 -0800 | [diff] [blame] | 183 | reg |= i << (PRT_TO_QID_SHIFT * i); |
| 184 | core_writel(priv, reg, CORE_PORT_TC2_QOS_MAP_PORT(port)); |
| 185 | |
Florian Fainelli | 9af197a | 2015-02-05 11:40:42 -0800 | [diff] [blame] | 186 | /* Re-enable the GPHY and re-apply workarounds */ |
Florian Fainelli | 8b7c94e | 2015-10-23 12:11:08 -0700 | [diff] [blame] | 187 | if (priv->int_phy_mask & 1 << port && priv->hw_params.num_gphy == 1) { |
Florian Fainelli | 9af197a | 2015-02-05 11:40:42 -0800 | [diff] [blame] | 188 | bcm_sf2_gphy_enable_set(ds, true); |
| 189 | if (phy) { |
| 190 | /* if phy_stop() has been called before, phy |
| 191 | * will be in halted state, and phy_start() |
| 192 | * will call resume. |
| 193 | * |
| 194 | * the resume path does not configure back |
| 195 | * autoneg settings, and since we hard reset |
| 196 | * the phy manually here, we need to reset the |
| 197 | * state machine also. |
| 198 | */ |
| 199 | phy->state = PHY_READY; |
| 200 | phy_init_hw(phy); |
| 201 | } |
| 202 | } |
| 203 | |
Florian Fainelli | 8b7c94e | 2015-10-23 12:11:08 -0700 | [diff] [blame] | 204 | /* Enable MoCA port interrupts to get notified */ |
| 205 | if (port == priv->moca_port) |
| 206 | bcm_sf2_port_intr_enable(priv, port); |
Florian Fainelli | 246d7f7 | 2014-08-27 17:04:56 -0700 | [diff] [blame] | 207 | |
Florian Fainelli | f86ad77 | 2017-09-19 10:46:54 -0700 | [diff] [blame] | 208 | return b53_enable_port(ds, port, phy); |
Florian Fainelli | 246d7f7 | 2014-08-27 17:04:56 -0700 | [diff] [blame] | 209 | } |
| 210 | |
Florian Fainelli | b6d045d | 2014-09-24 17:05:20 -0700 | [diff] [blame] | 211 | static void bcm_sf2_port_disable(struct dsa_switch *ds, int port, |
| 212 | struct phy_device *phy) |
Florian Fainelli | 246d7f7 | 2014-08-27 17:04:56 -0700 | [diff] [blame] | 213 | { |
Florian Fainelli | f458995 | 2016-08-26 12:18:33 -0700 | [diff] [blame] | 214 | struct bcm_sf2_priv *priv = bcm_sf2_to_priv(ds); |
Florian Fainelli | 246d7f7 | 2014-08-27 17:04:56 -0700 | [diff] [blame] | 215 | u32 off, reg; |
| 216 | |
Florian Fainelli | 96e65d7 | 2014-09-18 17:31:25 -0700 | [diff] [blame] | 217 | if (priv->wol_ports_mask & (1 << port)) |
| 218 | return; |
| 219 | |
Florian Fainelli | 8b7c94e | 2015-10-23 12:11:08 -0700 | [diff] [blame] | 220 | if (port == priv->moca_port) |
| 221 | bcm_sf2_port_intr_disable(priv, port); |
Florian Fainelli | b6d045d | 2014-09-24 17:05:20 -0700 | [diff] [blame] | 222 | |
Florian Fainelli | 8b7c94e | 2015-10-23 12:11:08 -0700 | [diff] [blame] | 223 | if (priv->int_phy_mask & 1 << port && priv->hw_params.num_gphy == 1) |
Florian Fainelli | 9af197a | 2015-02-05 11:40:42 -0800 | [diff] [blame] | 224 | bcm_sf2_gphy_enable_set(ds, false); |
| 225 | |
Florian Fainelli | 246d7f7 | 2014-08-27 17:04:56 -0700 | [diff] [blame] | 226 | if (dsa_is_cpu_port(ds, port)) |
| 227 | off = CORE_IMP_CTL; |
| 228 | else |
| 229 | off = CORE_G_PCTL_PORT(port); |
| 230 | |
Florian Fainelli | f86ad77 | 2017-09-19 10:46:54 -0700 | [diff] [blame] | 231 | b53_disable_port(ds, port, phy); |
Florian Fainelli | 246d7f7 | 2014-08-27 17:04:56 -0700 | [diff] [blame] | 232 | |
| 233 | /* Power down the port memory */ |
| 234 | reg = core_readl(priv, CORE_MEM_PSM_VDD_CTRL); |
| 235 | reg |= P_TXQ_PSM_VDD(port); |
| 236 | core_writel(priv, reg, CORE_MEM_PSM_VDD_CTRL); |
| 237 | } |
| 238 | |
Florian Fainelli | 450b05c | 2014-09-24 17:05:22 -0700 | [diff] [blame] | 239 | |
Florian Fainelli | 461cd1b0 | 2016-06-07 16:32:43 -0700 | [diff] [blame] | 240 | static int bcm_sf2_sw_indir_rw(struct bcm_sf2_priv *priv, int op, int addr, |
| 241 | int regnum, u16 val) |
| 242 | { |
| 243 | int ret = 0; |
| 244 | u32 reg; |
| 245 | |
| 246 | reg = reg_readl(priv, REG_SWITCH_CNTRL); |
| 247 | reg |= MDIO_MASTER_SEL; |
| 248 | reg_writel(priv, reg, REG_SWITCH_CNTRL); |
| 249 | |
| 250 | /* Page << 8 | offset */ |
| 251 | reg = 0x70; |
| 252 | reg <<= 2; |
| 253 | core_writel(priv, addr, reg); |
| 254 | |
| 255 | /* Page << 8 | offset */ |
| 256 | reg = 0x80 << 8 | regnum << 1; |
| 257 | reg <<= 2; |
| 258 | |
| 259 | if (op) |
| 260 | ret = core_readl(priv, reg); |
| 261 | else |
| 262 | core_writel(priv, val, reg); |
| 263 | |
| 264 | reg = reg_readl(priv, REG_SWITCH_CNTRL); |
| 265 | reg &= ~MDIO_MASTER_SEL; |
| 266 | reg_writel(priv, reg, REG_SWITCH_CNTRL); |
| 267 | |
| 268 | return ret & 0xffff; |
| 269 | } |
| 270 | |
| 271 | static int bcm_sf2_sw_mdio_read(struct mii_bus *bus, int addr, int regnum) |
| 272 | { |
| 273 | struct bcm_sf2_priv *priv = bus->priv; |
| 274 | |
| 275 | /* Intercept reads from Broadcom pseudo-PHY address, else, send |
| 276 | * them to our master MDIO bus controller |
| 277 | */ |
| 278 | if (addr == BRCM_PSEUDO_PHY_ADDR && priv->indir_phy_mask & BIT(addr)) |
| 279 | return bcm_sf2_sw_indir_rw(priv, 1, addr, regnum, 0); |
| 280 | else |
Florian Fainelli | 2cfe8f8 | 2017-01-07 21:01:57 -0800 | [diff] [blame] | 281 | return mdiobus_read_nested(priv->master_mii_bus, addr, regnum); |
Florian Fainelli | 461cd1b0 | 2016-06-07 16:32:43 -0700 | [diff] [blame] | 282 | } |
| 283 | |
| 284 | static int bcm_sf2_sw_mdio_write(struct mii_bus *bus, int addr, int regnum, |
| 285 | u16 val) |
| 286 | { |
| 287 | struct bcm_sf2_priv *priv = bus->priv; |
| 288 | |
| 289 | /* Intercept writes to the Broadcom pseudo-PHY address, else, |
| 290 | * send them to our master MDIO bus controller |
| 291 | */ |
| 292 | if (addr == BRCM_PSEUDO_PHY_ADDR && priv->indir_phy_mask & BIT(addr)) |
| 293 | bcm_sf2_sw_indir_rw(priv, 0, addr, regnum, val); |
| 294 | else |
Florian Fainelli | 2cfe8f8 | 2017-01-07 21:01:57 -0800 | [diff] [blame] | 295 | mdiobus_write_nested(priv->master_mii_bus, addr, regnum, val); |
Florian Fainelli | 461cd1b0 | 2016-06-07 16:32:43 -0700 | [diff] [blame] | 296 | |
| 297 | return 0; |
| 298 | } |
| 299 | |
Florian Fainelli | 246d7f7 | 2014-08-27 17:04:56 -0700 | [diff] [blame] | 300 | static irqreturn_t bcm_sf2_switch_0_isr(int irq, void *dev_id) |
| 301 | { |
| 302 | struct bcm_sf2_priv *priv = dev_id; |
| 303 | |
| 304 | priv->irq0_stat = intrl2_0_readl(priv, INTRL2_CPU_STATUS) & |
| 305 | ~priv->irq0_mask; |
| 306 | intrl2_0_writel(priv, priv->irq0_stat, INTRL2_CPU_CLEAR); |
| 307 | |
| 308 | return IRQ_HANDLED; |
| 309 | } |
| 310 | |
| 311 | static irqreturn_t bcm_sf2_switch_1_isr(int irq, void *dev_id) |
| 312 | { |
| 313 | struct bcm_sf2_priv *priv = dev_id; |
| 314 | |
| 315 | priv->irq1_stat = intrl2_1_readl(priv, INTRL2_CPU_STATUS) & |
| 316 | ~priv->irq1_mask; |
| 317 | intrl2_1_writel(priv, priv->irq1_stat, INTRL2_CPU_CLEAR); |
| 318 | |
| 319 | if (priv->irq1_stat & P_LINK_UP_IRQ(P7_IRQ_OFF)) |
| 320 | priv->port_sts[7].link = 1; |
| 321 | if (priv->irq1_stat & P_LINK_DOWN_IRQ(P7_IRQ_OFF)) |
| 322 | priv->port_sts[7].link = 0; |
| 323 | |
| 324 | return IRQ_HANDLED; |
| 325 | } |
| 326 | |
Florian Fainelli | 33f8461 | 2014-11-25 18:08:49 -0800 | [diff] [blame] | 327 | static int bcm_sf2_sw_rst(struct bcm_sf2_priv *priv) |
| 328 | { |
| 329 | unsigned int timeout = 1000; |
| 330 | u32 reg; |
| 331 | |
| 332 | reg = core_readl(priv, CORE_WATCHDOG_CTRL); |
| 333 | reg |= SOFTWARE_RESET | EN_CHIP_RST | EN_SW_RESET; |
| 334 | core_writel(priv, reg, CORE_WATCHDOG_CTRL); |
| 335 | |
| 336 | do { |
| 337 | reg = core_readl(priv, CORE_WATCHDOG_CTRL); |
| 338 | if (!(reg & SOFTWARE_RESET)) |
| 339 | break; |
| 340 | |
| 341 | usleep_range(1000, 2000); |
| 342 | } while (timeout-- > 0); |
| 343 | |
| 344 | if (timeout == 0) |
| 345 | return -ETIMEDOUT; |
| 346 | |
| 347 | return 0; |
| 348 | } |
| 349 | |
Florian Fainelli | 691c9a8 | 2015-01-20 16:42:00 -0800 | [diff] [blame] | 350 | static void bcm_sf2_intr_disable(struct bcm_sf2_priv *priv) |
| 351 | { |
Florian Fainelli | f01d598 | 2016-08-25 15:23:41 -0700 | [diff] [blame] | 352 | intrl2_0_mask_set(priv, 0xffffffff); |
Florian Fainelli | 691c9a8 | 2015-01-20 16:42:00 -0800 | [diff] [blame] | 353 | intrl2_0_writel(priv, 0xffffffff, INTRL2_CPU_CLEAR); |
Florian Fainelli | f01d598 | 2016-08-25 15:23:41 -0700 | [diff] [blame] | 354 | intrl2_1_mask_set(priv, 0xffffffff); |
Florian Fainelli | 691c9a8 | 2015-01-20 16:42:00 -0800 | [diff] [blame] | 355 | intrl2_1_writel(priv, 0xffffffff, INTRL2_CPU_CLEAR); |
Florian Fainelli | 691c9a8 | 2015-01-20 16:42:00 -0800 | [diff] [blame] | 356 | } |
| 357 | |
Florian Fainelli | 8b7c94e | 2015-10-23 12:11:08 -0700 | [diff] [blame] | 358 | static void bcm_sf2_identify_ports(struct bcm_sf2_priv *priv, |
| 359 | struct device_node *dn) |
| 360 | { |
| 361 | struct device_node *port; |
Florian Fainelli | 8b7c94e | 2015-10-23 12:11:08 -0700 | [diff] [blame] | 362 | int mode; |
| 363 | unsigned int port_num; |
Florian Fainelli | 8b7c94e | 2015-10-23 12:11:08 -0700 | [diff] [blame] | 364 | |
| 365 | priv->moca_port = -1; |
| 366 | |
| 367 | for_each_available_child_of_node(dn, port) { |
| 368 | if (of_property_read_u32(port, "reg", &port_num)) |
| 369 | continue; |
| 370 | |
| 371 | /* Internal PHYs get assigned a specific 'phy-mode' property |
| 372 | * value: "internal" to help flag them before MDIO probing |
| 373 | * has completed, since they might be turned off at that |
| 374 | * time |
| 375 | */ |
| 376 | mode = of_get_phy_mode(port); |
Florian Fainelli | bedd00c | 2017-06-23 10:33:16 -0700 | [diff] [blame] | 377 | if (mode < 0) |
| 378 | continue; |
Florian Fainelli | 8b7c94e | 2015-10-23 12:11:08 -0700 | [diff] [blame] | 379 | |
Florian Fainelli | bedd00c | 2017-06-23 10:33:16 -0700 | [diff] [blame] | 380 | if (mode == PHY_INTERFACE_MODE_INTERNAL) |
| 381 | priv->int_phy_mask |= 1 << port_num; |
Florian Fainelli | 8b7c94e | 2015-10-23 12:11:08 -0700 | [diff] [blame] | 382 | |
| 383 | if (mode == PHY_INTERFACE_MODE_MOCA) |
| 384 | priv->moca_port = port_num; |
Florian Fainelli | 64ff2ae | 2017-01-20 12:36:32 -0800 | [diff] [blame] | 385 | |
| 386 | if (of_property_read_bool(port, "brcm,use-bcm-hdr")) |
| 387 | priv->brcm_tag_mask |= 1 << port_num; |
Florian Fainelli | 8b7c94e | 2015-10-23 12:11:08 -0700 | [diff] [blame] | 388 | } |
| 389 | } |
| 390 | |
Florian Fainelli | 461cd1b0 | 2016-06-07 16:32:43 -0700 | [diff] [blame] | 391 | static int bcm_sf2_mdio_register(struct dsa_switch *ds) |
| 392 | { |
Florian Fainelli | f458995 | 2016-08-26 12:18:33 -0700 | [diff] [blame] | 393 | struct bcm_sf2_priv *priv = bcm_sf2_to_priv(ds); |
Florian Fainelli | 461cd1b0 | 2016-06-07 16:32:43 -0700 | [diff] [blame] | 394 | struct device_node *dn; |
| 395 | static int index; |
| 396 | int err; |
| 397 | |
| 398 | /* Find our integrated MDIO bus node */ |
| 399 | dn = of_find_compatible_node(NULL, NULL, "brcm,unimac-mdio"); |
| 400 | priv->master_mii_bus = of_mdio_find_bus(dn); |
| 401 | if (!priv->master_mii_bus) |
| 402 | return -EPROBE_DEFER; |
| 403 | |
| 404 | get_device(&priv->master_mii_bus->dev); |
| 405 | priv->master_mii_dn = dn; |
| 406 | |
| 407 | priv->slave_mii_bus = devm_mdiobus_alloc(ds->dev); |
| 408 | if (!priv->slave_mii_bus) |
| 409 | return -ENOMEM; |
| 410 | |
| 411 | priv->slave_mii_bus->priv = priv; |
| 412 | priv->slave_mii_bus->name = "sf2 slave mii"; |
| 413 | priv->slave_mii_bus->read = bcm_sf2_sw_mdio_read; |
| 414 | priv->slave_mii_bus->write = bcm_sf2_sw_mdio_write; |
| 415 | snprintf(priv->slave_mii_bus->id, MII_BUS_ID_SIZE, "sf2-%d", |
| 416 | index++); |
| 417 | priv->slave_mii_bus->dev.of_node = dn; |
| 418 | |
| 419 | /* Include the pseudo-PHY address to divert reads towards our |
| 420 | * workaround. This is only required for 7445D0, since 7445E0 |
| 421 | * disconnects the internal switch pseudo-PHY such that we can use the |
| 422 | * regular SWITCH_MDIO master controller instead. |
| 423 | * |
| 424 | * Here we flag the pseudo PHY as needing special treatment and would |
| 425 | * otherwise make all other PHY read/writes go to the master MDIO bus |
| 426 | * controller that comes with this switch backed by the "mdio-unimac" |
| 427 | * driver. |
| 428 | */ |
| 429 | if (of_machine_is_compatible("brcm,bcm7445d0")) |
| 430 | priv->indir_phy_mask |= (1 << BRCM_PSEUDO_PHY_ADDR); |
| 431 | else |
| 432 | priv->indir_phy_mask = 0; |
| 433 | |
| 434 | ds->phys_mii_mask = priv->indir_phy_mask; |
| 435 | ds->slave_mii_bus = priv->slave_mii_bus; |
| 436 | priv->slave_mii_bus->parent = ds->dev->parent; |
| 437 | priv->slave_mii_bus->phy_mask = ~priv->indir_phy_mask; |
| 438 | |
| 439 | if (dn) |
| 440 | err = of_mdiobus_register(priv->slave_mii_bus, dn); |
| 441 | else |
| 442 | err = mdiobus_register(priv->slave_mii_bus); |
| 443 | |
| 444 | if (err) |
| 445 | of_node_put(dn); |
| 446 | |
| 447 | return err; |
| 448 | } |
| 449 | |
| 450 | static void bcm_sf2_mdio_unregister(struct bcm_sf2_priv *priv) |
| 451 | { |
| 452 | mdiobus_unregister(priv->slave_mii_bus); |
| 453 | if (priv->master_mii_dn) |
| 454 | of_node_put(priv->master_mii_dn); |
| 455 | } |
| 456 | |
Florian Fainelli | aa9aef7 | 2014-09-19 13:07:55 -0700 | [diff] [blame] | 457 | static u32 bcm_sf2_sw_get_phy_flags(struct dsa_switch *ds, int port) |
| 458 | { |
Florian Fainelli | f458995 | 2016-08-26 12:18:33 -0700 | [diff] [blame] | 459 | struct bcm_sf2_priv *priv = bcm_sf2_to_priv(ds); |
Florian Fainelli | aa9aef7 | 2014-09-19 13:07:55 -0700 | [diff] [blame] | 460 | |
| 461 | /* The BCM7xxx PHY driver expects to find the integrated PHY revision |
| 462 | * in bits 15:8 and the patch level in bits 7:0 which is exactly what |
| 463 | * the REG_PHY_REVISION register layout is. |
| 464 | */ |
| 465 | |
| 466 | return priv->hw_params.gphy_rev; |
| 467 | } |
| 468 | |
Florian Fainelli | 246d7f7 | 2014-08-27 17:04:56 -0700 | [diff] [blame] | 469 | static void bcm_sf2_sw_adjust_link(struct dsa_switch *ds, int port, |
| 470 | struct phy_device *phydev) |
| 471 | { |
Florian Fainelli | f458995 | 2016-08-26 12:18:33 -0700 | [diff] [blame] | 472 | struct bcm_sf2_priv *priv = bcm_sf2_to_priv(ds); |
Florian Fainelli | 22256b0 | 2017-09-19 10:46:50 -0700 | [diff] [blame] | 473 | struct ethtool_eee *p = &priv->dev->ports[port].eee; |
Florian Fainelli | 246d7f7 | 2014-08-27 17:04:56 -0700 | [diff] [blame] | 474 | u32 id_mode_dis = 0, port_mode; |
| 475 | const char *str = NULL; |
Florian Fainelli | 0fe9933 | 2017-01-20 12:36:30 -0800 | [diff] [blame] | 476 | u32 reg, offset; |
| 477 | |
| 478 | if (priv->type == BCM7445_DEVICE_ID) |
| 479 | offset = CORE_STS_OVERRIDE_GMIIP_PORT(port); |
| 480 | else |
| 481 | offset = CORE_STS_OVERRIDE_GMIIP2_PORT(port); |
Florian Fainelli | 246d7f7 | 2014-08-27 17:04:56 -0700 | [diff] [blame] | 482 | |
| 483 | switch (phydev->interface) { |
| 484 | case PHY_INTERFACE_MODE_RGMII: |
| 485 | str = "RGMII (no delay)"; |
| 486 | id_mode_dis = 1; |
| 487 | case PHY_INTERFACE_MODE_RGMII_TXID: |
| 488 | if (!str) |
| 489 | str = "RGMII (TX delay)"; |
| 490 | port_mode = EXT_GPHY; |
| 491 | break; |
| 492 | case PHY_INTERFACE_MODE_MII: |
| 493 | str = "MII"; |
| 494 | port_mode = EXT_EPHY; |
| 495 | break; |
| 496 | case PHY_INTERFACE_MODE_REVMII: |
| 497 | str = "Reverse MII"; |
| 498 | port_mode = EXT_REVMII; |
| 499 | break; |
| 500 | default: |
Florian Fainelli | 7de1557 | 2014-09-24 17:05:19 -0700 | [diff] [blame] | 501 | /* All other PHYs: internal and MoCA */ |
| 502 | goto force_link; |
| 503 | } |
| 504 | |
| 505 | /* If the link is down, just disable the interface to conserve power */ |
| 506 | if (!phydev->link) { |
| 507 | reg = reg_readl(priv, REG_RGMII_CNTRL_P(port)); |
| 508 | reg &= ~RGMII_MODE_EN; |
| 509 | reg_writel(priv, reg, REG_RGMII_CNTRL_P(port)); |
Florian Fainelli | 246d7f7 | 2014-08-27 17:04:56 -0700 | [diff] [blame] | 510 | goto force_link; |
| 511 | } |
| 512 | |
| 513 | /* Clear id_mode_dis bit, and the existing port mode, but |
| 514 | * make sure we enable the RGMII block for data to pass |
| 515 | */ |
| 516 | reg = reg_readl(priv, REG_RGMII_CNTRL_P(port)); |
| 517 | reg &= ~ID_MODE_DIS; |
| 518 | reg &= ~(PORT_MODE_MASK << PORT_MODE_SHIFT); |
| 519 | reg &= ~(RX_PAUSE_EN | TX_PAUSE_EN); |
| 520 | |
| 521 | reg |= port_mode | RGMII_MODE_EN; |
| 522 | if (id_mode_dis) |
| 523 | reg |= ID_MODE_DIS; |
| 524 | |
| 525 | if (phydev->pause) { |
| 526 | if (phydev->asym_pause) |
| 527 | reg |= TX_PAUSE_EN; |
| 528 | reg |= RX_PAUSE_EN; |
| 529 | } |
| 530 | |
| 531 | reg_writel(priv, reg, REG_RGMII_CNTRL_P(port)); |
| 532 | |
| 533 | pr_info("Port %d configured for %s\n", port, str); |
| 534 | |
| 535 | force_link: |
| 536 | /* Force link settings detected from the PHY */ |
| 537 | reg = SW_OVERRIDE; |
| 538 | switch (phydev->speed) { |
| 539 | case SPEED_1000: |
| 540 | reg |= SPDSTS_1000 << SPEED_SHIFT; |
| 541 | break; |
| 542 | case SPEED_100: |
| 543 | reg |= SPDSTS_100 << SPEED_SHIFT; |
| 544 | break; |
| 545 | } |
| 546 | |
| 547 | if (phydev->link) |
| 548 | reg |= LINK_STS; |
| 549 | if (phydev->duplex == DUPLEX_FULL) |
| 550 | reg |= DUPLX_MODE; |
| 551 | |
Florian Fainelli | 0fe9933 | 2017-01-20 12:36:30 -0800 | [diff] [blame] | 552 | core_writel(priv, reg, offset); |
Florian Fainelli | 76da870 | 2016-11-22 11:40:58 -0800 | [diff] [blame] | 553 | |
| 554 | if (!phydev->is_pseudo_fixed_link) |
Florian Fainelli | 22256b0 | 2017-09-19 10:46:50 -0700 | [diff] [blame] | 555 | p->eee_enabled = b53_eee_init(ds, port, phydev); |
Florian Fainelli | 246d7f7 | 2014-08-27 17:04:56 -0700 | [diff] [blame] | 556 | } |
| 557 | |
| 558 | static void bcm_sf2_sw_fixed_link_update(struct dsa_switch *ds, int port, |
| 559 | struct fixed_phy_status *status) |
| 560 | { |
Florian Fainelli | f458995 | 2016-08-26 12:18:33 -0700 | [diff] [blame] | 561 | struct bcm_sf2_priv *priv = bcm_sf2_to_priv(ds); |
Florian Fainelli | 0fe9933 | 2017-01-20 12:36:30 -0800 | [diff] [blame] | 562 | u32 duplex, pause, offset; |
Florian Fainelli | 246d7f7 | 2014-08-27 17:04:56 -0700 | [diff] [blame] | 563 | u32 reg; |
| 564 | |
Florian Fainelli | 0fe9933 | 2017-01-20 12:36:30 -0800 | [diff] [blame] | 565 | if (priv->type == BCM7445_DEVICE_ID) |
| 566 | offset = CORE_STS_OVERRIDE_GMIIP_PORT(port); |
| 567 | else |
| 568 | offset = CORE_STS_OVERRIDE_GMIIP2_PORT(port); |
| 569 | |
Florian Fainelli | 246d7f7 | 2014-08-27 17:04:56 -0700 | [diff] [blame] | 570 | duplex = core_readl(priv, CORE_DUPSTS); |
| 571 | pause = core_readl(priv, CORE_PAUSESTS); |
Florian Fainelli | 246d7f7 | 2014-08-27 17:04:56 -0700 | [diff] [blame] | 572 | |
| 573 | status->link = 0; |
| 574 | |
Florian Fainelli | 8b7c94e | 2015-10-23 12:11:08 -0700 | [diff] [blame] | 575 | /* MoCA port is special as we do not get link status from CORE_LNKSTS, |
Florian Fainelli | 246d7f7 | 2014-08-27 17:04:56 -0700 | [diff] [blame] | 576 | * which means that we need to force the link at the port override |
| 577 | * level to get the data to flow. We do use what the interrupt handler |
| 578 | * did determine before. |
Florian Fainelli | 7855f67 | 2014-12-11 18:12:42 -0800 | [diff] [blame] | 579 | * |
| 580 | * For the other ports, we just force the link status, since this is |
| 581 | * a fixed PHY device. |
Florian Fainelli | 246d7f7 | 2014-08-27 17:04:56 -0700 | [diff] [blame] | 582 | */ |
Florian Fainelli | 8b7c94e | 2015-10-23 12:11:08 -0700 | [diff] [blame] | 583 | if (port == priv->moca_port) { |
Florian Fainelli | 246d7f7 | 2014-08-27 17:04:56 -0700 | [diff] [blame] | 584 | status->link = priv->port_sts[port].link; |
Florian Fainelli | 4ab7f91 | 2015-05-15 12:38:01 -0700 | [diff] [blame] | 585 | /* For MoCA interfaces, also force a link down notification |
| 586 | * since some version of the user-space daemon (mocad) use |
| 587 | * cmd->autoneg to force the link, which messes up the PHY |
| 588 | * state machine and make it go in PHY_FORCING state instead. |
| 589 | */ |
| 590 | if (!status->link) |
Andrew Lunn | c8b0980 | 2016-06-04 21:16:57 +0200 | [diff] [blame] | 591 | netif_carrier_off(ds->ports[port].netdev); |
Florian Fainelli | 246d7f7 | 2014-08-27 17:04:56 -0700 | [diff] [blame] | 592 | status->duplex = 1; |
| 593 | } else { |
Florian Fainelli | 7855f67 | 2014-12-11 18:12:42 -0800 | [diff] [blame] | 594 | status->link = 1; |
Florian Fainelli | 246d7f7 | 2014-08-27 17:04:56 -0700 | [diff] [blame] | 595 | status->duplex = !!(duplex & (1 << port)); |
| 596 | } |
| 597 | |
Florian Fainelli | 0fe9933 | 2017-01-20 12:36:30 -0800 | [diff] [blame] | 598 | reg = core_readl(priv, offset); |
Florian Fainelli | 7855f67 | 2014-12-11 18:12:42 -0800 | [diff] [blame] | 599 | reg |= SW_OVERRIDE; |
| 600 | if (status->link) |
| 601 | reg |= LINK_STS; |
| 602 | else |
| 603 | reg &= ~LINK_STS; |
Florian Fainelli | 0fe9933 | 2017-01-20 12:36:30 -0800 | [diff] [blame] | 604 | core_writel(priv, reg, offset); |
Florian Fainelli | 7855f67 | 2014-12-11 18:12:42 -0800 | [diff] [blame] | 605 | |
Florian Fainelli | 246d7f7 | 2014-08-27 17:04:56 -0700 | [diff] [blame] | 606 | if ((pause & (1 << port)) && |
| 607 | (pause & (1 << (port + PAUSESTS_TX_PAUSE_SHIFT)))) { |
| 608 | status->asym_pause = 1; |
| 609 | status->pause = 1; |
| 610 | } |
| 611 | |
| 612 | if (pause & (1 << port)) |
| 613 | status->pause = 1; |
| 614 | } |
| 615 | |
Florian Fainelli | 8cfa949 | 2014-09-18 17:31:23 -0700 | [diff] [blame] | 616 | static int bcm_sf2_sw_suspend(struct dsa_switch *ds) |
| 617 | { |
Florian Fainelli | f458995 | 2016-08-26 12:18:33 -0700 | [diff] [blame] | 618 | struct bcm_sf2_priv *priv = bcm_sf2_to_priv(ds); |
Florian Fainelli | 8cfa949 | 2014-09-18 17:31:23 -0700 | [diff] [blame] | 619 | unsigned int port; |
| 620 | |
Florian Fainelli | 691c9a8 | 2015-01-20 16:42:00 -0800 | [diff] [blame] | 621 | bcm_sf2_intr_disable(priv); |
Florian Fainelli | 8cfa949 | 2014-09-18 17:31:23 -0700 | [diff] [blame] | 622 | |
| 623 | /* Disable all ports physically present including the IMP |
| 624 | * port, the other ones have already been disabled during |
| 625 | * bcm_sf2_sw_setup |
| 626 | */ |
| 627 | for (port = 0; port < DSA_MAX_PORTS; port++) { |
Andrew Lunn | 74c3e2a | 2016-04-13 02:40:44 +0200 | [diff] [blame] | 628 | if ((1 << port) & ds->enabled_port_mask || |
Florian Fainelli | 8cfa949 | 2014-09-18 17:31:23 -0700 | [diff] [blame] | 629 | dsa_is_cpu_port(ds, port)) |
Florian Fainelli | b6d045d | 2014-09-24 17:05:20 -0700 | [diff] [blame] | 630 | bcm_sf2_port_disable(ds, port, NULL); |
Florian Fainelli | 8cfa949 | 2014-09-18 17:31:23 -0700 | [diff] [blame] | 631 | } |
| 632 | |
| 633 | return 0; |
| 634 | } |
| 635 | |
Florian Fainelli | 8cfa949 | 2014-09-18 17:31:23 -0700 | [diff] [blame] | 636 | static int bcm_sf2_sw_resume(struct dsa_switch *ds) |
| 637 | { |
Florian Fainelli | f458995 | 2016-08-26 12:18:33 -0700 | [diff] [blame] | 638 | struct bcm_sf2_priv *priv = bcm_sf2_to_priv(ds); |
Florian Fainelli | 8cfa949 | 2014-09-18 17:31:23 -0700 | [diff] [blame] | 639 | unsigned int port; |
Florian Fainelli | 8cfa949 | 2014-09-18 17:31:23 -0700 | [diff] [blame] | 640 | int ret; |
| 641 | |
| 642 | ret = bcm_sf2_sw_rst(priv); |
| 643 | if (ret) { |
| 644 | pr_err("%s: failed to software reset switch\n", __func__); |
| 645 | return ret; |
| 646 | } |
| 647 | |
Florian Fainelli | b083668 | 2015-02-05 11:40:41 -0800 | [diff] [blame] | 648 | if (priv->hw_params.num_gphy == 1) |
| 649 | bcm_sf2_gphy_enable_set(ds, true); |
Florian Fainelli | 8cfa949 | 2014-09-18 17:31:23 -0700 | [diff] [blame] | 650 | |
| 651 | for (port = 0; port < DSA_MAX_PORTS; port++) { |
Andrew Lunn | 74c3e2a | 2016-04-13 02:40:44 +0200 | [diff] [blame] | 652 | if ((1 << port) & ds->enabled_port_mask) |
Florian Fainelli | b6d045d | 2014-09-24 17:05:20 -0700 | [diff] [blame] | 653 | bcm_sf2_port_setup(ds, port, NULL); |
Florian Fainelli | 8cfa949 | 2014-09-18 17:31:23 -0700 | [diff] [blame] | 654 | else if (dsa_is_cpu_port(ds, port)) |
| 655 | bcm_sf2_imp_setup(ds, port); |
| 656 | } |
| 657 | |
| 658 | return 0; |
| 659 | } |
| 660 | |
Florian Fainelli | 96e65d7 | 2014-09-18 17:31:25 -0700 | [diff] [blame] | 661 | static void bcm_sf2_sw_get_wol(struct dsa_switch *ds, int port, |
| 662 | struct ethtool_wolinfo *wol) |
| 663 | { |
Vivien Didelot | 0abfd49 | 2017-09-20 12:28:05 -0400 | [diff] [blame] | 664 | struct net_device *p = ds->ports[port].cpu_dp->netdev; |
Florian Fainelli | f458995 | 2016-08-26 12:18:33 -0700 | [diff] [blame] | 665 | struct bcm_sf2_priv *priv = bcm_sf2_to_priv(ds); |
Florian Fainelli | 96e65d7 | 2014-09-18 17:31:25 -0700 | [diff] [blame] | 666 | struct ethtool_wolinfo pwol; |
| 667 | |
| 668 | /* Get the parent device WoL settings */ |
| 669 | p->ethtool_ops->get_wol(p, &pwol); |
| 670 | |
| 671 | /* Advertise the parent device supported settings */ |
| 672 | wol->supported = pwol.supported; |
| 673 | memset(&wol->sopass, 0, sizeof(wol->sopass)); |
| 674 | |
| 675 | if (pwol.wolopts & WAKE_MAGICSECURE) |
| 676 | memcpy(&wol->sopass, pwol.sopass, sizeof(wol->sopass)); |
| 677 | |
| 678 | if (priv->wol_ports_mask & (1 << port)) |
| 679 | wol->wolopts = pwol.wolopts; |
| 680 | else |
| 681 | wol->wolopts = 0; |
| 682 | } |
| 683 | |
| 684 | static int bcm_sf2_sw_set_wol(struct dsa_switch *ds, int port, |
| 685 | struct ethtool_wolinfo *wol) |
| 686 | { |
Vivien Didelot | 0abfd49 | 2017-09-20 12:28:05 -0400 | [diff] [blame] | 687 | struct net_device *p = ds->ports[port].cpu_dp->netdev; |
Florian Fainelli | f458995 | 2016-08-26 12:18:33 -0700 | [diff] [blame] | 688 | struct bcm_sf2_priv *priv = bcm_sf2_to_priv(ds); |
Vivien Didelot | 0abfd49 | 2017-09-20 12:28:05 -0400 | [diff] [blame] | 689 | s8 cpu_port = ds->ports[port].cpu_dp->index; |
Florian Fainelli | 96e65d7 | 2014-09-18 17:31:25 -0700 | [diff] [blame] | 690 | struct ethtool_wolinfo pwol; |
| 691 | |
| 692 | p->ethtool_ops->get_wol(p, &pwol); |
| 693 | if (wol->wolopts & ~pwol.supported) |
| 694 | return -EINVAL; |
| 695 | |
| 696 | if (wol->wolopts) |
| 697 | priv->wol_ports_mask |= (1 << port); |
| 698 | else |
| 699 | priv->wol_ports_mask &= ~(1 << port); |
| 700 | |
| 701 | /* If we have at least one port enabled, make sure the CPU port |
| 702 | * is also enabled. If the CPU port is the last one enabled, we disable |
| 703 | * it since this configuration does not make sense. |
| 704 | */ |
| 705 | if (priv->wol_ports_mask && priv->wol_ports_mask != (1 << cpu_port)) |
| 706 | priv->wol_ports_mask |= (1 << cpu_port); |
| 707 | else |
| 708 | priv->wol_ports_mask &= ~(1 << cpu_port); |
| 709 | |
| 710 | return p->ethtool_ops->set_wol(p, wol); |
| 711 | } |
| 712 | |
Florian Fainelli | de0b9d3 | 2016-08-26 12:18:34 -0700 | [diff] [blame] | 713 | static int bcm_sf2_vlan_op_wait(struct bcm_sf2_priv *priv) |
Florian Fainelli | 9c57a77 | 2016-06-09 17:42:08 -0700 | [diff] [blame] | 714 | { |
Florian Fainelli | de0b9d3 | 2016-08-26 12:18:34 -0700 | [diff] [blame] | 715 | unsigned int timeout = 10; |
| 716 | u32 reg; |
Florian Fainelli | 9c57a77 | 2016-06-09 17:42:08 -0700 | [diff] [blame] | 717 | |
Florian Fainelli | de0b9d3 | 2016-08-26 12:18:34 -0700 | [diff] [blame] | 718 | do { |
| 719 | reg = core_readl(priv, CORE_ARLA_VTBL_RWCTRL); |
| 720 | if (!(reg & ARLA_VTBL_STDN)) |
| 721 | return 0; |
Florian Fainelli | 9c57a77 | 2016-06-09 17:42:08 -0700 | [diff] [blame] | 722 | |
Florian Fainelli | de0b9d3 | 2016-08-26 12:18:34 -0700 | [diff] [blame] | 723 | usleep_range(1000, 2000); |
| 724 | } while (timeout--); |
Florian Fainelli | 9c57a77 | 2016-06-09 17:42:08 -0700 | [diff] [blame] | 725 | |
Florian Fainelli | de0b9d3 | 2016-08-26 12:18:34 -0700 | [diff] [blame] | 726 | return -ETIMEDOUT; |
| 727 | } |
Florian Fainelli | 9c57a77 | 2016-06-09 17:42:08 -0700 | [diff] [blame] | 728 | |
Florian Fainelli | de0b9d3 | 2016-08-26 12:18:34 -0700 | [diff] [blame] | 729 | static int bcm_sf2_vlan_op(struct bcm_sf2_priv *priv, u8 op) |
| 730 | { |
| 731 | core_writel(priv, ARLA_VTBL_STDN | op, CORE_ARLA_VTBL_RWCTRL); |
| 732 | |
| 733 | return bcm_sf2_vlan_op_wait(priv); |
Florian Fainelli | 9c57a77 | 2016-06-09 17:42:08 -0700 | [diff] [blame] | 734 | } |
| 735 | |
| 736 | static void bcm_sf2_sw_configure_vlan(struct dsa_switch *ds) |
| 737 | { |
Florian Fainelli | f458995 | 2016-08-26 12:18:33 -0700 | [diff] [blame] | 738 | struct bcm_sf2_priv *priv = bcm_sf2_to_priv(ds); |
Florian Fainelli | 9c57a77 | 2016-06-09 17:42:08 -0700 | [diff] [blame] | 739 | unsigned int port; |
| 740 | |
| 741 | /* Clear all VLANs */ |
| 742 | bcm_sf2_vlan_op(priv, ARLA_VTBL_CMD_CLEAR); |
| 743 | |
| 744 | for (port = 0; port < priv->hw_params.num_ports; port++) { |
| 745 | if (!((1 << port) & ds->enabled_port_mask)) |
| 746 | continue; |
| 747 | |
| 748 | core_writel(priv, 1, CORE_DEFAULT_1Q_TAG_P(port)); |
| 749 | } |
| 750 | } |
| 751 | |
Florian Fainelli | 7fbb1a9 | 2016-06-09 17:42:06 -0700 | [diff] [blame] | 752 | static int bcm_sf2_sw_setup(struct dsa_switch *ds) |
| 753 | { |
Florian Fainelli | f458995 | 2016-08-26 12:18:33 -0700 | [diff] [blame] | 754 | struct bcm_sf2_priv *priv = bcm_sf2_to_priv(ds); |
Florian Fainelli | 7fbb1a9 | 2016-06-09 17:42:06 -0700 | [diff] [blame] | 755 | unsigned int port; |
Florian Fainelli | d933802 | 2016-08-18 15:30:14 -0700 | [diff] [blame] | 756 | |
Florian Fainelli | 21a2774 | 2017-09-28 11:19:06 -0700 | [diff] [blame] | 757 | /* Enable all valid ports and disable those unused */ |
Florian Fainelli | d933802 | 2016-08-18 15:30:14 -0700 | [diff] [blame] | 758 | for (port = 0; port < priv->hw_params.num_ports; port++) { |
Florian Fainelli | 21a2774 | 2017-09-28 11:19:06 -0700 | [diff] [blame] | 759 | /* IMP port receives special treatment */ |
| 760 | if ((1 << port) & ds->enabled_port_mask) |
| 761 | bcm_sf2_port_setup(ds, port, NULL); |
| 762 | else if (dsa_is_cpu_port(ds, port)) |
Florian Fainelli | d933802 | 2016-08-18 15:30:14 -0700 | [diff] [blame] | 763 | bcm_sf2_imp_setup(ds, port); |
Florian Fainelli | 21a2774 | 2017-09-28 11:19:06 -0700 | [diff] [blame] | 764 | else |
Florian Fainelli | d933802 | 2016-08-18 15:30:14 -0700 | [diff] [blame] | 765 | bcm_sf2_port_disable(ds, port, NULL); |
| 766 | } |
| 767 | |
| 768 | bcm_sf2_sw_configure_vlan(ds); |
| 769 | |
| 770 | return 0; |
| 771 | } |
| 772 | |
Florian Fainelli | f458995 | 2016-08-26 12:18:33 -0700 | [diff] [blame] | 773 | /* The SWITCH_CORE register space is managed by b53 but operates on a page + |
| 774 | * register basis so we need to translate that into an address that the |
| 775 | * bus-glue understands. |
| 776 | */ |
| 777 | #define SF2_PAGE_REG_MKADDR(page, reg) ((page) << 10 | (reg) << 2) |
| 778 | |
| 779 | static int bcm_sf2_core_read8(struct b53_device *dev, u8 page, u8 reg, |
| 780 | u8 *val) |
| 781 | { |
| 782 | struct bcm_sf2_priv *priv = dev->priv; |
| 783 | |
| 784 | *val = core_readl(priv, SF2_PAGE_REG_MKADDR(page, reg)); |
| 785 | |
| 786 | return 0; |
| 787 | } |
| 788 | |
| 789 | static int bcm_sf2_core_read16(struct b53_device *dev, u8 page, u8 reg, |
| 790 | u16 *val) |
| 791 | { |
| 792 | struct bcm_sf2_priv *priv = dev->priv; |
| 793 | |
| 794 | *val = core_readl(priv, SF2_PAGE_REG_MKADDR(page, reg)); |
| 795 | |
| 796 | return 0; |
| 797 | } |
| 798 | |
| 799 | static int bcm_sf2_core_read32(struct b53_device *dev, u8 page, u8 reg, |
| 800 | u32 *val) |
| 801 | { |
| 802 | struct bcm_sf2_priv *priv = dev->priv; |
| 803 | |
| 804 | *val = core_readl(priv, SF2_PAGE_REG_MKADDR(page, reg)); |
| 805 | |
| 806 | return 0; |
| 807 | } |
| 808 | |
| 809 | static int bcm_sf2_core_read64(struct b53_device *dev, u8 page, u8 reg, |
| 810 | u64 *val) |
| 811 | { |
| 812 | struct bcm_sf2_priv *priv = dev->priv; |
| 813 | |
| 814 | *val = core_readq(priv, SF2_PAGE_REG_MKADDR(page, reg)); |
| 815 | |
| 816 | return 0; |
| 817 | } |
| 818 | |
| 819 | static int bcm_sf2_core_write8(struct b53_device *dev, u8 page, u8 reg, |
| 820 | u8 value) |
| 821 | { |
| 822 | struct bcm_sf2_priv *priv = dev->priv; |
| 823 | |
| 824 | core_writel(priv, value, SF2_PAGE_REG_MKADDR(page, reg)); |
| 825 | |
| 826 | return 0; |
| 827 | } |
| 828 | |
| 829 | static int bcm_sf2_core_write16(struct b53_device *dev, u8 page, u8 reg, |
| 830 | u16 value) |
| 831 | { |
| 832 | struct bcm_sf2_priv *priv = dev->priv; |
| 833 | |
| 834 | core_writel(priv, value, SF2_PAGE_REG_MKADDR(page, reg)); |
| 835 | |
| 836 | return 0; |
| 837 | } |
| 838 | |
| 839 | static int bcm_sf2_core_write32(struct b53_device *dev, u8 page, u8 reg, |
| 840 | u32 value) |
| 841 | { |
| 842 | struct bcm_sf2_priv *priv = dev->priv; |
| 843 | |
| 844 | core_writel(priv, value, SF2_PAGE_REG_MKADDR(page, reg)); |
| 845 | |
| 846 | return 0; |
| 847 | } |
| 848 | |
| 849 | static int bcm_sf2_core_write64(struct b53_device *dev, u8 page, u8 reg, |
| 850 | u64 value) |
| 851 | { |
| 852 | struct bcm_sf2_priv *priv = dev->priv; |
| 853 | |
| 854 | core_writeq(priv, value, SF2_PAGE_REG_MKADDR(page, reg)); |
| 855 | |
| 856 | return 0; |
| 857 | } |
| 858 | |
Bhumika Goyal | 7e3108f | 2017-08-29 22:17:52 +0530 | [diff] [blame] | 859 | static const struct b53_io_ops bcm_sf2_io_ops = { |
Florian Fainelli | f458995 | 2016-08-26 12:18:33 -0700 | [diff] [blame] | 860 | .read8 = bcm_sf2_core_read8, |
| 861 | .read16 = bcm_sf2_core_read16, |
| 862 | .read32 = bcm_sf2_core_read32, |
| 863 | .read48 = bcm_sf2_core_read64, |
| 864 | .read64 = bcm_sf2_core_read64, |
| 865 | .write8 = bcm_sf2_core_write8, |
| 866 | .write16 = bcm_sf2_core_write16, |
| 867 | .write32 = bcm_sf2_core_write32, |
| 868 | .write48 = bcm_sf2_core_write64, |
| 869 | .write64 = bcm_sf2_core_write64, |
| 870 | }; |
| 871 | |
Florian Fainelli | a82f67a | 2017-01-08 14:52:08 -0800 | [diff] [blame] | 872 | static const struct dsa_switch_ops bcm_sf2_ops = { |
Florian Fainelli | 73095cb | 2017-01-08 14:52:06 -0800 | [diff] [blame] | 873 | .get_tag_protocol = bcm_sf2_sw_get_tag_protocol, |
| 874 | .setup = bcm_sf2_sw_setup, |
| 875 | .get_strings = b53_get_strings, |
| 876 | .get_ethtool_stats = b53_get_ethtool_stats, |
| 877 | .get_sset_count = b53_get_sset_count, |
| 878 | .get_phy_flags = bcm_sf2_sw_get_phy_flags, |
| 879 | .adjust_link = bcm_sf2_sw_adjust_link, |
| 880 | .fixed_link_update = bcm_sf2_sw_fixed_link_update, |
| 881 | .suspend = bcm_sf2_sw_suspend, |
| 882 | .resume = bcm_sf2_sw_resume, |
| 883 | .get_wol = bcm_sf2_sw_get_wol, |
| 884 | .set_wol = bcm_sf2_sw_set_wol, |
| 885 | .port_enable = bcm_sf2_port_setup, |
| 886 | .port_disable = bcm_sf2_port_disable, |
Florian Fainelli | 22256b0 | 2017-09-19 10:46:50 -0700 | [diff] [blame] | 887 | .get_mac_eee = b53_get_mac_eee, |
| 888 | .set_mac_eee = b53_set_mac_eee, |
Florian Fainelli | 73095cb | 2017-01-08 14:52:06 -0800 | [diff] [blame] | 889 | .port_bridge_join = b53_br_join, |
| 890 | .port_bridge_leave = b53_br_leave, |
| 891 | .port_stp_state_set = b53_br_set_stp_state, |
| 892 | .port_fast_age = b53_br_fast_age, |
| 893 | .port_vlan_filtering = b53_vlan_filtering, |
| 894 | .port_vlan_prepare = b53_vlan_prepare, |
| 895 | .port_vlan_add = b53_vlan_add, |
| 896 | .port_vlan_del = b53_vlan_del, |
Florian Fainelli | 73095cb | 2017-01-08 14:52:06 -0800 | [diff] [blame] | 897 | .port_fdb_dump = b53_fdb_dump, |
| 898 | .port_fdb_add = b53_fdb_add, |
| 899 | .port_fdb_del = b53_fdb_del, |
Florian Fainelli | 7318166 | 2017-01-30 09:48:43 -0800 | [diff] [blame] | 900 | .get_rxnfc = bcm_sf2_get_rxnfc, |
| 901 | .set_rxnfc = bcm_sf2_set_rxnfc, |
Florian Fainelli | ec960de | 2017-01-30 12:41:43 -0800 | [diff] [blame] | 902 | .port_mirror_add = b53_mirror_add, |
| 903 | .port_mirror_del = b53_mirror_del, |
Florian Fainelli | 73095cb | 2017-01-08 14:52:06 -0800 | [diff] [blame] | 904 | }; |
| 905 | |
Florian Fainelli | a78e86e | 2017-01-20 12:36:29 -0800 | [diff] [blame] | 906 | struct bcm_sf2_of_data { |
| 907 | u32 type; |
| 908 | const u16 *reg_offsets; |
| 909 | unsigned int core_reg_align; |
Florian Fainelli | df19163 | 2017-08-30 12:39:33 -0700 | [diff] [blame] | 910 | unsigned int num_cfp_rules; |
Florian Fainelli | a78e86e | 2017-01-20 12:36:29 -0800 | [diff] [blame] | 911 | }; |
| 912 | |
| 913 | /* Register offsets for the SWITCH_REG_* block */ |
| 914 | static const u16 bcm_sf2_7445_reg_offsets[] = { |
| 915 | [REG_SWITCH_CNTRL] = 0x00, |
| 916 | [REG_SWITCH_STATUS] = 0x04, |
| 917 | [REG_DIR_DATA_WRITE] = 0x08, |
| 918 | [REG_DIR_DATA_READ] = 0x0C, |
| 919 | [REG_SWITCH_REVISION] = 0x18, |
| 920 | [REG_PHY_REVISION] = 0x1C, |
| 921 | [REG_SPHY_CNTRL] = 0x2C, |
| 922 | [REG_RGMII_0_CNTRL] = 0x34, |
| 923 | [REG_RGMII_1_CNTRL] = 0x40, |
| 924 | [REG_RGMII_2_CNTRL] = 0x4c, |
| 925 | [REG_LED_0_CNTRL] = 0x90, |
| 926 | [REG_LED_1_CNTRL] = 0x94, |
| 927 | [REG_LED_2_CNTRL] = 0x98, |
| 928 | }; |
| 929 | |
| 930 | static const struct bcm_sf2_of_data bcm_sf2_7445_data = { |
| 931 | .type = BCM7445_DEVICE_ID, |
| 932 | .core_reg_align = 0, |
| 933 | .reg_offsets = bcm_sf2_7445_reg_offsets, |
Florian Fainelli | df19163 | 2017-08-30 12:39:33 -0700 | [diff] [blame] | 934 | .num_cfp_rules = 256, |
Florian Fainelli | a78e86e | 2017-01-20 12:36:29 -0800 | [diff] [blame] | 935 | }; |
| 936 | |
Florian Fainelli | 0fe9933 | 2017-01-20 12:36:30 -0800 | [diff] [blame] | 937 | static const u16 bcm_sf2_7278_reg_offsets[] = { |
| 938 | [REG_SWITCH_CNTRL] = 0x00, |
| 939 | [REG_SWITCH_STATUS] = 0x04, |
| 940 | [REG_DIR_DATA_WRITE] = 0x08, |
| 941 | [REG_DIR_DATA_READ] = 0x0c, |
| 942 | [REG_SWITCH_REVISION] = 0x10, |
| 943 | [REG_PHY_REVISION] = 0x14, |
| 944 | [REG_SPHY_CNTRL] = 0x24, |
| 945 | [REG_RGMII_0_CNTRL] = 0xe0, |
| 946 | [REG_RGMII_1_CNTRL] = 0xec, |
| 947 | [REG_RGMII_2_CNTRL] = 0xf8, |
| 948 | [REG_LED_0_CNTRL] = 0x40, |
| 949 | [REG_LED_1_CNTRL] = 0x4c, |
| 950 | [REG_LED_2_CNTRL] = 0x58, |
| 951 | }; |
| 952 | |
| 953 | static const struct bcm_sf2_of_data bcm_sf2_7278_data = { |
| 954 | .type = BCM7278_DEVICE_ID, |
| 955 | .core_reg_align = 1, |
| 956 | .reg_offsets = bcm_sf2_7278_reg_offsets, |
Florian Fainelli | df19163 | 2017-08-30 12:39:33 -0700 | [diff] [blame] | 957 | .num_cfp_rules = 128, |
Florian Fainelli | 0fe9933 | 2017-01-20 12:36:30 -0800 | [diff] [blame] | 958 | }; |
| 959 | |
Florian Fainelli | a78e86e | 2017-01-20 12:36:29 -0800 | [diff] [blame] | 960 | static const struct of_device_id bcm_sf2_of_match[] = { |
| 961 | { .compatible = "brcm,bcm7445-switch-v4.0", |
| 962 | .data = &bcm_sf2_7445_data |
| 963 | }, |
Florian Fainelli | 0fe9933 | 2017-01-20 12:36:30 -0800 | [diff] [blame] | 964 | { .compatible = "brcm,bcm7278-switch-v4.0", |
| 965 | .data = &bcm_sf2_7278_data |
| 966 | }, |
Florian Fainelli | a78e86e | 2017-01-20 12:36:29 -0800 | [diff] [blame] | 967 | { /* sentinel */ }, |
| 968 | }; |
| 969 | MODULE_DEVICE_TABLE(of, bcm_sf2_of_match); |
| 970 | |
Florian Fainelli | d933802 | 2016-08-18 15:30:14 -0700 | [diff] [blame] | 971 | static int bcm_sf2_sw_probe(struct platform_device *pdev) |
| 972 | { |
| 973 | const char *reg_names[BCM_SF2_REGS_NUM] = BCM_SF2_REGS_NAME; |
| 974 | struct device_node *dn = pdev->dev.of_node; |
Florian Fainelli | a78e86e | 2017-01-20 12:36:29 -0800 | [diff] [blame] | 975 | const struct of_device_id *of_id = NULL; |
| 976 | const struct bcm_sf2_of_data *data; |
Florian Fainelli | f458995 | 2016-08-26 12:18:33 -0700 | [diff] [blame] | 977 | struct b53_platform_data *pdata; |
Florian Fainelli | a4c61b9 | 2017-01-07 21:01:56 -0800 | [diff] [blame] | 978 | struct dsa_switch_ops *ops; |
Florian Fainelli | d933802 | 2016-08-18 15:30:14 -0700 | [diff] [blame] | 979 | struct bcm_sf2_priv *priv; |
Florian Fainelli | f458995 | 2016-08-26 12:18:33 -0700 | [diff] [blame] | 980 | struct b53_device *dev; |
Florian Fainelli | d933802 | 2016-08-18 15:30:14 -0700 | [diff] [blame] | 981 | struct dsa_switch *ds; |
| 982 | void __iomem **base; |
Florian Fainelli | 4bd1167 | 2016-08-18 15:30:15 -0700 | [diff] [blame] | 983 | struct resource *r; |
Florian Fainelli | 7fbb1a9 | 2016-06-09 17:42:06 -0700 | [diff] [blame] | 984 | unsigned int i; |
| 985 | u32 reg, rev; |
| 986 | int ret; |
| 987 | |
Florian Fainelli | f458995 | 2016-08-26 12:18:33 -0700 | [diff] [blame] | 988 | priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); |
| 989 | if (!priv) |
Florian Fainelli | d933802 | 2016-08-18 15:30:14 -0700 | [diff] [blame] | 990 | return -ENOMEM; |
| 991 | |
Florian Fainelli | a4c61b9 | 2017-01-07 21:01:56 -0800 | [diff] [blame] | 992 | ops = devm_kzalloc(&pdev->dev, sizeof(*ops), GFP_KERNEL); |
| 993 | if (!ops) |
| 994 | return -ENOMEM; |
| 995 | |
Florian Fainelli | f458995 | 2016-08-26 12:18:33 -0700 | [diff] [blame] | 996 | dev = b53_switch_alloc(&pdev->dev, &bcm_sf2_io_ops, priv); |
| 997 | if (!dev) |
| 998 | return -ENOMEM; |
Florian Fainelli | d933802 | 2016-08-18 15:30:14 -0700 | [diff] [blame] | 999 | |
Florian Fainelli | f458995 | 2016-08-26 12:18:33 -0700 | [diff] [blame] | 1000 | pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); |
| 1001 | if (!pdata) |
| 1002 | return -ENOMEM; |
| 1003 | |
Florian Fainelli | a78e86e | 2017-01-20 12:36:29 -0800 | [diff] [blame] | 1004 | of_id = of_match_node(bcm_sf2_of_match, dn); |
| 1005 | if (!of_id || !of_id->data) |
| 1006 | return -EINVAL; |
| 1007 | |
| 1008 | data = of_id->data; |
| 1009 | |
| 1010 | /* Set SWITCH_REG register offsets and SWITCH_CORE align factor */ |
| 1011 | priv->type = data->type; |
| 1012 | priv->reg_offsets = data->reg_offsets; |
| 1013 | priv->core_reg_align = data->core_reg_align; |
Florian Fainelli | df19163 | 2017-08-30 12:39:33 -0700 | [diff] [blame] | 1014 | priv->num_cfp_rules = data->num_cfp_rules; |
Florian Fainelli | a78e86e | 2017-01-20 12:36:29 -0800 | [diff] [blame] | 1015 | |
Florian Fainelli | f458995 | 2016-08-26 12:18:33 -0700 | [diff] [blame] | 1016 | /* Auto-detection using standard registers will not work, so |
| 1017 | * provide an indication of what kind of device we are for |
| 1018 | * b53_common to work with |
| 1019 | */ |
Florian Fainelli | a78e86e | 2017-01-20 12:36:29 -0800 | [diff] [blame] | 1020 | pdata->chip_id = priv->type; |
Florian Fainelli | f458995 | 2016-08-26 12:18:33 -0700 | [diff] [blame] | 1021 | dev->pdata = pdata; |
| 1022 | |
| 1023 | priv->dev = dev; |
| 1024 | ds = dev->ds; |
Florian Fainelli | 73095cb | 2017-01-08 14:52:06 -0800 | [diff] [blame] | 1025 | ds->ops = &bcm_sf2_ops; |
Florian Fainelli | f458995 | 2016-08-26 12:18:33 -0700 | [diff] [blame] | 1026 | |
Florian Fainelli | 18118377 | 2017-09-03 20:27:02 -0700 | [diff] [blame] | 1027 | /* Advertise the 8 egress queues */ |
| 1028 | ds->num_tx_queues = SF2_NUM_EGRESS_QUEUES; |
| 1029 | |
Florian Fainelli | f458995 | 2016-08-26 12:18:33 -0700 | [diff] [blame] | 1030 | dev_set_drvdata(&pdev->dev, priv); |
Florian Fainelli | d933802 | 2016-08-18 15:30:14 -0700 | [diff] [blame] | 1031 | |
Florian Fainelli | 7fbb1a9 | 2016-06-09 17:42:06 -0700 | [diff] [blame] | 1032 | spin_lock_init(&priv->indir_lock); |
| 1033 | mutex_init(&priv->stats_mutex); |
Florian Fainelli | 7318166 | 2017-01-30 09:48:43 -0800 | [diff] [blame] | 1034 | mutex_init(&priv->cfp.lock); |
| 1035 | |
| 1036 | /* CFP rule #0 cannot be used for specific classifications, flag it as |
| 1037 | * permanently used |
| 1038 | */ |
| 1039 | set_bit(0, priv->cfp.used); |
Florian Fainelli | 7fbb1a9 | 2016-06-09 17:42:06 -0700 | [diff] [blame] | 1040 | |
Florian Fainelli | d933802 | 2016-08-18 15:30:14 -0700 | [diff] [blame] | 1041 | bcm_sf2_identify_ports(priv, dn->child); |
Florian Fainelli | 7fbb1a9 | 2016-06-09 17:42:06 -0700 | [diff] [blame] | 1042 | |
| 1043 | priv->irq0 = irq_of_parse_and_map(dn, 0); |
| 1044 | priv->irq1 = irq_of_parse_and_map(dn, 1); |
| 1045 | |
| 1046 | base = &priv->core; |
| 1047 | for (i = 0; i < BCM_SF2_REGS_NUM; i++) { |
Florian Fainelli | 4bd1167 | 2016-08-18 15:30:15 -0700 | [diff] [blame] | 1048 | r = platform_get_resource(pdev, IORESOURCE_MEM, i); |
| 1049 | *base = devm_ioremap_resource(&pdev->dev, r); |
| 1050 | if (IS_ERR(*base)) { |
Florian Fainelli | 7fbb1a9 | 2016-06-09 17:42:06 -0700 | [diff] [blame] | 1051 | pr_err("unable to find register: %s\n", reg_names[i]); |
Florian Fainelli | 4bd1167 | 2016-08-18 15:30:15 -0700 | [diff] [blame] | 1052 | return PTR_ERR(*base); |
Florian Fainelli | 7fbb1a9 | 2016-06-09 17:42:06 -0700 | [diff] [blame] | 1053 | } |
| 1054 | base++; |
| 1055 | } |
| 1056 | |
| 1057 | ret = bcm_sf2_sw_rst(priv); |
| 1058 | if (ret) { |
| 1059 | pr_err("unable to software reset switch: %d\n", ret); |
Florian Fainelli | 4bd1167 | 2016-08-18 15:30:15 -0700 | [diff] [blame] | 1060 | return ret; |
Florian Fainelli | 7fbb1a9 | 2016-06-09 17:42:06 -0700 | [diff] [blame] | 1061 | } |
| 1062 | |
| 1063 | ret = bcm_sf2_mdio_register(ds); |
| 1064 | if (ret) { |
| 1065 | pr_err("failed to register MDIO bus\n"); |
Florian Fainelli | 4bd1167 | 2016-08-18 15:30:15 -0700 | [diff] [blame] | 1066 | return ret; |
Florian Fainelli | 7fbb1a9 | 2016-06-09 17:42:06 -0700 | [diff] [blame] | 1067 | } |
| 1068 | |
Florian Fainelli | 7318166 | 2017-01-30 09:48:43 -0800 | [diff] [blame] | 1069 | ret = bcm_sf2_cfp_rst(priv); |
| 1070 | if (ret) { |
| 1071 | pr_err("failed to reset CFP\n"); |
| 1072 | goto out_mdio; |
| 1073 | } |
| 1074 | |
Florian Fainelli | 7fbb1a9 | 2016-06-09 17:42:06 -0700 | [diff] [blame] | 1075 | /* Disable all interrupts and request them */ |
| 1076 | bcm_sf2_intr_disable(priv); |
| 1077 | |
Florian Fainelli | 4bd1167 | 2016-08-18 15:30:15 -0700 | [diff] [blame] | 1078 | ret = devm_request_irq(&pdev->dev, priv->irq0, bcm_sf2_switch_0_isr, 0, |
| 1079 | "switch_0", priv); |
Florian Fainelli | 7fbb1a9 | 2016-06-09 17:42:06 -0700 | [diff] [blame] | 1080 | if (ret < 0) { |
| 1081 | pr_err("failed to request switch_0 IRQ\n"); |
Florian Fainelli | bb9c0fa | 2016-07-29 12:35:57 -0700 | [diff] [blame] | 1082 | goto out_mdio; |
Florian Fainelli | 7fbb1a9 | 2016-06-09 17:42:06 -0700 | [diff] [blame] | 1083 | } |
| 1084 | |
Florian Fainelli | 4bd1167 | 2016-08-18 15:30:15 -0700 | [diff] [blame] | 1085 | ret = devm_request_irq(&pdev->dev, priv->irq1, bcm_sf2_switch_1_isr, 0, |
| 1086 | "switch_1", priv); |
Florian Fainelli | 7fbb1a9 | 2016-06-09 17:42:06 -0700 | [diff] [blame] | 1087 | if (ret < 0) { |
| 1088 | pr_err("failed to request switch_1 IRQ\n"); |
Florian Fainelli | 4bd1167 | 2016-08-18 15:30:15 -0700 | [diff] [blame] | 1089 | goto out_mdio; |
Florian Fainelli | 7fbb1a9 | 2016-06-09 17:42:06 -0700 | [diff] [blame] | 1090 | } |
| 1091 | |
| 1092 | /* Reset the MIB counters */ |
| 1093 | reg = core_readl(priv, CORE_GMNCFGCFG); |
| 1094 | reg |= RST_MIB_CNT; |
| 1095 | core_writel(priv, reg, CORE_GMNCFGCFG); |
| 1096 | reg &= ~RST_MIB_CNT; |
| 1097 | core_writel(priv, reg, CORE_GMNCFGCFG); |
| 1098 | |
| 1099 | /* Get the maximum number of ports for this switch */ |
| 1100 | priv->hw_params.num_ports = core_readl(priv, CORE_IMP0_PRT_ID) + 1; |
| 1101 | if (priv->hw_params.num_ports > DSA_MAX_PORTS) |
| 1102 | priv->hw_params.num_ports = DSA_MAX_PORTS; |
| 1103 | |
| 1104 | /* Assume a single GPHY setup if we can't read that property */ |
| 1105 | if (of_property_read_u32(dn, "brcm,num-gphy", |
| 1106 | &priv->hw_params.num_gphy)) |
| 1107 | priv->hw_params.num_gphy = 1; |
| 1108 | |
Florian Fainelli | 7fbb1a9 | 2016-06-09 17:42:06 -0700 | [diff] [blame] | 1109 | rev = reg_readl(priv, REG_SWITCH_REVISION); |
| 1110 | priv->hw_params.top_rev = (rev >> SWITCH_TOP_REV_SHIFT) & |
| 1111 | SWITCH_TOP_REV_MASK; |
| 1112 | priv->hw_params.core_rev = (rev & SF2_REV_MASK); |
| 1113 | |
| 1114 | rev = reg_readl(priv, REG_PHY_REVISION); |
| 1115 | priv->hw_params.gphy_rev = rev & PHY_REVISION_MASK; |
| 1116 | |
Florian Fainelli | f458995 | 2016-08-26 12:18:33 -0700 | [diff] [blame] | 1117 | ret = b53_switch_register(dev); |
Florian Fainelli | d933802 | 2016-08-18 15:30:14 -0700 | [diff] [blame] | 1118 | if (ret) |
Florian Fainelli | 4bd1167 | 2016-08-18 15:30:15 -0700 | [diff] [blame] | 1119 | goto out_mdio; |
Florian Fainelli | d933802 | 2016-08-18 15:30:14 -0700 | [diff] [blame] | 1120 | |
Florian Fainelli | 7fbb1a9 | 2016-06-09 17:42:06 -0700 | [diff] [blame] | 1121 | pr_info("Starfighter 2 top: %x.%02x, core: %x.%02x base: 0x%p, IRQs: %d, %d\n", |
| 1122 | priv->hw_params.top_rev >> 8, priv->hw_params.top_rev & 0xff, |
| 1123 | priv->hw_params.core_rev >> 8, priv->hw_params.core_rev & 0xff, |
| 1124 | priv->core, priv->irq0, priv->irq1); |
| 1125 | |
| 1126 | return 0; |
| 1127 | |
Florian Fainelli | bb9c0fa | 2016-07-29 12:35:57 -0700 | [diff] [blame] | 1128 | out_mdio: |
| 1129 | bcm_sf2_mdio_unregister(priv); |
Florian Fainelli | 7fbb1a9 | 2016-06-09 17:42:06 -0700 | [diff] [blame] | 1130 | return ret; |
| 1131 | } |
| 1132 | |
Florian Fainelli | d933802 | 2016-08-18 15:30:14 -0700 | [diff] [blame] | 1133 | static int bcm_sf2_sw_remove(struct platform_device *pdev) |
Florian Fainelli | 246d7f7 | 2014-08-27 17:04:56 -0700 | [diff] [blame] | 1134 | { |
Florian Fainelli | f458995 | 2016-08-26 12:18:33 -0700 | [diff] [blame] | 1135 | struct bcm_sf2_priv *priv = platform_get_drvdata(pdev); |
Florian Fainelli | d933802 | 2016-08-18 15:30:14 -0700 | [diff] [blame] | 1136 | |
| 1137 | /* Disable all ports and interrupts */ |
| 1138 | priv->wol_ports_mask = 0; |
Florian Fainelli | f458995 | 2016-08-26 12:18:33 -0700 | [diff] [blame] | 1139 | bcm_sf2_sw_suspend(priv->dev->ds); |
| 1140 | dsa_unregister_switch(priv->dev->ds); |
Florian Fainelli | d933802 | 2016-08-18 15:30:14 -0700 | [diff] [blame] | 1141 | bcm_sf2_mdio_unregister(priv); |
Florian Fainelli | 246d7f7 | 2014-08-27 17:04:56 -0700 | [diff] [blame] | 1142 | |
| 1143 | return 0; |
| 1144 | } |
Florian Fainelli | 246d7f7 | 2014-08-27 17:04:56 -0700 | [diff] [blame] | 1145 | |
Florian Fainelli | 2399d61 | 2016-10-20 09:32:19 -0700 | [diff] [blame] | 1146 | static void bcm_sf2_sw_shutdown(struct platform_device *pdev) |
| 1147 | { |
| 1148 | struct bcm_sf2_priv *priv = platform_get_drvdata(pdev); |
| 1149 | |
| 1150 | /* For a kernel about to be kexec'd we want to keep the GPHY on for a |
| 1151 | * successful MDIO bus scan to occur. If we did turn off the GPHY |
| 1152 | * before (e.g: port_disable), this will also power it back on. |
Florian Fainelli | 4a2947e | 2016-10-21 14:21:56 -0700 | [diff] [blame] | 1153 | * |
| 1154 | * Do not rely on kexec_in_progress, just power the PHY on. |
Florian Fainelli | 2399d61 | 2016-10-20 09:32:19 -0700 | [diff] [blame] | 1155 | */ |
| 1156 | if (priv->hw_params.num_gphy == 1) |
Florian Fainelli | 4a2947e | 2016-10-21 14:21:56 -0700 | [diff] [blame] | 1157 | bcm_sf2_gphy_enable_set(priv->dev->ds, true); |
Florian Fainelli | 2399d61 | 2016-10-20 09:32:19 -0700 | [diff] [blame] | 1158 | } |
| 1159 | |
Florian Fainelli | d933802 | 2016-08-18 15:30:14 -0700 | [diff] [blame] | 1160 | #ifdef CONFIG_PM_SLEEP |
| 1161 | static int bcm_sf2_suspend(struct device *dev) |
Florian Fainelli | 246d7f7 | 2014-08-27 17:04:56 -0700 | [diff] [blame] | 1162 | { |
Florian Fainelli | d933802 | 2016-08-18 15:30:14 -0700 | [diff] [blame] | 1163 | struct platform_device *pdev = to_platform_device(dev); |
Florian Fainelli | f458995 | 2016-08-26 12:18:33 -0700 | [diff] [blame] | 1164 | struct bcm_sf2_priv *priv = platform_get_drvdata(pdev); |
Florian Fainelli | d933802 | 2016-08-18 15:30:14 -0700 | [diff] [blame] | 1165 | |
Florian Fainelli | f458995 | 2016-08-26 12:18:33 -0700 | [diff] [blame] | 1166 | return dsa_switch_suspend(priv->dev->ds); |
Florian Fainelli | 246d7f7 | 2014-08-27 17:04:56 -0700 | [diff] [blame] | 1167 | } |
Florian Fainelli | d933802 | 2016-08-18 15:30:14 -0700 | [diff] [blame] | 1168 | |
| 1169 | static int bcm_sf2_resume(struct device *dev) |
| 1170 | { |
| 1171 | struct platform_device *pdev = to_platform_device(dev); |
Florian Fainelli | f458995 | 2016-08-26 12:18:33 -0700 | [diff] [blame] | 1172 | struct bcm_sf2_priv *priv = platform_get_drvdata(pdev); |
Florian Fainelli | d933802 | 2016-08-18 15:30:14 -0700 | [diff] [blame] | 1173 | |
Florian Fainelli | f458995 | 2016-08-26 12:18:33 -0700 | [diff] [blame] | 1174 | return dsa_switch_resume(priv->dev->ds); |
Florian Fainelli | d933802 | 2016-08-18 15:30:14 -0700 | [diff] [blame] | 1175 | } |
| 1176 | #endif /* CONFIG_PM_SLEEP */ |
| 1177 | |
| 1178 | static SIMPLE_DEV_PM_OPS(bcm_sf2_pm_ops, |
| 1179 | bcm_sf2_suspend, bcm_sf2_resume); |
| 1180 | |
Florian Fainelli | d933802 | 2016-08-18 15:30:14 -0700 | [diff] [blame] | 1181 | |
| 1182 | static struct platform_driver bcm_sf2_driver = { |
| 1183 | .probe = bcm_sf2_sw_probe, |
| 1184 | .remove = bcm_sf2_sw_remove, |
Florian Fainelli | 2399d61 | 2016-10-20 09:32:19 -0700 | [diff] [blame] | 1185 | .shutdown = bcm_sf2_sw_shutdown, |
Florian Fainelli | d933802 | 2016-08-18 15:30:14 -0700 | [diff] [blame] | 1186 | .driver = { |
| 1187 | .name = "brcm-sf2", |
| 1188 | .of_match_table = bcm_sf2_of_match, |
| 1189 | .pm = &bcm_sf2_pm_ops, |
| 1190 | }, |
| 1191 | }; |
| 1192 | module_platform_driver(bcm_sf2_driver); |
Florian Fainelli | 246d7f7 | 2014-08-27 17:04:56 -0700 | [diff] [blame] | 1193 | |
| 1194 | MODULE_AUTHOR("Broadcom Corporation"); |
| 1195 | MODULE_DESCRIPTION("Driver for Broadcom Starfighter 2 ethernet switch chip"); |
| 1196 | MODULE_LICENSE("GPL"); |
| 1197 | MODULE_ALIAS("platform:brcm-sf2"); |