1 /* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */
2 /* Copyright (c) 2019-2020 Marvell International Ltd. All rights reserved. */
4 #ifndef _PRESTERA_HW_H_
5 #define _PRESTERA_HW_H_
7 #include <linux/types.h>
8 #include "prestera_acl.h"
10 enum prestera_accept_frm_type {
11 PRESTERA_ACCEPT_FRAME_TYPE_TAGGED,
12 PRESTERA_ACCEPT_FRAME_TYPE_UNTAGGED,
13 PRESTERA_ACCEPT_FRAME_TYPE_ALL,
16 enum prestera_fdb_flush_mode {
17 PRESTERA_FDB_FLUSH_MODE_DYNAMIC = BIT(0),
18 PRESTERA_FDB_FLUSH_MODE_STATIC = BIT(1),
19 PRESTERA_FDB_FLUSH_MODE_ALL = PRESTERA_FDB_FLUSH_MODE_DYNAMIC
20 | PRESTERA_FDB_FLUSH_MODE_STATIC,
24 PRESTERA_MAC_MODE_INTERNAL,
25 PRESTERA_MAC_MODE_SGMII,
26 PRESTERA_MAC_MODE_1000BASE_X,
28 PRESTERA_MAC_MODE_KR2,
29 PRESTERA_MAC_MODE_KR4,
31 PRESTERA_MAC_MODE_CR2,
32 PRESTERA_MAC_MODE_CR4,
33 PRESTERA_MAC_MODE_SR_LR,
34 PRESTERA_MAC_MODE_SR_LR2,
35 PRESTERA_MAC_MODE_SR_LR4,
41 PRESTERA_LINK_MODE_10baseT_Half,
42 PRESTERA_LINK_MODE_10baseT_Full,
43 PRESTERA_LINK_MODE_100baseT_Half,
44 PRESTERA_LINK_MODE_100baseT_Full,
45 PRESTERA_LINK_MODE_1000baseT_Half,
46 PRESTERA_LINK_MODE_1000baseT_Full,
47 PRESTERA_LINK_MODE_1000baseX_Full,
48 PRESTERA_LINK_MODE_1000baseKX_Full,
49 PRESTERA_LINK_MODE_2500baseX_Full,
50 PRESTERA_LINK_MODE_10GbaseKR_Full,
51 PRESTERA_LINK_MODE_10GbaseSR_Full,
52 PRESTERA_LINK_MODE_10GbaseLR_Full,
53 PRESTERA_LINK_MODE_20GbaseKR2_Full,
54 PRESTERA_LINK_MODE_25GbaseCR_Full,
55 PRESTERA_LINK_MODE_25GbaseKR_Full,
56 PRESTERA_LINK_MODE_25GbaseSR_Full,
57 PRESTERA_LINK_MODE_40GbaseKR4_Full,
58 PRESTERA_LINK_MODE_40GbaseCR4_Full,
59 PRESTERA_LINK_MODE_40GbaseSR4_Full,
60 PRESTERA_LINK_MODE_50GbaseCR2_Full,
61 PRESTERA_LINK_MODE_50GbaseKR2_Full,
62 PRESTERA_LINK_MODE_50GbaseSR2_Full,
63 PRESTERA_LINK_MODE_100GbaseKR4_Full,
64 PRESTERA_LINK_MODE_100GbaseSR4_Full,
65 PRESTERA_LINK_MODE_100GbaseCR4_Full,
67 PRESTERA_LINK_MODE_MAX
71 PRESTERA_PORT_TYPE_NONE,
72 PRESTERA_PORT_TYPE_TP,
73 PRESTERA_PORT_TYPE_AUI,
74 PRESTERA_PORT_TYPE_MII,
75 PRESTERA_PORT_TYPE_FIBRE,
76 PRESTERA_PORT_TYPE_BNC,
77 PRESTERA_PORT_TYPE_DA,
78 PRESTERA_PORT_TYPE_OTHER,
80 PRESTERA_PORT_TYPE_MAX
84 PRESTERA_PORT_TCVR_COPPER,
85 PRESTERA_PORT_TCVR_SFP,
87 PRESTERA_PORT_TCVR_MAX
91 PRESTERA_PORT_FEC_OFF,
92 PRESTERA_PORT_FEC_BASER,
99 PRESTERA_PORT_DUPLEX_HALF,
100 PRESTERA_PORT_DUPLEX_FULL,
104 PRESTERA_STP_DISABLED,
105 PRESTERA_STP_BLOCK_LISTEN,
107 PRESTERA_STP_FORWARD,
111 PRESTERA_POLICER_TYPE_INGRESS,
112 PRESTERA_POLICER_TYPE_EGRESS
115 enum prestera_hw_cpu_code_cnt_t {
116 PRESTERA_HW_CPU_CODE_CNT_TYPE_DROP = 0,
117 PRESTERA_HW_CPU_CODE_CNT_TYPE_TRAP = 1,
120 enum prestera_hw_vtcam_direction_t {
121 PRESTERA_HW_VTCAM_DIR_INGRESS = 0,
122 PRESTERA_HW_VTCAM_DIR_EGRESS = 1,
126 PRESTERA_HW_COUNTER_CLIENT_LOOKUP_0 = 0,
127 PRESTERA_HW_COUNTER_CLIENT_LOOKUP_1 = 1,
128 PRESTERA_HW_COUNTER_CLIENT_LOOKUP_2 = 2,
131 struct prestera_switch;
132 struct prestera_port;
133 struct prestera_port_stats;
134 struct prestera_port_caps;
135 enum prestera_event_type;
136 struct prestera_event;
138 typedef void (*prestera_event_cb_t)
139 (struct prestera_switch *sw, struct prestera_event *evt, void *arg);
141 struct prestera_rxtx_params;
142 struct prestera_acl_hw_action_info;
143 struct prestera_acl_iface;
144 struct prestera_counter_stats;
145 struct prestera_iface;
148 int prestera_hw_switch_init(struct prestera_switch *sw);
149 void prestera_hw_switch_fini(struct prestera_switch *sw);
150 int prestera_hw_switch_ageing_set(struct prestera_switch *sw, u32 ageing_ms);
151 int prestera_hw_switch_mac_set(struct prestera_switch *sw, const char *mac);
154 int prestera_hw_port_info_get(const struct prestera_port *port,
155 u32 *dev_id, u32 *hw_id, u16 *fp_id);
157 int prestera_hw_port_mac_mode_get(const struct prestera_port *port,
158 u32 *mode, u32 *speed, u8 *duplex, u8 *fec);
159 int prestera_hw_port_mac_mode_set(const struct prestera_port *port,
160 bool admin, u32 mode, u8 inband,
161 u32 speed, u8 duplex, u8 fec);
162 int prestera_hw_port_phy_mode_get(const struct prestera_port *port,
163 u8 *mdix, u64 *lmode_bmap,
164 bool *fc_pause, bool *fc_asym);
165 int prestera_hw_port_phy_mode_set(const struct prestera_port *port,
166 bool admin, bool adv, u32 mode, u64 modes,
169 int prestera_hw_port_mtu_set(const struct prestera_port *port, u32 mtu);
170 int prestera_hw_port_mtu_get(const struct prestera_port *port, u32 *mtu);
171 int prestera_hw_port_mac_set(const struct prestera_port *port, const char *mac);
172 int prestera_hw_port_mac_get(const struct prestera_port *port, char *mac);
173 int prestera_hw_port_cap_get(const struct prestera_port *port,
174 struct prestera_port_caps *caps);
175 int prestera_hw_port_type_get(const struct prestera_port *port, u8 *type);
176 int prestera_hw_port_autoneg_restart(struct prestera_port *port);
177 int prestera_hw_port_stats_get(const struct prestera_port *port,
178 struct prestera_port_stats *stats);
179 int prestera_hw_port_speed_get(const struct prestera_port *port, u32 *speed);
180 int prestera_hw_port_learning_set(struct prestera_port *port, bool enable);
181 int prestera_hw_port_flood_set(struct prestera_port *port, unsigned long mask,
183 int prestera_hw_port_accept_frm_type(struct prestera_port *port,
184 enum prestera_accept_frm_type type);
186 int prestera_hw_vlan_create(struct prestera_switch *sw, u16 vid);
187 int prestera_hw_vlan_delete(struct prestera_switch *sw, u16 vid);
188 int prestera_hw_vlan_port_set(struct prestera_port *port, u16 vid,
189 bool is_member, bool untagged);
190 int prestera_hw_vlan_port_vid_set(struct prestera_port *port, u16 vid);
191 int prestera_hw_vlan_port_stp_set(struct prestera_port *port, u16 vid, u8 state);
194 int prestera_hw_fdb_add(struct prestera_port *port, const unsigned char *mac,
195 u16 vid, bool dynamic);
196 int prestera_hw_fdb_del(struct prestera_port *port, const unsigned char *mac,
198 int prestera_hw_fdb_flush_port(struct prestera_port *port, u32 mode);
199 int prestera_hw_fdb_flush_vlan(struct prestera_switch *sw, u16 vid, u32 mode);
200 int prestera_hw_fdb_flush_port_vlan(struct prestera_port *port, u16 vid,
204 int prestera_hw_bridge_create(struct prestera_switch *sw, u16 *bridge_id);
205 int prestera_hw_bridge_delete(struct prestera_switch *sw, u16 bridge_id);
206 int prestera_hw_bridge_port_add(struct prestera_port *port, u16 bridge_id);
207 int prestera_hw_bridge_port_delete(struct prestera_port *port, u16 bridge_id);
210 int prestera_hw_vtcam_create(struct prestera_switch *sw,
211 u8 lookup, const u32 *keymask, u32 *vtcam_id,
212 enum prestera_hw_vtcam_direction_t direction);
213 int prestera_hw_vtcam_rule_add(struct prestera_switch *sw, u32 vtcam_id,
214 u32 prio, void *key, void *keymask,
215 struct prestera_acl_hw_action_info *act,
216 u8 n_act, u32 *rule_id);
217 int prestera_hw_vtcam_rule_del(struct prestera_switch *sw,
218 u32 vtcam_id, u32 rule_id);
219 int prestera_hw_vtcam_destroy(struct prestera_switch *sw, u32 vtcam_id);
220 int prestera_hw_vtcam_iface_bind(struct prestera_switch *sw,
221 struct prestera_acl_iface *iface,
222 u32 vtcam_id, u16 pcl_id);
223 int prestera_hw_vtcam_iface_unbind(struct prestera_switch *sw,
224 struct prestera_acl_iface *iface,
228 int prestera_hw_counter_trigger(struct prestera_switch *sw, u32 block_id);
229 int prestera_hw_counter_abort(struct prestera_switch *sw);
230 int prestera_hw_counters_get(struct prestera_switch *sw, u32 idx,
231 u32 *len, bool *done,
232 struct prestera_counter_stats *stats);
233 int prestera_hw_counter_block_get(struct prestera_switch *sw,
234 u32 client, u32 *block_id, u32 *offset,
236 int prestera_hw_counter_block_release(struct prestera_switch *sw,
238 int prestera_hw_counter_clear(struct prestera_switch *sw, u32 block_id,
242 int prestera_hw_span_get(const struct prestera_port *port, u8 *span_id);
243 int prestera_hw_span_bind(const struct prestera_port *port, u8 span_id);
244 int prestera_hw_span_unbind(const struct prestera_port *port);
245 int prestera_hw_span_release(struct prestera_switch *sw, u8 span_id);
248 int prestera_hw_rif_create(struct prestera_switch *sw,
249 struct prestera_iface *iif, u8 *mac, u16 *rif_id);
250 int prestera_hw_rif_delete(struct prestera_switch *sw, u16 rif_id,
251 struct prestera_iface *iif);
253 /* Virtual Router API */
254 int prestera_hw_vr_create(struct prestera_switch *sw, u16 *vr_id);
255 int prestera_hw_vr_delete(struct prestera_switch *sw, u16 vr_id);
258 int prestera_hw_lpm_add(struct prestera_switch *sw, u16 vr_id,
259 __be32 dst, u32 dst_len, u32 grp_id);
260 int prestera_hw_lpm_del(struct prestera_switch *sw, u16 vr_id,
261 __be32 dst, u32 dst_len);
264 int prestera_hw_event_handler_register(struct prestera_switch *sw,
265 enum prestera_event_type type,
266 prestera_event_cb_t fn,
268 void prestera_hw_event_handler_unregister(struct prestera_switch *sw,
269 enum prestera_event_type type,
270 prestera_event_cb_t fn);
273 int prestera_hw_rxtx_init(struct prestera_switch *sw,
274 struct prestera_rxtx_params *params);
277 int prestera_hw_lag_member_add(struct prestera_port *port, u16 lag_id);
278 int prestera_hw_lag_member_del(struct prestera_port *port, u16 lag_id);
279 int prestera_hw_lag_member_enable(struct prestera_port *port, u16 lag_id,
281 int prestera_hw_lag_fdb_add(struct prestera_switch *sw, u16 lag_id,
282 const unsigned char *mac, u16 vid, bool dynamic);
283 int prestera_hw_lag_fdb_del(struct prestera_switch *sw, u16 lag_id,
284 const unsigned char *mac, u16 vid);
285 int prestera_hw_fdb_flush_lag(struct prestera_switch *sw, u16 lag_id,
287 int prestera_hw_fdb_flush_lag_vlan(struct prestera_switch *sw,
288 u16 lag_id, u16 vid, u32 mode);
290 /* HW trap/drop counters API */
292 prestera_hw_cpu_code_counters_get(struct prestera_switch *sw, u8 code,
293 enum prestera_hw_cpu_code_cnt_t counter_type,
297 int prestera_hw_policer_create(struct prestera_switch *sw, u8 type,
299 int prestera_hw_policer_release(struct prestera_switch *sw,
301 int prestera_hw_policer_sr_tcm_set(struct prestera_switch *sw,
302 u32 policer_id, u64 cir, u32 cbs);
304 #endif /* _PRESTERA_HW_H_ */