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 9 enum prestera_accept_frm_type { 10 PRESTERA_ACCEPT_FRAME_TYPE_TAGGED, 11 PRESTERA_ACCEPT_FRAME_TYPE_UNTAGGED, 12 PRESTERA_ACCEPT_FRAME_TYPE_ALL, 13 }; 14 15 enum prestera_fdb_flush_mode { 16 PRESTERA_FDB_FLUSH_MODE_DYNAMIC = BIT(0), 17 PRESTERA_FDB_FLUSH_MODE_STATIC = BIT(1), 18 PRESTERA_FDB_FLUSH_MODE_ALL = PRESTERA_FDB_FLUSH_MODE_DYNAMIC 19 | PRESTERA_FDB_FLUSH_MODE_STATIC, 20 }; 21 22 enum { 23 PRESTERA_MAC_MODE_INTERNAL, 24 PRESTERA_MAC_MODE_SGMII, 25 PRESTERA_MAC_MODE_1000BASE_X, 26 PRESTERA_MAC_MODE_KR, 27 PRESTERA_MAC_MODE_KR2, 28 PRESTERA_MAC_MODE_KR4, 29 PRESTERA_MAC_MODE_CR, 30 PRESTERA_MAC_MODE_CR2, 31 PRESTERA_MAC_MODE_CR4, 32 PRESTERA_MAC_MODE_SR_LR, 33 PRESTERA_MAC_MODE_SR_LR2, 34 PRESTERA_MAC_MODE_SR_LR4, 35 36 PRESTERA_MAC_MODE_MAX 37 }; 38 39 enum { 40 PRESTERA_LINK_MODE_10baseT_Half, 41 PRESTERA_LINK_MODE_10baseT_Full, 42 PRESTERA_LINK_MODE_100baseT_Half, 43 PRESTERA_LINK_MODE_100baseT_Full, 44 PRESTERA_LINK_MODE_1000baseT_Half, 45 PRESTERA_LINK_MODE_1000baseT_Full, 46 PRESTERA_LINK_MODE_1000baseX_Full, 47 PRESTERA_LINK_MODE_1000baseKX_Full, 48 PRESTERA_LINK_MODE_2500baseX_Full, 49 PRESTERA_LINK_MODE_10GbaseKR_Full, 50 PRESTERA_LINK_MODE_10GbaseSR_Full, 51 PRESTERA_LINK_MODE_10GbaseLR_Full, 52 PRESTERA_LINK_MODE_20GbaseKR2_Full, 53 PRESTERA_LINK_MODE_25GbaseCR_Full, 54 PRESTERA_LINK_MODE_25GbaseKR_Full, 55 PRESTERA_LINK_MODE_25GbaseSR_Full, 56 PRESTERA_LINK_MODE_40GbaseKR4_Full, 57 PRESTERA_LINK_MODE_40GbaseCR4_Full, 58 PRESTERA_LINK_MODE_40GbaseSR4_Full, 59 PRESTERA_LINK_MODE_50GbaseCR2_Full, 60 PRESTERA_LINK_MODE_50GbaseKR2_Full, 61 PRESTERA_LINK_MODE_50GbaseSR2_Full, 62 PRESTERA_LINK_MODE_100GbaseKR4_Full, 63 PRESTERA_LINK_MODE_100GbaseSR4_Full, 64 PRESTERA_LINK_MODE_100GbaseCR4_Full, 65 66 PRESTERA_LINK_MODE_MAX 67 }; 68 69 enum { 70 PRESTERA_PORT_TYPE_NONE, 71 PRESTERA_PORT_TYPE_TP, 72 PRESTERA_PORT_TYPE_AUI, 73 PRESTERA_PORT_TYPE_MII, 74 PRESTERA_PORT_TYPE_FIBRE, 75 PRESTERA_PORT_TYPE_BNC, 76 PRESTERA_PORT_TYPE_DA, 77 PRESTERA_PORT_TYPE_OTHER, 78 79 PRESTERA_PORT_TYPE_MAX 80 }; 81 82 enum { 83 PRESTERA_PORT_TCVR_COPPER, 84 PRESTERA_PORT_TCVR_SFP, 85 86 PRESTERA_PORT_TCVR_MAX 87 }; 88 89 enum { 90 PRESTERA_PORT_FEC_OFF, 91 PRESTERA_PORT_FEC_BASER, 92 PRESTERA_PORT_FEC_RS, 93 94 PRESTERA_PORT_FEC_MAX 95 }; 96 97 enum { 98 PRESTERA_PORT_DUPLEX_HALF, 99 PRESTERA_PORT_DUPLEX_FULL, 100 }; 101 102 enum { 103 PRESTERA_STP_DISABLED, 104 PRESTERA_STP_BLOCK_LISTEN, 105 PRESTERA_STP_LEARN, 106 PRESTERA_STP_FORWARD, 107 }; 108 109 enum prestera_hw_cpu_code_cnt_t { 110 PRESTERA_HW_CPU_CODE_CNT_TYPE_DROP = 0, 111 PRESTERA_HW_CPU_CODE_CNT_TYPE_TRAP = 1, 112 }; 113 114 struct prestera_switch; 115 struct prestera_port; 116 struct prestera_port_stats; 117 struct prestera_port_caps; 118 enum prestera_event_type; 119 struct prestera_event; 120 struct prestera_acl_rule; 121 122 typedef void (*prestera_event_cb_t) 123 (struct prestera_switch *sw, struct prestera_event *evt, void *arg); 124 125 struct prestera_rxtx_params; 126 127 /* Switch API */ 128 int prestera_hw_switch_init(struct prestera_switch *sw); 129 void prestera_hw_switch_fini(struct prestera_switch *sw); 130 int prestera_hw_switch_ageing_set(struct prestera_switch *sw, u32 ageing_ms); 131 int prestera_hw_switch_mac_set(struct prestera_switch *sw, const char *mac); 132 133 /* Port API */ 134 int prestera_hw_port_info_get(const struct prestera_port *port, 135 u32 *dev_id, u32 *hw_id, u16 *fp_id); 136 137 int prestera_hw_port_mac_mode_get(const struct prestera_port *port, 138 u32 *mode, u32 *speed, u8 *duplex, u8 *fec); 139 int prestera_hw_port_mac_mode_set(const struct prestera_port *port, 140 bool admin, u32 mode, u8 inband, 141 u32 speed, u8 duplex, u8 fec); 142 int prestera_hw_port_phy_mode_get(const struct prestera_port *port, 143 u8 *mdix, u64 *lmode_bmap, 144 bool *fc_pause, bool *fc_asym); 145 int prestera_hw_port_phy_mode_set(const struct prestera_port *port, 146 bool admin, bool adv, u32 mode, u64 modes, 147 u8 mdix); 148 149 int prestera_hw_port_mtu_set(const struct prestera_port *port, u32 mtu); 150 int prestera_hw_port_mtu_get(const struct prestera_port *port, u32 *mtu); 151 int prestera_hw_port_mac_set(const struct prestera_port *port, const char *mac); 152 int prestera_hw_port_mac_get(const struct prestera_port *port, char *mac); 153 int prestera_hw_port_cap_get(const struct prestera_port *port, 154 struct prestera_port_caps *caps); 155 int prestera_hw_port_type_get(const struct prestera_port *port, u8 *type); 156 int prestera_hw_port_autoneg_restart(struct prestera_port *port); 157 int prestera_hw_port_stats_get(const struct prestera_port *port, 158 struct prestera_port_stats *stats); 159 int prestera_hw_port_speed_get(const struct prestera_port *port, u32 *speed); 160 int prestera_hw_port_learning_set(struct prestera_port *port, bool enable); 161 int prestera_hw_port_flood_set(struct prestera_port *port, unsigned long mask, 162 unsigned long val); 163 int prestera_hw_port_accept_frm_type(struct prestera_port *port, 164 enum prestera_accept_frm_type type); 165 /* Vlan API */ 166 int prestera_hw_vlan_create(struct prestera_switch *sw, u16 vid); 167 int prestera_hw_vlan_delete(struct prestera_switch *sw, u16 vid); 168 int prestera_hw_vlan_port_set(struct prestera_port *port, u16 vid, 169 bool is_member, bool untagged); 170 int prestera_hw_vlan_port_vid_set(struct prestera_port *port, u16 vid); 171 int prestera_hw_vlan_port_stp_set(struct prestera_port *port, u16 vid, u8 state); 172 173 /* FDB API */ 174 int prestera_hw_fdb_add(struct prestera_port *port, const unsigned char *mac, 175 u16 vid, bool dynamic); 176 int prestera_hw_fdb_del(struct prestera_port *port, const unsigned char *mac, 177 u16 vid); 178 int prestera_hw_fdb_flush_port(struct prestera_port *port, u32 mode); 179 int prestera_hw_fdb_flush_vlan(struct prestera_switch *sw, u16 vid, u32 mode); 180 int prestera_hw_fdb_flush_port_vlan(struct prestera_port *port, u16 vid, 181 u32 mode); 182 183 /* Bridge API */ 184 int prestera_hw_bridge_create(struct prestera_switch *sw, u16 *bridge_id); 185 int prestera_hw_bridge_delete(struct prestera_switch *sw, u16 bridge_id); 186 int prestera_hw_bridge_port_add(struct prestera_port *port, u16 bridge_id); 187 int prestera_hw_bridge_port_delete(struct prestera_port *port, u16 bridge_id); 188 189 /* ACL API */ 190 int prestera_hw_acl_ruleset_create(struct prestera_switch *sw, 191 u16 *ruleset_id); 192 int prestera_hw_acl_ruleset_del(struct prestera_switch *sw, 193 u16 ruleset_id); 194 int prestera_hw_acl_rule_add(struct prestera_switch *sw, 195 struct prestera_acl_rule *rule, 196 u32 *rule_id); 197 int prestera_hw_acl_rule_del(struct prestera_switch *sw, u32 rule_id); 198 int prestera_hw_acl_rule_stats_get(struct prestera_switch *sw, 199 u32 rule_id, u64 *packets, u64 *bytes); 200 int prestera_hw_acl_port_bind(const struct prestera_port *port, 201 u16 ruleset_id); 202 int prestera_hw_acl_port_unbind(const struct prestera_port *port, 203 u16 ruleset_id); 204 205 /* SPAN API */ 206 int prestera_hw_span_get(const struct prestera_port *port, u8 *span_id); 207 int prestera_hw_span_bind(const struct prestera_port *port, u8 span_id); 208 int prestera_hw_span_unbind(const struct prestera_port *port); 209 int prestera_hw_span_release(struct prestera_switch *sw, u8 span_id); 210 211 /* Event handlers */ 212 int prestera_hw_event_handler_register(struct prestera_switch *sw, 213 enum prestera_event_type type, 214 prestera_event_cb_t fn, 215 void *arg); 216 void prestera_hw_event_handler_unregister(struct prestera_switch *sw, 217 enum prestera_event_type type, 218 prestera_event_cb_t fn); 219 220 /* RX/TX */ 221 int prestera_hw_rxtx_init(struct prestera_switch *sw, 222 struct prestera_rxtx_params *params); 223 224 /* LAG API */ 225 int prestera_hw_lag_member_add(struct prestera_port *port, u16 lag_id); 226 int prestera_hw_lag_member_del(struct prestera_port *port, u16 lag_id); 227 int prestera_hw_lag_member_enable(struct prestera_port *port, u16 lag_id, 228 bool enable); 229 int prestera_hw_lag_fdb_add(struct prestera_switch *sw, u16 lag_id, 230 const unsigned char *mac, u16 vid, bool dynamic); 231 int prestera_hw_lag_fdb_del(struct prestera_switch *sw, u16 lag_id, 232 const unsigned char *mac, u16 vid); 233 int prestera_hw_fdb_flush_lag(struct prestera_switch *sw, u16 lag_id, 234 u32 mode); 235 int prestera_hw_fdb_flush_lag_vlan(struct prestera_switch *sw, 236 u16 lag_id, u16 vid, u32 mode); 237 238 /* HW trap/drop counters API */ 239 int 240 prestera_hw_cpu_code_counters_get(struct prestera_switch *sw, u8 code, 241 enum prestera_hw_cpu_code_cnt_t counter_type, 242 u64 *packet_count); 243 244 #endif /* _PRESTERA_HW_H_ */ 245