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