xref: /openbmc/linux/drivers/net/dsa/microchip/ksz8.h (revision 486f9ca715d7b70ed79dbe91296b9e0110deaab5)
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_masks {
16 	PORT_802_1P_REMAPPING,
17 	SW_TAIL_TAG_ENABLE,
18 	MIB_COUNTER_OVERFLOW,
19 	MIB_COUNTER_VALID,
20 	VLAN_TABLE_FID,
21 	VLAN_TABLE_MEMBERSHIP,
22 	VLAN_TABLE_VALID,
23 	STATIC_MAC_TABLE_VALID,
24 	STATIC_MAC_TABLE_USE_FID,
25 	STATIC_MAC_TABLE_FID,
26 	STATIC_MAC_TABLE_OVERRIDE,
27 	STATIC_MAC_TABLE_FWD_PORTS,
28 	DYNAMIC_MAC_TABLE_ENTRIES_H,
29 	DYNAMIC_MAC_TABLE_MAC_EMPTY,
30 	DYNAMIC_MAC_TABLE_NOT_READY,
31 	DYNAMIC_MAC_TABLE_ENTRIES,
32 	DYNAMIC_MAC_TABLE_FID,
33 	DYNAMIC_MAC_TABLE_SRC_PORT,
34 	DYNAMIC_MAC_TABLE_TIMESTAMP,
35 };
36 
37 enum ksz_shifts {
38 	VLAN_TABLE_MEMBERSHIP_S,
39 	VLAN_TABLE,
40 	STATIC_MAC_FWD_PORTS,
41 	STATIC_MAC_FID,
42 	DYNAMIC_MAC_ENTRIES_H,
43 	DYNAMIC_MAC_ENTRIES,
44 	DYNAMIC_MAC_FID,
45 	DYNAMIC_MAC_TIMESTAMP,
46 	DYNAMIC_MAC_SRC_PORT,
47 };
48 
49 struct ksz8 {
50 	const u32 *masks;
51 	const u8 *shifts;
52 	void *priv;
53 };
54 
55 int ksz8_setup(struct dsa_switch *ds);
56 u32 ksz8_get_port_addr(int port, int offset);
57 void ksz8_cfg_port_member(struct ksz_device *dev, int port, u8 member);
58 void ksz8_flush_dyn_mac_table(struct ksz_device *dev, int port);
59 void ksz8_port_setup(struct ksz_device *dev, int port, bool cpu_port);
60 void ksz8_r_phy(struct ksz_device *dev, u16 phy, u16 reg, u16 *val);
61 void ksz8_w_phy(struct ksz_device *dev, u16 phy, u16 reg, u16 val);
62 int ksz8_r_dyn_mac_table(struct ksz_device *dev, u16 addr, u8 *mac_addr,
63 			 u8 *fid, u8 *src_port, u8 *timestamp, u16 *entries);
64 int ksz8_r_sta_mac_table(struct ksz_device *dev, u16 addr,
65 			 struct alu_struct *alu);
66 void ksz8_w_sta_mac_table(struct ksz_device *dev, u16 addr,
67 			  struct alu_struct *alu);
68 void ksz8_r_mib_cnt(struct ksz_device *dev, int port, u16 addr, u64 *cnt);
69 void ksz8_r_mib_pkt(struct ksz_device *dev, int port, u16 addr,
70 		    u64 *dropped, u64 *cnt);
71 void ksz8_freeze_mib(struct ksz_device *dev, int port, bool freeze);
72 void ksz8_port_init_cnt(struct ksz_device *dev, int port);
73 int ksz8_fdb_dump(struct ksz_device *dev, int port,
74 		  dsa_fdb_dump_cb_t *cb, void *data);
75 int ksz8_mdb_add(struct ksz_device *dev, int port,
76 		 const struct switchdev_obj_port_mdb *mdb, struct dsa_db db);
77 int ksz8_mdb_del(struct ksz_device *dev, int port,
78 		 const struct switchdev_obj_port_mdb *mdb, struct dsa_db db);
79 int ksz8_port_vlan_filtering(struct ksz_device *dev, int port, bool flag,
80 			     struct netlink_ext_ack *extack);
81 int ksz8_port_vlan_add(struct ksz_device *dev, int port,
82 		       const struct switchdev_obj_port_vlan *vlan,
83 		       struct netlink_ext_ack *extack);
84 int ksz8_port_vlan_del(struct ksz_device *dev, int port,
85 		       const struct switchdev_obj_port_vlan *vlan);
86 int ksz8_port_mirror_add(struct ksz_device *dev, int port,
87 			 struct dsa_mall_mirror_tc_entry *mirror,
88 			 bool ingress, struct netlink_ext_ack *extack);
89 void ksz8_port_mirror_del(struct ksz_device *dev, int port,
90 			  struct dsa_mall_mirror_tc_entry *mirror);
91 int ksz8_get_stp_reg(void);
92 void ksz8_get_caps(struct ksz_device *dev, int port,
93 		   struct phylink_config *config);
94 void ksz8_config_cpu_port(struct dsa_switch *ds);
95 int ksz8_enable_stp_addr(struct ksz_device *dev);
96 int ksz8_reset_switch(struct ksz_device *dev);
97 int ksz8_switch_detect(struct ksz_device *dev);
98 int ksz8_switch_init(struct ksz_device *dev);
99 void ksz8_switch_exit(struct ksz_device *dev);
100 
101 #endif
102