xref: /linux/drivers/net/dsa/microchip/ksz8.h (revision 63769819079d87dc322fefaf981589e227de2978)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Microchip KSZ8XXX series register access
4  *
5  * Copyright (C) 2020 Pengutronix, Michael Grzeschik <kernel@pengutronix.de>
6  */
7 
8 #ifndef __KSZ8XXX_H
9 #define __KSZ8XXX_H
10 
11 #include <linux/types.h>
12 #include <net/dsa.h>
13 #include "ksz_common.h"
14 
15 enum ksz_regs {
16 	REG_IND_CTRL_0,
17 	REG_IND_DATA_8,
18 	REG_IND_DATA_CHECK,
19 	REG_IND_DATA_HI,
20 	REG_IND_DATA_LO,
21 	REG_IND_MIB_CHECK,
22 	REG_IND_BYTE,
23 	P_FORCE_CTRL,
24 	P_LINK_STATUS,
25 	P_LOCAL_CTRL,
26 	P_NEG_RESTART_CTRL,
27 	P_REMOTE_STATUS,
28 	P_SPEED_STATUS,
29 	S_TAIL_TAG_CTRL,
30 };
31 
32 enum ksz_masks {
33 	PORT_802_1P_REMAPPING,
34 	SW_TAIL_TAG_ENABLE,
35 	MIB_COUNTER_OVERFLOW,
36 	MIB_COUNTER_VALID,
37 	VLAN_TABLE_FID,
38 	VLAN_TABLE_MEMBERSHIP,
39 	VLAN_TABLE_VALID,
40 	STATIC_MAC_TABLE_VALID,
41 	STATIC_MAC_TABLE_USE_FID,
42 	STATIC_MAC_TABLE_FID,
43 	STATIC_MAC_TABLE_OVERRIDE,
44 	STATIC_MAC_TABLE_FWD_PORTS,
45 	DYNAMIC_MAC_TABLE_ENTRIES_H,
46 	DYNAMIC_MAC_TABLE_MAC_EMPTY,
47 	DYNAMIC_MAC_TABLE_NOT_READY,
48 	DYNAMIC_MAC_TABLE_ENTRIES,
49 	DYNAMIC_MAC_TABLE_FID,
50 	DYNAMIC_MAC_TABLE_SRC_PORT,
51 	DYNAMIC_MAC_TABLE_TIMESTAMP,
52 };
53 
54 enum ksz_shifts {
55 	VLAN_TABLE_MEMBERSHIP_S,
56 	VLAN_TABLE,
57 	STATIC_MAC_FWD_PORTS,
58 	STATIC_MAC_FID,
59 	DYNAMIC_MAC_ENTRIES_H,
60 	DYNAMIC_MAC_ENTRIES,
61 	DYNAMIC_MAC_FID,
62 	DYNAMIC_MAC_TIMESTAMP,
63 	DYNAMIC_MAC_SRC_PORT,
64 };
65 
66 struct ksz8 {
67 	const u8 *regs;
68 	const u32 *masks;
69 	const u8 *shifts;
70 	void *priv;
71 };
72 
73 int ksz8_setup(struct dsa_switch *ds);
74 u32 ksz8_get_port_addr(int port, int offset);
75 void ksz8_cfg_port_member(struct ksz_device *dev, int port, u8 member);
76 void ksz8_flush_dyn_mac_table(struct ksz_device *dev, int port);
77 void ksz8_port_setup(struct ksz_device *dev, int port, bool cpu_port);
78 void ksz8_r_phy(struct ksz_device *dev, u16 phy, u16 reg, u16 *val);
79 void ksz8_w_phy(struct ksz_device *dev, u16 phy, u16 reg, u16 val);
80 int ksz8_r_dyn_mac_table(struct ksz_device *dev, u16 addr, u8 *mac_addr,
81 			 u8 *fid, u8 *src_port, u8 *timestamp, u16 *entries);
82 int ksz8_r_sta_mac_table(struct ksz_device *dev, u16 addr,
83 			 struct alu_struct *alu);
84 void ksz8_w_sta_mac_table(struct ksz_device *dev, u16 addr,
85 			  struct alu_struct *alu);
86 void ksz8_r_mib_cnt(struct ksz_device *dev, int port, u16 addr, u64 *cnt);
87 void ksz8_r_mib_pkt(struct ksz_device *dev, int port, u16 addr,
88 		    u64 *dropped, u64 *cnt);
89 void ksz8_freeze_mib(struct ksz_device *dev, int port, bool freeze);
90 void ksz8_port_init_cnt(struct ksz_device *dev, int port);
91 int ksz8_fdb_dump(struct ksz_device *dev, int port,
92 		  dsa_fdb_dump_cb_t *cb, void *data);
93 int ksz8_mdb_add(struct ksz_device *dev, int port,
94 		 const struct switchdev_obj_port_mdb *mdb, struct dsa_db db);
95 int ksz8_mdb_del(struct ksz_device *dev, int port,
96 		 const struct switchdev_obj_port_mdb *mdb, struct dsa_db db);
97 int ksz8_port_vlan_filtering(struct ksz_device *dev, int port, bool flag,
98 			     struct netlink_ext_ack *extack);
99 int ksz8_port_vlan_add(struct ksz_device *dev, int port,
100 		       const struct switchdev_obj_port_vlan *vlan,
101 		       struct netlink_ext_ack *extack);
102 int ksz8_port_vlan_del(struct ksz_device *dev, int port,
103 		       const struct switchdev_obj_port_vlan *vlan);
104 int ksz8_port_mirror_add(struct ksz_device *dev, int port,
105 			 struct dsa_mall_mirror_tc_entry *mirror,
106 			 bool ingress, struct netlink_ext_ack *extack);
107 void ksz8_port_mirror_del(struct ksz_device *dev, int port,
108 			  struct dsa_mall_mirror_tc_entry *mirror);
109 int ksz8_get_stp_reg(void);
110 void ksz8_get_caps(struct ksz_device *dev, int port,
111 		   struct phylink_config *config);
112 void ksz8_config_cpu_port(struct dsa_switch *ds);
113 int ksz8_enable_stp_addr(struct ksz_device *dev);
114 int ksz8_reset_switch(struct ksz_device *dev);
115 int ksz8_switch_detect(struct ksz_device *dev);
116 int ksz8_switch_init(struct ksz_device *dev);
117 void ksz8_switch_exit(struct ksz_device *dev);
118 
119 #endif
120