xref: /linux/drivers/net/dsa/microchip/ksz9477.h (revision 9cebfe6504488198b012e746bc6b313f88b95439)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Microchip KSZ9477 series Header file
4  *
5  * Copyright (C) 2017-2025 Microchip Technology Inc.
6  */
7 
8 #ifndef __KSZ9477_H
9 #define __KSZ9477_H
10 
11 #include <net/dsa.h>
12 #include "ksz_common.h"
13 
14 u32 ksz9477_get_port_addr(int port, int offset);
15 void ksz9477_cfg_port_member(struct ksz_device *dev, int port, u8 member);
16 void ksz9477_flush_dyn_mac_table(struct dsa_switch *ds, int port);
17 void ksz9477_r_mib_cnt(struct ksz_device *dev, int port, u16 addr, u64 *cnt);
18 void ksz9477_r_mib_pkt(struct ksz_device *dev, int port, u16 addr,
19 		       u64 *dropped, u64 *cnt);
20 void ksz9477_freeze_mib(struct ksz_device *dev, int port, bool freeze);
21 void ksz9477_port_init_cnt(struct ksz_device *dev, int port);
22 int ksz9477_port_vlan_filtering(struct dsa_switch *ds, int port,
23 				bool flag, struct netlink_ext_ack *extack);
24 int ksz9477_max_mtu(struct dsa_switch *ds, int port);
25 int ksz9477_port_vlan_add(struct dsa_switch *ds, int port,
26 			  const struct switchdev_obj_port_vlan *vlan,
27 			  struct netlink_ext_ack *extack);
28 int ksz9477_port_vlan_del(struct dsa_switch *ds, int port,
29 			  const struct switchdev_obj_port_vlan *vlan);
30 int ksz9477_port_mirror_add(struct dsa_switch *ds, int port,
31 			    struct dsa_mall_mirror_tc_entry *mirror,
32 			    bool ingress, struct netlink_ext_ack *extack);
33 void ksz9477_port_mirror_del(struct dsa_switch *ds, int port,
34 			     struct dsa_mall_mirror_tc_entry *mirror);
35 int ksz9477_fdb_dump(struct dsa_switch *ds, int port,
36 		     dsa_fdb_dump_cb_t *cb, void *data);
37 int ksz9477_fdb_add(struct dsa_switch *ds, int port,
38 		    const unsigned char *addr, u16 vid, struct dsa_db db);
39 int ksz9477_fdb_del(struct dsa_switch *ds, int port,
40 		    const unsigned char *addr, u16 vid, struct dsa_db db);
41 int ksz9477_mdb_add(struct dsa_switch *ds, int port,
42 		    const struct switchdev_obj_port_mdb *mdb, struct dsa_db db);
43 int ksz9477_mdb_del(struct dsa_switch *ds, int port,
44 		    const struct switchdev_obj_port_mdb *mdb, struct dsa_db db);
45 int ksz9477_enable_stp_addr(struct ksz_device *dev);
46 void ksz9477_port_queue_split(struct ksz_device *dev, int port);
47 int ksz9477_set_default_prio_queue_mapping(struct ksz_device *dev, int port);
48 
49 int ksz9477_port_acl_init(struct ksz_device *dev, int port);
50 void ksz9477_port_acl_free(struct ksz_device *dev, int port);
51 int ksz9477_cls_flower_add(struct dsa_switch *ds, int port,
52 			   struct flow_cls_offload *cls, bool ingress);
53 int ksz9477_cls_flower_del(struct dsa_switch *ds, int port,
54 			   struct flow_cls_offload *cls, bool ingress);
55 
56 #define KSZ9477_ACL_ENTRY_SIZE		18
57 #define KSZ9477_ACL_MAX_ENTRIES		16
58 
59 struct ksz9477_acl_entry {
60 	u8 entry[KSZ9477_ACL_ENTRY_SIZE];
61 	unsigned long cookie;
62 	u32 prio;
63 };
64 
65 struct ksz9477_acl_entries {
66 	struct ksz9477_acl_entry entries[KSZ9477_ACL_MAX_ENTRIES];
67 	int entries_count;
68 };
69 
70 struct ksz9477_acl_priv {
71 	struct ksz9477_acl_entries acles;
72 };
73 
74 void ksz9477_acl_remove_entries(struct ksz_device *dev, int port,
75 				struct ksz9477_acl_entries *acles,
76 				unsigned long cookie);
77 int ksz9477_acl_write_list(struct ksz_device *dev, int port);
78 int ksz9477_sort_acl_entries(struct ksz_device *dev, int port);
79 void ksz9477_acl_action_rule_cfg(u8 *entry, bool force_prio, u8 prio_val);
80 void ksz9477_acl_processing_rule_set_action(u8 *entry, u8 action_idx);
81 void ksz9477_acl_match_process_l2(struct ksz_device *dev, int port,
82 				  u16 ethtype, u8 *src_mac, u8 *dst_mac,
83 				  unsigned long cookie, u32 prio);
84 
85 void ksz9477_phylink_mac_link_up(struct phylink_config *config,
86 				 struct phy_device *phydev,
87 				 unsigned int mode,
88 				 phy_interface_t interface,
89 				 int speed, int duplex, bool tx_pause,
90 				 bool rx_pause);
91 
92 extern const struct ksz_dev_ops ksz9477_dev_ops;
93 extern const struct phylink_mac_ops ksz9477_phylink_mac_ops;
94 extern const struct dsa_switch_ops ksz9477_switch_ops;
95 
96 #endif
97