blob: 00afc94ce522c03e2eae81016e7f56541df22054 [file] [log] [blame]
Thomas Gleixner2874c5f2019-05-27 08:55:01 +02001/* SPDX-License-Identifier: GPL-2.0-or-later */
Florian Fainelli246d7f72014-08-27 17:04:56 -07002/*
3 * Broadcom Starfighter2 private context
4 *
5 * Copyright (C) 2014, Broadcom Corporation
Florian Fainelli246d7f72014-08-27 17:04:56 -07006 */
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 Fainelli450b05c2014-09-24 17:05:22 -070017#include <linux/ethtool.h>
Florian Fainelli680060d2015-10-23 11:38:07 -070018#include <linux/types.h>
19#include <linux/bitops.h>
Florian Fainelli9c57a772016-06-09 17:42:08 -070020#include <linux/if_vlan.h>
Florian Fainellieee87e42019-11-04 13:51:39 -080021#include <linux/reset.h>
Florian Fainelli246d7f72014-08-27 17:04:56 -070022
23#include <net/dsa.h>
24
25#include "bcm_sf2_regs.h"
Florian Fainellif4589952016-08-26 12:18:33 -070026#include "b53/b53_priv.h"
Florian Fainelli246d7f72014-08-27 17:04:56 -070027
28struct bcm_sf2_hw_params {
29 u16 top_rev;
30 u16 core_rev;
Florian Fainelliaa9aef72014-09-19 13:07:55 -070031 u16 gphy_rev;
Florian Fainelli246d7f72014-08-27 17:04:56 -070032 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
46struct bcm_sf2_port_status {
Rafał Miłecki01488a02021-03-12 11:41:07 +010047 phy_interface_t mode;
Florian Fainelli246d7f72014-08-27 17:04:56 -070048 unsigned int link;
Florian Fainelli2ee3adc2020-09-01 15:59:13 -070049 bool enabled;
Florian Fainelli246d7f72014-08-27 17:04:56 -070050};
51
Florian Fainelli73181662017-01-30 09:48:43 -080052struct 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 Fainelliba0696c2017-10-20 14:39:47 -070056 DECLARE_BITMAP(unique, CFP_NUM_RULES);
Florian Fainelli73181662017-01-30 09:48:43 -080057 unsigned int rules_cnt;
Florian Fainelliae7a5af2018-11-06 12:58:37 -080058 struct list_head rules_list;
Florian Fainelli73181662017-01-30 09:48:43 -080059};
60
Florian Fainelli246d7f72014-08-27 17:04:56 -070061struct 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 Fainellieee87e42019-11-04 13:51:39 -080070 struct reset_control *rcdev;
71
Florian Fainellia78e86e2017-01-20 12:36:29 -080072 /* Register offsets indirection tables */
73 u32 type;
74 const u16 *reg_offsets;
75 unsigned int core_reg_align;
Florian Fainellidf191632017-08-30 12:39:33 -070076 unsigned int num_cfp_rules;
Rafał Miłeckia9349f02021-03-12 11:41:08 +010077 unsigned int num_crossbar_int_ports;
Florian Fainellia78e86e2017-01-20 12:36:29 -080078
Florian Fainelli246d7f72014-08-27 17:04:56 -070079 /* 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 Fainellif4589952016-08-26 12:18:33 -070089 /* Backing b53_device */
90 struct b53_device *dev;
91
Florian Fainelli246d7f72014-08-27 17:04:56 -070092 struct bcm_sf2_hw_params hw_params;
93
94 struct bcm_sf2_port_status port_sts[DSA_MAX_PORTS];
Florian Fainelli96e65d72014-09-18 17:31:25 -070095
96 /* Mask of ports enabled for Wake-on-LAN */
97 u32 wol_ports_mask;
Florian Fainelli8b7c94e2015-10-23 12:11:08 -070098
Florian Fainellie9ec5c32020-09-01 15:59:12 -070099 struct clk *clk;
Florian Fainelli2ee3adc2020-09-01 15:59:13 -0700100 struct clk *clk_mdiv;
Florian Fainellie9ec5c32020-09-01 15:59:12 -0700101
Florian Fainelli8b7c94e2015-10-23 12:11:08 -0700102 /* MoCA port location */
103 int moca_port;
104
105 /* Bitmask of ports having an integrated PHY */
106 unsigned int int_phy_mask;
Florian Fainelli461cd1b02016-06-07 16:32:43 -0700107
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 Fainelli64ff2ae2017-01-20 12:36:32 -0800113
114 /* Bitmask of ports needing BRCM tags */
115 unsigned int brcm_tag_mask;
Florian Fainelli73181662017-01-30 09:48:43 -0800116
117 /* CFP rules context */
118 struct bcm_sf2_cfp_priv cfp;
Florian Fainelli246d7f72014-08-27 17:04:56 -0700119};
120
Florian Fainellif4589952016-08-26 12:18:33 -0700121static inline struct bcm_sf2_priv *bcm_sf2_to_priv(struct dsa_switch *ds)
122{
Vivien Didelot04bed142016-08-31 18:06:13 -0400123 struct b53_device *dev = ds->priv;
Florian Fainellif4589952016-08-26 12:18:33 -0700124
125 return dev->priv;
126}
127
Florian Fainellia78e86e2017-01-20 12:36:29 -0800128static inline u32 bcm_sf2_mangle_addr(struct bcm_sf2_priv *priv, u32 off)
129{
130 return off << priv->core_reg_align;
131}
132
Florian Fainelli246d7f72014-08-27 17:04:56 -0700133#define SF2_IO_MACRO(name) \
134static inline u32 name##_readl(struct bcm_sf2_priv *priv, u32 off) \
135{ \
Florian Fainellifdb71a22017-08-29 13:35:16 -0700136 return readl_relaxed(priv->name + off); \
Florian Fainelli246d7f72014-08-27 17:04:56 -0700137} \
138static inline void name##_writel(struct bcm_sf2_priv *priv, \
139 u32 val, u32 off) \
140{ \
Florian Fainellifdb71a22017-08-29 13:35:16 -0700141 writel_relaxed(val, priv->name + off); \
Florian Fainelli246d7f72014-08-27 17:04:56 -0700142} \
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) \
150static inline u64 name##_readq(struct bcm_sf2_priv *priv, u32 off) \
151{ \
152 u32 indir, dir; \
153 spin_lock(&priv->indir_lock); \
Florian Fainelli329b5c52017-01-20 12:36:28 -0800154 dir = name##_readl(priv, off); \
Florian Fainelliddede6d2015-02-19 11:09:27 -0800155 indir = reg_readl(priv, REG_DIR_DATA_READ); \
Florian Fainelli246d7f72014-08-27 17:04:56 -0700156 spin_unlock(&priv->indir_lock); \
157 return (u64)indir << 32 | dir; \
158} \
Florian Fainelli03679a12015-09-08 20:06:41 -0700159static inline void name##_writeq(struct bcm_sf2_priv *priv, u64 val, \
160 u32 off) \
Florian Fainelli246d7f72014-08-27 17:04:56 -0700161{ \
162 spin_lock(&priv->indir_lock); \
163 reg_writel(priv, upper_32_bits(val), REG_DIR_DATA_WRITE); \
Florian Fainelli329b5c52017-01-20 12:36:28 -0800164 name##_writel(priv, lower_32_bits(val), off); \
Florian Fainelli246d7f72014-08-27 17:04:56 -0700165 spin_unlock(&priv->indir_lock); \
166}
167
168#define SWITCH_INTR_L2(which) \
169static inline void intrl2_##which##_mask_clear(struct bcm_sf2_priv *priv, \
170 u32 mask) \
171{ \
Florian Fainelli246d7f72014-08-27 17:04:56 -0700172 priv->irq##which##_mask &= ~(mask); \
Florian Fainelli4f101c42016-08-24 11:01:20 -0700173 intrl2_##which##_writel(priv, mask, INTRL2_CPU_MASK_CLEAR); \
Florian Fainelli246d7f72014-08-27 17:04:56 -0700174} \
175static 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 Fainellia78e86e2017-01-20 12:36:29 -0800182static inline u32 core_readl(struct bcm_sf2_priv *priv, u32 off)
183{
184 u32 tmp = bcm_sf2_mangle_addr(priv, off);
Florian Fainellifdb71a22017-08-29 13:35:16 -0700185 return readl_relaxed(priv->core + tmp);
Florian Fainellia78e86e2017-01-20 12:36:29 -0800186}
187
188static inline void core_writel(struct bcm_sf2_priv *priv, u32 val, u32 off)
189{
190 u32 tmp = bcm_sf2_mangle_addr(priv, off);
Florian Fainellifdb71a22017-08-29 13:35:16 -0700191 writel_relaxed(val, priv->core + tmp);
Florian Fainellia78e86e2017-01-20 12:36:29 -0800192}
193
194static inline u32 reg_readl(struct bcm_sf2_priv *priv, u16 off)
195{
Florian Fainellifdb71a22017-08-29 13:35:16 -0700196 return readl_relaxed(priv->reg + priv->reg_offsets[off]);
Florian Fainellia78e86e2017-01-20 12:36:29 -0800197}
198
199static inline void reg_writel(struct bcm_sf2_priv *priv, u32 val, u16 off)
200{
Florian Fainellifdb71a22017-08-29 13:35:16 -0700201 writel_relaxed(val, priv->reg + priv->reg_offsets[off]);
Florian Fainellia78e86e2017-01-20 12:36:29 -0800202}
203
Florian Fainelli246d7f72014-08-27 17:04:56 -0700204SF2_IO64_MACRO(core);
205SF2_IO_MACRO(intrl2_0);
206SF2_IO_MACRO(intrl2_1);
207SF2_IO_MACRO(fcb);
208SF2_IO_MACRO(acb);
209
210SWITCH_INTR_L2(0);
211SWITCH_INTR_L2(1);
212
Rafał Miłeckiaf30f8e2021-12-29 18:16:42 +0100213static 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
218static 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 Fainelli73181662017-01-30 09:48:43 -0800223/* RXNFC */
224int bcm_sf2_get_rxnfc(struct dsa_switch *ds, int port,
225 struct ethtool_rxnfc *nfc, u32 *rule_locs);
226int bcm_sf2_set_rxnfc(struct dsa_switch *ds, int port,
227 struct ethtool_rxnfc *nfc);
228int bcm_sf2_cfp_rst(struct bcm_sf2_priv *priv);
Florian Fainelliae7a5af2018-11-06 12:58:37 -0800229void bcm_sf2_cfp_exit(struct dsa_switch *ds);
Florian Fainelli1c0130f2018-11-06 12:58:39 -0800230int bcm_sf2_cfp_resume(struct dsa_switch *ds);
Florian Fainellif4ae9c02019-02-06 12:45:59 -0800231void bcm_sf2_cfp_get_strings(struct dsa_switch *ds, int port,
232 u32 stringset, uint8_t *data);
233void bcm_sf2_cfp_get_ethtool_stats(struct dsa_switch *ds, int port,
234 uint64_t *data);
235int bcm_sf2_cfp_get_sset_count(struct dsa_switch *ds, int port, int sset);
Florian Fainelli73181662017-01-30 09:48:43 -0800236
Florian Fainelli246d7f72014-08-27 17:04:56 -0700237#endif /* __BCM_SF2_H */