xref: /openbmc/linux/drivers/net/dsa/sja1105/sja1105.h (revision 5804c19b80bf625c6a9925317f845e497434d6d3)
1b790b554SNishad Kamdar /* SPDX-License-Identifier: GPL-2.0 */
2b790b554SNishad Kamdar /* Copyright (c) 2018, Sensor-Technik Wiedemann GmbH
38aa9ebccSVladimir Oltean  * Copyright (c) 2018-2019, Vladimir Oltean <olteanv@gmail.com>
48aa9ebccSVladimir Oltean  */
58aa9ebccSVladimir Oltean #ifndef _SJA1105_H
68aa9ebccSVladimir Oltean #define _SJA1105_H
78aa9ebccSVladimir Oltean 
8bb77f36aSVladimir Oltean #include <linux/ptp_clock_kernel.h>
9bb77f36aSVladimir Oltean #include <linux/timecounter.h>
108aa9ebccSVladimir Oltean #include <linux/dsa/sja1105.h>
11ac02a451SVladimir Oltean #include <linux/dsa/8021q.h>
128aa9ebccSVladimir Oltean #include <net/dsa.h>
13227d07a0SVladimir Oltean #include <linux/mutex.h>
148aa9ebccSVladimir Oltean #include "sja1105_static_config.h"
158aa9ebccSVladimir Oltean 
168aa9ebccSVladimir Oltean #define SJA1105ET_FDB_BIN_SIZE		4
178456721dSVladimir Oltean /* The hardware value is in multiples of 10 ms.
188456721dSVladimir Oltean  * The passed parameter is in multiples of 1 ms.
198456721dSVladimir Oltean  */
208456721dSVladimir Oltean #define SJA1105_AGEING_TIME_MS(ms)	((ms) / 10)
213e77e59bSVladimir Oltean #define SJA1105_NUM_L2_POLICERS		SJA1110_MAX_L2_POLICING_COUNT
228aa9ebccSVladimir Oltean 
239ca482a2SVladimir Oltean /* Calculated assuming 1Gbps, where the clock has 125 MHz (8 ns period)
249ca482a2SVladimir Oltean  * To avoid floating point operations, we'll multiply the degrees by 10
259ca482a2SVladimir Oltean  * to get a "phase" and get 1 decimal point precision.
269ca482a2SVladimir Oltean  */
279ca482a2SVladimir Oltean #define SJA1105_RGMII_DELAY_PS_TO_PHASE(ps) \
289ca482a2SVladimir Oltean 	(((ps) * 360) / 800)
299ca482a2SVladimir Oltean #define SJA1105_RGMII_DELAY_PHASE_TO_PS(phase) \
309ca482a2SVladimir Oltean 	((800 * (phase)) / 360)
319ca482a2SVladimir Oltean #define SJA1105_RGMII_DELAY_PHASE_TO_HW(phase) \
329ca482a2SVladimir Oltean 	(((phase) - 738) / 9)
339ca482a2SVladimir Oltean #define SJA1105_RGMII_DELAY_PS_TO_HW(ps) \
349ca482a2SVladimir Oltean 	SJA1105_RGMII_DELAY_PHASE_TO_HW(SJA1105_RGMII_DELAY_PS_TO_PHASE(ps))
359ca482a2SVladimir Oltean 
369ca482a2SVladimir Oltean /* Valid range in degrees is a value between 73.8 and 101.7
379ca482a2SVladimir Oltean  * in 0.9 degree increments
389ca482a2SVladimir Oltean  */
399ca482a2SVladimir Oltean #define SJA1105_RGMII_DELAY_MIN_PS \
409ca482a2SVladimir Oltean 	SJA1105_RGMII_DELAY_PHASE_TO_PS(738)
419ca482a2SVladimir Oltean #define SJA1105_RGMII_DELAY_MAX_PS \
429ca482a2SVladimir Oltean 	SJA1105_RGMII_DELAY_PHASE_TO_PS(1017)
439ca482a2SVladimir Oltean 
4441603d78SVladimir Oltean typedef enum {
4541603d78SVladimir Oltean 	SPI_READ = 0,
4641603d78SVladimir Oltean 	SPI_WRITE = 1,
4741603d78SVladimir Oltean } sja1105_spi_rw_mode_t;
4841603d78SVladimir Oltean 
49317ab5b8SVladimir Oltean #include "sja1105_tas.h"
50a9d6ed7aSVladimir Oltean #include "sja1105_ptp.h"
51317ab5b8SVladimir Oltean 
52039b167dSVladimir Oltean enum sja1105_stats_area {
53039b167dSVladimir Oltean 	MAC,
54039b167dSVladimir Oltean 	HL1,
55039b167dSVladimir Oltean 	HL2,
56039b167dSVladimir Oltean 	ETHER,
57039b167dSVladimir Oltean 	__MAX_SJA1105_STATS_AREA,
58039b167dSVladimir Oltean };
59039b167dSVladimir Oltean 
608aa9ebccSVladimir Oltean /* Keeps the different addresses between E/T and P/Q/R/S */
618aa9ebccSVladimir Oltean struct sja1105_regs {
628aa9ebccSVladimir Oltean 	u64 device_id;
638aa9ebccSVladimir Oltean 	u64 prod_id;
648aa9ebccSVladimir Oltean 	u64 status;
651a4c6940SVladimir Oltean 	u64 port_control;
668aa9ebccSVladimir Oltean 	u64 rgu;
67834f8933SVladimir Oltean 	u64 vl_status;
688aa9ebccSVladimir Oltean 	u64 config;
698aa9ebccSVladimir Oltean 	u64 rmii_pll1;
70747e5eb3SVladimir Oltean 	u64 ptppinst;
71747e5eb3SVladimir Oltean 	u64 ptppindur;
72bb77f36aSVladimir Oltean 	u64 ptp_control;
732fb079a2SVladimir Oltean 	u64 ptpclkval;
74bb77f36aSVladimir Oltean 	u64 ptpclkrate;
7586db36a3SVladimir Oltean 	u64 ptpclkcorp;
76747e5eb3SVladimir Oltean 	u64 ptpsyncts;
7786db36a3SVladimir Oltean 	u64 ptpschtm;
7882760d7fSVladimir Oltean 	u64 ptpegr_ts[SJA1105_MAX_NUM_PORTS];
7982760d7fSVladimir Oltean 	u64 pad_mii_tx[SJA1105_MAX_NUM_PORTS];
8082760d7fSVladimir Oltean 	u64 pad_mii_rx[SJA1105_MAX_NUM_PORTS];
8182760d7fSVladimir Oltean 	u64 pad_mii_id[SJA1105_MAX_NUM_PORTS];
8282760d7fSVladimir Oltean 	u64 cgu_idiv[SJA1105_MAX_NUM_PORTS];
8382760d7fSVladimir Oltean 	u64 mii_tx_clk[SJA1105_MAX_NUM_PORTS];
8482760d7fSVladimir Oltean 	u64 mii_rx_clk[SJA1105_MAX_NUM_PORTS];
8582760d7fSVladimir Oltean 	u64 mii_ext_tx_clk[SJA1105_MAX_NUM_PORTS];
8682760d7fSVladimir Oltean 	u64 mii_ext_rx_clk[SJA1105_MAX_NUM_PORTS];
8782760d7fSVladimir Oltean 	u64 rgmii_tx_clk[SJA1105_MAX_NUM_PORTS];
8882760d7fSVladimir Oltean 	u64 rmii_ref_clk[SJA1105_MAX_NUM_PORTS];
8982760d7fSVladimir Oltean 	u64 rmii_ext_tx_clk[SJA1105_MAX_NUM_PORTS];
9082760d7fSVladimir Oltean 	u64 stats[__MAX_SJA1105_STATS_AREA][SJA1105_MAX_NUM_PORTS];
915a8f0974SVladimir Oltean 	u64 mdio_100base_tx;
925a8f0974SVladimir Oltean 	u64 mdio_100base_t1;
9327871359SVladimir Oltean 	u64 pcs_base[SJA1105_MAX_NUM_PORTS];
945a8f0974SVladimir Oltean };
955a8f0974SVladimir Oltean 
965a8f0974SVladimir Oltean struct sja1105_mdio_private {
975a8f0974SVladimir Oltean 	struct sja1105_private *priv;
988aa9ebccSVladimir Oltean };
998aa9ebccSVladimir Oltean 
10041fed17fSVladimir Oltean enum {
10141fed17fSVladimir Oltean 	SJA1105_SPEED_AUTO,
10241fed17fSVladimir Oltean 	SJA1105_SPEED_10MBPS,
10341fed17fSVladimir Oltean 	SJA1105_SPEED_100MBPS,
10441fed17fSVladimir Oltean 	SJA1105_SPEED_1000MBPS,
10541fed17fSVladimir Oltean 	SJA1105_SPEED_2500MBPS,
10641fed17fSVladimir Oltean 	SJA1105_SPEED_MAX,
10741fed17fSVladimir Oltean };
10841fed17fSVladimir Oltean 
1095a8f0974SVladimir Oltean enum sja1105_internal_phy_t {
1105a8f0974SVladimir Oltean 	SJA1105_NO_PHY		= 0,
1115a8f0974SVladimir Oltean 	SJA1105_PHY_BASE_TX,
1125a8f0974SVladimir Oltean 	SJA1105_PHY_BASE_T1,
1135a8f0974SVladimir Oltean };
1145a8f0974SVladimir Oltean 
1158aa9ebccSVladimir Oltean struct sja1105_info {
1168aa9ebccSVladimir Oltean 	u64 device_id;
1178aa9ebccSVladimir Oltean 	/* Needed for distinction between P and R, and between Q and S
1188aa9ebccSVladimir Oltean 	 * (since the parts with/without SGMII share the same
1198aa9ebccSVladimir Oltean 	 * switch core and device_id)
1208aa9ebccSVladimir Oltean 	 */
1218aa9ebccSVladimir Oltean 	u64 part_no;
12247ed985eSVladimir Oltean 	/* E/T and P/Q/R/S have partial timestamps of different sizes.
12347ed985eSVladimir Oltean 	 * They must be reconstructed on both families anyway to get the full
12447ed985eSVladimir Oltean 	 * 64-bit values back.
12547ed985eSVladimir Oltean 	 */
12647ed985eSVladimir Oltean 	int ptp_ts_bits;
12747ed985eSVladimir Oltean 	/* Also SPI commands are of different sizes to retrieve
12847ed985eSVladimir Oltean 	 * the egress timestamps.
12947ed985eSVladimir Oltean 	 */
13047ed985eSVladimir Oltean 	int ptpegr_ts_bytes;
1314d752508SVladimir Oltean 	int num_cbs_shapers;
1321bf658eeSVladimir Oltean 	int max_frame_mem;
1333e77e59bSVladimir Oltean 	int num_ports;
1346c0de59bSVladimir Oltean 	bool multiple_cascade_ports;
135180a7419SVladimir Oltean 	/* Every {port, TXQ} has its own CBS shaper */
136180a7419SVladimir Oltean 	bool fixed_cbs_mapping;
1374913b8ebSVladimir Oltean 	enum dsa_tag_protocol tag_proto;
1388aa9ebccSVladimir Oltean 	const struct sja1105_dynamic_table_ops *dyn_ops;
1398aa9ebccSVladimir Oltean 	const struct sja1105_table_ops *static_ops;
1408aa9ebccSVladimir Oltean 	const struct sja1105_regs *regs;
1414d942354SVladimir Oltean 	bool can_limit_mcast_flood;
142abfb228aSVladimir Oltean 	int (*reset_cmd)(struct dsa_switch *ds);
143f5b8631cSVladimir Oltean 	int (*setup_rgmii_delay)(const void *ctx, int port);
1449dfa6911SVladimir Oltean 	/* Prototypes from include/net/dsa.h */
1459dfa6911SVladimir Oltean 	int (*fdb_add_cmd)(struct dsa_switch *ds, int port,
1469dfa6911SVladimir Oltean 			   const unsigned char *addr, u16 vid);
1479dfa6911SVladimir Oltean 	int (*fdb_del_cmd)(struct dsa_switch *ds, int port,
1489dfa6911SVladimir Oltean 			   const unsigned char *addr, u16 vid);
14941603d78SVladimir Oltean 	void (*ptp_cmd_packing)(u8 *buf, struct sja1105_ptp_cmd *cmd,
15041603d78SVladimir Oltean 				enum packing_op op);
15130b73242SVladimir Oltean 	bool (*rxtstamp)(struct dsa_switch *ds, int port, struct sk_buff *skb);
152566b18c8SVladimir Oltean 	void (*txtstamp)(struct dsa_switch *ds, int port, struct sk_buff *skb);
153c5037678SVladimir Oltean 	int (*clocking_setup)(struct sja1105_private *priv);
154ae271547SAndrew Lunn 	int (*pcs_mdio_read_c45)(struct mii_bus *bus, int phy, int mmd,
155ae271547SAndrew Lunn 				 int reg);
156ae271547SAndrew Lunn 	int (*pcs_mdio_write_c45)(struct mii_bus *bus, int phy, int mmd,
157ae271547SAndrew Lunn 				  int reg, u16 val);
158cb5a82d2SVladimir Oltean 	int (*disable_microcontroller)(struct sja1105_private *priv);
1598aa9ebccSVladimir Oltean 	const char *name;
16091a05078SVladimir Oltean 	bool supports_mii[SJA1105_MAX_NUM_PORTS];
16191a05078SVladimir Oltean 	bool supports_rmii[SJA1105_MAX_NUM_PORTS];
16291a05078SVladimir Oltean 	bool supports_rgmii[SJA1105_MAX_NUM_PORTS];
16391a05078SVladimir Oltean 	bool supports_sgmii[SJA1105_MAX_NUM_PORTS];
16491a05078SVladimir Oltean 	bool supports_2500basex[SJA1105_MAX_NUM_PORTS];
1655a8f0974SVladimir Oltean 	enum sja1105_internal_phy_t internal_phy[SJA1105_MAX_NUM_PORTS];
16641fed17fSVladimir Oltean 	const u64 port_speed[SJA1105_SPEED_MAX];
1678aa9ebccSVladimir Oltean };
1688aa9ebccSVladimir Oltean 
169b70bb8d4SVladimir Oltean enum sja1105_key_type {
170b70bb8d4SVladimir Oltean 	SJA1105_KEY_BCAST,
171b70bb8d4SVladimir Oltean 	SJA1105_KEY_TC,
172b70bb8d4SVladimir Oltean 	SJA1105_KEY_VLAN_UNAWARE_VL,
173b70bb8d4SVladimir Oltean 	SJA1105_KEY_VLAN_AWARE_VL,
174b70bb8d4SVladimir Oltean };
175b70bb8d4SVladimir Oltean 
176b70bb8d4SVladimir Oltean struct sja1105_key {
177b70bb8d4SVladimir Oltean 	enum sja1105_key_type type;
178b70bb8d4SVladimir Oltean 
179b70bb8d4SVladimir Oltean 	union {
180b70bb8d4SVladimir Oltean 		/* SJA1105_KEY_TC */
181b70bb8d4SVladimir Oltean 		struct {
182b70bb8d4SVladimir Oltean 			int pcp;
183b70bb8d4SVladimir Oltean 		} tc;
184b70bb8d4SVladimir Oltean 
185b70bb8d4SVladimir Oltean 		/* SJA1105_KEY_VLAN_UNAWARE_VL */
186b70bb8d4SVladimir Oltean 		/* SJA1105_KEY_VLAN_AWARE_VL */
187b70bb8d4SVladimir Oltean 		struct {
188b70bb8d4SVladimir Oltean 			u64 dmac;
189b70bb8d4SVladimir Oltean 			u16 vid;
190b70bb8d4SVladimir Oltean 			u16 pcp;
191b70bb8d4SVladimir Oltean 		} vl;
192b70bb8d4SVladimir Oltean 	};
193b70bb8d4SVladimir Oltean };
194b70bb8d4SVladimir Oltean 
195a6af7763SVladimir Oltean enum sja1105_rule_type {
196a6af7763SVladimir Oltean 	SJA1105_RULE_BCAST_POLICER,
197a6af7763SVladimir Oltean 	SJA1105_RULE_TC_POLICER,
198dfacc5a2SVladimir Oltean 	SJA1105_RULE_VL,
199dfacc5a2SVladimir Oltean };
200dfacc5a2SVladimir Oltean 
201dfacc5a2SVladimir Oltean enum sja1105_vl_type {
202dfacc5a2SVladimir Oltean 	SJA1105_VL_NONCRITICAL,
203dfacc5a2SVladimir Oltean 	SJA1105_VL_RATE_CONSTRAINED,
204dfacc5a2SVladimir Oltean 	SJA1105_VL_TIME_TRIGGERED,
205a6af7763SVladimir Oltean };
206a6af7763SVladimir Oltean 
207a6af7763SVladimir Oltean struct sja1105_rule {
208a6af7763SVladimir Oltean 	struct list_head list;
209a6af7763SVladimir Oltean 	unsigned long cookie;
210a6af7763SVladimir Oltean 	unsigned long port_mask;
211b70bb8d4SVladimir Oltean 	struct sja1105_key key;
212a6af7763SVladimir Oltean 	enum sja1105_rule_type type;
213a6af7763SVladimir Oltean 
214dfacc5a2SVladimir Oltean 	/* Action */
215a6af7763SVladimir Oltean 	union {
216a6af7763SVladimir Oltean 		/* SJA1105_RULE_BCAST_POLICER */
217a6af7763SVladimir Oltean 		struct {
218a6af7763SVladimir Oltean 			int sharindx;
219a6af7763SVladimir Oltean 		} bcast_pol;
220a6af7763SVladimir Oltean 
221a6af7763SVladimir Oltean 		/* SJA1105_RULE_TC_POLICER */
222a6af7763SVladimir Oltean 		struct {
223a6af7763SVladimir Oltean 			int sharindx;
224a6af7763SVladimir Oltean 		} tc_pol;
225dfacc5a2SVladimir Oltean 
226dfacc5a2SVladimir Oltean 		/* SJA1105_RULE_VL */
227dfacc5a2SVladimir Oltean 		struct {
228dfacc5a2SVladimir Oltean 			enum sja1105_vl_type type;
229834f8933SVladimir Oltean 			unsigned long destports;
230834f8933SVladimir Oltean 			int sharindx;
231834f8933SVladimir Oltean 			int maxlen;
232834f8933SVladimir Oltean 			int ipv;
233834f8933SVladimir Oltean 			u64 base_time;
234834f8933SVladimir Oltean 			u64 cycle_time;
235834f8933SVladimir Oltean 			int num_entries;
236834f8933SVladimir Oltean 			struct action_gate_entry *entries;
237834f8933SVladimir Oltean 			struct flow_stats stats;
238dfacc5a2SVladimir Oltean 		} vl;
239a6af7763SVladimir Oltean 	};
240a6af7763SVladimir Oltean };
241a6af7763SVladimir Oltean 
242a6af7763SVladimir Oltean struct sja1105_flow_block {
243a6af7763SVladimir Oltean 	struct list_head rules;
244a6af7763SVladimir Oltean 	bool l2_policer_used[SJA1105_NUM_L2_POLICERS];
245dfacc5a2SVladimir Oltean 	int num_virtual_links;
246a6af7763SVladimir Oltean };
247a6af7763SVladimir Oltean 
2488aa9ebccSVladimir Oltean struct sja1105_private {
2498aa9ebccSVladimir Oltean 	struct sja1105_static_config static_config;
2509ca482a2SVladimir Oltean 	int rgmii_rx_delay_ps[SJA1105_MAX_NUM_PORTS];
2519ca482a2SVladimir Oltean 	int rgmii_tx_delay_ps[SJA1105_MAX_NUM_PORTS];
252bf4edf4aSVladimir Oltean 	phy_interface_t phy_mode[SJA1105_MAX_NUM_PORTS];
25329afb83aSVladimir Oltean 	bool fixed_link[SJA1105_MAX_NUM_PORTS];
2547f7ccdeaSVladimir Oltean 	unsigned long ucast_egress_floods;
2557f7ccdeaSVladimir Oltean 	unsigned long bcast_egress_floods;
2566f6770abSVladimir Oltean 	unsigned long hwts_tx_en;
257a372d66aSVladimir Oltean 	unsigned long hwts_rx_en;
2588aa9ebccSVladimir Oltean 	const struct sja1105_info *info;
259718bad0eSVladimir Oltean 	size_t max_xfer_len;
2608aa9ebccSVladimir Oltean 	struct spi_device *spidev;
2618aa9ebccSVladimir Oltean 	struct dsa_switch *ds;
2626dfd23d3SVladimir Oltean 	u16 bridge_pvid[SJA1105_MAX_NUM_PORTS];
2636dfd23d3SVladimir Oltean 	u16 tag_8021q_pvid[SJA1105_MAX_NUM_PORTS];
264a6af7763SVladimir Oltean 	struct sja1105_flow_block flow_block;
265227d07a0SVladimir Oltean 	/* Serializes transmission of management frames so that
266227d07a0SVladimir Oltean 	 * the switch doesn't confuse them with one another.
267227d07a0SVladimir Oltean 	 */
268227d07a0SVladimir Oltean 	struct mutex mgmt_lock;
269*ea32690dSVladimir Oltean 	/* Serializes accesses to the FDB */
270*ea32690dSVladimir Oltean 	struct mutex fdb_lock;
27122ee9f8eSVladimir Oltean 	/* PTP two-step TX timestamp ID, and its serialization lock */
27222ee9f8eSVladimir Oltean 	spinlock_t ts_id_lock;
27322ee9f8eSVladimir Oltean 	u8 ts_id;
274eb016afdSVladimir Oltean 	/* Serializes access to the dynamic config interface */
275eb016afdSVladimir Oltean 	struct mutex dynamic_config_lock;
276bf425b82SVladimir Oltean 	struct devlink_region **regions;
2774d752508SVladimir Oltean 	struct sja1105_cbs_entry *cbs;
2785a8f0974SVladimir Oltean 	struct mii_bus *mdio_base_t1;
2795a8f0974SVladimir Oltean 	struct mii_bus *mdio_base_tx;
2803ad1d171SVladimir Oltean 	struct mii_bus *mdio_pcs;
2813ad1d171SVladimir Oltean 	struct dw_xpcs *xpcs[SJA1105_MAX_NUM_PORTS];
282a9d6ed7aSVladimir Oltean 	struct sja1105_ptp_data ptp_data;
283317ab5b8SVladimir Oltean 	struct sja1105_tas_data tas_data;
2848aa9ebccSVladimir Oltean };
2858aa9ebccSVladimir Oltean 
2868aa9ebccSVladimir Oltean #include "sja1105_dynamic_config.h"
2878aa9ebccSVladimir Oltean 
2888aa9ebccSVladimir Oltean struct sja1105_spi_message {
2898aa9ebccSVladimir Oltean 	u64 access;
2908aa9ebccSVladimir Oltean 	u64 read_count;
2918aa9ebccSVladimir Oltean 	u64 address;
2928aa9ebccSVladimir Oltean };
2938aa9ebccSVladimir Oltean 
294317ab5b8SVladimir Oltean /* From sja1105_main.c */
2952eea1fa8SVladimir Oltean enum sja1105_reset_reason {
2962eea1fa8SVladimir Oltean 	SJA1105_VLAN_FILTERING = 0,
2972eea1fa8SVladimir Oltean 	SJA1105_AGEING_TIME,
2982eea1fa8SVladimir Oltean 	SJA1105_SCHEDULING,
299c279c726SVladimir Oltean 	SJA1105_BEST_EFFORT_POLICING,
300dfacc5a2SVladimir Oltean 	SJA1105_VIRTUAL_LINKS,
3012eea1fa8SVladimir Oltean };
3022eea1fa8SVladimir Oltean 
3032eea1fa8SVladimir Oltean int sja1105_static_config_reload(struct sja1105_private *priv,
3042eea1fa8SVladimir Oltean 				 enum sja1105_reset_reason reason);
30589153ed6SVladimir Oltean int sja1105_vlan_filtering(struct dsa_switch *ds, int port, bool enabled,
30689153ed6SVladimir Oltean 			   struct netlink_ext_ack *extack);
307aaa270c6SVladimir Oltean void sja1105_frame_memory_partitioning(struct sja1105_private *priv);
308aaa270c6SVladimir Oltean 
3095a8f0974SVladimir Oltean /* From sja1105_mdio.c */
3105a8f0974SVladimir Oltean int sja1105_mdiobus_register(struct dsa_switch *ds);
3115a8f0974SVladimir Oltean void sja1105_mdiobus_unregister(struct dsa_switch *ds);
312ae271547SAndrew Lunn int sja1105_pcs_mdio_read_c45(struct mii_bus *bus, int phy, int mmd, int reg);
313ae271547SAndrew Lunn int sja1105_pcs_mdio_write_c45(struct mii_bus *bus, int phy, int mmd, int reg,
314ae271547SAndrew Lunn 			       u16 val);
315ae271547SAndrew Lunn int sja1110_pcs_mdio_read_c45(struct mii_bus *bus, int phy, int mmd, int reg);
316ae271547SAndrew Lunn int sja1110_pcs_mdio_write_c45(struct mii_bus *bus, int phy, int mmd, int reg,
317ae271547SAndrew Lunn 			       u16 val);
3185a8f0974SVladimir Oltean 
3190a7bdbc2SVladimir Oltean /* From sja1105_devlink.c */
3200a7bdbc2SVladimir Oltean int sja1105_devlink_setup(struct dsa_switch *ds);
3210a7bdbc2SVladimir Oltean void sja1105_devlink_teardown(struct dsa_switch *ds);
322ff4cf8eaSVladimir Oltean int sja1105_devlink_info_get(struct dsa_switch *ds,
323ff4cf8eaSVladimir Oltean 			     struct devlink_info_req *req,
324ff4cf8eaSVladimir Oltean 			     struct netlink_ext_ack *extack);
3250a7bdbc2SVladimir Oltean 
3268aa9ebccSVladimir Oltean /* From sja1105_spi.c */
3271bd44870SVladimir Oltean int sja1105_xfer_buf(const struct sja1105_private *priv,
3288aa9ebccSVladimir Oltean 		     sja1105_spi_rw_mode_t rw, u64 reg_addr,
32908839c06SVladimir Oltean 		     u8 *buf, size_t len);
330dff79620SVladimir Oltean int sja1105_xfer_u32(const struct sja1105_private *priv,
33134d76e9fSVladimir Oltean 		     sja1105_spi_rw_mode_t rw, u64 reg_addr, u32 *value,
33234d76e9fSVladimir Oltean 		     struct ptp_system_timestamp *ptp_sts);
333dff79620SVladimir Oltean int sja1105_xfer_u64(const struct sja1105_private *priv,
33434d76e9fSVladimir Oltean 		     sja1105_spi_rw_mode_t rw, u64 reg_addr, u64 *value,
33534d76e9fSVladimir Oltean 		     struct ptp_system_timestamp *ptp_sts);
336bf425b82SVladimir Oltean int static_config_buf_prepare_for_upload(struct sja1105_private *priv,
337bf425b82SVladimir Oltean 					 void *config_buf, int buf_len);
3388aa9ebccSVladimir Oltean int sja1105_static_config_upload(struct sja1105_private *priv);
339d114fb04SVladimir Oltean int sja1105_inhibit_tx(const struct sja1105_private *priv,
340d114fb04SVladimir Oltean 		       unsigned long port_bitmap, bool tx_inhibited);
3418aa9ebccSVladimir Oltean 
34213c832a4SVladimir Oltean extern const struct sja1105_info sja1105e_info;
34313c832a4SVladimir Oltean extern const struct sja1105_info sja1105t_info;
34413c832a4SVladimir Oltean extern const struct sja1105_info sja1105p_info;
34513c832a4SVladimir Oltean extern const struct sja1105_info sja1105q_info;
34613c832a4SVladimir Oltean extern const struct sja1105_info sja1105r_info;
34713c832a4SVladimir Oltean extern const struct sja1105_info sja1105s_info;
3483e77e59bSVladimir Oltean extern const struct sja1105_info sja1110a_info;
3493e77e59bSVladimir Oltean extern const struct sja1105_info sja1110b_info;
3503e77e59bSVladimir Oltean extern const struct sja1105_info sja1110c_info;
3513e77e59bSVladimir Oltean extern const struct sja1105_info sja1110d_info;
3528aa9ebccSVladimir Oltean 
3538aa9ebccSVladimir Oltean /* From sja1105_clocking.c */
3548aa9ebccSVladimir Oltean 
3558aa9ebccSVladimir Oltean typedef enum {
3568aa9ebccSVladimir Oltean 	XMII_MAC = 0,
3578aa9ebccSVladimir Oltean 	XMII_PHY = 1,
3588aa9ebccSVladimir Oltean } sja1105_mii_role_t;
3598aa9ebccSVladimir Oltean 
3608aa9ebccSVladimir Oltean typedef enum {
3618aa9ebccSVladimir Oltean 	XMII_MODE_MII		= 0,
3628aa9ebccSVladimir Oltean 	XMII_MODE_RMII		= 1,
3638aa9ebccSVladimir Oltean 	XMII_MODE_RGMII		= 2,
364ffe10e67SVladimir Oltean 	XMII_MODE_SGMII		= 3,
3658aa9ebccSVladimir Oltean } sja1105_phy_interface_t;
3668aa9ebccSVladimir Oltean 
367c05ec3d4SVladimir Oltean int sja1105pqrs_setup_rgmii_delay(const void *ctx, int port);
3683e77e59bSVladimir Oltean int sja1110_setup_rgmii_delay(const void *ctx, int port);
3698aa9ebccSVladimir Oltean int sja1105_clocking_setup_port(struct sja1105_private *priv, int port);
3708aa9ebccSVladimir Oltean int sja1105_clocking_setup(struct sja1105_private *priv);
371cb5a82d2SVladimir Oltean int sja1110_disable_microcontroller(struct sja1105_private *priv);
3728aa9ebccSVladimir Oltean 
37352c34e6eSVladimir Oltean /* From sja1105_ethtool.c */
37452c34e6eSVladimir Oltean void sja1105_get_ethtool_stats(struct dsa_switch *ds, int port, u64 *data);
37552c34e6eSVladimir Oltean void sja1105_get_strings(struct dsa_switch *ds, int port,
37652c34e6eSVladimir Oltean 			 u32 stringset, u8 *data);
37752c34e6eSVladimir Oltean int sja1105_get_sset_count(struct dsa_switch *ds, int port, int sset);
3788aa9ebccSVladimir Oltean 
37952c34e6eSVladimir Oltean /* From sja1105_dynamic_config.c */
3808aa9ebccSVladimir Oltean int sja1105_dynamic_config_read(struct sja1105_private *priv,
3818aa9ebccSVladimir Oltean 				enum sja1105_blk_idx blk_idx,
3828aa9ebccSVladimir Oltean 				int index, void *entry);
3838aa9ebccSVladimir Oltean int sja1105_dynamic_config_write(struct sja1105_private *priv,
3848aa9ebccSVladimir Oltean 				 enum sja1105_blk_idx blk_idx,
3858aa9ebccSVladimir Oltean 				 int index, void *entry, bool keep);
3868aa9ebccSVladimir Oltean 
3871da73821SVladimir Oltean enum sja1105_iotag {
3881da73821SVladimir Oltean 	SJA1105_C_TAG = 0, /* Inner VLAN header */
3891da73821SVladimir Oltean 	SJA1105_S_TAG = 1, /* Outer VLAN header */
3901da73821SVladimir Oltean };
3911da73821SVladimir Oltean 
3923e77e59bSVladimir Oltean enum sja1110_vlan_type {
3933e77e59bSVladimir Oltean 	SJA1110_VLAN_INVALID = 0,
3943e77e59bSVladimir Oltean 	SJA1110_VLAN_C_TAG = 1, /* Single inner VLAN tag */
3953e77e59bSVladimir Oltean 	SJA1110_VLAN_S_TAG = 2, /* Single outer VLAN tag */
3963e77e59bSVladimir Oltean 	SJA1110_VLAN_D_TAG = 3, /* Double tagged, use outer tag for lookup */
3973e77e59bSVladimir Oltean };
3983e77e59bSVladimir Oltean 
3993e77e59bSVladimir Oltean enum sja1110_shaper_type {
4003e77e59bSVladimir Oltean 	SJA1110_LEAKY_BUCKET_SHAPER = 0,
4013e77e59bSVladimir Oltean 	SJA1110_CBS_SHAPER = 1,
4023e77e59bSVladimir Oltean };
4033e77e59bSVladimir Oltean 
4049dfa6911SVladimir Oltean u8 sja1105et_fdb_hash(struct sja1105_private *priv, const u8 *addr, u16 vid);
4059dfa6911SVladimir Oltean int sja1105et_fdb_add(struct dsa_switch *ds, int port,
4069dfa6911SVladimir Oltean 		      const unsigned char *addr, u16 vid);
4079dfa6911SVladimir Oltean int sja1105et_fdb_del(struct dsa_switch *ds, int port,
4089dfa6911SVladimir Oltean 		      const unsigned char *addr, u16 vid);
4099dfa6911SVladimir Oltean int sja1105pqrs_fdb_add(struct dsa_switch *ds, int port,
4109dfa6911SVladimir Oltean 			const unsigned char *addr, u16 vid);
4119dfa6911SVladimir Oltean int sja1105pqrs_fdb_del(struct dsa_switch *ds, int port,
4129dfa6911SVladimir Oltean 			const unsigned char *addr, u16 vid);
413291d1e72SVladimir Oltean 
414a6af7763SVladimir Oltean /* From sja1105_flower.c */
415a6af7763SVladimir Oltean int sja1105_cls_flower_del(struct dsa_switch *ds, int port,
416a6af7763SVladimir Oltean 			   struct flow_cls_offload *cls, bool ingress);
417a6af7763SVladimir Oltean int sja1105_cls_flower_add(struct dsa_switch *ds, int port,
418a6af7763SVladimir Oltean 			   struct flow_cls_offload *cls, bool ingress);
419834f8933SVladimir Oltean int sja1105_cls_flower_stats(struct dsa_switch *ds, int port,
420834f8933SVladimir Oltean 			     struct flow_cls_offload *cls, bool ingress);
421a6af7763SVladimir Oltean void sja1105_flower_setup(struct dsa_switch *ds);
422a6af7763SVladimir Oltean void sja1105_flower_teardown(struct dsa_switch *ds);
423dfacc5a2SVladimir Oltean struct sja1105_rule *sja1105_rule_find(struct sja1105_private *priv,
424dfacc5a2SVladimir Oltean 				       unsigned long cookie);
425a6af7763SVladimir Oltean 
4268aa9ebccSVladimir Oltean #endif
427