1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Texas Instruments N-Port Ethernet Switch Address Lookup Engine APIs
5 * Copyright (C) 2012 Texas Instruments
8 #ifndef __TI_CPSW_ALE_H__
9 #define __TI_CPSW_ALE_H__
11 struct cpsw_ale_params
{
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.
23 /* mask bit used in NU Switch ALE is 3 bits instead of 8 bits. So
24 * pass it from caller.
30 struct cpsw_ale_params params
;
31 struct timer_list timer
;
34 /* These bits are different on NetCP NU Switch ALE */
38 unsigned long *p0_untag_vid_mask
;
41 enum cpsw_ale_control
{
57 ALE_PORT_DROP_UNTAGGED
,
58 ALE_PORT_DROP_UNKNOWN_VLAN
,
60 ALE_PORT_NO_SA_UPDATE
,
61 ALE_PORT_UNKNOWN_VLAN_MEMBER
,
62 ALE_PORT_UNKNOWN_MCAST_FLOOD
,
63 ALE_PORT_UNKNOWN_REG_MCAST_FLOOD
,
64 ALE_PORT_UNTAGGED_EGRESS
,
70 enum cpsw_ale_port_state
{
71 ALE_PORT_STATE_DISABLE
= 0x00,
72 ALE_PORT_STATE_BLOCK
= 0x01,
73 ALE_PORT_STATE_LEARN
= 0x02,
74 ALE_PORT_STATE_FORWARD
= 0x03,
77 /* ALE unicast entry flags - passed into cpsw_ale_add_ucast() */
78 #define ALE_SECURE BIT(0)
79 #define ALE_BLOCKED BIT(1)
80 #define ALE_SUPER BIT(2)
81 #define ALE_VLAN BIT(3)
83 #define ALE_PORT_HOST BIT(0)
84 #define ALE_PORT_1 BIT(1)
85 #define ALE_PORT_2 BIT(2)
87 #define ALE_MCAST_FWD 0
88 #define ALE_MCAST_BLOCK_LEARN_FWD 1
89 #define ALE_MCAST_FWD_LEARN 2
90 #define ALE_MCAST_FWD_2 3
92 #define ALE_ENTRY_BITS 68
93 #define ALE_ENTRY_WORDS DIV_ROUND_UP(ALE_ENTRY_BITS, 32)
95 struct cpsw_ale
*cpsw_ale_create(struct cpsw_ale_params
*params
);
97 void cpsw_ale_start(struct cpsw_ale
*ale
);
98 void cpsw_ale_stop(struct cpsw_ale
*ale
);
100 int cpsw_ale_flush_multicast(struct cpsw_ale
*ale
, int port_mask
, int vid
);
101 int cpsw_ale_add_ucast(struct cpsw_ale
*ale
, const u8
*addr
, int port
,
103 int cpsw_ale_del_ucast(struct cpsw_ale
*ale
, const u8
*addr
, int port
,
105 int cpsw_ale_add_mcast(struct cpsw_ale
*ale
, const u8
*addr
, int port_mask
,
106 int flags
, u16 vid
, int mcast_state
);
107 int cpsw_ale_del_mcast(struct cpsw_ale
*ale
, const u8
*addr
, int port_mask
,
109 int cpsw_ale_add_vlan(struct cpsw_ale
*ale
, u16 vid
, int port
, int untag
,
110 int reg_mcast
, int unreg_mcast
);
111 int cpsw_ale_del_vlan(struct cpsw_ale
*ale
, u16 vid
, int port
);
112 void cpsw_ale_set_allmulti(struct cpsw_ale
*ale
, int allmulti
, int port
);
114 int cpsw_ale_control_get(struct cpsw_ale
*ale
, int port
, int control
);
115 int cpsw_ale_control_set(struct cpsw_ale
*ale
, int port
,
116 int control
, int value
);
117 void cpsw_ale_dump(struct cpsw_ale
*ale
, u32
*data
);
119 static inline int cpsw_ale_get_vlan_p0_untag(struct cpsw_ale
*ale
, u16 vid
)
121 return test_bit(vid
, ale
->p0_untag_vid_mask
);
124 int cpsw_ale_vlan_add_modify(struct cpsw_ale
*ale
, u16 vid
, int port_mask
,
125 int untag_mask
, int reg_mcast
, int unreg_mcast
);
126 void cpsw_ale_set_unreg_mcast(struct cpsw_ale
*ale
, int unreg_mcast_mask
,