1b31141d3SNishad Kamdar /* SPDX-License-Identifier: GPL-2.0 */
2b31141d3SNishad Kamdar /* Microchip switch driver common header
3c2e86691STristram Ha *
47c6ff470STristram Ha * Copyright (C) 2017-2019 Microchip Technology Inc.
5c2e86691STristram Ha */
6c2e86691STristram Ha
7c2e86691STristram Ha #ifndef __KSZ_COMMON_H
8c2e86691STristram Ha #define __KSZ_COMMON_H
9c2e86691STristram Ha
106a7abc61SMarek Vasut #include <linux/etherdevice.h>
116a7abc61SMarek Vasut #include <linux/kernel.h>
126a7abc61SMarek Vasut #include <linux/mutex.h>
136a7abc61SMarek Vasut #include <linux/phy.h>
14ee394feaSMarek Vasut #include <linux/regmap.h>
156a7abc61SMarek Vasut #include <net/dsa.h>
16c9cd961cSArun Ramadoss #include <linux/irq.h>
176a7abc61SMarek Vasut
18eac1ea20SChristian Eggers #include "ksz_ptp.h"
19eac1ea20SChristian Eggers
2065ac79e1SArun Ramadoss #define KSZ_MAX_NUM_PORTS 8
2165ac79e1SArun Ramadoss
22f3c16545SArun Ramadoss struct ksz_device;
23cc13ab18SArun Ramadoss struct ksz_port;
24f3c16545SArun Ramadoss
25b8311f46SVladimir Oltean enum ksz_regmap_width {
26b8311f46SVladimir Oltean KSZ_REGMAP_8,
27b8311f46SVladimir Oltean KSZ_REGMAP_16,
28b8311f46SVladimir Oltean KSZ_REGMAP_32,
29b8311f46SVladimir Oltean __KSZ_NUM_REGMAPS,
30b8311f46SVladimir Oltean };
31b8311f46SVladimir Oltean
326a7abc61SMarek Vasut struct vlan_table {
336a7abc61SMarek Vasut u32 table[3];
346a7abc61SMarek Vasut };
356a7abc61SMarek Vasut
366a7abc61SMarek Vasut struct ksz_port_mib {
376a7abc61SMarek Vasut struct mutex cnt_mutex; /* structure access */
386a7abc61SMarek Vasut u8 cnt_ptr;
396a7abc61SMarek Vasut u64 *counters;
40a7f4f13aSOleksij Rempel struct rtnl_link_stats64 stats64;
41c4748ff6SOleksij Rempel struct ethtool_pause_stats pause_stats;
42a7f4f13aSOleksij Rempel struct spinlock stats64_lock;
436a7abc61SMarek Vasut };
446a7abc61SMarek Vasut
45a530e6f2SArun Ramadoss struct ksz_mib_names {
46a530e6f2SArun Ramadoss int index;
47a530e6f2SArun Ramadoss char string[ETH_GSTRING_LEN];
48a530e6f2SArun Ramadoss };
49a530e6f2SArun Ramadoss
50462d5250SArun Ramadoss struct ksz_chip_data {
51462d5250SArun Ramadoss u32 chip_id;
52462d5250SArun Ramadoss const char *dev_name;
53462d5250SArun Ramadoss int num_vlans;
54462d5250SArun Ramadoss int num_alus;
55462d5250SArun Ramadoss int num_statics;
56462d5250SArun Ramadoss int cpu_ports;
57462d5250SArun Ramadoss int port_cnt;
58978f1f72SArun Ramadoss u8 port_nirqs;
59e30f33a5SArun Ramadoss u8 num_tx_queues;
6071d7920fSArun Ramadoss bool tc_cbs_supported;
61c570f861SOleksij Rempel bool tc_ets_supported;
626ec23aaaSArun Ramadoss const struct ksz_dev_ops *ops;
63462d5250SArun Ramadoss bool ksz87xx_eee_link_erratum;
64a530e6f2SArun Ramadoss const struct ksz_mib_names *mib_names;
65a530e6f2SArun Ramadoss int mib_cnt;
66a530e6f2SArun Ramadoss u8 reg_mib_cnt;
67a02579dfSArun Ramadoss const u16 *regs;
68d23a5e18SArun Ramadoss const u32 *masks;
6934e48383SArun Ramadoss const u8 *shifts;
70aa5b8b73SArun Ramadoss const u8 *xmii_ctrl0;
7146f80fa8SArun Ramadoss const u8 *xmii_ctrl1;
72e593df51SArun Ramadoss int stp_ctrl_reg;
731ca6437fSArun Ramadoss int broadcast_ctrl_reg;
740abab9f3SArun Ramadoss int multicast_ctrl_reg;
75ad08ac18SArun Ramadoss int start_ctrl_reg;
7665ac79e1SArun Ramadoss bool supports_mii[KSZ_MAX_NUM_PORTS];
7765ac79e1SArun Ramadoss bool supports_rmii[KSZ_MAX_NUM_PORTS];
7865ac79e1SArun Ramadoss bool supports_rgmii[KSZ_MAX_NUM_PORTS];
7965ac79e1SArun Ramadoss bool internal_phy[KSZ_MAX_NUM_PORTS];
80505bf320SOleksij Rempel bool gbit_capable[KSZ_MAX_NUM_PORTS];
81ec6ba50cSOleksij Rempel const struct regmap_access_table *wr_table;
82ec6ba50cSOleksij Rempel const struct regmap_access_table *rd_table;
83462d5250SArun Ramadoss };
84462d5250SArun Ramadoss
85c9cd961cSArun Ramadoss struct ksz_irq {
86c9cd961cSArun Ramadoss u16 masked;
87e1add7ddSArun Ramadoss u16 reg_mask;
88e1add7ddSArun Ramadoss u16 reg_status;
89c9cd961cSArun Ramadoss struct irq_domain *domain;
90c9cd961cSArun Ramadoss int nirqs;
91e1add7ddSArun Ramadoss int irq_num;
92c9cd961cSArun Ramadoss char name[16];
93e1add7ddSArun Ramadoss struct ksz_device *dev;
94c9cd961cSArun Ramadoss };
95c9cd961cSArun Ramadoss
96cc13ab18SArun Ramadoss struct ksz_ptp_irq {
97cc13ab18SArun Ramadoss struct ksz_port *port;
98cc13ab18SArun Ramadoss u16 ts_reg;
99ab32f56aSChristian Eggers bool ts_en;
100cc13ab18SArun Ramadoss char name[16];
101cc13ab18SArun Ramadoss int num;
102cc13ab18SArun Ramadoss };
103cc13ab18SArun Ramadoss
1046a7abc61SMarek Vasut struct ksz_port {
1058f4f58f8SBen Hutchings bool remove_tag; /* Remove Tag flag set, for ksz8795 only */
10615f7cfaeSVladimir Oltean bool learning;
1076a7abc61SMarek Vasut int stp_state;
1086a7abc61SMarek Vasut struct phy_device phydev;
1096a7abc61SMarek Vasut
1106a7abc61SMarek Vasut u32 fiber:1; /* port is fiber */
1116a7abc61SMarek Vasut u32 force:1;
1126a7abc61SMarek Vasut u32 read:1; /* read MIB counters in background */
1136a7abc61SMarek Vasut u32 freeze:1; /* MIB counter freeze is enabled */
1146a7abc61SMarek Vasut
1156a7abc61SMarek Vasut struct ksz_port_mib mib;
116edecfa98SHelmut Grohne phy_interface_t interface;
117b19ac41fSArun Ramadoss u32 rgmii_tx_val;
118b19ac41fSArun Ramadoss u32 rgmii_rx_val;
119f3c16545SArun Ramadoss struct ksz_device *ksz_dev;
120c9cd961cSArun Ramadoss struct ksz_irq pirq;
121f3c16545SArun Ramadoss u8 num;
122c59e12a1SChristian Eggers #if IS_ENABLED(CONFIG_NET_DSA_MICROCHIP_KSZ_PTP)
123c59e12a1SChristian Eggers struct hwtstamp_config tstamp_config;
124c2977c61SArun Ramadoss bool hwts_tx_en;
125c2977c61SArun Ramadoss bool hwts_rx_en;
126cc13ab18SArun Ramadoss struct ksz_irq ptpirq;
127cc13ab18SArun Ramadoss struct ksz_ptp_irq ptpmsg_irq[3];
128ab32f56aSChristian Eggers ktime_t tstamp_msg;
129ab32f56aSChristian Eggers struct completion tstamp_msg_comp;
130c59e12a1SChristian Eggers #endif
1316a7abc61SMarek Vasut };
1326a7abc61SMarek Vasut
1336a7abc61SMarek Vasut struct ksz_device {
1346a7abc61SMarek Vasut struct dsa_switch *ds;
1356a7abc61SMarek Vasut struct ksz_platform_data *pdata;
136462d5250SArun Ramadoss const struct ksz_chip_data *info;
1376a7abc61SMarek Vasut
1386a7abc61SMarek Vasut struct mutex dev_mutex; /* device access */
139013572a2SMarek Vasut struct mutex regmap_mutex; /* regmap access */
1406a7abc61SMarek Vasut struct mutex alu_mutex; /* ALU access */
1416a7abc61SMarek Vasut struct mutex vlan_mutex; /* vlan access */
1426a7abc61SMarek Vasut const struct ksz_dev_ops *dev_ops;
1436a7abc61SMarek Vasut
1446a7abc61SMarek Vasut struct device *dev;
145b8311f46SVladimir Oltean struct regmap *regmap[__KSZ_NUM_REGMAPS];
1466a7abc61SMarek Vasut
1476a7abc61SMarek Vasut void *priv;
148c9cd961cSArun Ramadoss int irq;
1496a7abc61SMarek Vasut
1506a7abc61SMarek Vasut struct gpio_desc *reset_gpio; /* Optional reset GPIO */
1516a7abc61SMarek Vasut
1526a7abc61SMarek Vasut /* chip specific data */
1536a7abc61SMarek Vasut u32 chip_id;
15491a98917SArun Ramadoss u8 chip_rev;
1556a7abc61SMarek Vasut int cpu_port; /* port connected to CPU */
1566a7abc61SMarek Vasut int phy_port_cnt;
157edecfa98SHelmut Grohne phy_interface_t compat_interface;
1586a7abc61SMarek Vasut bool synclko_125;
15948bf8b8aSRobert Hancock bool synclko_disable;
1606a7abc61SMarek Vasut
1616a7abc61SMarek Vasut struct vlan_table *vlan_cache;
1626a7abc61SMarek Vasut
1636a7abc61SMarek Vasut struct ksz_port *ports;
164469b390eSGeorge McCollister struct delayed_work mib_read;
1656a7abc61SMarek Vasut unsigned long mib_read_interval;
1666a7abc61SMarek Vasut u16 mirror_rx;
1676a7abc61SMarek Vasut u16 mirror_tx;
1686a7abc61SMarek Vasut u16 port_mask;
169c9cd961cSArun Ramadoss struct mutex lock_irq; /* IRQ Access */
170c9cd961cSArun Ramadoss struct ksz_irq girq;
171eac1ea20SChristian Eggers struct ksz_ptp_data ptp_data;
1726a7abc61SMarek Vasut };
1736a7abc61SMarek Vasut
174462d5250SArun Ramadoss /* List of supported models */
175462d5250SArun Ramadoss enum ksz_model {
176b4490809SOleksij Rempel KSZ8563,
177462d5250SArun Ramadoss KSZ8795,
178462d5250SArun Ramadoss KSZ8794,
179462d5250SArun Ramadoss KSZ8765,
180462d5250SArun Ramadoss KSZ8830,
181462d5250SArun Ramadoss KSZ9477,
1822eb3ff3cSRomain Naour KSZ9896,
183462d5250SArun Ramadoss KSZ9897,
184462d5250SArun Ramadoss KSZ9893,
185ef912fe4SRakesh Sankaranarayanan KSZ9563,
186462d5250SArun Ramadoss KSZ9567,
187462d5250SArun Ramadoss LAN9370,
188462d5250SArun Ramadoss LAN9371,
189462d5250SArun Ramadoss LAN9372,
190462d5250SArun Ramadoss LAN9373,
191462d5250SArun Ramadoss LAN9374,
192462d5250SArun Ramadoss };
193462d5250SArun Ramadoss
194462d5250SArun Ramadoss enum ksz_chip_id {
195b4490809SOleksij Rempel KSZ8563_CHIP_ID = 0x8563,
196462d5250SArun Ramadoss KSZ8795_CHIP_ID = 0x8795,
197462d5250SArun Ramadoss KSZ8794_CHIP_ID = 0x8794,
198462d5250SArun Ramadoss KSZ8765_CHIP_ID = 0x8765,
199462d5250SArun Ramadoss KSZ8830_CHIP_ID = 0x8830,
200462d5250SArun Ramadoss KSZ9477_CHIP_ID = 0x00947700,
2012eb3ff3cSRomain Naour KSZ9896_CHIP_ID = 0x00989600,
202462d5250SArun Ramadoss KSZ9897_CHIP_ID = 0x00989700,
203462d5250SArun Ramadoss KSZ9893_CHIP_ID = 0x00989300,
204ef912fe4SRakesh Sankaranarayanan KSZ9563_CHIP_ID = 0x00956300,
205462d5250SArun Ramadoss KSZ9567_CHIP_ID = 0x00956700,
206462d5250SArun Ramadoss LAN9370_CHIP_ID = 0x00937000,
207462d5250SArun Ramadoss LAN9371_CHIP_ID = 0x00937100,
208462d5250SArun Ramadoss LAN9372_CHIP_ID = 0x00937200,
209462d5250SArun Ramadoss LAN9373_CHIP_ID = 0x00937300,
210462d5250SArun Ramadoss LAN9374_CHIP_ID = 0x00937400,
211462d5250SArun Ramadoss };
212462d5250SArun Ramadoss
213486f9ca7SArun Ramadoss enum ksz_regs {
214486f9ca7SArun Ramadoss REG_IND_CTRL_0,
215486f9ca7SArun Ramadoss REG_IND_DATA_8,
216486f9ca7SArun Ramadoss REG_IND_DATA_CHECK,
217486f9ca7SArun Ramadoss REG_IND_DATA_HI,
218486f9ca7SArun Ramadoss REG_IND_DATA_LO,
219486f9ca7SArun Ramadoss REG_IND_MIB_CHECK,
220486f9ca7SArun Ramadoss REG_IND_BYTE,
221486f9ca7SArun Ramadoss P_FORCE_CTRL,
222486f9ca7SArun Ramadoss P_LINK_STATUS,
223486f9ca7SArun Ramadoss P_LOCAL_CTRL,
224486f9ca7SArun Ramadoss P_NEG_RESTART_CTRL,
225486f9ca7SArun Ramadoss P_REMOTE_STATUS,
226486f9ca7SArun Ramadoss P_SPEED_STATUS,
227486f9ca7SArun Ramadoss S_TAIL_TAG_CTRL,
2286877102fSArun Ramadoss P_STP_CTRL,
2299d95329cSArun Ramadoss S_START_CTRL,
2309d95329cSArun Ramadoss S_BROADCAST_CTRL,
2319d95329cSArun Ramadoss S_MULTICAST_CTRL,
232aa5b8b73SArun Ramadoss P_XMII_CTRL_0,
23346f80fa8SArun Ramadoss P_XMII_CTRL_1,
234486f9ca7SArun Ramadoss };
235486f9ca7SArun Ramadoss
236d23a5e18SArun Ramadoss enum ksz_masks {
237d23a5e18SArun Ramadoss PORT_802_1P_REMAPPING,
238d23a5e18SArun Ramadoss SW_TAIL_TAG_ENABLE,
239d23a5e18SArun Ramadoss MIB_COUNTER_OVERFLOW,
240d23a5e18SArun Ramadoss MIB_COUNTER_VALID,
241d23a5e18SArun Ramadoss VLAN_TABLE_FID,
242d23a5e18SArun Ramadoss VLAN_TABLE_MEMBERSHIP,
243d23a5e18SArun Ramadoss VLAN_TABLE_VALID,
244d23a5e18SArun Ramadoss STATIC_MAC_TABLE_VALID,
245d23a5e18SArun Ramadoss STATIC_MAC_TABLE_USE_FID,
246d23a5e18SArun Ramadoss STATIC_MAC_TABLE_FID,
247d23a5e18SArun Ramadoss STATIC_MAC_TABLE_OVERRIDE,
248d23a5e18SArun Ramadoss STATIC_MAC_TABLE_FWD_PORTS,
249d23a5e18SArun Ramadoss DYNAMIC_MAC_TABLE_ENTRIES_H,
250d23a5e18SArun Ramadoss DYNAMIC_MAC_TABLE_MAC_EMPTY,
251d23a5e18SArun Ramadoss DYNAMIC_MAC_TABLE_NOT_READY,
252d23a5e18SArun Ramadoss DYNAMIC_MAC_TABLE_ENTRIES,
253d23a5e18SArun Ramadoss DYNAMIC_MAC_TABLE_FID,
254d23a5e18SArun Ramadoss DYNAMIC_MAC_TABLE_SRC_PORT,
255d23a5e18SArun Ramadoss DYNAMIC_MAC_TABLE_TIMESTAMP,
256457c182aSArun Ramadoss ALU_STAT_WRITE,
257457c182aSArun Ramadoss ALU_STAT_READ,
2588560664fSArun Ramadoss P_MII_TX_FLOW_CTRL,
2598560664fSArun Ramadoss P_MII_RX_FLOW_CTRL,
260d23a5e18SArun Ramadoss };
261d23a5e18SArun Ramadoss
26234e48383SArun Ramadoss enum ksz_shifts {
26334e48383SArun Ramadoss VLAN_TABLE_MEMBERSHIP_S,
26434e48383SArun Ramadoss VLAN_TABLE,
26534e48383SArun Ramadoss STATIC_MAC_FWD_PORTS,
26634e48383SArun Ramadoss STATIC_MAC_FID,
26734e48383SArun Ramadoss DYNAMIC_MAC_ENTRIES_H,
26834e48383SArun Ramadoss DYNAMIC_MAC_ENTRIES,
26934e48383SArun Ramadoss DYNAMIC_MAC_FID,
27034e48383SArun Ramadoss DYNAMIC_MAC_TIMESTAMP,
27134e48383SArun Ramadoss DYNAMIC_MAC_SRC_PORT,
272457c182aSArun Ramadoss ALU_STAT_INDEX,
27334e48383SArun Ramadoss };
27434e48383SArun Ramadoss
275aa5b8b73SArun Ramadoss enum ksz_xmii_ctrl0 {
276aa5b8b73SArun Ramadoss P_MII_100MBIT,
277aa5b8b73SArun Ramadoss P_MII_10MBIT,
2788560664fSArun Ramadoss P_MII_FULL_DUPLEX,
2798560664fSArun Ramadoss P_MII_HALF_DUPLEX,
280aa5b8b73SArun Ramadoss };
281aa5b8b73SArun Ramadoss
28246f80fa8SArun Ramadoss enum ksz_xmii_ctrl1 {
283dc1c596eSArun Ramadoss P_RGMII_SEL,
284dc1c596eSArun Ramadoss P_RMII_SEL,
285dc1c596eSArun Ramadoss P_GMII_SEL,
286dc1c596eSArun Ramadoss P_MII_SEL,
28746f80fa8SArun Ramadoss P_GMII_1GBIT,
28846f80fa8SArun Ramadoss P_GMII_NOT_1GBIT,
28946f80fa8SArun Ramadoss };
29046f80fa8SArun Ramadoss
2916a7abc61SMarek Vasut struct alu_struct {
2926a7abc61SMarek Vasut /* entry 1 */
2936a7abc61SMarek Vasut u8 is_static:1;
2946a7abc61SMarek Vasut u8 is_src_filter:1;
2956a7abc61SMarek Vasut u8 is_dst_filter:1;
2966a7abc61SMarek Vasut u8 prio_age:3;
2976a7abc61SMarek Vasut u32 _reserv_0_1:23;
2986a7abc61SMarek Vasut u8 mstp:3;
2996a7abc61SMarek Vasut /* entry 2 */
3006a7abc61SMarek Vasut u8 is_override:1;
3016a7abc61SMarek Vasut u8 is_use_fid:1;
3026a7abc61SMarek Vasut u32 _reserv_1_1:23;
3036a7abc61SMarek Vasut u8 port_forward:7;
3046a7abc61SMarek Vasut /* entry 3 & 4*/
3056a7abc61SMarek Vasut u32 _reserv_2_1:9;
3066a7abc61SMarek Vasut u8 fid:7;
3076a7abc61SMarek Vasut u8 mac[ETH_ALEN];
3086a7abc61SMarek Vasut };
3096a7abc61SMarek Vasut
3106a7abc61SMarek Vasut struct ksz_dev_ops {
311d2822e68SArun Ramadoss int (*setup)(struct dsa_switch *ds);
312c9cd961cSArun Ramadoss void (*teardown)(struct dsa_switch *ds);
3136a7abc61SMarek Vasut u32 (*get_port_addr)(int port, int offset);
3146a7abc61SMarek Vasut void (*cfg_port_member)(struct ksz_device *dev, int port, u8 member);
3156a7abc61SMarek Vasut void (*flush_dyn_mac_table)(struct ksz_device *dev, int port);
3166a7abc61SMarek Vasut void (*port_cleanup)(struct ksz_device *dev, int port);
3176a7abc61SMarek Vasut void (*port_setup)(struct ksz_device *dev, int port, bool cpu_port);
3182c119d99SArun Ramadoss int (*set_ageing_time)(struct ksz_device *dev, unsigned int msecs);
3198f420456SOleksij Rempel int (*r_phy)(struct ksz_device *dev, u16 phy, u16 reg, u16 *val);
3208f420456SOleksij Rempel int (*w_phy)(struct ksz_device *dev, u16 phy, u16 reg, u16 val);
3216a7abc61SMarek Vasut void (*r_mib_cnt)(struct ksz_device *dev, int port, u16 addr,
3226a7abc61SMarek Vasut u64 *cnt);
3236a7abc61SMarek Vasut void (*r_mib_pkt)(struct ksz_device *dev, int port, u16 addr,
3246a7abc61SMarek Vasut u64 *dropped, u64 *cnt);
325a7f4f13aSOleksij Rempel void (*r_mib_stat64)(struct ksz_device *dev, int port);
326f0d997e3SArun Ramadoss int (*vlan_filtering)(struct ksz_device *dev, int port,
327f0d997e3SArun Ramadoss bool flag, struct netlink_ext_ack *extack);
328f0d997e3SArun Ramadoss int (*vlan_add)(struct ksz_device *dev, int port,
329f0d997e3SArun Ramadoss const struct switchdev_obj_port_vlan *vlan,
330f0d997e3SArun Ramadoss struct netlink_ext_ack *extack);
331f0d997e3SArun Ramadoss int (*vlan_del)(struct ksz_device *dev, int port,
332f0d997e3SArun Ramadoss const struct switchdev_obj_port_vlan *vlan);
33300a298bbSArun Ramadoss int (*mirror_add)(struct ksz_device *dev, int port,
33400a298bbSArun Ramadoss struct dsa_mall_mirror_tc_entry *mirror,
33500a298bbSArun Ramadoss bool ingress, struct netlink_ext_ack *extack);
33600a298bbSArun Ramadoss void (*mirror_del)(struct ksz_device *dev, int port,
33700a298bbSArun Ramadoss struct dsa_mall_mirror_tc_entry *mirror);
338e587be75SArun Ramadoss int (*fdb_add)(struct ksz_device *dev, int port,
339e587be75SArun Ramadoss const unsigned char *addr, u16 vid, struct dsa_db db);
340e587be75SArun Ramadoss int (*fdb_del)(struct ksz_device *dev, int port,
341e587be75SArun Ramadoss const unsigned char *addr, u16 vid, struct dsa_db db);
342e587be75SArun Ramadoss int (*fdb_dump)(struct ksz_device *dev, int port,
343e587be75SArun Ramadoss dsa_fdb_dump_cb_t *cb, void *data);
344980c7d17SArun Ramadoss int (*mdb_add)(struct ksz_device *dev, int port,
345980c7d17SArun Ramadoss const struct switchdev_obj_port_mdb *mdb,
346980c7d17SArun Ramadoss struct dsa_db db);
347980c7d17SArun Ramadoss int (*mdb_del)(struct ksz_device *dev, int port,
348980c7d17SArun Ramadoss const struct switchdev_obj_port_mdb *mdb,
349980c7d17SArun Ramadoss struct dsa_db db);
3507012033cSArun Ramadoss void (*get_caps)(struct ksz_device *dev, int port,
3517012033cSArun Ramadoss struct phylink_config *config);
3521fe94f54SArun Ramadoss int (*change_mtu)(struct ksz_device *dev, int port, int mtu);
3536a7abc61SMarek Vasut void (*freeze_mib)(struct ksz_device *dev, int port, bool freeze);
3546a7abc61SMarek Vasut void (*port_init_cnt)(struct ksz_device *dev, int port);
355a0cb1aa4SArun Ramadoss void (*phylink_mac_config)(struct ksz_device *dev, int port,
356a0cb1aa4SArun Ramadoss unsigned int mode,
357a0cb1aa4SArun Ramadoss const struct phylink_link_state *state);
358f597d3adSArun Ramadoss void (*phylink_mac_link_up)(struct ksz_device *dev, int port,
359f597d3adSArun Ramadoss unsigned int mode,
360f597d3adSArun Ramadoss phy_interface_t interface,
361f597d3adSArun Ramadoss struct phy_device *phydev, int speed,
362f597d3adSArun Ramadoss int duplex, bool tx_pause, bool rx_pause);
363b19ac41fSArun Ramadoss void (*setup_rgmii_delay)(struct ksz_device *dev, int port);
36471d7920fSArun Ramadoss int (*tc_cbs_set_cinc)(struct ksz_device *dev, int port, u32 val);
365fb9324beSArun Ramadoss void (*config_cpu_port)(struct dsa_switch *ds);
366331d64f7SArun Ramadoss int (*enable_stp_addr)(struct ksz_device *dev);
367673b196fSArun Ramadoss int (*reset)(struct ksz_device *dev);
3686a7abc61SMarek Vasut int (*init)(struct ksz_device *dev);
3696a7abc61SMarek Vasut void (*exit)(struct ksz_device *dev);
3706a7abc61SMarek Vasut };
3716a7abc61SMarek Vasut
3726a7abc61SMarek Vasut struct ksz_device *ksz_switch_alloc(struct device *base, void *priv);
3736ec23aaaSArun Ramadoss int ksz_switch_register(struct ksz_device *dev);
3746a7abc61SMarek Vasut void ksz_switch_remove(struct ksz_device *dev);
3756a7abc61SMarek Vasut
3767c6ff470STristram Ha void ksz_init_mib_timer(struct ksz_device *dev);
377c6101dd7SArun Ramadoss void ksz_r_mib_stats64(struct ksz_device *dev, int port);
378bde55dd9SOleksij Rempel void ksz88xx_r_mib_stats64(struct ksz_device *dev, int port);
379e593df51SArun Ramadoss void ksz_port_stp_state_set(struct dsa_switch *ds, int port, u8 state);
38046f80fa8SArun Ramadoss bool ksz_get_gbit(struct ksz_device *dev, int port);
3810ab7f6bfSArun Ramadoss phy_interface_t ksz_get_xmii(struct ksz_device *dev, int port, bool gbit);
3821958eee8SArun Ramadoss extern const struct ksz_chip_data ksz_switch_chips[];
383c2e86691STristram Ha
384c2e86691STristram Ha /* Common register access functions */
ksz_regmap_8(struct ksz_device * dev)385b8311f46SVladimir Oltean static inline struct regmap *ksz_regmap_8(struct ksz_device *dev)
386b8311f46SVladimir Oltean {
387b8311f46SVladimir Oltean return dev->regmap[KSZ_REGMAP_8];
388b8311f46SVladimir Oltean }
389b8311f46SVladimir Oltean
ksz_regmap_16(struct ksz_device * dev)390b8311f46SVladimir Oltean static inline struct regmap *ksz_regmap_16(struct ksz_device *dev)
391b8311f46SVladimir Oltean {
392b8311f46SVladimir Oltean return dev->regmap[KSZ_REGMAP_16];
393b8311f46SVladimir Oltean }
394b8311f46SVladimir Oltean
ksz_regmap_32(struct ksz_device * dev)395b8311f46SVladimir Oltean static inline struct regmap *ksz_regmap_32(struct ksz_device *dev)
396b8311f46SVladimir Oltean {
397b8311f46SVladimir Oltean return dev->regmap[KSZ_REGMAP_32];
398b8311f46SVladimir Oltean }
399c2e86691STristram Ha
ksz_read8(struct ksz_device * dev,u32 reg,u8 * val)400c2e86691STristram Ha static inline int ksz_read8(struct ksz_device *dev, u32 reg, u8 *val)
401c2e86691STristram Ha {
402ee394feaSMarek Vasut unsigned int value;
403b8311f46SVladimir Oltean int ret = regmap_read(ksz_regmap_8(dev), reg, &value);
404c2e86691STristram Ha
405ec6ba50cSOleksij Rempel if (ret)
406ec6ba50cSOleksij Rempel dev_err(dev->dev, "can't read 8bit reg: 0x%x %pe\n", reg,
407ec6ba50cSOleksij Rempel ERR_PTR(ret));
408ec6ba50cSOleksij Rempel
409ee394feaSMarek Vasut *val = value;
410c2e86691STristram Ha return ret;
411c2e86691STristram Ha }
412c2e86691STristram Ha
ksz_read16(struct ksz_device * dev,u32 reg,u16 * val)413c2e86691STristram Ha static inline int ksz_read16(struct ksz_device *dev, u32 reg, u16 *val)
414c2e86691STristram Ha {
415ee394feaSMarek Vasut unsigned int value;
416b8311f46SVladimir Oltean int ret = regmap_read(ksz_regmap_16(dev), reg, &value);
417c2e86691STristram Ha
418ec6ba50cSOleksij Rempel if (ret)
419ec6ba50cSOleksij Rempel dev_err(dev->dev, "can't read 16bit reg: 0x%x %pe\n", reg,
420ec6ba50cSOleksij Rempel ERR_PTR(ret));
421ec6ba50cSOleksij Rempel
422ee394feaSMarek Vasut *val = value;
423c2e86691STristram Ha return ret;
424c2e86691STristram Ha }
425c2e86691STristram Ha
ksz_read32(struct ksz_device * dev,u32 reg,u32 * val)426c2e86691STristram Ha static inline int ksz_read32(struct ksz_device *dev, u32 reg, u32 *val)
427c2e86691STristram Ha {
428ee394feaSMarek Vasut unsigned int value;
429b8311f46SVladimir Oltean int ret = regmap_read(ksz_regmap_32(dev), reg, &value);
430c2e86691STristram Ha
431ec6ba50cSOleksij Rempel if (ret)
432ec6ba50cSOleksij Rempel dev_err(dev->dev, "can't read 32bit reg: 0x%x %pe\n", reg,
433ec6ba50cSOleksij Rempel ERR_PTR(ret));
434ec6ba50cSOleksij Rempel
435ee394feaSMarek Vasut *val = value;
436c2e86691STristram Ha return ret;
437c2e86691STristram Ha }
438c2e86691STristram Ha
ksz_read64(struct ksz_device * dev,u32 reg,u64 * val)439e66f840cSTristram Ha static inline int ksz_read64(struct ksz_device *dev, u32 reg, u64 *val)
440e66f840cSTristram Ha {
441e66f840cSTristram Ha u32 value[2];
442e66f840cSTristram Ha int ret;
443e66f840cSTristram Ha
444b8311f46SVladimir Oltean ret = regmap_bulk_read(ksz_regmap_32(dev), reg, value, 2);
445ec6ba50cSOleksij Rempel if (ret)
446ec6ba50cSOleksij Rempel dev_err(dev->dev, "can't read 64bit reg: 0x%x %pe\n", reg,
447ec6ba50cSOleksij Rempel ERR_PTR(ret));
448ec6ba50cSOleksij Rempel else
449c34f674cSBen Hutchings *val = (u64)value[0] << 32 | value[1];
450e66f840cSTristram Ha
451e66f840cSTristram Ha return ret;
452e66f840cSTristram Ha }
453e66f840cSTristram Ha
ksz_write8(struct ksz_device * dev,u32 reg,u8 value)454c2e86691STristram Ha static inline int ksz_write8(struct ksz_device *dev, u32 reg, u8 value)
455c2e86691STristram Ha {
456ec6ba50cSOleksij Rempel int ret;
457ec6ba50cSOleksij Rempel
458b8311f46SVladimir Oltean ret = regmap_write(ksz_regmap_8(dev), reg, value);
459ec6ba50cSOleksij Rempel if (ret)
460ec6ba50cSOleksij Rempel dev_err(dev->dev, "can't write 8bit reg: 0x%x %pe\n", reg,
461ec6ba50cSOleksij Rempel ERR_PTR(ret));
462ec6ba50cSOleksij Rempel
463ec6ba50cSOleksij Rempel return ret;
464c2e86691STristram Ha }
465c2e86691STristram Ha
ksz_write16(struct ksz_device * dev,u32 reg,u16 value)466c2e86691STristram Ha static inline int ksz_write16(struct ksz_device *dev, u32 reg, u16 value)
467c2e86691STristram Ha {
468ec6ba50cSOleksij Rempel int ret;
469ec6ba50cSOleksij Rempel
470b8311f46SVladimir Oltean ret = regmap_write(ksz_regmap_16(dev), reg, value);
471ec6ba50cSOleksij Rempel if (ret)
472ec6ba50cSOleksij Rempel dev_err(dev->dev, "can't write 16bit reg: 0x%x %pe\n", reg,
473ec6ba50cSOleksij Rempel ERR_PTR(ret));
474ec6ba50cSOleksij Rempel
475ec6ba50cSOleksij Rempel return ret;
476c2e86691STristram Ha }
477c2e86691STristram Ha
ksz_write32(struct ksz_device * dev,u32 reg,u32 value)478c2e86691STristram Ha static inline int ksz_write32(struct ksz_device *dev, u32 reg, u32 value)
479c2e86691STristram Ha {
480ec6ba50cSOleksij Rempel int ret;
481ec6ba50cSOleksij Rempel
482b8311f46SVladimir Oltean ret = regmap_write(ksz_regmap_32(dev), reg, value);
483ec6ba50cSOleksij Rempel if (ret)
484ec6ba50cSOleksij Rempel dev_err(dev->dev, "can't write 32bit reg: 0x%x %pe\n", reg,
485ec6ba50cSOleksij Rempel ERR_PTR(ret));
486ec6ba50cSOleksij Rempel
487ec6ba50cSOleksij Rempel return ret;
488c2e86691STristram Ha }
489c2e86691STristram Ha
ksz_rmw16(struct ksz_device * dev,u32 reg,u16 mask,u16 value)490eac1ea20SChristian Eggers static inline int ksz_rmw16(struct ksz_device *dev, u32 reg, u16 mask,
491eac1ea20SChristian Eggers u16 value)
492eac1ea20SChristian Eggers {
493eac1ea20SChristian Eggers int ret;
494eac1ea20SChristian Eggers
495b8311f46SVladimir Oltean ret = regmap_update_bits(ksz_regmap_16(dev), reg, mask, value);
496eac1ea20SChristian Eggers if (ret)
497eac1ea20SChristian Eggers dev_err(dev->dev, "can't rmw 16bit reg 0x%x: %pe\n", reg,
498eac1ea20SChristian Eggers ERR_PTR(ret));
499eac1ea20SChristian Eggers
500eac1ea20SChristian Eggers return ret;
501eac1ea20SChristian Eggers }
502eac1ea20SChristian Eggers
ksz_rmw32(struct ksz_device * dev,u32 reg,u32 mask,u32 value)5031f12ae5bSChristian Eggers static inline int ksz_rmw32(struct ksz_device *dev, u32 reg, u32 mask,
5041f12ae5bSChristian Eggers u32 value)
5051f12ae5bSChristian Eggers {
5061f12ae5bSChristian Eggers int ret;
5071f12ae5bSChristian Eggers
508b8311f46SVladimir Oltean ret = regmap_update_bits(ksz_regmap_32(dev), reg, mask, value);
5091f12ae5bSChristian Eggers if (ret)
5101f12ae5bSChristian Eggers dev_err(dev->dev, "can't rmw 32bit reg 0x%x: %pe\n", reg,
5111f12ae5bSChristian Eggers ERR_PTR(ret));
5121f12ae5bSChristian Eggers
5131f12ae5bSChristian Eggers return ret;
5141f12ae5bSChristian Eggers }
5151f12ae5bSChristian Eggers
ksz_write64(struct ksz_device * dev,u32 reg,u64 value)516e66f840cSTristram Ha static inline int ksz_write64(struct ksz_device *dev, u32 reg, u64 value)
517e66f840cSTristram Ha {
518e66f840cSTristram Ha u32 val[2];
519e66f840cSTristram Ha
520e66f840cSTristram Ha /* Ick! ToDo: Add 64bit R/W to regmap on 32bit systems */
521e66f840cSTristram Ha value = swab64(value);
522e66f840cSTristram Ha val[0] = swab32(value & 0xffffffffULL);
523e66f840cSTristram Ha val[1] = swab32(value >> 32ULL);
524e66f840cSTristram Ha
525b8311f46SVladimir Oltean return regmap_bulk_write(ksz_regmap_32(dev), reg, val, 2);
526e66f840cSTristram Ha }
527e66f840cSTristram Ha
ksz_rmw8(struct ksz_device * dev,int offset,u8 mask,u8 val)5286f1b986aSOleksij Rempel static inline int ksz_rmw8(struct ksz_device *dev, int offset, u8 mask, u8 val)
5296f1b986aSOleksij Rempel {
5302f0d5799SOleksij Rempel int ret;
5312f0d5799SOleksij Rempel
532b8311f46SVladimir Oltean ret = regmap_update_bits(ksz_regmap_8(dev), offset, mask, val);
5332f0d5799SOleksij Rempel if (ret)
5342f0d5799SOleksij Rempel dev_err(dev->dev, "can't rmw 8bit reg 0x%x: %pe\n", offset,
5352f0d5799SOleksij Rempel ERR_PTR(ret));
5362f0d5799SOleksij Rempel
5372f0d5799SOleksij Rempel return ret;
5386f1b986aSOleksij Rempel }
5396f1b986aSOleksij Rempel
ksz_pread8(struct ksz_device * dev,int port,int offset,u8 * data)540d38bc3b4SOleksij Rempel static inline int ksz_pread8(struct ksz_device *dev, int port, int offset,
541c2e86691STristram Ha u8 *data)
542c2e86691STristram Ha {
543d38bc3b4SOleksij Rempel return ksz_read8(dev, dev->dev_ops->get_port_addr(port, offset), data);
544c2e86691STristram Ha }
545c2e86691STristram Ha
ksz_pread16(struct ksz_device * dev,int port,int offset,u16 * data)546d38bc3b4SOleksij Rempel static inline int ksz_pread16(struct ksz_device *dev, int port, int offset,
547c2e86691STristram Ha u16 *data)
548c2e86691STristram Ha {
549d38bc3b4SOleksij Rempel return ksz_read16(dev, dev->dev_ops->get_port_addr(port, offset), data);
550c2e86691STristram Ha }
551c2e86691STristram Ha
ksz_pread32(struct ksz_device * dev,int port,int offset,u32 * data)552d38bc3b4SOleksij Rempel static inline int ksz_pread32(struct ksz_device *dev, int port, int offset,
553c2e86691STristram Ha u32 *data)
554c2e86691STristram Ha {
555d38bc3b4SOleksij Rempel return ksz_read32(dev, dev->dev_ops->get_port_addr(port, offset), data);
556c2e86691STristram Ha }
557c2e86691STristram Ha
ksz_pwrite8(struct ksz_device * dev,int port,int offset,u8 data)558d38bc3b4SOleksij Rempel static inline int ksz_pwrite8(struct ksz_device *dev, int port, int offset,
559c2e86691STristram Ha u8 data)
560c2e86691STristram Ha {
561d38bc3b4SOleksij Rempel return ksz_write8(dev, dev->dev_ops->get_port_addr(port, offset), data);
562c2e86691STristram Ha }
563c2e86691STristram Ha
ksz_pwrite16(struct ksz_device * dev,int port,int offset,u16 data)564d38bc3b4SOleksij Rempel static inline int ksz_pwrite16(struct ksz_device *dev, int port, int offset,
565c2e86691STristram Ha u16 data)
566c2e86691STristram Ha {
567d38bc3b4SOleksij Rempel return ksz_write16(dev, dev->dev_ops->get_port_addr(port, offset),
568d38bc3b4SOleksij Rempel data);
569c2e86691STristram Ha }
570c2e86691STristram Ha
ksz_pwrite32(struct ksz_device * dev,int port,int offset,u32 data)571d38bc3b4SOleksij Rempel static inline int ksz_pwrite32(struct ksz_device *dev, int port, int offset,
572c2e86691STristram Ha u32 data)
573c2e86691STristram Ha {
574d38bc3b4SOleksij Rempel return ksz_write32(dev, dev->dev_ops->get_port_addr(port, offset),
575d38bc3b4SOleksij Rempel data);
576c2e86691STristram Ha }
577c2e86691STristram Ha
ksz_prmw8(struct ksz_device * dev,int port,int offset,u8 mask,u8 val)5782f0d5799SOleksij Rempel static inline int ksz_prmw8(struct ksz_device *dev, int port, int offset,
5798560664fSArun Ramadoss u8 mask, u8 val)
5808560664fSArun Ramadoss {
5813b42fbd5SRasmus Villemoes return ksz_rmw8(dev, dev->dev_ops->get_port_addr(port, offset),
5828560664fSArun Ramadoss mask, val);
5838560664fSArun Ramadoss }
5848560664fSArun Ramadoss
ksz_prmw32(struct ksz_device * dev,int port,int offset,u32 mask,u32 val)585ece28ecbSRasmus Villemoes static inline int ksz_prmw32(struct ksz_device *dev, int port, int offset,
586ece28ecbSRasmus Villemoes u32 mask, u32 val)
587ece28ecbSRasmus Villemoes {
588ece28ecbSRasmus Villemoes return ksz_rmw32(dev, dev->dev_ops->get_port_addr(port, offset),
589ece28ecbSRasmus Villemoes mask, val);
590ece28ecbSRasmus Villemoes }
591ece28ecbSRasmus Villemoes
ksz_regmap_lock(void * __mtx)592013572a2SMarek Vasut static inline void ksz_regmap_lock(void *__mtx)
593013572a2SMarek Vasut {
594013572a2SMarek Vasut struct mutex *mtx = __mtx;
595013572a2SMarek Vasut mutex_lock(mtx);
596013572a2SMarek Vasut }
597013572a2SMarek Vasut
ksz_regmap_unlock(void * __mtx)598013572a2SMarek Vasut static inline void ksz_regmap_unlock(void *__mtx)
599013572a2SMarek Vasut {
600013572a2SMarek Vasut struct mutex *mtx = __mtx;
601013572a2SMarek Vasut mutex_unlock(mtx);
602013572a2SMarek Vasut }
603013572a2SMarek Vasut
ksz_is_ksz87xx(struct ksz_device * dev)604*4bdf79d6STristram Ha static inline bool ksz_is_ksz87xx(struct ksz_device *dev)
605*4bdf79d6STristram Ha {
606*4bdf79d6STristram Ha return dev->chip_id == KSZ8795_CHIP_ID ||
607*4bdf79d6STristram Ha dev->chip_id == KSZ8794_CHIP_ID ||
608*4bdf79d6STristram Ha dev->chip_id == KSZ8765_CHIP_ID;
609*4bdf79d6STristram Ha }
610*4bdf79d6STristram Ha
ksz_is_ksz88x3(struct ksz_device * dev)611f3d890f5SArun Ramadoss static inline bool ksz_is_ksz88x3(struct ksz_device *dev)
612f3d890f5SArun Ramadoss {
613f3d890f5SArun Ramadoss return dev->chip_id == KSZ8830_CHIP_ID;
614f3d890f5SArun Ramadoss }
615f3d890f5SArun Ramadoss
is_lan937x(struct ksz_device * dev)61699b16df0SArun Ramadoss static inline int is_lan937x(struct ksz_device *dev)
61799b16df0SArun Ramadoss {
61899b16df0SArun Ramadoss return dev->chip_id == LAN9370_CHIP_ID ||
61999b16df0SArun Ramadoss dev->chip_id == LAN9371_CHIP_ID ||
62099b16df0SArun Ramadoss dev->chip_id == LAN9372_CHIP_ID ||
62199b16df0SArun Ramadoss dev->chip_id == LAN9373_CHIP_ID ||
62299b16df0SArun Ramadoss dev->chip_id == LAN9374_CHIP_ID;
62399b16df0SArun Ramadoss }
62499b16df0SArun Ramadoss
625de6dd626SArun Ramadoss /* STP State Defines */
626de6dd626SArun Ramadoss #define PORT_TX_ENABLE BIT(2)
627de6dd626SArun Ramadoss #define PORT_RX_ENABLE BIT(1)
628de6dd626SArun Ramadoss #define PORT_LEARN_DISABLE BIT(0)
629de6dd626SArun Ramadoss
63091a98917SArun Ramadoss /* Switch ID Defines */
63191a98917SArun Ramadoss #define REG_CHIP_ID0 0x00
63291a98917SArun Ramadoss
63391a98917SArun Ramadoss #define SW_FAMILY_ID_M GENMASK(15, 8)
63491a98917SArun Ramadoss #define KSZ87_FAMILY_ID 0x87
63591a98917SArun Ramadoss #define KSZ88_FAMILY_ID 0x88
63691a98917SArun Ramadoss
63791a98917SArun Ramadoss #define KSZ8_PORT_STATUS_0 0x08
63891a98917SArun Ramadoss #define KSZ8_PORT_FIBER_MODE BIT(7)
63991a98917SArun Ramadoss
64091a98917SArun Ramadoss #define SW_CHIP_ID_M GENMASK(7, 4)
64191a98917SArun Ramadoss #define KSZ87_CHIP_ID_94 0x6
64291a98917SArun Ramadoss #define KSZ87_CHIP_ID_95 0x9
64391a98917SArun Ramadoss #define KSZ88_CHIP_ID_63 0x3
64491a98917SArun Ramadoss
64591a98917SArun Ramadoss #define SW_REV_ID_M GENMASK(7, 4)
64691a98917SArun Ramadoss
647b4490809SOleksij Rempel /* KSZ9893, KSZ9563, KSZ8563 specific register */
648b4490809SOleksij Rempel #define REG_CHIP_ID4 0x0f
649b4490809SOleksij Rempel #define SKU_ID_KSZ8563 0x3c
650ef912fe4SRakesh Sankaranarayanan #define SKU_ID_KSZ9563 0x1c
651b4490809SOleksij Rempel
6521ca6437fSArun Ramadoss /* Driver set switch broadcast storm protection at 10% rate. */
6531ca6437fSArun Ramadoss #define BROADCAST_STORM_PROT_RATE 10
6541ca6437fSArun Ramadoss
6551ca6437fSArun Ramadoss /* 148,800 frames * 67 ms / 100 */
6561ca6437fSArun Ramadoss #define BROADCAST_STORM_VALUE 9969
6571ca6437fSArun Ramadoss
6581ca6437fSArun Ramadoss #define BROADCAST_STORM_RATE_HI 0x07
6591ca6437fSArun Ramadoss #define BROADCAST_STORM_RATE_LO 0xFF
6601ca6437fSArun Ramadoss #define BROADCAST_STORM_RATE 0x07FF
6611ca6437fSArun Ramadoss
6620abab9f3SArun Ramadoss #define MULTICAST_STORM_DISABLE BIT(6)
6630abab9f3SArun Ramadoss
664ad08ac18SArun Ramadoss #define SW_START 0x01
665ad08ac18SArun Ramadoss
66646f80fa8SArun Ramadoss /* xMII configuration */
6678560664fSArun Ramadoss #define P_MII_DUPLEX_M BIT(6)
668aa5b8b73SArun Ramadoss #define P_MII_100MBIT_M BIT(4)
669aa5b8b73SArun Ramadoss
67046f80fa8SArun Ramadoss #define P_GMII_1GBIT_M BIT(6)
671dc1c596eSArun Ramadoss #define P_RGMII_ID_IG_ENABLE BIT(4)
672dc1c596eSArun Ramadoss #define P_RGMII_ID_EG_ENABLE BIT(3)
6730ab7f6bfSArun Ramadoss #define P_MII_MAC_MODE BIT(2)
674dc1c596eSArun Ramadoss #define P_MII_SEL_M 0x3
67546f80fa8SArun Ramadoss
676ff319a64SArun Ramadoss /* Interrupt */
677e1add7ddSArun Ramadoss #define REG_SW_PORT_INT_STATUS__1 0x001B
678e1add7ddSArun Ramadoss #define REG_SW_PORT_INT_MASK__1 0x001F
679ff319a64SArun Ramadoss
680ff319a64SArun Ramadoss #define REG_PORT_INT_STATUS 0x001B
681ff319a64SArun Ramadoss #define REG_PORT_INT_MASK 0x001F
682ff319a64SArun Ramadoss
683ff319a64SArun Ramadoss #define PORT_SRC_PHY_INT 1
684cc13ab18SArun Ramadoss #define PORT_SRC_PTP_INT 2
685ff319a64SArun Ramadoss
68629d1e85fSOleksij Rempel #define KSZ8795_HUGE_PACKET_SIZE 2000
68729d1e85fSOleksij Rempel #define KSZ8863_HUGE_PACKET_SIZE 1916
68829d1e85fSOleksij Rempel #define KSZ8863_NORMAL_PACKET_SIZE 1536
68929d1e85fSOleksij Rempel #define KSZ8_LEGAL_PACKET_SIZE 1518
690838c19f8SOleksij Rempel #define KSZ9477_MAX_FRAME_SIZE 9000
691838c19f8SOleksij Rempel
692c570f861SOleksij Rempel #define KSZ9477_REG_PORT_OUT_RATE_0 0x0420
693c570f861SOleksij Rempel #define KSZ9477_OUT_RATE_NO_LIMIT 0
694c570f861SOleksij Rempel
695c570f861SOleksij Rempel #define KSZ9477_PORT_MRI_TC_MAP__4 0x0808
696c570f861SOleksij Rempel
697c570f861SOleksij Rempel #define KSZ9477_PORT_TC_MAP_S 4
698c570f861SOleksij Rempel #define KSZ9477_MAX_TC_PRIO 7
699c570f861SOleksij Rempel
70071d7920fSArun Ramadoss /* CBS related registers */
70171d7920fSArun Ramadoss #define REG_PORT_MTI_QUEUE_INDEX__4 0x0900
70271d7920fSArun Ramadoss
70371d7920fSArun Ramadoss #define REG_PORT_MTI_QUEUE_CTRL_0 0x0914
70471d7920fSArun Ramadoss
70569444581SOleksij Rempel #define MTI_SCHEDULE_MODE_M GENMASK(7, 6)
70671d7920fSArun Ramadoss #define MTI_SCHEDULE_STRICT_PRIO 0
70771d7920fSArun Ramadoss #define MTI_SCHEDULE_WRR 2
70869444581SOleksij Rempel #define MTI_SHAPING_M GENMASK(5, 4)
70971d7920fSArun Ramadoss #define MTI_SHAPING_OFF 0
71071d7920fSArun Ramadoss #define MTI_SHAPING_SRP 1
71171d7920fSArun Ramadoss #define MTI_SHAPING_TIME_AWARE 2
71271d7920fSArun Ramadoss
713c570f861SOleksij Rempel #define KSZ9477_PORT_MTI_QUEUE_CTRL_1 0x0915
714c570f861SOleksij Rempel #define KSZ9477_DEFAULT_WRR_WEIGHT 1
715c570f861SOleksij Rempel
71671d7920fSArun Ramadoss #define REG_PORT_MTI_HI_WATER_MARK 0x0916
71771d7920fSArun Ramadoss #define REG_PORT_MTI_LO_WATER_MARK 0x0918
71871d7920fSArun Ramadoss
719255b59adSMarek Vasut /* Regmap tables generation */
720255b59adSMarek Vasut #define KSZ_SPI_OP_RD 3
721255b59adSMarek Vasut #define KSZ_SPI_OP_WR 2
722255b59adSMarek Vasut
72320e03777STristram Ha #define swabnot_used(x) 0
72420e03777STristram Ha
725255b59adSMarek Vasut #define KSZ_SPI_OP_FLAG_MASK(opcode, swp, regbits, regpad) \
726255b59adSMarek Vasut swab##swp((opcode) << ((regbits) + (regpad)))
727255b59adSMarek Vasut
728255b59adSMarek Vasut #define KSZ_REGMAP_ENTRY(width, swp, regbits, regpad, regalign) \
729255b59adSMarek Vasut { \
7305f81d545SGeorge McCollister .name = #width, \
731255b59adSMarek Vasut .val_bits = (width), \
732a3aa6e65SMarek Vasut .reg_stride = 1, \
733255b59adSMarek Vasut .reg_bits = (regbits) + (regalign), \
734255b59adSMarek Vasut .pad_bits = (regpad), \
735255b59adSMarek Vasut .max_register = BIT(regbits) - 1, \
736255b59adSMarek Vasut .cache_type = REGCACHE_NONE, \
737255b59adSMarek Vasut .read_flag_mask = \
738255b59adSMarek Vasut KSZ_SPI_OP_FLAG_MASK(KSZ_SPI_OP_RD, swp, \
739255b59adSMarek Vasut regbits, regpad), \
740255b59adSMarek Vasut .write_flag_mask = \
741255b59adSMarek Vasut KSZ_SPI_OP_FLAG_MASK(KSZ_SPI_OP_WR, swp, \
742255b59adSMarek Vasut regbits, regpad), \
743013572a2SMarek Vasut .lock = ksz_regmap_lock, \
744013572a2SMarek Vasut .unlock = ksz_regmap_unlock, \
745255b59adSMarek Vasut .reg_format_endian = REGMAP_ENDIAN_BIG, \
746255b59adSMarek Vasut .val_format_endian = REGMAP_ENDIAN_BIG \
747255b59adSMarek Vasut }
748255b59adSMarek Vasut
749255b59adSMarek Vasut #define KSZ_REGMAP_TABLE(ksz, swp, regbits, regpad, regalign) \
750255b59adSMarek Vasut static const struct regmap_config ksz##_regmap_config[] = { \
751b8311f46SVladimir Oltean [KSZ_REGMAP_8] = KSZ_REGMAP_ENTRY(8, swp, (regbits), (regpad), (regalign)), \
752b8311f46SVladimir Oltean [KSZ_REGMAP_16] = KSZ_REGMAP_ENTRY(16, swp, (regbits), (regpad), (regalign)), \
753b8311f46SVladimir Oltean [KSZ_REGMAP_32] = KSZ_REGMAP_ENTRY(32, swp, (regbits), (regpad), (regalign)), \
754255b59adSMarek Vasut }
755255b59adSMarek Vasut
756c2e86691STristram Ha #endif
757