1 /* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */
2 /* Copyright (c) 2019-2020 Marvell International Ltd. All rights reserved. */
3 
4 #ifndef _PRESTERA_HW_H_
5 #define _PRESTERA_HW_H_
6 
7 #include <linux/types.h>
8 #include "prestera_acl.h"
9 
10 enum prestera_accept_frm_type {
11 	PRESTERA_ACCEPT_FRAME_TYPE_TAGGED,
12 	PRESTERA_ACCEPT_FRAME_TYPE_UNTAGGED,
13 	PRESTERA_ACCEPT_FRAME_TYPE_ALL,
14 };
15 
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,
21 };
22 
23 enum {
24 	PRESTERA_MAC_MODE_INTERNAL,
25 	PRESTERA_MAC_MODE_SGMII,
26 	PRESTERA_MAC_MODE_1000BASE_X,
27 	PRESTERA_MAC_MODE_KR,
28 	PRESTERA_MAC_MODE_KR2,
29 	PRESTERA_MAC_MODE_KR4,
30 	PRESTERA_MAC_MODE_CR,
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,
36 
37 	PRESTERA_MAC_MODE_MAX
38 };
39 
40 enum {
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,
66 
67 	PRESTERA_LINK_MODE_MAX
68 };
69 
70 enum {
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,
79 
80 	PRESTERA_PORT_TYPE_MAX
81 };
82 
83 enum {
84 	PRESTERA_PORT_TCVR_COPPER,
85 	PRESTERA_PORT_TCVR_SFP,
86 
87 	PRESTERA_PORT_TCVR_MAX
88 };
89 
90 enum {
91 	PRESTERA_PORT_FEC_OFF,
92 	PRESTERA_PORT_FEC_BASER,
93 	PRESTERA_PORT_FEC_RS,
94 
95 	PRESTERA_PORT_FEC_MAX
96 };
97 
98 enum {
99 	PRESTERA_PORT_DUPLEX_HALF,
100 	PRESTERA_PORT_DUPLEX_FULL,
101 };
102 
103 enum {
104 	PRESTERA_STP_DISABLED,
105 	PRESTERA_STP_BLOCK_LISTEN,
106 	PRESTERA_STP_LEARN,
107 	PRESTERA_STP_FORWARD,
108 };
109 
110 enum {
111 	PRESTERA_POLICER_TYPE_INGRESS,
112 	PRESTERA_POLICER_TYPE_EGRESS
113 };
114 
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,
118 };
119 
120 enum prestera_hw_vtcam_direction_t {
121 	PRESTERA_HW_VTCAM_DIR_INGRESS = 0,
122 	PRESTERA_HW_VTCAM_DIR_EGRESS = 1,
123 };
124 
125 enum {
126 	PRESTERA_HW_COUNTER_CLIENT_INGRESS_LOOKUP_0 = 0,
127 	PRESTERA_HW_COUNTER_CLIENT_INGRESS_LOOKUP_1 = 1,
128 	PRESTERA_HW_COUNTER_CLIENT_INGRESS_LOOKUP_2 = 2,
129 	PRESTERA_HW_COUNTER_CLIENT_EGRESS_LOOKUP = 3,
130 };
131 
132 struct prestera_switch;
133 struct prestera_port;
134 struct prestera_port_stats;
135 struct prestera_port_caps;
136 enum prestera_event_type;
137 struct prestera_event;
138 
139 typedef void (*prestera_event_cb_t)
140 	(struct prestera_switch *sw, struct prestera_event *evt, void *arg);
141 
142 struct prestera_rxtx_params;
143 struct prestera_acl_hw_action_info;
144 struct prestera_acl_iface;
145 struct prestera_counter_stats;
146 struct prestera_iface;
147 struct prestera_flood_domain;
148 struct prestera_mdb_entry;
149 struct prestera_neigh_info;
150 
151 /* Switch API */
152 int prestera_hw_switch_init(struct prestera_switch *sw);
153 void prestera_hw_switch_fini(struct prestera_switch *sw);
154 int prestera_hw_switch_ageing_set(struct prestera_switch *sw, u32 ageing_ms);
155 int prestera_hw_switch_mac_set(struct prestera_switch *sw, const char *mac);
156 
157 /* Port API */
158 int prestera_hw_port_info_get(const struct prestera_port *port,
159 			      u32 *dev_id, u32 *hw_id, u16 *fp_id);
160 
161 int prestera_hw_port_mac_mode_get(const struct prestera_port *port,
162 				  u32 *mode, u32 *speed, u8 *duplex, u8 *fec);
163 int prestera_hw_port_mac_mode_set(const struct prestera_port *port,
164 				  bool admin, u32 mode, u8 inband,
165 				  u32 speed, u8 duplex, u8 fec);
166 int prestera_hw_port_phy_mode_get(const struct prestera_port *port,
167 				  u8 *mdix, u64 *lmode_bmap,
168 				  bool *fc_pause, bool *fc_asym);
169 int prestera_hw_port_phy_mode_set(const struct prestera_port *port,
170 				  bool admin, bool adv, u32 mode, u64 modes,
171 				  u8 mdix);
172 
173 int prestera_hw_port_mtu_set(const struct prestera_port *port, u32 mtu);
174 int prestera_hw_port_mtu_get(const struct prestera_port *port, u32 *mtu);
175 int prestera_hw_port_mac_set(const struct prestera_port *port, const char *mac);
176 int prestera_hw_port_mac_get(const struct prestera_port *port, char *mac);
177 int prestera_hw_port_cap_get(const struct prestera_port *port,
178 			     struct prestera_port_caps *caps);
179 int prestera_hw_port_type_get(const struct prestera_port *port, u8 *type);
180 int prestera_hw_port_autoneg_restart(struct prestera_port *port);
181 int prestera_hw_port_stats_get(const struct prestera_port *port,
182 			       struct prestera_port_stats *stats);
183 int prestera_hw_port_speed_get(const struct prestera_port *port, u32 *speed);
184 int prestera_hw_port_learning_set(struct prestera_port *port, bool enable);
185 int prestera_hw_port_uc_flood_set(const struct prestera_port *port, bool flood);
186 int prestera_hw_port_mc_flood_set(const struct prestera_port *port, bool flood);
187 int prestera_hw_port_br_locked_set(const struct prestera_port *port,
188 				   bool br_locked);
189 int prestera_hw_port_accept_frm_type(struct prestera_port *port,
190 				     enum prestera_accept_frm_type type);
191 /* Vlan API */
192 int prestera_hw_vlan_create(struct prestera_switch *sw, u16 vid);
193 int prestera_hw_vlan_delete(struct prestera_switch *sw, u16 vid);
194 int prestera_hw_vlan_port_set(struct prestera_port *port, u16 vid,
195 			      bool is_member, bool untagged);
196 int prestera_hw_vlan_port_vid_set(struct prestera_port *port, u16 vid);
197 int prestera_hw_vlan_port_stp_set(struct prestera_port *port, u16 vid, u8 state);
198 
199 /* FDB API */
200 int prestera_hw_fdb_add(struct prestera_port *port, const unsigned char *mac,
201 			u16 vid, bool dynamic);
202 int prestera_hw_fdb_del(struct prestera_port *port, const unsigned char *mac,
203 			u16 vid);
204 int prestera_hw_fdb_flush_port(struct prestera_port *port, u32 mode);
205 int prestera_hw_fdb_flush_vlan(struct prestera_switch *sw, u16 vid, u32 mode);
206 int prestera_hw_fdb_flush_port_vlan(struct prestera_port *port, u16 vid,
207 				    u32 mode);
208 
209 /* Bridge API */
210 int prestera_hw_bridge_create(struct prestera_switch *sw, u16 *bridge_id);
211 int prestera_hw_bridge_delete(struct prestera_switch *sw, u16 bridge_id);
212 int prestera_hw_bridge_port_add(struct prestera_port *port, u16 bridge_id);
213 int prestera_hw_bridge_port_delete(struct prestera_port *port, u16 bridge_id);
214 
215 /* vTCAM API */
216 int prestera_hw_vtcam_create(struct prestera_switch *sw,
217 			     u8 lookup, const u32 *keymask, u32 *vtcam_id,
218 			     enum prestera_hw_vtcam_direction_t direction);
219 int prestera_hw_vtcam_rule_add(struct prestera_switch *sw, u32 vtcam_id,
220 			       u32 prio, void *key, void *keymask,
221 			       struct prestera_acl_hw_action_info *act,
222 			       u8 n_act, u32 *rule_id);
223 int prestera_hw_vtcam_rule_del(struct prestera_switch *sw,
224 			       u32 vtcam_id, u32 rule_id);
225 int prestera_hw_vtcam_destroy(struct prestera_switch *sw, u32 vtcam_id);
226 int prestera_hw_vtcam_iface_bind(struct prestera_switch *sw,
227 				 struct prestera_acl_iface *iface,
228 				 u32 vtcam_id, u16 pcl_id);
229 int prestera_hw_vtcam_iface_unbind(struct prestera_switch *sw,
230 				   struct prestera_acl_iface *iface,
231 				   u32 vtcam_id);
232 
233 /* Counter API */
234 int prestera_hw_counter_trigger(struct prestera_switch *sw, u32 block_id);
235 int prestera_hw_counter_abort(struct prestera_switch *sw);
236 int prestera_hw_counters_get(struct prestera_switch *sw, u32 idx,
237 			     u32 *len, bool *done,
238 			     struct prestera_counter_stats *stats);
239 int prestera_hw_counter_block_get(struct prestera_switch *sw,
240 				  u32 client, u32 *block_id, u32 *offset,
241 				  u32 *num_counters);
242 int prestera_hw_counter_block_release(struct prestera_switch *sw,
243 				      u32 block_id);
244 int prestera_hw_counter_clear(struct prestera_switch *sw, u32 block_id,
245 			      u32 counter_id);
246 
247 /* SPAN API */
248 int prestera_hw_span_get(const struct prestera_port *port, u8 *span_id);
249 int prestera_hw_span_bind(const struct prestera_port *port, u8 span_id,
250 			  bool ingress);
251 int prestera_hw_span_unbind(const struct prestera_port *port, bool ingress);
252 int prestera_hw_span_release(struct prestera_switch *sw, u8 span_id);
253 
254 /* Router API */
255 int prestera_hw_rif_create(struct prestera_switch *sw,
256 			   struct prestera_iface *iif, u8 *mac, u16 *rif_id);
257 int prestera_hw_rif_delete(struct prestera_switch *sw, u16 rif_id,
258 			   struct prestera_iface *iif);
259 
260 /* Virtual Router API */
261 int prestera_hw_vr_create(struct prestera_switch *sw, u16 *vr_id);
262 int prestera_hw_vr_delete(struct prestera_switch *sw, u16 vr_id);
263 
264 /* LPM PI */
265 int prestera_hw_lpm_add(struct prestera_switch *sw, u16 vr_id,
266 			__be32 dst, u32 dst_len, u32 grp_id);
267 int prestera_hw_lpm_del(struct prestera_switch *sw, u16 vr_id,
268 			__be32 dst, u32 dst_len);
269 
270 /* NH API */
271 int prestera_hw_nh_entries_set(struct prestera_switch *sw, int count,
272 			       struct prestera_neigh_info *nhs, u32 grp_id);
273 int prestera_hw_nhgrp_blk_get(struct prestera_switch *sw,
274 			      u8 *hw_state, u32 buf_size /* Buffer in bytes */);
275 int prestera_hw_nh_group_create(struct prestera_switch *sw, u16 nh_count,
276 				u32 *grp_id);
277 int prestera_hw_nh_group_delete(struct prestera_switch *sw, u16 nh_count,
278 				u32 grp_id);
279 
280 /* Event handlers */
281 int prestera_hw_event_handler_register(struct prestera_switch *sw,
282 				       enum prestera_event_type type,
283 				       prestera_event_cb_t fn,
284 				       void *arg);
285 void prestera_hw_event_handler_unregister(struct prestera_switch *sw,
286 					  enum prestera_event_type type,
287 					  prestera_event_cb_t fn);
288 
289 /* RX/TX */
290 int prestera_hw_rxtx_init(struct prestera_switch *sw,
291 			  struct prestera_rxtx_params *params);
292 
293 /* LAG API */
294 int prestera_hw_lag_member_add(struct prestera_port *port, u16 lag_id);
295 int prestera_hw_lag_member_del(struct prestera_port *port, u16 lag_id);
296 int prestera_hw_lag_member_enable(struct prestera_port *port, u16 lag_id,
297 				  bool enable);
298 int prestera_hw_lag_fdb_add(struct prestera_switch *sw, u16 lag_id,
299 			    const unsigned char *mac, u16 vid, bool dynamic);
300 int prestera_hw_lag_fdb_del(struct prestera_switch *sw, u16 lag_id,
301 			    const unsigned char *mac, u16 vid);
302 int prestera_hw_fdb_flush_lag(struct prestera_switch *sw, u16 lag_id,
303 			      u32 mode);
304 int prestera_hw_fdb_flush_lag_vlan(struct prestera_switch *sw,
305 				   u16 lag_id, u16 vid, u32 mode);
306 
307 /* HW trap/drop counters API */
308 int
309 prestera_hw_cpu_code_counters_get(struct prestera_switch *sw, u8 code,
310 				  enum prestera_hw_cpu_code_cnt_t counter_type,
311 				  u64 *packet_count);
312 
313 /* Policer API */
314 int prestera_hw_policer_create(struct prestera_switch *sw, u8 type,
315 			       u32 *policer_id);
316 int prestera_hw_policer_release(struct prestera_switch *sw,
317 				u32 policer_id);
318 int prestera_hw_policer_sr_tcm_set(struct prestera_switch *sw,
319 				   u32 policer_id, u64 cir, u32 cbs);
320 
321 /* Flood domain / MDB API */
322 int prestera_hw_flood_domain_create(struct prestera_flood_domain *domain);
323 int prestera_hw_flood_domain_destroy(struct prestera_flood_domain *domain);
324 int prestera_hw_flood_domain_ports_set(struct prestera_flood_domain *domain);
325 int prestera_hw_flood_domain_ports_reset(struct prestera_flood_domain *domain);
326 
327 int prestera_hw_mdb_create(struct prestera_mdb_entry *mdb);
328 int prestera_hw_mdb_destroy(struct prestera_mdb_entry *mdb);
329 
330 #endif /* _PRESTERA_HW_H_ */
331