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_LOOKUP_0 = 0, 127 PRESTERA_HW_COUNTER_CLIENT_LOOKUP_1 = 1, 128 PRESTERA_HW_COUNTER_CLIENT_LOOKUP_2 = 2, 129 }; 130 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; 137 138 typedef void (*prestera_event_cb_t) 139 (struct prestera_switch *sw, struct prestera_event *evt, void *arg); 140 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; 146 147 /* Switch API */ 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); 152 153 /* Port API */ 154 int prestera_hw_port_info_get(const struct prestera_port *port, 155 u32 *dev_id, u32 *hw_id, u16 *fp_id); 156 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, 167 u8 mdix); 168 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, 182 unsigned long val); 183 int prestera_hw_port_accept_frm_type(struct prestera_port *port, 184 enum prestera_accept_frm_type type); 185 /* Vlan API */ 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); 192 193 /* FDB API */ 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, 197 u16 vid); 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, 201 u32 mode); 202 203 /* Bridge API */ 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); 208 209 /* vTCAM API */ 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, 225 u32 vtcam_id); 226 227 /* Counter API */ 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, 235 u32 *num_counters); 236 int prestera_hw_counter_block_release(struct prestera_switch *sw, 237 u32 block_id); 238 int prestera_hw_counter_clear(struct prestera_switch *sw, u32 block_id, 239 u32 counter_id); 240 241 /* SPAN API */ 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); 246 247 /* Router API */ 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); 252 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); 256 257 /* LPM PI */ 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); 262 263 /* Event handlers */ 264 int prestera_hw_event_handler_register(struct prestera_switch *sw, 265 enum prestera_event_type type, 266 prestera_event_cb_t fn, 267 void *arg); 268 void prestera_hw_event_handler_unregister(struct prestera_switch *sw, 269 enum prestera_event_type type, 270 prestera_event_cb_t fn); 271 272 /* RX/TX */ 273 int prestera_hw_rxtx_init(struct prestera_switch *sw, 274 struct prestera_rxtx_params *params); 275 276 /* LAG API */ 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, 280 bool enable); 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, 286 u32 mode); 287 int prestera_hw_fdb_flush_lag_vlan(struct prestera_switch *sw, 288 u16 lag_id, u16 vid, u32 mode); 289 290 /* HW trap/drop counters API */ 291 int 292 prestera_hw_cpu_code_counters_get(struct prestera_switch *sw, u8 code, 293 enum prestera_hw_cpu_code_cnt_t counter_type, 294 u64 *packet_count); 295 296 /* Policer API */ 297 int prestera_hw_policer_create(struct prestera_switch *sw, u8 type, 298 u32 *policer_id); 299 int prestera_hw_policer_release(struct prestera_switch *sw, 300 u32 policer_id); 301 int prestera_hw_policer_sr_tcm_set(struct prestera_switch *sw, 302 u32 policer_id, u64 cir, u32 cbs); 303 304 #endif /* _PRESTERA_HW_H_ */ 305