|
| 1 | +/* SPDX-License-Identifier: GPL-2.0 |
| 2 | + * Copyright (c) 2018, Sensor-Technik Wiedemann GmbH |
| 3 | + * Copyright (c) 2018-2019, Vladimir Oltean <[email protected]> |
| 4 | + */ |
| 5 | +#ifndef _SJA1105_H |
| 6 | +#define _SJA1105_H |
| 7 | + |
| 8 | +#include <linux/dsa/sja1105.h> |
| 9 | +#include <net/dsa.h> |
| 10 | +#include "sja1105_static_config.h" |
| 11 | + |
| 12 | +#define SJA1105_NUM_PORTS 5 |
| 13 | +#define SJA1105_NUM_TC 8 |
| 14 | +#define SJA1105ET_FDB_BIN_SIZE 4 |
| 15 | + |
| 16 | +/* Keeps the different addresses between E/T and P/Q/R/S */ |
| 17 | +struct sja1105_regs { |
| 18 | + u64 device_id; |
| 19 | + u64 prod_id; |
| 20 | + u64 status; |
| 21 | + u64 rgu; |
| 22 | + u64 config; |
| 23 | + u64 rmii_pll1; |
| 24 | + u64 pad_mii_tx[SJA1105_NUM_PORTS]; |
| 25 | + u64 cgu_idiv[SJA1105_NUM_PORTS]; |
| 26 | + u64 rgmii_pad_mii_tx[SJA1105_NUM_PORTS]; |
| 27 | + u64 mii_tx_clk[SJA1105_NUM_PORTS]; |
| 28 | + u64 mii_rx_clk[SJA1105_NUM_PORTS]; |
| 29 | + u64 mii_ext_tx_clk[SJA1105_NUM_PORTS]; |
| 30 | + u64 mii_ext_rx_clk[SJA1105_NUM_PORTS]; |
| 31 | + u64 rgmii_tx_clk[SJA1105_NUM_PORTS]; |
| 32 | + u64 rmii_ref_clk[SJA1105_NUM_PORTS]; |
| 33 | + u64 rmii_ext_tx_clk[SJA1105_NUM_PORTS]; |
| 34 | + u64 mac[SJA1105_NUM_PORTS]; |
| 35 | + u64 mac_hl1[SJA1105_NUM_PORTS]; |
| 36 | + u64 mac_hl2[SJA1105_NUM_PORTS]; |
| 37 | + u64 qlevel[SJA1105_NUM_PORTS]; |
| 38 | +}; |
| 39 | + |
| 40 | +struct sja1105_info { |
| 41 | + u64 device_id; |
| 42 | + /* Needed for distinction between P and R, and between Q and S |
| 43 | + * (since the parts with/without SGMII share the same |
| 44 | + * switch core and device_id) |
| 45 | + */ |
| 46 | + u64 part_no; |
| 47 | + const struct sja1105_dynamic_table_ops *dyn_ops; |
| 48 | + const struct sja1105_table_ops *static_ops; |
| 49 | + const struct sja1105_regs *regs; |
| 50 | + int (*reset_cmd)(const void *ctx, const void *data); |
| 51 | + const char *name; |
| 52 | +}; |
| 53 | + |
| 54 | +struct sja1105_private { |
| 55 | + struct sja1105_static_config static_config; |
| 56 | + const struct sja1105_info *info; |
| 57 | + struct gpio_desc *reset_gpio; |
| 58 | + struct spi_device *spidev; |
| 59 | + struct dsa_switch *ds; |
| 60 | +}; |
| 61 | + |
| 62 | +#include "sja1105_dynamic_config.h" |
| 63 | + |
| 64 | +struct sja1105_spi_message { |
| 65 | + u64 access; |
| 66 | + u64 read_count; |
| 67 | + u64 address; |
| 68 | +}; |
| 69 | + |
| 70 | +typedef enum { |
| 71 | + SPI_READ = 0, |
| 72 | + SPI_WRITE = 1, |
| 73 | +} sja1105_spi_rw_mode_t; |
| 74 | + |
| 75 | +/* From sja1105_spi.c */ |
| 76 | +int sja1105_spi_send_packed_buf(const struct sja1105_private *priv, |
| 77 | + sja1105_spi_rw_mode_t rw, u64 reg_addr, |
| 78 | + void *packed_buf, size_t size_bytes); |
| 79 | +int sja1105_spi_send_int(const struct sja1105_private *priv, |
| 80 | + sja1105_spi_rw_mode_t rw, u64 reg_addr, |
| 81 | + u64 *value, u64 size_bytes); |
| 82 | +int sja1105_spi_send_long_packed_buf(const struct sja1105_private *priv, |
| 83 | + sja1105_spi_rw_mode_t rw, u64 base_addr, |
| 84 | + void *packed_buf, u64 buf_len); |
| 85 | +int sja1105_static_config_upload(struct sja1105_private *priv); |
| 86 | + |
| 87 | +extern struct sja1105_info sja1105e_info; |
| 88 | +extern struct sja1105_info sja1105t_info; |
| 89 | +extern struct sja1105_info sja1105p_info; |
| 90 | +extern struct sja1105_info sja1105q_info; |
| 91 | +extern struct sja1105_info sja1105r_info; |
| 92 | +extern struct sja1105_info sja1105s_info; |
| 93 | + |
| 94 | +/* From sja1105_clocking.c */ |
| 95 | + |
| 96 | +typedef enum { |
| 97 | + XMII_MAC = 0, |
| 98 | + XMII_PHY = 1, |
| 99 | +} sja1105_mii_role_t; |
| 100 | + |
| 101 | +typedef enum { |
| 102 | + XMII_MODE_MII = 0, |
| 103 | + XMII_MODE_RMII = 1, |
| 104 | + XMII_MODE_RGMII = 2, |
| 105 | +} sja1105_phy_interface_t; |
| 106 | + |
| 107 | +typedef enum { |
| 108 | + SJA1105_SPEED_10MBPS = 3, |
| 109 | + SJA1105_SPEED_100MBPS = 2, |
| 110 | + SJA1105_SPEED_1000MBPS = 1, |
| 111 | + SJA1105_SPEED_AUTO = 0, |
| 112 | +} sja1105_speed_t; |
| 113 | + |
| 114 | +int sja1105_clocking_setup_port(struct sja1105_private *priv, int port); |
| 115 | +int sja1105_clocking_setup(struct sja1105_private *priv); |
| 116 | + |
| 117 | +/* From sja1105_dynamic_config.c */ |
| 118 | + |
| 119 | +int sja1105_dynamic_config_read(struct sja1105_private *priv, |
| 120 | + enum sja1105_blk_idx blk_idx, |
| 121 | + int index, void *entry); |
| 122 | +int sja1105_dynamic_config_write(struct sja1105_private *priv, |
| 123 | + enum sja1105_blk_idx blk_idx, |
| 124 | + int index, void *entry, bool keep); |
| 125 | + |
| 126 | +/* Common implementations for the static and dynamic configs */ |
| 127 | +size_t sja1105_l2_forwarding_entry_packing(void *buf, void *entry_ptr, |
| 128 | + enum packing_op op); |
| 129 | +size_t sja1105pqrs_l2_lookup_entry_packing(void *buf, void *entry_ptr, |
| 130 | + enum packing_op op); |
| 131 | +size_t sja1105et_l2_lookup_entry_packing(void *buf, void *entry_ptr, |
| 132 | + enum packing_op op); |
| 133 | +size_t sja1105_vlan_lookup_entry_packing(void *buf, void *entry_ptr, |
| 134 | + enum packing_op op); |
| 135 | +size_t sja1105pqrs_mac_config_entry_packing(void *buf, void *entry_ptr, |
| 136 | + enum packing_op op); |
| 137 | + |
| 138 | +#endif |
0 commit comments