xref: /openbmc/linux/drivers/net/dsa/sja1105/sja1105.h (revision 291d1e72b756424eac7b1ea2be326a59f004a580)
18aa9ebccSVladimir Oltean /* SPDX-License-Identifier: GPL-2.0
28aa9ebccSVladimir Oltean  * 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 
88aa9ebccSVladimir Oltean #include <linux/dsa/sja1105.h>
98aa9ebccSVladimir Oltean #include <net/dsa.h>
108aa9ebccSVladimir Oltean #include "sja1105_static_config.h"
118aa9ebccSVladimir Oltean 
128aa9ebccSVladimir Oltean #define SJA1105_NUM_PORTS		5
138aa9ebccSVladimir Oltean #define SJA1105_NUM_TC			8
148aa9ebccSVladimir Oltean #define SJA1105ET_FDB_BIN_SIZE		4
158aa9ebccSVladimir Oltean 
168aa9ebccSVladimir Oltean /* Keeps the different addresses between E/T and P/Q/R/S */
178aa9ebccSVladimir Oltean struct sja1105_regs {
188aa9ebccSVladimir Oltean 	u64 device_id;
198aa9ebccSVladimir Oltean 	u64 prod_id;
208aa9ebccSVladimir Oltean 	u64 status;
218aa9ebccSVladimir Oltean 	u64 rgu;
228aa9ebccSVladimir Oltean 	u64 config;
238aa9ebccSVladimir Oltean 	u64 rmii_pll1;
248aa9ebccSVladimir Oltean 	u64 pad_mii_tx[SJA1105_NUM_PORTS];
258aa9ebccSVladimir Oltean 	u64 cgu_idiv[SJA1105_NUM_PORTS];
268aa9ebccSVladimir Oltean 	u64 rgmii_pad_mii_tx[SJA1105_NUM_PORTS];
278aa9ebccSVladimir Oltean 	u64 mii_tx_clk[SJA1105_NUM_PORTS];
288aa9ebccSVladimir Oltean 	u64 mii_rx_clk[SJA1105_NUM_PORTS];
298aa9ebccSVladimir Oltean 	u64 mii_ext_tx_clk[SJA1105_NUM_PORTS];
308aa9ebccSVladimir Oltean 	u64 mii_ext_rx_clk[SJA1105_NUM_PORTS];
318aa9ebccSVladimir Oltean 	u64 rgmii_tx_clk[SJA1105_NUM_PORTS];
328aa9ebccSVladimir Oltean 	u64 rmii_ref_clk[SJA1105_NUM_PORTS];
338aa9ebccSVladimir Oltean 	u64 rmii_ext_tx_clk[SJA1105_NUM_PORTS];
348aa9ebccSVladimir Oltean 	u64 mac[SJA1105_NUM_PORTS];
358aa9ebccSVladimir Oltean 	u64 mac_hl1[SJA1105_NUM_PORTS];
368aa9ebccSVladimir Oltean 	u64 mac_hl2[SJA1105_NUM_PORTS];
378aa9ebccSVladimir Oltean 	u64 qlevel[SJA1105_NUM_PORTS];
388aa9ebccSVladimir Oltean };
398aa9ebccSVladimir Oltean 
408aa9ebccSVladimir Oltean struct sja1105_info {
418aa9ebccSVladimir Oltean 	u64 device_id;
428aa9ebccSVladimir Oltean 	/* Needed for distinction between P and R, and between Q and S
438aa9ebccSVladimir Oltean 	 * (since the parts with/without SGMII share the same
448aa9ebccSVladimir Oltean 	 * switch core and device_id)
458aa9ebccSVladimir Oltean 	 */
468aa9ebccSVladimir Oltean 	u64 part_no;
478aa9ebccSVladimir Oltean 	const struct sja1105_dynamic_table_ops *dyn_ops;
488aa9ebccSVladimir Oltean 	const struct sja1105_table_ops *static_ops;
498aa9ebccSVladimir Oltean 	const struct sja1105_regs *regs;
508aa9ebccSVladimir Oltean 	int (*reset_cmd)(const void *ctx, const void *data);
518aa9ebccSVladimir Oltean 	const char *name;
528aa9ebccSVladimir Oltean };
538aa9ebccSVladimir Oltean 
548aa9ebccSVladimir Oltean struct sja1105_private {
558aa9ebccSVladimir Oltean 	struct sja1105_static_config static_config;
568aa9ebccSVladimir Oltean 	const struct sja1105_info *info;
578aa9ebccSVladimir Oltean 	struct gpio_desc *reset_gpio;
588aa9ebccSVladimir Oltean 	struct spi_device *spidev;
598aa9ebccSVladimir Oltean 	struct dsa_switch *ds;
608aa9ebccSVladimir Oltean };
618aa9ebccSVladimir Oltean 
628aa9ebccSVladimir Oltean #include "sja1105_dynamic_config.h"
638aa9ebccSVladimir Oltean 
648aa9ebccSVladimir Oltean struct sja1105_spi_message {
658aa9ebccSVladimir Oltean 	u64 access;
668aa9ebccSVladimir Oltean 	u64 read_count;
678aa9ebccSVladimir Oltean 	u64 address;
688aa9ebccSVladimir Oltean };
698aa9ebccSVladimir Oltean 
708aa9ebccSVladimir Oltean typedef enum {
718aa9ebccSVladimir Oltean 	SPI_READ = 0,
728aa9ebccSVladimir Oltean 	SPI_WRITE = 1,
738aa9ebccSVladimir Oltean } sja1105_spi_rw_mode_t;
748aa9ebccSVladimir Oltean 
758aa9ebccSVladimir Oltean /* From sja1105_spi.c */
768aa9ebccSVladimir Oltean int sja1105_spi_send_packed_buf(const struct sja1105_private *priv,
778aa9ebccSVladimir Oltean 				sja1105_spi_rw_mode_t rw, u64 reg_addr,
788aa9ebccSVladimir Oltean 				void *packed_buf, size_t size_bytes);
798aa9ebccSVladimir Oltean int sja1105_spi_send_int(const struct sja1105_private *priv,
808aa9ebccSVladimir Oltean 			 sja1105_spi_rw_mode_t rw, u64 reg_addr,
818aa9ebccSVladimir Oltean 			 u64 *value, u64 size_bytes);
828aa9ebccSVladimir Oltean int sja1105_spi_send_long_packed_buf(const struct sja1105_private *priv,
838aa9ebccSVladimir Oltean 				     sja1105_spi_rw_mode_t rw, u64 base_addr,
848aa9ebccSVladimir Oltean 				     void *packed_buf, u64 buf_len);
858aa9ebccSVladimir Oltean int sja1105_static_config_upload(struct sja1105_private *priv);
868aa9ebccSVladimir Oltean 
878aa9ebccSVladimir Oltean extern struct sja1105_info sja1105e_info;
888aa9ebccSVladimir Oltean extern struct sja1105_info sja1105t_info;
898aa9ebccSVladimir Oltean extern struct sja1105_info sja1105p_info;
908aa9ebccSVladimir Oltean extern struct sja1105_info sja1105q_info;
918aa9ebccSVladimir Oltean extern struct sja1105_info sja1105r_info;
928aa9ebccSVladimir Oltean extern struct sja1105_info sja1105s_info;
938aa9ebccSVladimir Oltean 
948aa9ebccSVladimir Oltean /* From sja1105_clocking.c */
958aa9ebccSVladimir Oltean 
968aa9ebccSVladimir Oltean typedef enum {
978aa9ebccSVladimir Oltean 	XMII_MAC = 0,
988aa9ebccSVladimir Oltean 	XMII_PHY = 1,
998aa9ebccSVladimir Oltean } sja1105_mii_role_t;
1008aa9ebccSVladimir Oltean 
1018aa9ebccSVladimir Oltean typedef enum {
1028aa9ebccSVladimir Oltean 	XMII_MODE_MII		= 0,
1038aa9ebccSVladimir Oltean 	XMII_MODE_RMII		= 1,
1048aa9ebccSVladimir Oltean 	XMII_MODE_RGMII		= 2,
1058aa9ebccSVladimir Oltean } sja1105_phy_interface_t;
1068aa9ebccSVladimir Oltean 
1078aa9ebccSVladimir Oltean typedef enum {
1088aa9ebccSVladimir Oltean 	SJA1105_SPEED_10MBPS	= 3,
1098aa9ebccSVladimir Oltean 	SJA1105_SPEED_100MBPS	= 2,
1108aa9ebccSVladimir Oltean 	SJA1105_SPEED_1000MBPS	= 1,
1118aa9ebccSVladimir Oltean 	SJA1105_SPEED_AUTO	= 0,
1128aa9ebccSVladimir Oltean } sja1105_speed_t;
1138aa9ebccSVladimir Oltean 
1148aa9ebccSVladimir Oltean int sja1105_clocking_setup_port(struct sja1105_private *priv, int port);
1158aa9ebccSVladimir Oltean int sja1105_clocking_setup(struct sja1105_private *priv);
1168aa9ebccSVladimir Oltean 
1178aa9ebccSVladimir Oltean /* From sja1105_dynamic_config.c */
1188aa9ebccSVladimir Oltean 
1198aa9ebccSVladimir Oltean int sja1105_dynamic_config_read(struct sja1105_private *priv,
1208aa9ebccSVladimir Oltean 				enum sja1105_blk_idx blk_idx,
1218aa9ebccSVladimir Oltean 				int index, void *entry);
1228aa9ebccSVladimir Oltean int sja1105_dynamic_config_write(struct sja1105_private *priv,
1238aa9ebccSVladimir Oltean 				 enum sja1105_blk_idx blk_idx,
1248aa9ebccSVladimir Oltean 				 int index, void *entry, bool keep);
1258aa9ebccSVladimir Oltean 
126*291d1e72SVladimir Oltean u8 sja1105_fdb_hash(struct sja1105_private *priv, const u8 *addr, u16 vid);
127*291d1e72SVladimir Oltean 
1288aa9ebccSVladimir Oltean /* Common implementations for the static and dynamic configs */
1298aa9ebccSVladimir Oltean size_t sja1105_l2_forwarding_entry_packing(void *buf, void *entry_ptr,
1308aa9ebccSVladimir Oltean 					   enum packing_op op);
1318aa9ebccSVladimir Oltean size_t sja1105pqrs_l2_lookup_entry_packing(void *buf, void *entry_ptr,
1328aa9ebccSVladimir Oltean 					   enum packing_op op);
1338aa9ebccSVladimir Oltean size_t sja1105et_l2_lookup_entry_packing(void *buf, void *entry_ptr,
1348aa9ebccSVladimir Oltean 					 enum packing_op op);
1358aa9ebccSVladimir Oltean size_t sja1105_vlan_lookup_entry_packing(void *buf, void *entry_ptr,
1368aa9ebccSVladimir Oltean 					 enum packing_op op);
1378aa9ebccSVladimir Oltean size_t sja1105pqrs_mac_config_entry_packing(void *buf, void *entry_ptr,
1388aa9ebccSVladimir Oltean 					    enum packing_op op);
1398aa9ebccSVladimir Oltean 
1408aa9ebccSVladimir Oltean #endif
141