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> 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 2341603d78SVladimir Oltean typedef enum { 2441603d78SVladimir Oltean SPI_READ = 0, 2541603d78SVladimir Oltean SPI_WRITE = 1, 2641603d78SVladimir Oltean } sja1105_spi_rw_mode_t; 2741603d78SVladimir Oltean 28317ab5b8SVladimir Oltean #include "sja1105_tas.h" 29a9d6ed7aSVladimir Oltean #include "sja1105_ptp.h" 30317ab5b8SVladimir Oltean 318aa9ebccSVladimir Oltean /* Keeps the different addresses between E/T and P/Q/R/S */ 328aa9ebccSVladimir Oltean struct sja1105_regs { 338aa9ebccSVladimir Oltean u64 device_id; 348aa9ebccSVladimir Oltean u64 prod_id; 358aa9ebccSVladimir Oltean u64 status; 361a4c6940SVladimir Oltean u64 port_control; 378aa9ebccSVladimir Oltean u64 rgu; 388aa9ebccSVladimir Oltean u64 config; 39*ffe10e67SVladimir Oltean u64 sgmii; 408aa9ebccSVladimir Oltean u64 rmii_pll1; 41bb77f36aSVladimir Oltean u64 ptp_control; 422fb079a2SVladimir Oltean u64 ptpclkval; 43bb77f36aSVladimir Oltean u64 ptpclkrate; 4486db36a3SVladimir Oltean u64 ptpclkcorp; 4586db36a3SVladimir Oltean u64 ptpschtm; 4647ed985eSVladimir Oltean u64 ptpegr_ts[SJA1105_NUM_PORTS]; 478aa9ebccSVladimir Oltean u64 pad_mii_tx[SJA1105_NUM_PORTS]; 48b5b0c7f4SVladimir Oltean u64 pad_mii_id[SJA1105_NUM_PORTS]; 498aa9ebccSVladimir Oltean u64 cgu_idiv[SJA1105_NUM_PORTS]; 508aa9ebccSVladimir Oltean u64 mii_tx_clk[SJA1105_NUM_PORTS]; 518aa9ebccSVladimir Oltean u64 mii_rx_clk[SJA1105_NUM_PORTS]; 528aa9ebccSVladimir Oltean u64 mii_ext_tx_clk[SJA1105_NUM_PORTS]; 538aa9ebccSVladimir Oltean u64 mii_ext_rx_clk[SJA1105_NUM_PORTS]; 548aa9ebccSVladimir Oltean u64 rgmii_tx_clk[SJA1105_NUM_PORTS]; 558aa9ebccSVladimir Oltean u64 rmii_ref_clk[SJA1105_NUM_PORTS]; 568aa9ebccSVladimir Oltean u64 rmii_ext_tx_clk[SJA1105_NUM_PORTS]; 578aa9ebccSVladimir Oltean u64 mac[SJA1105_NUM_PORTS]; 588aa9ebccSVladimir Oltean u64 mac_hl1[SJA1105_NUM_PORTS]; 598aa9ebccSVladimir Oltean u64 mac_hl2[SJA1105_NUM_PORTS]; 608aa9ebccSVladimir Oltean u64 qlevel[SJA1105_NUM_PORTS]; 618aa9ebccSVladimir Oltean }; 628aa9ebccSVladimir Oltean 638aa9ebccSVladimir Oltean struct sja1105_info { 648aa9ebccSVladimir Oltean u64 device_id; 658aa9ebccSVladimir Oltean /* Needed for distinction between P and R, and between Q and S 668aa9ebccSVladimir Oltean * (since the parts with/without SGMII share the same 678aa9ebccSVladimir Oltean * switch core and device_id) 688aa9ebccSVladimir Oltean */ 698aa9ebccSVladimir Oltean u64 part_no; 7047ed985eSVladimir Oltean /* E/T and P/Q/R/S have partial timestamps of different sizes. 7147ed985eSVladimir Oltean * They must be reconstructed on both families anyway to get the full 7247ed985eSVladimir Oltean * 64-bit values back. 7347ed985eSVladimir Oltean */ 7447ed985eSVladimir Oltean int ptp_ts_bits; 7547ed985eSVladimir Oltean /* Also SPI commands are of different sizes to retrieve 7647ed985eSVladimir Oltean * the egress timestamps. 7747ed985eSVladimir Oltean */ 7847ed985eSVladimir Oltean int ptpegr_ts_bytes; 798aa9ebccSVladimir Oltean const struct sja1105_dynamic_table_ops *dyn_ops; 808aa9ebccSVladimir Oltean const struct sja1105_table_ops *static_ops; 818aa9ebccSVladimir Oltean const struct sja1105_regs *regs; 82abfb228aSVladimir Oltean int (*reset_cmd)(struct dsa_switch *ds); 83f5b8631cSVladimir Oltean int (*setup_rgmii_delay)(const void *ctx, int port); 849dfa6911SVladimir Oltean /* Prototypes from include/net/dsa.h */ 859dfa6911SVladimir Oltean int (*fdb_add_cmd)(struct dsa_switch *ds, int port, 869dfa6911SVladimir Oltean const unsigned char *addr, u16 vid); 879dfa6911SVladimir Oltean int (*fdb_del_cmd)(struct dsa_switch *ds, int port, 889dfa6911SVladimir Oltean const unsigned char *addr, u16 vid); 8941603d78SVladimir Oltean void (*ptp_cmd_packing)(u8 *buf, struct sja1105_ptp_cmd *cmd, 9041603d78SVladimir Oltean enum packing_op op); 918aa9ebccSVladimir Oltean const char *name; 928aa9ebccSVladimir Oltean }; 938aa9ebccSVladimir Oltean 948aa9ebccSVladimir Oltean struct sja1105_private { 958aa9ebccSVladimir Oltean struct sja1105_static_config static_config; 96f5b8631cSVladimir Oltean bool rgmii_rx_delay[SJA1105_NUM_PORTS]; 97f5b8631cSVladimir Oltean bool rgmii_tx_delay[SJA1105_NUM_PORTS]; 988aa9ebccSVladimir Oltean const struct sja1105_info *info; 998aa9ebccSVladimir Oltean struct gpio_desc *reset_gpio; 1008aa9ebccSVladimir Oltean struct spi_device *spidev; 1018aa9ebccSVladimir Oltean struct dsa_switch *ds; 102227d07a0SVladimir Oltean struct sja1105_port ports[SJA1105_NUM_PORTS]; 103227d07a0SVladimir Oltean /* Serializes transmission of management frames so that 104227d07a0SVladimir Oltean * the switch doesn't confuse them with one another. 105227d07a0SVladimir Oltean */ 106227d07a0SVladimir Oltean struct mutex mgmt_lock; 107844d7edcSVladimir Oltean struct sja1105_tagger_data tagger_data; 108a9d6ed7aSVladimir Oltean struct sja1105_ptp_data ptp_data; 109317ab5b8SVladimir Oltean struct sja1105_tas_data tas_data; 1108aa9ebccSVladimir Oltean }; 1118aa9ebccSVladimir Oltean 1128aa9ebccSVladimir Oltean #include "sja1105_dynamic_config.h" 1138aa9ebccSVladimir Oltean 1148aa9ebccSVladimir Oltean struct sja1105_spi_message { 1158aa9ebccSVladimir Oltean u64 access; 1168aa9ebccSVladimir Oltean u64 read_count; 1178aa9ebccSVladimir Oltean u64 address; 1188aa9ebccSVladimir Oltean }; 1198aa9ebccSVladimir Oltean 120317ab5b8SVladimir Oltean /* From sja1105_main.c */ 1212eea1fa8SVladimir Oltean enum sja1105_reset_reason { 1222eea1fa8SVladimir Oltean SJA1105_VLAN_FILTERING = 0, 1232eea1fa8SVladimir Oltean SJA1105_RX_HWTSTAMPING, 1242eea1fa8SVladimir Oltean SJA1105_AGEING_TIME, 1252eea1fa8SVladimir Oltean SJA1105_SCHEDULING, 1262eea1fa8SVladimir Oltean }; 1272eea1fa8SVladimir Oltean 1282eea1fa8SVladimir Oltean int sja1105_static_config_reload(struct sja1105_private *priv, 1292eea1fa8SVladimir Oltean enum sja1105_reset_reason reason); 130317ab5b8SVladimir Oltean 1318aa9ebccSVladimir Oltean /* From sja1105_spi.c */ 1321bd44870SVladimir Oltean int sja1105_xfer_buf(const struct sja1105_private *priv, 1338aa9ebccSVladimir Oltean sja1105_spi_rw_mode_t rw, u64 reg_addr, 13408839c06SVladimir Oltean u8 *buf, size_t len); 135dff79620SVladimir Oltean int sja1105_xfer_u32(const struct sja1105_private *priv, 13634d76e9fSVladimir Oltean sja1105_spi_rw_mode_t rw, u64 reg_addr, u32 *value, 13734d76e9fSVladimir Oltean struct ptp_system_timestamp *ptp_sts); 138dff79620SVladimir Oltean int sja1105_xfer_u64(const struct sja1105_private *priv, 13934d76e9fSVladimir Oltean sja1105_spi_rw_mode_t rw, u64 reg_addr, u64 *value, 14034d76e9fSVladimir Oltean struct ptp_system_timestamp *ptp_sts); 1418aa9ebccSVladimir Oltean int sja1105_static_config_upload(struct sja1105_private *priv); 142d114fb04SVladimir Oltean int sja1105_inhibit_tx(const struct sja1105_private *priv, 143d114fb04SVladimir Oltean unsigned long port_bitmap, bool tx_inhibited); 1448aa9ebccSVladimir Oltean 1458aa9ebccSVladimir Oltean extern struct sja1105_info sja1105e_info; 1468aa9ebccSVladimir Oltean extern struct sja1105_info sja1105t_info; 1478aa9ebccSVladimir Oltean extern struct sja1105_info sja1105p_info; 1488aa9ebccSVladimir Oltean extern struct sja1105_info sja1105q_info; 1498aa9ebccSVladimir Oltean extern struct sja1105_info sja1105r_info; 1508aa9ebccSVladimir Oltean extern struct sja1105_info sja1105s_info; 1518aa9ebccSVladimir Oltean 1528aa9ebccSVladimir Oltean /* From sja1105_clocking.c */ 1538aa9ebccSVladimir Oltean 1548aa9ebccSVladimir Oltean typedef enum { 1558aa9ebccSVladimir Oltean XMII_MAC = 0, 1568aa9ebccSVladimir Oltean XMII_PHY = 1, 1578aa9ebccSVladimir Oltean } sja1105_mii_role_t; 1588aa9ebccSVladimir Oltean 1598aa9ebccSVladimir Oltean typedef enum { 1608aa9ebccSVladimir Oltean XMII_MODE_MII = 0, 1618aa9ebccSVladimir Oltean XMII_MODE_RMII = 1, 1628aa9ebccSVladimir Oltean XMII_MODE_RGMII = 2, 163*ffe10e67SVladimir Oltean XMII_MODE_SGMII = 3, 1648aa9ebccSVladimir Oltean } sja1105_phy_interface_t; 1658aa9ebccSVladimir Oltean 1668aa9ebccSVladimir Oltean typedef enum { 1678aa9ebccSVladimir Oltean SJA1105_SPEED_10MBPS = 3, 1688aa9ebccSVladimir Oltean SJA1105_SPEED_100MBPS = 2, 1698aa9ebccSVladimir Oltean SJA1105_SPEED_1000MBPS = 1, 1708aa9ebccSVladimir Oltean SJA1105_SPEED_AUTO = 0, 1718aa9ebccSVladimir Oltean } sja1105_speed_t; 1728aa9ebccSVladimir Oltean 173c05ec3d4SVladimir Oltean int sja1105pqrs_setup_rgmii_delay(const void *ctx, int port); 1748aa9ebccSVladimir Oltean int sja1105_clocking_setup_port(struct sja1105_private *priv, int port); 1758aa9ebccSVladimir Oltean int sja1105_clocking_setup(struct sja1105_private *priv); 1768aa9ebccSVladimir Oltean 17752c34e6eSVladimir Oltean /* From sja1105_ethtool.c */ 17852c34e6eSVladimir Oltean void sja1105_get_ethtool_stats(struct dsa_switch *ds, int port, u64 *data); 17952c34e6eSVladimir Oltean void sja1105_get_strings(struct dsa_switch *ds, int port, 18052c34e6eSVladimir Oltean u32 stringset, u8 *data); 18152c34e6eSVladimir Oltean int sja1105_get_sset_count(struct dsa_switch *ds, int port, int sset); 1828aa9ebccSVladimir Oltean 18352c34e6eSVladimir Oltean /* From sja1105_dynamic_config.c */ 1848aa9ebccSVladimir Oltean int sja1105_dynamic_config_read(struct sja1105_private *priv, 1858aa9ebccSVladimir Oltean enum sja1105_blk_idx blk_idx, 1868aa9ebccSVladimir Oltean int index, void *entry); 1878aa9ebccSVladimir Oltean int sja1105_dynamic_config_write(struct sja1105_private *priv, 1888aa9ebccSVladimir Oltean enum sja1105_blk_idx blk_idx, 1898aa9ebccSVladimir Oltean int index, void *entry, bool keep); 1908aa9ebccSVladimir Oltean 1911da73821SVladimir Oltean enum sja1105_iotag { 1921da73821SVladimir Oltean SJA1105_C_TAG = 0, /* Inner VLAN header */ 1931da73821SVladimir Oltean SJA1105_S_TAG = 1, /* Outer VLAN header */ 1941da73821SVladimir Oltean }; 1951da73821SVladimir Oltean 1969dfa6911SVladimir Oltean u8 sja1105et_fdb_hash(struct sja1105_private *priv, const u8 *addr, u16 vid); 1979dfa6911SVladimir Oltean int sja1105et_fdb_add(struct dsa_switch *ds, int port, 1989dfa6911SVladimir Oltean const unsigned char *addr, u16 vid); 1999dfa6911SVladimir Oltean int sja1105et_fdb_del(struct dsa_switch *ds, int port, 2009dfa6911SVladimir Oltean const unsigned char *addr, u16 vid); 2019dfa6911SVladimir Oltean int sja1105pqrs_fdb_add(struct dsa_switch *ds, int port, 2029dfa6911SVladimir Oltean const unsigned char *addr, u16 vid); 2039dfa6911SVladimir Oltean int sja1105pqrs_fdb_del(struct dsa_switch *ds, int port, 2049dfa6911SVladimir Oltean const unsigned char *addr, u16 vid); 205291d1e72SVladimir Oltean 2068aa9ebccSVladimir Oltean /* Common implementations for the static and dynamic configs */ 2078aa9ebccSVladimir Oltean size_t sja1105_l2_forwarding_entry_packing(void *buf, void *entry_ptr, 2088aa9ebccSVladimir Oltean enum packing_op op); 2098aa9ebccSVladimir Oltean size_t sja1105pqrs_l2_lookup_entry_packing(void *buf, void *entry_ptr, 2108aa9ebccSVladimir Oltean enum packing_op op); 2118aa9ebccSVladimir Oltean size_t sja1105et_l2_lookup_entry_packing(void *buf, void *entry_ptr, 2128aa9ebccSVladimir Oltean enum packing_op op); 2138aa9ebccSVladimir Oltean size_t sja1105_vlan_lookup_entry_packing(void *buf, void *entry_ptr, 2148aa9ebccSVladimir Oltean enum packing_op op); 2158aa9ebccSVladimir Oltean size_t sja1105pqrs_mac_config_entry_packing(void *buf, void *entry_ptr, 2168aa9ebccSVladimir Oltean enum packing_op op); 2178aa9ebccSVladimir Oltean 2188aa9ebccSVladimir Oltean #endif 219