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 
150 /* Switch API */
151 int prestera_hw_switch_init(struct prestera_switch *sw);
152 void prestera_hw_switch_fini(struct prestera_switch *sw);
153 int prestera_hw_switch_ageing_set(struct prestera_switch *sw, u32 ageing_ms);
154 int prestera_hw_switch_mac_set(struct prestera_switch *sw, const char *mac);
155 
156 /* Port API */
157 int prestera_hw_port_info_get(const struct prestera_port *port,
158 			      u32 *dev_id, u32 *hw_id, u16 *fp_id);
159 
160 int prestera_hw_port_mac_mode_get(const struct prestera_port *port,
161 				  u32 *mode, u32 *speed, u8 *duplex, u8 *fec);
162 int prestera_hw_port_mac_mode_set(const struct prestera_port *port,
163 				  bool admin, u32 mode, u8 inband,
164 				  u32 speed, u8 duplex, u8 fec);
165 int prestera_hw_port_phy_mode_get(const struct prestera_port *port,
166 				  u8 *mdix, u64 *lmode_bmap,
167 				  bool *fc_pause, bool *fc_asym);
168 int prestera_hw_port_phy_mode_set(const struct prestera_port *port,
169 				  bool admin, bool adv, u32 mode, u64 modes,
170 				  u8 mdix);
171 
172 int prestera_hw_port_mtu_set(const struct prestera_port *port, u32 mtu);
173 int prestera_hw_port_mtu_get(const struct prestera_port *port, u32 *mtu);
174 int prestera_hw_port_mac_set(const struct prestera_port *port, const char *mac);
175 int prestera_hw_port_mac_get(const struct prestera_port *port, char *mac);
176 int prestera_hw_port_cap_get(const struct prestera_port *port,
177 			     struct prestera_port_caps *caps);
178 int prestera_hw_port_type_get(const struct prestera_port *port, u8 *type);
179 int prestera_hw_port_autoneg_restart(struct prestera_port *port);
180 int prestera_hw_port_stats_get(const struct prestera_port *port,
181 			       struct prestera_port_stats *stats);
182 int prestera_hw_port_speed_get(const struct prestera_port *port, u32 *speed);
183 int prestera_hw_port_learning_set(struct prestera_port *port, bool enable);
184 int prestera_hw_port_uc_flood_set(const struct prestera_port *port, bool flood);
185 int prestera_hw_port_mc_flood_set(const struct prestera_port *port, bool flood);
186 int prestera_hw_port_accept_frm_type(struct prestera_port *port,
187 				     enum prestera_accept_frm_type type);
188 /* Vlan API */
189 int prestera_hw_vlan_create(struct prestera_switch *sw, u16 vid);
190 int prestera_hw_vlan_delete(struct prestera_switch *sw, u16 vid);
191 int prestera_hw_vlan_port_set(struct prestera_port *port, u16 vid,
192 			      bool is_member, bool untagged);
193 int prestera_hw_vlan_port_vid_set(struct prestera_port *port, u16 vid);
194 int prestera_hw_vlan_port_stp_set(struct prestera_port *port, u16 vid, u8 state);
195 
196 /* FDB API */
197 int prestera_hw_fdb_add(struct prestera_port *port, const unsigned char *mac,
198 			u16 vid, bool dynamic);
199 int prestera_hw_fdb_del(struct prestera_port *port, const unsigned char *mac,
200 			u16 vid);
201 int prestera_hw_fdb_flush_port(struct prestera_port *port, u32 mode);
202 int prestera_hw_fdb_flush_vlan(struct prestera_switch *sw, u16 vid, u32 mode);
203 int prestera_hw_fdb_flush_port_vlan(struct prestera_port *port, u16 vid,
204 				    u32 mode);
205 
206 /* Bridge API */
207 int prestera_hw_bridge_create(struct prestera_switch *sw, u16 *bridge_id);
208 int prestera_hw_bridge_delete(struct prestera_switch *sw, u16 bridge_id);
209 int prestera_hw_bridge_port_add(struct prestera_port *port, u16 bridge_id);
210 int prestera_hw_bridge_port_delete(struct prestera_port *port, u16 bridge_id);
211 
212 /* vTCAM API */
213 int prestera_hw_vtcam_create(struct prestera_switch *sw,
214 			     u8 lookup, const u32 *keymask, u32 *vtcam_id,
215 			     enum prestera_hw_vtcam_direction_t direction);
216 int prestera_hw_vtcam_rule_add(struct prestera_switch *sw, u32 vtcam_id,
217 			       u32 prio, void *key, void *keymask,
218 			       struct prestera_acl_hw_action_info *act,
219 			       u8 n_act, u32 *rule_id);
220 int prestera_hw_vtcam_rule_del(struct prestera_switch *sw,
221 			       u32 vtcam_id, u32 rule_id);
222 int prestera_hw_vtcam_destroy(struct prestera_switch *sw, u32 vtcam_id);
223 int prestera_hw_vtcam_iface_bind(struct prestera_switch *sw,
224 				 struct prestera_acl_iface *iface,
225 				 u32 vtcam_id, u16 pcl_id);
226 int prestera_hw_vtcam_iface_unbind(struct prestera_switch *sw,
227 				   struct prestera_acl_iface *iface,
228 				   u32 vtcam_id);
229 
230 /* Counter API */
231 int prestera_hw_counter_trigger(struct prestera_switch *sw, u32 block_id);
232 int prestera_hw_counter_abort(struct prestera_switch *sw);
233 int prestera_hw_counters_get(struct prestera_switch *sw, u32 idx,
234 			     u32 *len, bool *done,
235 			     struct prestera_counter_stats *stats);
236 int prestera_hw_counter_block_get(struct prestera_switch *sw,
237 				  u32 client, u32 *block_id, u32 *offset,
238 				  u32 *num_counters);
239 int prestera_hw_counter_block_release(struct prestera_switch *sw,
240 				      u32 block_id);
241 int prestera_hw_counter_clear(struct prestera_switch *sw, u32 block_id,
242 			      u32 counter_id);
243 
244 /* SPAN API */
245 int prestera_hw_span_get(const struct prestera_port *port, u8 *span_id);
246 int prestera_hw_span_bind(const struct prestera_port *port, u8 span_id);
247 int prestera_hw_span_unbind(const struct prestera_port *port);
248 int prestera_hw_span_release(struct prestera_switch *sw, u8 span_id);
249 
250 /* Router API */
251 int prestera_hw_rif_create(struct prestera_switch *sw,
252 			   struct prestera_iface *iif, u8 *mac, u16 *rif_id);
253 int prestera_hw_rif_delete(struct prestera_switch *sw, u16 rif_id,
254 			   struct prestera_iface *iif);
255 
256 /* Virtual Router API */
257 int prestera_hw_vr_create(struct prestera_switch *sw, u16 *vr_id);
258 int prestera_hw_vr_delete(struct prestera_switch *sw, u16 vr_id);
259 
260 /* LPM PI */
261 int prestera_hw_lpm_add(struct prestera_switch *sw, u16 vr_id,
262 			__be32 dst, u32 dst_len, u32 grp_id);
263 int prestera_hw_lpm_del(struct prestera_switch *sw, u16 vr_id,
264 			__be32 dst, u32 dst_len);
265 
266 /* Event handlers */
267 int prestera_hw_event_handler_register(struct prestera_switch *sw,
268 				       enum prestera_event_type type,
269 				       prestera_event_cb_t fn,
270 				       void *arg);
271 void prestera_hw_event_handler_unregister(struct prestera_switch *sw,
272 					  enum prestera_event_type type,
273 					  prestera_event_cb_t fn);
274 
275 /* RX/TX */
276 int prestera_hw_rxtx_init(struct prestera_switch *sw,
277 			  struct prestera_rxtx_params *params);
278 
279 /* LAG API */
280 int prestera_hw_lag_member_add(struct prestera_port *port, u16 lag_id);
281 int prestera_hw_lag_member_del(struct prestera_port *port, u16 lag_id);
282 int prestera_hw_lag_member_enable(struct prestera_port *port, u16 lag_id,
283 				  bool enable);
284 int prestera_hw_lag_fdb_add(struct prestera_switch *sw, u16 lag_id,
285 			    const unsigned char *mac, u16 vid, bool dynamic);
286 int prestera_hw_lag_fdb_del(struct prestera_switch *sw, u16 lag_id,
287 			    const unsigned char *mac, u16 vid);
288 int prestera_hw_fdb_flush_lag(struct prestera_switch *sw, u16 lag_id,
289 			      u32 mode);
290 int prestera_hw_fdb_flush_lag_vlan(struct prestera_switch *sw,
291 				   u16 lag_id, u16 vid, u32 mode);
292 
293 /* HW trap/drop counters API */
294 int
295 prestera_hw_cpu_code_counters_get(struct prestera_switch *sw, u8 code,
296 				  enum prestera_hw_cpu_code_cnt_t counter_type,
297 				  u64 *packet_count);
298 
299 /* Policer API */
300 int prestera_hw_policer_create(struct prestera_switch *sw, u8 type,
301 			       u32 *policer_id);
302 int prestera_hw_policer_release(struct prestera_switch *sw,
303 				u32 policer_id);
304 int prestera_hw_policer_sr_tcm_set(struct prestera_switch *sw,
305 				   u32 policer_id, u64 cir, u32 cbs);
306 
307 /* Flood domain / MDB API */
308 int prestera_hw_flood_domain_create(struct prestera_flood_domain *domain);
309 int prestera_hw_flood_domain_destroy(struct prestera_flood_domain *domain);
310 int prestera_hw_flood_domain_ports_set(struct prestera_flood_domain *domain);
311 int prestera_hw_flood_domain_ports_reset(struct prestera_flood_domain *domain);
312 
313 int prestera_hw_mdb_create(struct prestera_mdb_entry *mdb);
314 int prestera_hw_mdb_destroy(struct prestera_mdb_entry *mdb);
315 
316 #endif /* _PRESTERA_HW_H_ */
317