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