xref: /linux/drivers/net/ethernet/marvell/prestera/prestera_hw.h (revision a4eb44a6435d6d8f9e642407a4a06f65eb90ca04)
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 prestera_hw_cpu_code_cnt_t {
111 	PRESTERA_HW_CPU_CODE_CNT_TYPE_DROP = 0,
112 	PRESTERA_HW_CPU_CODE_CNT_TYPE_TRAP = 1,
113 };
114 
115 enum prestera_hw_vtcam_direction_t {
116 	PRESTERA_HW_VTCAM_DIR_INGRESS = 0,
117 	PRESTERA_HW_VTCAM_DIR_EGRESS = 1,
118 };
119 
120 enum {
121 	PRESTERA_HW_COUNTER_CLIENT_LOOKUP_0 = 0,
122 	PRESTERA_HW_COUNTER_CLIENT_LOOKUP_1 = 1,
123 	PRESTERA_HW_COUNTER_CLIENT_LOOKUP_2 = 2,
124 };
125 
126 struct prestera_switch;
127 struct prestera_port;
128 struct prestera_port_stats;
129 struct prestera_port_caps;
130 enum prestera_event_type;
131 struct prestera_event;
132 
133 typedef void (*prestera_event_cb_t)
134 	(struct prestera_switch *sw, struct prestera_event *evt, void *arg);
135 
136 struct prestera_rxtx_params;
137 struct prestera_acl_hw_action_info;
138 struct prestera_acl_iface;
139 struct prestera_counter_stats;
140 struct prestera_iface;
141 
142 /* Switch API */
143 int prestera_hw_switch_init(struct prestera_switch *sw);
144 void prestera_hw_switch_fini(struct prestera_switch *sw);
145 int prestera_hw_switch_ageing_set(struct prestera_switch *sw, u32 ageing_ms);
146 int prestera_hw_switch_mac_set(struct prestera_switch *sw, const char *mac);
147 
148 /* Port API */
149 int prestera_hw_port_info_get(const struct prestera_port *port,
150 			      u32 *dev_id, u32 *hw_id, u16 *fp_id);
151 
152 int prestera_hw_port_mac_mode_get(const struct prestera_port *port,
153 				  u32 *mode, u32 *speed, u8 *duplex, u8 *fec);
154 int prestera_hw_port_mac_mode_set(const struct prestera_port *port,
155 				  bool admin, u32 mode, u8 inband,
156 				  u32 speed, u8 duplex, u8 fec);
157 int prestera_hw_port_phy_mode_get(const struct prestera_port *port,
158 				  u8 *mdix, u64 *lmode_bmap,
159 				  bool *fc_pause, bool *fc_asym);
160 int prestera_hw_port_phy_mode_set(const struct prestera_port *port,
161 				  bool admin, bool adv, u32 mode, u64 modes,
162 				  u8 mdix);
163 
164 int prestera_hw_port_mtu_set(const struct prestera_port *port, u32 mtu);
165 int prestera_hw_port_mtu_get(const struct prestera_port *port, u32 *mtu);
166 int prestera_hw_port_mac_set(const struct prestera_port *port, const char *mac);
167 int prestera_hw_port_mac_get(const struct prestera_port *port, char *mac);
168 int prestera_hw_port_cap_get(const struct prestera_port *port,
169 			     struct prestera_port_caps *caps);
170 int prestera_hw_port_type_get(const struct prestera_port *port, u8 *type);
171 int prestera_hw_port_autoneg_restart(struct prestera_port *port);
172 int prestera_hw_port_stats_get(const struct prestera_port *port,
173 			       struct prestera_port_stats *stats);
174 int prestera_hw_port_speed_get(const struct prestera_port *port, u32 *speed);
175 int prestera_hw_port_learning_set(struct prestera_port *port, bool enable);
176 int prestera_hw_port_flood_set(struct prestera_port *port, unsigned long mask,
177 			       unsigned long val);
178 int prestera_hw_port_accept_frm_type(struct prestera_port *port,
179 				     enum prestera_accept_frm_type type);
180 /* Vlan API */
181 int prestera_hw_vlan_create(struct prestera_switch *sw, u16 vid);
182 int prestera_hw_vlan_delete(struct prestera_switch *sw, u16 vid);
183 int prestera_hw_vlan_port_set(struct prestera_port *port, u16 vid,
184 			      bool is_member, bool untagged);
185 int prestera_hw_vlan_port_vid_set(struct prestera_port *port, u16 vid);
186 int prestera_hw_vlan_port_stp_set(struct prestera_port *port, u16 vid, u8 state);
187 
188 /* FDB API */
189 int prestera_hw_fdb_add(struct prestera_port *port, const unsigned char *mac,
190 			u16 vid, bool dynamic);
191 int prestera_hw_fdb_del(struct prestera_port *port, const unsigned char *mac,
192 			u16 vid);
193 int prestera_hw_fdb_flush_port(struct prestera_port *port, u32 mode);
194 int prestera_hw_fdb_flush_vlan(struct prestera_switch *sw, u16 vid, u32 mode);
195 int prestera_hw_fdb_flush_port_vlan(struct prestera_port *port, u16 vid,
196 				    u32 mode);
197 
198 /* Bridge API */
199 int prestera_hw_bridge_create(struct prestera_switch *sw, u16 *bridge_id);
200 int prestera_hw_bridge_delete(struct prestera_switch *sw, u16 bridge_id);
201 int prestera_hw_bridge_port_add(struct prestera_port *port, u16 bridge_id);
202 int prestera_hw_bridge_port_delete(struct prestera_port *port, u16 bridge_id);
203 
204 /* vTCAM API */
205 int prestera_hw_vtcam_create(struct prestera_switch *sw,
206 			     u8 lookup, const u32 *keymask, u32 *vtcam_id,
207 			     enum prestera_hw_vtcam_direction_t direction);
208 int prestera_hw_vtcam_rule_add(struct prestera_switch *sw, u32 vtcam_id,
209 			       u32 prio, void *key, void *keymask,
210 			       struct prestera_acl_hw_action_info *act,
211 			       u8 n_act, u32 *rule_id);
212 int prestera_hw_vtcam_rule_del(struct prestera_switch *sw,
213 			       u32 vtcam_id, u32 rule_id);
214 int prestera_hw_vtcam_destroy(struct prestera_switch *sw, u32 vtcam_id);
215 int prestera_hw_vtcam_iface_bind(struct prestera_switch *sw,
216 				 struct prestera_acl_iface *iface,
217 				 u32 vtcam_id, u16 pcl_id);
218 int prestera_hw_vtcam_iface_unbind(struct prestera_switch *sw,
219 				   struct prestera_acl_iface *iface,
220 				   u32 vtcam_id);
221 
222 /* Counter API */
223 int prestera_hw_counter_trigger(struct prestera_switch *sw, u32 block_id);
224 int prestera_hw_counter_abort(struct prestera_switch *sw);
225 int prestera_hw_counters_get(struct prestera_switch *sw, u32 idx,
226 			     u32 *len, bool *done,
227 			     struct prestera_counter_stats *stats);
228 int prestera_hw_counter_block_get(struct prestera_switch *sw,
229 				  u32 client, u32 *block_id, u32 *offset,
230 				  u32 *num_counters);
231 int prestera_hw_counter_block_release(struct prestera_switch *sw,
232 				      u32 block_id);
233 int prestera_hw_counter_clear(struct prestera_switch *sw, u32 block_id,
234 			      u32 counter_id);
235 
236 /* SPAN API */
237 int prestera_hw_span_get(const struct prestera_port *port, u8 *span_id);
238 int prestera_hw_span_bind(const struct prestera_port *port, u8 span_id);
239 int prestera_hw_span_unbind(const struct prestera_port *port);
240 int prestera_hw_span_release(struct prestera_switch *sw, u8 span_id);
241 
242 /* Router API */
243 int prestera_hw_rif_create(struct prestera_switch *sw,
244 			   struct prestera_iface *iif, u8 *mac, u16 *rif_id);
245 int prestera_hw_rif_delete(struct prestera_switch *sw, u16 rif_id,
246 			   struct prestera_iface *iif);
247 
248 /* Virtual Router API */
249 int prestera_hw_vr_create(struct prestera_switch *sw, u16 *vr_id);
250 int prestera_hw_vr_delete(struct prestera_switch *sw, u16 vr_id);
251 
252 /* Event handlers */
253 int prestera_hw_event_handler_register(struct prestera_switch *sw,
254 				       enum prestera_event_type type,
255 				       prestera_event_cb_t fn,
256 				       void *arg);
257 void prestera_hw_event_handler_unregister(struct prestera_switch *sw,
258 					  enum prestera_event_type type,
259 					  prestera_event_cb_t fn);
260 
261 /* RX/TX */
262 int prestera_hw_rxtx_init(struct prestera_switch *sw,
263 			  struct prestera_rxtx_params *params);
264 
265 /* LAG API */
266 int prestera_hw_lag_member_add(struct prestera_port *port, u16 lag_id);
267 int prestera_hw_lag_member_del(struct prestera_port *port, u16 lag_id);
268 int prestera_hw_lag_member_enable(struct prestera_port *port, u16 lag_id,
269 				  bool enable);
270 int prestera_hw_lag_fdb_add(struct prestera_switch *sw, u16 lag_id,
271 			    const unsigned char *mac, u16 vid, bool dynamic);
272 int prestera_hw_lag_fdb_del(struct prestera_switch *sw, u16 lag_id,
273 			    const unsigned char *mac, u16 vid);
274 int prestera_hw_fdb_flush_lag(struct prestera_switch *sw, u16 lag_id,
275 			      u32 mode);
276 int prestera_hw_fdb_flush_lag_vlan(struct prestera_switch *sw,
277 				   u16 lag_id, u16 vid, u32 mode);
278 
279 /* HW trap/drop counters API */
280 int
281 prestera_hw_cpu_code_counters_get(struct prestera_switch *sw, u8 code,
282 				  enum prestera_hw_cpu_code_cnt_t counter_type,
283 				  u64 *packet_count);
284 
285 #endif /* _PRESTERA_HW_H_ */
286