xref: /openbmc/linux/drivers/net/ethernet/ti/cpsw_ale.h (revision 23015ff1)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Texas Instruments N-Port Ethernet Switch Address Lookup Engine APIs
4  *
5  * Copyright (C) 2012 Texas Instruments
6  *
7  */
8 #ifndef __TI_CPSW_ALE_H__
9 #define __TI_CPSW_ALE_H__
10 
11 struct cpsw_ale_params {
12 	struct device		*dev;
13 	void __iomem		*ale_regs;
14 	unsigned long		ale_ageout;	/* in secs */
15 	unsigned long		ale_entries;
16 	unsigned long		ale_ports;
17 	/* NU Switch has specific handling as number of bits in ALE entries
18 	 * are different than other versions of ALE. Also there are specific
19 	 * registers for unknown vlan specific fields. So use nu_switch_ale
20 	 * to identify this hardware.
21 	 */
22 	bool			nu_switch_ale;
23 	/* mask bit used in NU Switch ALE is 3 bits instead of 8 bits. So
24 	 * pass it from caller.
25 	 */
26 	u32			major_ver_mask;
27 	const char		*dev_id;
28 	unsigned long		bus_freq;
29 };
30 
31 struct cpsw_ale {
32 	struct cpsw_ale_params	params;
33 	struct timer_list	timer;
34 	unsigned long		ageout;
35 	u32			version;
36 	u32			features;
37 	/* These bits are different on NetCP NU Switch ALE */
38 	u32			port_mask_bits;
39 	u32			port_num_bits;
40 	u32			vlan_field_bits;
41 	unsigned long		*p0_untag_vid_mask;
42 };
43 
44 enum cpsw_ale_control {
45 	/* global */
46 	ALE_ENABLE,
47 	ALE_CLEAR,
48 	ALE_AGEOUT,
49 	ALE_P0_UNI_FLOOD,
50 	ALE_VLAN_NOLEARN,
51 	ALE_NO_PORT_VLAN,
52 	ALE_OUI_DENY,
53 	ALE_BYPASS,
54 	ALE_RATE_LIMIT_TX,
55 	ALE_VLAN_AWARE,
56 	ALE_AUTH_ENABLE,
57 	ALE_RATE_LIMIT,
58 	/* port controls */
59 	ALE_PORT_STATE,
60 	ALE_PORT_DROP_UNTAGGED,
61 	ALE_PORT_DROP_UNKNOWN_VLAN,
62 	ALE_PORT_NOLEARN,
63 	ALE_PORT_NO_SA_UPDATE,
64 	ALE_PORT_UNKNOWN_VLAN_MEMBER,
65 	ALE_PORT_UNKNOWN_MCAST_FLOOD,
66 	ALE_PORT_UNKNOWN_REG_MCAST_FLOOD,
67 	ALE_PORT_UNTAGGED_EGRESS,
68 	ALE_PORT_MACONLY,
69 	ALE_PORT_MACONLY_CAF,
70 	ALE_PORT_BCAST_LIMIT,
71 	ALE_PORT_MCAST_LIMIT,
72 	ALE_DEFAULT_THREAD_ID,
73 	ALE_DEFAULT_THREAD_ENABLE,
74 	ALE_NUM_CONTROLS,
75 };
76 
77 enum cpsw_ale_port_state {
78 	ALE_PORT_STATE_DISABLE	= 0x00,
79 	ALE_PORT_STATE_BLOCK	= 0x01,
80 	ALE_PORT_STATE_LEARN	= 0x02,
81 	ALE_PORT_STATE_FORWARD	= 0x03,
82 };
83 
84 /* ALE unicast entry flags - passed into cpsw_ale_add_ucast() */
85 #define ALE_SECURE			BIT(0)
86 #define ALE_BLOCKED			BIT(1)
87 #define ALE_SUPER			BIT(2)
88 #define ALE_VLAN			BIT(3)
89 
90 #define ALE_PORT_HOST			BIT(0)
91 #define ALE_PORT_1			BIT(1)
92 #define ALE_PORT_2			BIT(2)
93 
94 #define ALE_MCAST_FWD			0
95 #define ALE_MCAST_BLOCK_LEARN_FWD	1
96 #define ALE_MCAST_FWD_LEARN		2
97 #define ALE_MCAST_FWD_2			3
98 
99 #define ALE_ENTRY_BITS		68
100 #define ALE_ENTRY_WORDS	DIV_ROUND_UP(ALE_ENTRY_BITS, 32)
101 
102 struct cpsw_ale *cpsw_ale_create(struct cpsw_ale_params *params);
103 
104 void cpsw_ale_start(struct cpsw_ale *ale);
105 void cpsw_ale_stop(struct cpsw_ale *ale);
106 
107 int cpsw_ale_flush_multicast(struct cpsw_ale *ale, int port_mask, int vid);
108 int cpsw_ale_add_ucast(struct cpsw_ale *ale, const u8 *addr, int port,
109 		       int flags, u16 vid);
110 int cpsw_ale_del_ucast(struct cpsw_ale *ale, const u8 *addr, int port,
111 		       int flags, u16 vid);
112 int cpsw_ale_add_mcast(struct cpsw_ale *ale, const u8 *addr, int port_mask,
113 		       int flags, u16 vid, int mcast_state);
114 int cpsw_ale_del_mcast(struct cpsw_ale *ale, const u8 *addr, int port_mask,
115 		       int flags, u16 vid);
116 int cpsw_ale_add_vlan(struct cpsw_ale *ale, u16 vid, int port, int untag,
117 			int reg_mcast, int unreg_mcast);
118 int cpsw_ale_del_vlan(struct cpsw_ale *ale, u16 vid, int port);
119 void cpsw_ale_set_allmulti(struct cpsw_ale *ale, int allmulti, int port);
120 
121 int cpsw_ale_control_get(struct cpsw_ale *ale, int port, int control);
122 int cpsw_ale_control_set(struct cpsw_ale *ale, int port,
123 			 int control, int value);
124 void cpsw_ale_dump(struct cpsw_ale *ale, u32 *data);
125 u32 cpsw_ale_get_num_entries(struct cpsw_ale *ale);
126 
127 static inline int cpsw_ale_get_vlan_p0_untag(struct cpsw_ale *ale, u16 vid)
128 {
129 	return test_bit(vid, ale->p0_untag_vid_mask);
130 }
131 
132 int cpsw_ale_vlan_add_modify(struct cpsw_ale *ale, u16 vid, int port_mask,
133 			     int untag_mask, int reg_mcast, int unreg_mcast);
134 void cpsw_ale_set_unreg_mcast(struct cpsw_ale *ale, int unreg_mcast_mask,
135 			      bool add);
136 
137 #endif
138