Thomas Gleixner | 2874c5f | 2019-05-27 08:55:01 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
Florian Fainelli | 246d7f7 | 2014-08-27 17:04:56 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Broadcom Starfighter2 private context |
| 4 | * |
| 5 | * Copyright (C) 2014, Broadcom Corporation |
Florian Fainelli | 246d7f7 | 2014-08-27 17:04:56 -0700 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #ifndef __BCM_SF2_H |
| 9 | #define __BCM_SF2_H |
| 10 | |
| 11 | #include <linux/platform_device.h> |
| 12 | #include <linux/kernel.h> |
| 13 | #include <linux/io.h> |
| 14 | #include <linux/spinlock.h> |
| 15 | #include <linux/mutex.h> |
| 16 | #include <linux/mii.h> |
Florian Fainelli | 450b05c | 2014-09-24 17:05:22 -0700 | [diff] [blame] | 17 | #include <linux/ethtool.h> |
Florian Fainelli | 680060d | 2015-10-23 11:38:07 -0700 | [diff] [blame] | 18 | #include <linux/types.h> |
| 19 | #include <linux/bitops.h> |
Florian Fainelli | 9c57a77 | 2016-06-09 17:42:08 -0700 | [diff] [blame] | 20 | #include <linux/if_vlan.h> |
Florian Fainelli | eee87e4 | 2019-11-04 13:51:39 -0800 | [diff] [blame] | 21 | #include <linux/reset.h> |
Florian Fainelli | 246d7f7 | 2014-08-27 17:04:56 -0700 | [diff] [blame] | 22 | |
| 23 | #include <net/dsa.h> |
| 24 | |
| 25 | #include "bcm_sf2_regs.h" |
Florian Fainelli | f458995 | 2016-08-26 12:18:33 -0700 | [diff] [blame] | 26 | #include "b53/b53_priv.h" |
Florian Fainelli | 246d7f7 | 2014-08-27 17:04:56 -0700 | [diff] [blame] | 27 | |
| 28 | struct bcm_sf2_hw_params { |
| 29 | u16 top_rev; |
| 30 | u16 core_rev; |
Florian Fainelli | aa9aef7 | 2014-09-19 13:07:55 -0700 | [diff] [blame] | 31 | u16 gphy_rev; |
Florian Fainelli | 246d7f7 | 2014-08-27 17:04:56 -0700 | [diff] [blame] | 32 | u32 num_gphy; |
| 33 | u8 num_acb_queue; |
| 34 | u8 num_rgmii; |
| 35 | u8 num_ports; |
| 36 | u8 fcb_pause_override:1; |
| 37 | u8 acb_packets_inflight:1; |
| 38 | }; |
| 39 | |
| 40 | #define BCM_SF2_REGS_NAME {\ |
| 41 | "core", "reg", "intrl2_0", "intrl2_1", "fcb", "acb" \ |
| 42 | } |
| 43 | |
| 44 | #define BCM_SF2_REGS_NUM 6 |
| 45 | |
| 46 | struct bcm_sf2_port_status { |
Rafał Miłecki | 01488a0 | 2021-03-12 11:41:07 +0100 | [diff] [blame] | 47 | phy_interface_t mode; |
Florian Fainelli | 246d7f7 | 2014-08-27 17:04:56 -0700 | [diff] [blame] | 48 | unsigned int link; |
Florian Fainelli | 2ee3adc | 2020-09-01 15:59:13 -0700 | [diff] [blame] | 49 | bool enabled; |
Florian Fainelli | 246d7f7 | 2014-08-27 17:04:56 -0700 | [diff] [blame] | 50 | }; |
| 51 | |
Florian Fainelli | 7318166 | 2017-01-30 09:48:43 -0800 | [diff] [blame] | 52 | struct bcm_sf2_cfp_priv { |
| 53 | /* Mutex protecting concurrent accesses to the CFP registers */ |
| 54 | struct mutex lock; |
| 55 | DECLARE_BITMAP(used, CFP_NUM_RULES); |
Florian Fainelli | ba0696c | 2017-10-20 14:39:47 -0700 | [diff] [blame] | 56 | DECLARE_BITMAP(unique, CFP_NUM_RULES); |
Florian Fainelli | 7318166 | 2017-01-30 09:48:43 -0800 | [diff] [blame] | 57 | unsigned int rules_cnt; |
Florian Fainelli | ae7a5af | 2018-11-06 12:58:37 -0800 | [diff] [blame] | 58 | struct list_head rules_list; |
Florian Fainelli | 7318166 | 2017-01-30 09:48:43 -0800 | [diff] [blame] | 59 | }; |
| 60 | |
Florian Fainelli | 246d7f7 | 2014-08-27 17:04:56 -0700 | [diff] [blame] | 61 | struct bcm_sf2_priv { |
| 62 | /* Base registers, keep those in order with BCM_SF2_REGS_NAME */ |
| 63 | void __iomem *core; |
| 64 | void __iomem *reg; |
| 65 | void __iomem *intrl2_0; |
| 66 | void __iomem *intrl2_1; |
| 67 | void __iomem *fcb; |
| 68 | void __iomem *acb; |
| 69 | |
Florian Fainelli | eee87e4 | 2019-11-04 13:51:39 -0800 | [diff] [blame] | 70 | struct reset_control *rcdev; |
| 71 | |
Florian Fainelli | a78e86e | 2017-01-20 12:36:29 -0800 | [diff] [blame] | 72 | /* Register offsets indirection tables */ |
| 73 | u32 type; |
| 74 | const u16 *reg_offsets; |
| 75 | unsigned int core_reg_align; |
Florian Fainelli | df19163 | 2017-08-30 12:39:33 -0700 | [diff] [blame] | 76 | unsigned int num_cfp_rules; |
Rafał Miłecki | a9349f0 | 2021-03-12 11:41:08 +0100 | [diff] [blame] | 77 | unsigned int num_crossbar_int_ports; |
Florian Fainelli | a78e86e | 2017-01-20 12:36:29 -0800 | [diff] [blame] | 78 | |
Florian Fainelli | 246d7f7 | 2014-08-27 17:04:56 -0700 | [diff] [blame] | 79 | /* spinlock protecting access to the indirect registers */ |
| 80 | spinlock_t indir_lock; |
| 81 | |
| 82 | int irq0; |
| 83 | int irq1; |
| 84 | u32 irq0_stat; |
| 85 | u32 irq0_mask; |
| 86 | u32 irq1_stat; |
| 87 | u32 irq1_mask; |
| 88 | |
Florian Fainelli | f458995 | 2016-08-26 12:18:33 -0700 | [diff] [blame] | 89 | /* Backing b53_device */ |
| 90 | struct b53_device *dev; |
| 91 | |
Florian Fainelli | 246d7f7 | 2014-08-27 17:04:56 -0700 | [diff] [blame] | 92 | struct bcm_sf2_hw_params hw_params; |
| 93 | |
| 94 | struct bcm_sf2_port_status port_sts[DSA_MAX_PORTS]; |
Florian Fainelli | 96e65d7 | 2014-09-18 17:31:25 -0700 | [diff] [blame] | 95 | |
| 96 | /* Mask of ports enabled for Wake-on-LAN */ |
| 97 | u32 wol_ports_mask; |
Florian Fainelli | 8b7c94e | 2015-10-23 12:11:08 -0700 | [diff] [blame] | 98 | |
Florian Fainelli | e9ec5c3 | 2020-09-01 15:59:12 -0700 | [diff] [blame] | 99 | struct clk *clk; |
Florian Fainelli | 2ee3adc | 2020-09-01 15:59:13 -0700 | [diff] [blame] | 100 | struct clk *clk_mdiv; |
Florian Fainelli | e9ec5c3 | 2020-09-01 15:59:12 -0700 | [diff] [blame] | 101 | |
Florian Fainelli | 8b7c94e | 2015-10-23 12:11:08 -0700 | [diff] [blame] | 102 | /* MoCA port location */ |
| 103 | int moca_port; |
| 104 | |
| 105 | /* Bitmask of ports having an integrated PHY */ |
| 106 | unsigned int int_phy_mask; |
Florian Fainelli | 461cd1b0 | 2016-06-07 16:32:43 -0700 | [diff] [blame] | 107 | |
| 108 | /* Master and slave MDIO bus controller */ |
| 109 | unsigned int indir_phy_mask; |
| 110 | struct device_node *master_mii_dn; |
| 111 | struct mii_bus *slave_mii_bus; |
| 112 | struct mii_bus *master_mii_bus; |
Florian Fainelli | 64ff2ae | 2017-01-20 12:36:32 -0800 | [diff] [blame] | 113 | |
| 114 | /* Bitmask of ports needing BRCM tags */ |
| 115 | unsigned int brcm_tag_mask; |
Florian Fainelli | 7318166 | 2017-01-30 09:48:43 -0800 | [diff] [blame] | 116 | |
| 117 | /* CFP rules context */ |
| 118 | struct bcm_sf2_cfp_priv cfp; |
Florian Fainelli | 246d7f7 | 2014-08-27 17:04:56 -0700 | [diff] [blame] | 119 | }; |
| 120 | |
Florian Fainelli | f458995 | 2016-08-26 12:18:33 -0700 | [diff] [blame] | 121 | static inline struct bcm_sf2_priv *bcm_sf2_to_priv(struct dsa_switch *ds) |
| 122 | { |
Vivien Didelot | 04bed14 | 2016-08-31 18:06:13 -0400 | [diff] [blame] | 123 | struct b53_device *dev = ds->priv; |
Florian Fainelli | f458995 | 2016-08-26 12:18:33 -0700 | [diff] [blame] | 124 | |
| 125 | return dev->priv; |
| 126 | } |
| 127 | |
Florian Fainelli | a78e86e | 2017-01-20 12:36:29 -0800 | [diff] [blame] | 128 | static inline u32 bcm_sf2_mangle_addr(struct bcm_sf2_priv *priv, u32 off) |
| 129 | { |
| 130 | return off << priv->core_reg_align; |
| 131 | } |
| 132 | |
Florian Fainelli | 246d7f7 | 2014-08-27 17:04:56 -0700 | [diff] [blame] | 133 | #define SF2_IO_MACRO(name) \ |
| 134 | static inline u32 name##_readl(struct bcm_sf2_priv *priv, u32 off) \ |
| 135 | { \ |
Florian Fainelli | fdb71a2 | 2017-08-29 13:35:16 -0700 | [diff] [blame] | 136 | return readl_relaxed(priv->name + off); \ |
Florian Fainelli | 246d7f7 | 2014-08-27 17:04:56 -0700 | [diff] [blame] | 137 | } \ |
| 138 | static inline void name##_writel(struct bcm_sf2_priv *priv, \ |
| 139 | u32 val, u32 off) \ |
| 140 | { \ |
Florian Fainelli | fdb71a2 | 2017-08-29 13:35:16 -0700 | [diff] [blame] | 141 | writel_relaxed(val, priv->name + off); \ |
Florian Fainelli | 246d7f7 | 2014-08-27 17:04:56 -0700 | [diff] [blame] | 142 | } \ |
| 143 | |
| 144 | /* Accesses to 64-bits register requires us to latch the hi/lo pairs |
| 145 | * using the REG_DIR_DATA_{READ,WRITE} ancillary registers. The 'indir_lock' |
| 146 | * spinlock is automatically grabbed and released to provide relative |
| 147 | * atomiticy with latched reads/writes. |
| 148 | */ |
| 149 | #define SF2_IO64_MACRO(name) \ |
| 150 | static inline u64 name##_readq(struct bcm_sf2_priv *priv, u32 off) \ |
| 151 | { \ |
| 152 | u32 indir, dir; \ |
| 153 | spin_lock(&priv->indir_lock); \ |
Florian Fainelli | 329b5c5 | 2017-01-20 12:36:28 -0800 | [diff] [blame] | 154 | dir = name##_readl(priv, off); \ |
Florian Fainelli | ddede6d | 2015-02-19 11:09:27 -0800 | [diff] [blame] | 155 | indir = reg_readl(priv, REG_DIR_DATA_READ); \ |
Florian Fainelli | 246d7f7 | 2014-08-27 17:04:56 -0700 | [diff] [blame] | 156 | spin_unlock(&priv->indir_lock); \ |
| 157 | return (u64)indir << 32 | dir; \ |
| 158 | } \ |
Florian Fainelli | 03679a1 | 2015-09-08 20:06:41 -0700 | [diff] [blame] | 159 | static inline void name##_writeq(struct bcm_sf2_priv *priv, u64 val, \ |
| 160 | u32 off) \ |
Florian Fainelli | 246d7f7 | 2014-08-27 17:04:56 -0700 | [diff] [blame] | 161 | { \ |
| 162 | spin_lock(&priv->indir_lock); \ |
| 163 | reg_writel(priv, upper_32_bits(val), REG_DIR_DATA_WRITE); \ |
Florian Fainelli | 329b5c5 | 2017-01-20 12:36:28 -0800 | [diff] [blame] | 164 | name##_writel(priv, lower_32_bits(val), off); \ |
Florian Fainelli | 246d7f7 | 2014-08-27 17:04:56 -0700 | [diff] [blame] | 165 | spin_unlock(&priv->indir_lock); \ |
| 166 | } |
| 167 | |
| 168 | #define SWITCH_INTR_L2(which) \ |
| 169 | static inline void intrl2_##which##_mask_clear(struct bcm_sf2_priv *priv, \ |
| 170 | u32 mask) \ |
| 171 | { \ |
Florian Fainelli | 246d7f7 | 2014-08-27 17:04:56 -0700 | [diff] [blame] | 172 | priv->irq##which##_mask &= ~(mask); \ |
Florian Fainelli | 4f101c4 | 2016-08-24 11:01:20 -0700 | [diff] [blame] | 173 | intrl2_##which##_writel(priv, mask, INTRL2_CPU_MASK_CLEAR); \ |
Florian Fainelli | 246d7f7 | 2014-08-27 17:04:56 -0700 | [diff] [blame] | 174 | } \ |
| 175 | static inline void intrl2_##which##_mask_set(struct bcm_sf2_priv *priv, \ |
| 176 | u32 mask) \ |
| 177 | { \ |
| 178 | intrl2_## which##_writel(priv, mask, INTRL2_CPU_MASK_SET); \ |
| 179 | priv->irq##which##_mask |= (mask); \ |
| 180 | } \ |
| 181 | |
Florian Fainelli | a78e86e | 2017-01-20 12:36:29 -0800 | [diff] [blame] | 182 | static inline u32 core_readl(struct bcm_sf2_priv *priv, u32 off) |
| 183 | { |
| 184 | u32 tmp = bcm_sf2_mangle_addr(priv, off); |
Florian Fainelli | fdb71a2 | 2017-08-29 13:35:16 -0700 | [diff] [blame] | 185 | return readl_relaxed(priv->core + tmp); |
Florian Fainelli | a78e86e | 2017-01-20 12:36:29 -0800 | [diff] [blame] | 186 | } |
| 187 | |
| 188 | static inline void core_writel(struct bcm_sf2_priv *priv, u32 val, u32 off) |
| 189 | { |
| 190 | u32 tmp = bcm_sf2_mangle_addr(priv, off); |
Florian Fainelli | fdb71a2 | 2017-08-29 13:35:16 -0700 | [diff] [blame] | 191 | writel_relaxed(val, priv->core + tmp); |
Florian Fainelli | a78e86e | 2017-01-20 12:36:29 -0800 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | static inline u32 reg_readl(struct bcm_sf2_priv *priv, u16 off) |
| 195 | { |
Florian Fainelli | fdb71a2 | 2017-08-29 13:35:16 -0700 | [diff] [blame] | 196 | return readl_relaxed(priv->reg + priv->reg_offsets[off]); |
Florian Fainelli | a78e86e | 2017-01-20 12:36:29 -0800 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | static inline void reg_writel(struct bcm_sf2_priv *priv, u32 val, u16 off) |
| 200 | { |
Florian Fainelli | fdb71a2 | 2017-08-29 13:35:16 -0700 | [diff] [blame] | 201 | writel_relaxed(val, priv->reg + priv->reg_offsets[off]); |
Florian Fainelli | a78e86e | 2017-01-20 12:36:29 -0800 | [diff] [blame] | 202 | } |
| 203 | |
Florian Fainelli | 246d7f7 | 2014-08-27 17:04:56 -0700 | [diff] [blame] | 204 | SF2_IO64_MACRO(core); |
| 205 | SF2_IO_MACRO(intrl2_0); |
| 206 | SF2_IO_MACRO(intrl2_1); |
| 207 | SF2_IO_MACRO(fcb); |
| 208 | SF2_IO_MACRO(acb); |
| 209 | |
| 210 | SWITCH_INTR_L2(0); |
| 211 | SWITCH_INTR_L2(1); |
| 212 | |
Rafał Miłecki | af30f8e | 2021-12-29 18:16:42 +0100 | [diff] [blame] | 213 | static inline u32 reg_led_readl(struct bcm_sf2_priv *priv, u16 off, u16 reg) |
| 214 | { |
| 215 | return readl_relaxed(priv->reg + priv->reg_offsets[off] + reg); |
| 216 | } |
| 217 | |
| 218 | static inline void reg_led_writel(struct bcm_sf2_priv *priv, u32 val, u16 off, u16 reg) |
| 219 | { |
| 220 | writel_relaxed(val, priv->reg + priv->reg_offsets[off] + reg); |
| 221 | } |
| 222 | |
Florian Fainelli | 7318166 | 2017-01-30 09:48:43 -0800 | [diff] [blame] | 223 | /* RXNFC */ |
| 224 | int bcm_sf2_get_rxnfc(struct dsa_switch *ds, int port, |
| 225 | struct ethtool_rxnfc *nfc, u32 *rule_locs); |
| 226 | int bcm_sf2_set_rxnfc(struct dsa_switch *ds, int port, |
| 227 | struct ethtool_rxnfc *nfc); |
| 228 | int bcm_sf2_cfp_rst(struct bcm_sf2_priv *priv); |
Florian Fainelli | ae7a5af | 2018-11-06 12:58:37 -0800 | [diff] [blame] | 229 | void bcm_sf2_cfp_exit(struct dsa_switch *ds); |
Florian Fainelli | 1c0130f | 2018-11-06 12:58:39 -0800 | [diff] [blame] | 230 | int bcm_sf2_cfp_resume(struct dsa_switch *ds); |
Florian Fainelli | f4ae9c0 | 2019-02-06 12:45:59 -0800 | [diff] [blame] | 231 | void bcm_sf2_cfp_get_strings(struct dsa_switch *ds, int port, |
| 232 | u32 stringset, uint8_t *data); |
| 233 | void bcm_sf2_cfp_get_ethtool_stats(struct dsa_switch *ds, int port, |
| 234 | uint64_t *data); |
| 235 | int bcm_sf2_cfp_get_sset_count(struct dsa_switch *ds, int port, int sset); |
Florian Fainelli | 7318166 | 2017-01-30 09:48:43 -0800 | [diff] [blame] | 236 | |
Florian Fainelli | 246d7f7 | 2014-08-27 17:04:56 -0700 | [diff] [blame] | 237 | #endif /* __BCM_SF2_H */ |