xref: /openbmc/linux/drivers/net/dsa/sja1105/sja1105.h (revision b790b5549bdf498ab0ecc5632610a9149532fa38)
1*b790b554SNishad Kamdar /* SPDX-License-Identifier: GPL-2.0 */
2*b790b554SNishad 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>
118aa9ebccSVladimir Oltean #include <net/dsa.h>
12227d07a0SVladimir Oltean #include <linux/mutex.h>
138aa9ebccSVladimir Oltean #include "sja1105_static_config.h"
148aa9ebccSVladimir Oltean 
158aa9ebccSVladimir Oltean #define SJA1105_NUM_PORTS		5
168aa9ebccSVladimir Oltean #define SJA1105_NUM_TC			8
178aa9ebccSVladimir Oltean #define SJA1105ET_FDB_BIN_SIZE		4
188456721dSVladimir Oltean /* The hardware value is in multiples of 10 ms.
198456721dSVladimir Oltean  * The passed parameter is in multiples of 1 ms.
208456721dSVladimir Oltean  */
218456721dSVladimir Oltean #define SJA1105_AGEING_TIME_MS(ms)	((ms) / 10)
228aa9ebccSVladimir Oltean 
23317ab5b8SVladimir Oltean #include "sja1105_tas.h"
24317ab5b8SVladimir Oltean 
258aa9ebccSVladimir Oltean /* Keeps the different addresses between E/T and P/Q/R/S */
268aa9ebccSVladimir Oltean struct sja1105_regs {
278aa9ebccSVladimir Oltean 	u64 device_id;
288aa9ebccSVladimir Oltean 	u64 prod_id;
298aa9ebccSVladimir Oltean 	u64 status;
301a4c6940SVladimir Oltean 	u64 port_control;
318aa9ebccSVladimir Oltean 	u64 rgu;
328aa9ebccSVladimir Oltean 	u64 config;
338aa9ebccSVladimir Oltean 	u64 rmii_pll1;
34bb77f36aSVladimir Oltean 	u64 ptp_control;
35bb77f36aSVladimir Oltean 	u64 ptpclk;
36bb77f36aSVladimir Oltean 	u64 ptpclkrate;
37bb77f36aSVladimir Oltean 	u64 ptptsclk;
3847ed985eSVladimir Oltean 	u64 ptpegr_ts[SJA1105_NUM_PORTS];
398aa9ebccSVladimir Oltean 	u64 pad_mii_tx[SJA1105_NUM_PORTS];
40b5b0c7f4SVladimir Oltean 	u64 pad_mii_id[SJA1105_NUM_PORTS];
418aa9ebccSVladimir Oltean 	u64 cgu_idiv[SJA1105_NUM_PORTS];
428aa9ebccSVladimir Oltean 	u64 mii_tx_clk[SJA1105_NUM_PORTS];
438aa9ebccSVladimir Oltean 	u64 mii_rx_clk[SJA1105_NUM_PORTS];
448aa9ebccSVladimir Oltean 	u64 mii_ext_tx_clk[SJA1105_NUM_PORTS];
458aa9ebccSVladimir Oltean 	u64 mii_ext_rx_clk[SJA1105_NUM_PORTS];
468aa9ebccSVladimir Oltean 	u64 rgmii_tx_clk[SJA1105_NUM_PORTS];
478aa9ebccSVladimir Oltean 	u64 rmii_ref_clk[SJA1105_NUM_PORTS];
488aa9ebccSVladimir Oltean 	u64 rmii_ext_tx_clk[SJA1105_NUM_PORTS];
498aa9ebccSVladimir Oltean 	u64 mac[SJA1105_NUM_PORTS];
508aa9ebccSVladimir Oltean 	u64 mac_hl1[SJA1105_NUM_PORTS];
518aa9ebccSVladimir Oltean 	u64 mac_hl2[SJA1105_NUM_PORTS];
528aa9ebccSVladimir Oltean 	u64 qlevel[SJA1105_NUM_PORTS];
538aa9ebccSVladimir Oltean };
548aa9ebccSVladimir Oltean 
558aa9ebccSVladimir Oltean struct sja1105_info {
568aa9ebccSVladimir Oltean 	u64 device_id;
578aa9ebccSVladimir Oltean 	/* Needed for distinction between P and R, and between Q and S
588aa9ebccSVladimir Oltean 	 * (since the parts with/without SGMII share the same
598aa9ebccSVladimir Oltean 	 * switch core and device_id)
608aa9ebccSVladimir Oltean 	 */
618aa9ebccSVladimir Oltean 	u64 part_no;
6247ed985eSVladimir Oltean 	/* E/T and P/Q/R/S have partial timestamps of different sizes.
6347ed985eSVladimir Oltean 	 * They must be reconstructed on both families anyway to get the full
6447ed985eSVladimir Oltean 	 * 64-bit values back.
6547ed985eSVladimir Oltean 	 */
6647ed985eSVladimir Oltean 	int ptp_ts_bits;
6747ed985eSVladimir Oltean 	/* Also SPI commands are of different sizes to retrieve
6847ed985eSVladimir Oltean 	 * the egress timestamps.
6947ed985eSVladimir Oltean 	 */
7047ed985eSVladimir Oltean 	int ptpegr_ts_bytes;
718aa9ebccSVladimir Oltean 	const struct sja1105_dynamic_table_ops *dyn_ops;
728aa9ebccSVladimir Oltean 	const struct sja1105_table_ops *static_ops;
738aa9ebccSVladimir Oltean 	const struct sja1105_regs *regs;
74bb77f36aSVladimir Oltean 	int (*ptp_cmd)(const void *ctx, const void *data);
758aa9ebccSVladimir Oltean 	int (*reset_cmd)(const void *ctx, const void *data);
76f5b8631cSVladimir Oltean 	int (*setup_rgmii_delay)(const void *ctx, int port);
779dfa6911SVladimir Oltean 	/* Prototypes from include/net/dsa.h */
789dfa6911SVladimir Oltean 	int (*fdb_add_cmd)(struct dsa_switch *ds, int port,
799dfa6911SVladimir Oltean 			   const unsigned char *addr, u16 vid);
809dfa6911SVladimir Oltean 	int (*fdb_del_cmd)(struct dsa_switch *ds, int port,
819dfa6911SVladimir Oltean 			   const unsigned char *addr, u16 vid);
828aa9ebccSVladimir Oltean 	const char *name;
838aa9ebccSVladimir Oltean };
848aa9ebccSVladimir Oltean 
858aa9ebccSVladimir Oltean struct sja1105_private {
868aa9ebccSVladimir Oltean 	struct sja1105_static_config static_config;
87f5b8631cSVladimir Oltean 	bool rgmii_rx_delay[SJA1105_NUM_PORTS];
88f5b8631cSVladimir Oltean 	bool rgmii_tx_delay[SJA1105_NUM_PORTS];
898aa9ebccSVladimir Oltean 	const struct sja1105_info *info;
908aa9ebccSVladimir Oltean 	struct gpio_desc *reset_gpio;
918aa9ebccSVladimir Oltean 	struct spi_device *spidev;
928aa9ebccSVladimir Oltean 	struct dsa_switch *ds;
93227d07a0SVladimir Oltean 	struct sja1105_port ports[SJA1105_NUM_PORTS];
94bb77f36aSVladimir Oltean 	struct ptp_clock_info ptp_caps;
95bb77f36aSVladimir Oltean 	struct ptp_clock *clock;
96bb77f36aSVladimir Oltean 	/* The cycle counter translates the PTP timestamps (based on
97bb77f36aSVladimir Oltean 	 * a free-running counter) into a software time domain.
98bb77f36aSVladimir Oltean 	 */
99bb77f36aSVladimir Oltean 	struct cyclecounter tstamp_cc;
100bb77f36aSVladimir Oltean 	struct timecounter tstamp_tc;
101bb77f36aSVladimir Oltean 	struct delayed_work refresh_work;
102bb77f36aSVladimir Oltean 	/* Serializes all operations on the cycle counter */
103bb77f36aSVladimir Oltean 	struct mutex ptp_lock;
104227d07a0SVladimir Oltean 	/* Serializes transmission of management frames so that
105227d07a0SVladimir Oltean 	 * the switch doesn't confuse them with one another.
106227d07a0SVladimir Oltean 	 */
107227d07a0SVladimir Oltean 	struct mutex mgmt_lock;
108844d7edcSVladimir Oltean 	struct sja1105_tagger_data tagger_data;
109317ab5b8SVladimir Oltean 	struct sja1105_tas_data tas_data;
1108aa9ebccSVladimir Oltean };
1118aa9ebccSVladimir Oltean 
1128aa9ebccSVladimir Oltean #include "sja1105_dynamic_config.h"
113bb77f36aSVladimir Oltean #include "sja1105_ptp.h"
1148aa9ebccSVladimir Oltean 
1158aa9ebccSVladimir Oltean struct sja1105_spi_message {
1168aa9ebccSVladimir Oltean 	u64 access;
1178aa9ebccSVladimir Oltean 	u64 read_count;
1188aa9ebccSVladimir Oltean 	u64 address;
1198aa9ebccSVladimir Oltean };
1208aa9ebccSVladimir Oltean 
1218aa9ebccSVladimir Oltean typedef enum {
1228aa9ebccSVladimir Oltean 	SPI_READ = 0,
1238aa9ebccSVladimir Oltean 	SPI_WRITE = 1,
1248aa9ebccSVladimir Oltean } sja1105_spi_rw_mode_t;
1258aa9ebccSVladimir Oltean 
126317ab5b8SVladimir Oltean /* From sja1105_main.c */
127317ab5b8SVladimir Oltean int sja1105_static_config_reload(struct sja1105_private *priv);
128317ab5b8SVladimir Oltean 
1298aa9ebccSVladimir Oltean /* From sja1105_spi.c */
1308aa9ebccSVladimir Oltean int sja1105_spi_send_packed_buf(const struct sja1105_private *priv,
1318aa9ebccSVladimir Oltean 				sja1105_spi_rw_mode_t rw, u64 reg_addr,
1328aa9ebccSVladimir Oltean 				void *packed_buf, size_t size_bytes);
1338aa9ebccSVladimir Oltean int sja1105_spi_send_int(const struct sja1105_private *priv,
1348aa9ebccSVladimir Oltean 			 sja1105_spi_rw_mode_t rw, u64 reg_addr,
1358aa9ebccSVladimir Oltean 			 u64 *value, u64 size_bytes);
1368aa9ebccSVladimir Oltean int sja1105_spi_send_long_packed_buf(const struct sja1105_private *priv,
1378aa9ebccSVladimir Oltean 				     sja1105_spi_rw_mode_t rw, u64 base_addr,
1388aa9ebccSVladimir Oltean 				     void *packed_buf, u64 buf_len);
1398aa9ebccSVladimir Oltean int sja1105_static_config_upload(struct sja1105_private *priv);
140d114fb04SVladimir Oltean int sja1105_inhibit_tx(const struct sja1105_private *priv,
141d114fb04SVladimir Oltean 		       unsigned long port_bitmap, bool tx_inhibited);
1428aa9ebccSVladimir Oltean 
1438aa9ebccSVladimir Oltean extern struct sja1105_info sja1105e_info;
1448aa9ebccSVladimir Oltean extern struct sja1105_info sja1105t_info;
1458aa9ebccSVladimir Oltean extern struct sja1105_info sja1105p_info;
1468aa9ebccSVladimir Oltean extern struct sja1105_info sja1105q_info;
1478aa9ebccSVladimir Oltean extern struct sja1105_info sja1105r_info;
1488aa9ebccSVladimir Oltean extern struct sja1105_info sja1105s_info;
1498aa9ebccSVladimir Oltean 
1508aa9ebccSVladimir Oltean /* From sja1105_clocking.c */
1518aa9ebccSVladimir Oltean 
1528aa9ebccSVladimir Oltean typedef enum {
1538aa9ebccSVladimir Oltean 	XMII_MAC = 0,
1548aa9ebccSVladimir Oltean 	XMII_PHY = 1,
1558aa9ebccSVladimir Oltean } sja1105_mii_role_t;
1568aa9ebccSVladimir Oltean 
1578aa9ebccSVladimir Oltean typedef enum {
1588aa9ebccSVladimir Oltean 	XMII_MODE_MII		= 0,
1598aa9ebccSVladimir Oltean 	XMII_MODE_RMII		= 1,
1608aa9ebccSVladimir Oltean 	XMII_MODE_RGMII		= 2,
1618aa9ebccSVladimir Oltean } sja1105_phy_interface_t;
1628aa9ebccSVladimir Oltean 
1638aa9ebccSVladimir Oltean typedef enum {
1648aa9ebccSVladimir Oltean 	SJA1105_SPEED_10MBPS	= 3,
1658aa9ebccSVladimir Oltean 	SJA1105_SPEED_100MBPS	= 2,
1668aa9ebccSVladimir Oltean 	SJA1105_SPEED_1000MBPS	= 1,
1678aa9ebccSVladimir Oltean 	SJA1105_SPEED_AUTO	= 0,
1688aa9ebccSVladimir Oltean } sja1105_speed_t;
1698aa9ebccSVladimir Oltean 
170c05ec3d4SVladimir Oltean int sja1105pqrs_setup_rgmii_delay(const void *ctx, int port);
1718aa9ebccSVladimir Oltean int sja1105_clocking_setup_port(struct sja1105_private *priv, int port);
1728aa9ebccSVladimir Oltean int sja1105_clocking_setup(struct sja1105_private *priv);
1738aa9ebccSVladimir Oltean 
17452c34e6eSVladimir Oltean /* From sja1105_ethtool.c */
17552c34e6eSVladimir Oltean void sja1105_get_ethtool_stats(struct dsa_switch *ds, int port, u64 *data);
17652c34e6eSVladimir Oltean void sja1105_get_strings(struct dsa_switch *ds, int port,
17752c34e6eSVladimir Oltean 			 u32 stringset, u8 *data);
17852c34e6eSVladimir Oltean int sja1105_get_sset_count(struct dsa_switch *ds, int port, int sset);
1798aa9ebccSVladimir Oltean 
18052c34e6eSVladimir Oltean /* From sja1105_dynamic_config.c */
1818aa9ebccSVladimir Oltean int sja1105_dynamic_config_read(struct sja1105_private *priv,
1828aa9ebccSVladimir Oltean 				enum sja1105_blk_idx blk_idx,
1838aa9ebccSVladimir Oltean 				int index, void *entry);
1848aa9ebccSVladimir Oltean int sja1105_dynamic_config_write(struct sja1105_private *priv,
1858aa9ebccSVladimir Oltean 				 enum sja1105_blk_idx blk_idx,
1868aa9ebccSVladimir Oltean 				 int index, void *entry, bool keep);
1878aa9ebccSVladimir Oltean 
1881da73821SVladimir Oltean enum sja1105_iotag {
1891da73821SVladimir Oltean 	SJA1105_C_TAG = 0, /* Inner VLAN header */
1901da73821SVladimir Oltean 	SJA1105_S_TAG = 1, /* Outer VLAN header */
1911da73821SVladimir Oltean };
1921da73821SVladimir Oltean 
1939dfa6911SVladimir Oltean u8 sja1105et_fdb_hash(struct sja1105_private *priv, const u8 *addr, u16 vid);
1949dfa6911SVladimir Oltean int sja1105et_fdb_add(struct dsa_switch *ds, int port,
1959dfa6911SVladimir Oltean 		      const unsigned char *addr, u16 vid);
1969dfa6911SVladimir Oltean int sja1105et_fdb_del(struct dsa_switch *ds, int port,
1979dfa6911SVladimir Oltean 		      const unsigned char *addr, u16 vid);
1989dfa6911SVladimir Oltean int sja1105pqrs_fdb_add(struct dsa_switch *ds, int port,
1999dfa6911SVladimir Oltean 			const unsigned char *addr, u16 vid);
2009dfa6911SVladimir Oltean int sja1105pqrs_fdb_del(struct dsa_switch *ds, int port,
2019dfa6911SVladimir Oltean 			const unsigned char *addr, u16 vid);
202291d1e72SVladimir Oltean 
2038aa9ebccSVladimir Oltean /* Common implementations for the static and dynamic configs */
2048aa9ebccSVladimir Oltean size_t sja1105_l2_forwarding_entry_packing(void *buf, void *entry_ptr,
2058aa9ebccSVladimir Oltean 					   enum packing_op op);
2068aa9ebccSVladimir Oltean size_t sja1105pqrs_l2_lookup_entry_packing(void *buf, void *entry_ptr,
2078aa9ebccSVladimir Oltean 					   enum packing_op op);
2088aa9ebccSVladimir Oltean size_t sja1105et_l2_lookup_entry_packing(void *buf, void *entry_ptr,
2098aa9ebccSVladimir Oltean 					 enum packing_op op);
2108aa9ebccSVladimir Oltean size_t sja1105_vlan_lookup_entry_packing(void *buf, void *entry_ptr,
2118aa9ebccSVladimir Oltean 					 enum packing_op op);
2128aa9ebccSVladimir Oltean size_t sja1105pqrs_mac_config_entry_packing(void *buf, void *entry_ptr,
2138aa9ebccSVladimir Oltean 					    enum packing_op op);
2148aa9ebccSVladimir Oltean 
2158aa9ebccSVladimir Oltean #endif
216