1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 * Broadcom Starfighter2 private context
5 * Copyright (C) 2014, Broadcom Corporation
11 #include <linux/platform_device.h>
12 #include <linux/kernel.h>
14 #include <linux/spinlock.h>
15 #include <linux/mutex.h>
16 #include <linux/mii.h>
17 #include <linux/ethtool.h>
18 #include <linux/types.h>
19 #include <linux/bitops.h>
20 #include <linux/if_vlan.h>
21 #include <linux/reset.h>
25 #include "bcm_sf2_regs.h"
26 #include "b53/b53_priv.h"
28 struct bcm_sf2_hw_params
{
36 u8 fcb_pause_override
:1;
37 u8 acb_packets_inflight
:1;
40 #define BCM_SF2_REGS_NAME {\
41 "core", "reg", "intrl2_0", "intrl2_1", "fcb", "acb" \
44 #define BCM_SF2_REGS_NUM 6
46 struct bcm_sf2_port_status
{
52 struct bcm_sf2_cfp_priv
{
53 /* Mutex protecting concurrent accesses to the CFP registers */
55 DECLARE_BITMAP(used
, CFP_NUM_RULES
);
56 DECLARE_BITMAP(unique
, CFP_NUM_RULES
);
57 unsigned int rules_cnt
;
58 struct list_head rules_list
;
62 /* Base registers, keep those in order with BCM_SF2_REGS_NAME */
65 void __iomem
*intrl2_0
;
66 void __iomem
*intrl2_1
;
70 struct reset_control
*rcdev
;
72 /* Register offsets indirection tables */
74 const u16
*reg_offsets
;
75 unsigned int core_reg_align
;
76 unsigned int num_cfp_rules
;
77 unsigned int num_crossbar_int_ports
;
78 unsigned int num_crossbar_ext_bits
;
80 /* spinlock protecting access to the indirect registers */
81 spinlock_t indir_lock
;
90 /* Backing b53_device */
91 struct b53_device
*dev
;
93 struct bcm_sf2_hw_params hw_params
;
95 struct bcm_sf2_port_status port_sts
[DSA_MAX_PORTS
];
97 /* Mask of ports enabled for Wake-on-LAN */
101 struct clk
*clk_mdiv
;
103 /* MoCA port location */
106 /* Bitmask of ports having an integrated PHY */
107 unsigned int int_phy_mask
;
109 /* Master and slave MDIO bus controller */
110 unsigned int indir_phy_mask
;
111 struct mii_bus
*user_mii_bus
;
112 struct mii_bus
*master_mii_bus
;
114 /* Bitmask of ports needing BRCM tags */
115 unsigned int brcm_tag_mask
;
117 /* CFP rules context */
118 struct bcm_sf2_cfp_priv cfp
;
121 static inline struct bcm_sf2_priv
*bcm_sf2_to_priv(struct dsa_switch
*ds
)
123 struct b53_device
*dev
= ds
->priv
;
128 static inline u32
bcm_sf2_mangle_addr(struct bcm_sf2_priv
*priv
, u32 off
)
130 return off
<< priv
->core_reg_align
;
133 #define SF2_IO_MACRO(name) \
134 static inline u32 name##_readl(struct bcm_sf2_priv *priv, u32 off) \
136 return readl_relaxed(priv->name + off); \
138 static inline void name##_writel(struct bcm_sf2_priv *priv, \
141 writel_relaxed(val, priv->name + off); \
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.
149 #define SF2_IO64_MACRO(name) \
150 static inline u64 name##_readq(struct bcm_sf2_priv *priv, u32 off) \
153 spin_lock(&priv->indir_lock); \
154 dir = name##_readl(priv, off); \
155 indir = reg_readl(priv, REG_DIR_DATA_READ); \
156 spin_unlock(&priv->indir_lock); \
157 return (u64)indir << 32 | dir; \
159 static inline void name##_writeq(struct bcm_sf2_priv *priv, u64 val, \
162 spin_lock(&priv->indir_lock); \
163 reg_writel(priv, upper_32_bits(val), REG_DIR_DATA_WRITE); \
164 name##_writel(priv, lower_32_bits(val), off); \
165 spin_unlock(&priv->indir_lock); \
168 #define SWITCH_INTR_L2(which) \
169 static inline void intrl2_##which##_mask_clear(struct bcm_sf2_priv *priv, \
172 priv->irq##which##_mask &= ~(mask); \
173 intrl2_##which##_writel(priv, mask, INTRL2_CPU_MASK_CLEAR); \
175 static inline void intrl2_##which##_mask_set(struct bcm_sf2_priv *priv, \
178 intrl2_## which##_writel(priv, mask, INTRL2_CPU_MASK_SET); \
179 priv->irq##which##_mask |= (mask); \
182 static inline u32 core_readl(struct bcm_sf2_priv *priv, u32 off)
184 u32 tmp
= bcm_sf2_mangle_addr(priv
, off
);
185 return readl_relaxed(priv
->core
+ tmp
);
188 static inline void core_writel(struct bcm_sf2_priv
*priv
, u32 val
, u32 off
)
190 u32 tmp
= bcm_sf2_mangle_addr(priv
, off
);
191 writel_relaxed(val
, priv
->core
+ tmp
);
194 static inline u32
reg_readl(struct bcm_sf2_priv
*priv
, u16 off
)
196 return readl_relaxed(priv
->reg
+ priv
->reg_offsets
[off
]);
199 static inline void reg_writel(struct bcm_sf2_priv
*priv
, u32 val
, u16 off
)
201 writel_relaxed(val
, priv
->reg
+ priv
->reg_offsets
[off
]);
204 SF2_IO64_MACRO(core
);
205 SF2_IO_MACRO(intrl2_0
);
206 SF2_IO_MACRO(intrl2_1
);
213 static inline u32
reg_led_readl(struct bcm_sf2_priv
*priv
, u16 off
, u16 reg
)
215 return readl_relaxed(priv
->reg
+ priv
->reg_offsets
[off
] + reg
);
218 static inline void reg_led_writel(struct bcm_sf2_priv
*priv
, u32 val
, u16 off
, u16 reg
)
220 writel_relaxed(val
, priv
->reg
+ priv
->reg_offsets
[off
] + reg
);
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
);
229 void bcm_sf2_cfp_exit(struct dsa_switch
*ds
);
230 int bcm_sf2_cfp_resume(struct dsa_switch
*ds
);
231 void bcm_sf2_cfp_get_strings(struct dsa_switch
*ds
, int port
, u32 stringset
,
233 void bcm_sf2_cfp_get_ethtool_stats(struct dsa_switch
*ds
, int port
,
235 int bcm_sf2_cfp_get_sset_count(struct dsa_switch
*ds
, int port
, int sset
);
237 #endif /* __BCM_SF2_H */