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 104 typedef void (*prestera_event_cb_t) 105 (struct prestera_switch *sw, struct prestera_event *evt, void *arg); 106 107 struct prestera_rxtx_params; 108 109 /* Switch API */ 110 int prestera_hw_switch_init(struct prestera_switch *sw); 111 void prestera_hw_switch_fini(struct prestera_switch *sw); 112 int prestera_hw_switch_ageing_set(struct prestera_switch *sw, u32 ageing_ms); 113 int prestera_hw_switch_mac_set(struct prestera_switch *sw, const char *mac); 114 115 /* Port API */ 116 int prestera_hw_port_info_get(const struct prestera_port *port, 117 u32 *dev_id, u32 *hw_id, u16 *fp_id); 118 int prestera_hw_port_state_set(const struct prestera_port *port, 119 bool admin_state); 120 int prestera_hw_port_mtu_set(const struct prestera_port *port, u32 mtu); 121 int prestera_hw_port_mtu_get(const struct prestera_port *port, u32 *mtu); 122 int prestera_hw_port_mac_set(const struct prestera_port *port, const char *mac); 123 int prestera_hw_port_mac_get(const struct prestera_port *port, char *mac); 124 int prestera_hw_port_cap_get(const struct prestera_port *port, 125 struct prestera_port_caps *caps); 126 int prestera_hw_port_remote_cap_get(const struct prestera_port *port, 127 u64 *link_mode_bitmap); 128 int prestera_hw_port_remote_fc_get(const struct prestera_port *port, 129 bool *pause, bool *asym_pause); 130 int prestera_hw_port_type_get(const struct prestera_port *port, u8 *type); 131 int prestera_hw_port_fec_get(const struct prestera_port *port, u8 *fec); 132 int prestera_hw_port_fec_set(const struct prestera_port *port, u8 fec); 133 int prestera_hw_port_autoneg_set(const struct prestera_port *port, 134 bool autoneg, u64 link_modes, u8 fec); 135 int prestera_hw_port_autoneg_restart(struct prestera_port *port); 136 int prestera_hw_port_duplex_get(const struct prestera_port *port, u8 *duplex); 137 int prestera_hw_port_stats_get(const struct prestera_port *port, 138 struct prestera_port_stats *stats); 139 int prestera_hw_port_link_mode_set(const struct prestera_port *port, u32 mode); 140 int prestera_hw_port_link_mode_get(const struct prestera_port *port, u32 *mode); 141 int prestera_hw_port_mdix_get(const struct prestera_port *port, u8 *status, 142 u8 *admin_mode); 143 int prestera_hw_port_mdix_set(const struct prestera_port *port, u8 mode); 144 int prestera_hw_port_speed_get(const struct prestera_port *port, u32 *speed); 145 int prestera_hw_port_learning_set(struct prestera_port *port, bool enable); 146 int prestera_hw_port_flood_set(struct prestera_port *port, unsigned long mask, 147 unsigned long val); 148 int prestera_hw_port_accept_frm_type(struct prestera_port *port, 149 enum prestera_accept_frm_type type); 150 /* Vlan API */ 151 int prestera_hw_vlan_create(struct prestera_switch *sw, u16 vid); 152 int prestera_hw_vlan_delete(struct prestera_switch *sw, u16 vid); 153 int prestera_hw_vlan_port_set(struct prestera_port *port, u16 vid, 154 bool is_member, bool untagged); 155 int prestera_hw_vlan_port_vid_set(struct prestera_port *port, u16 vid); 156 int prestera_hw_vlan_port_stp_set(struct prestera_port *port, u16 vid, u8 state); 157 158 /* FDB API */ 159 int prestera_hw_fdb_add(struct prestera_port *port, const unsigned char *mac, 160 u16 vid, bool dynamic); 161 int prestera_hw_fdb_del(struct prestera_port *port, const unsigned char *mac, 162 u16 vid); 163 int prestera_hw_fdb_flush_port(struct prestera_port *port, u32 mode); 164 int prestera_hw_fdb_flush_vlan(struct prestera_switch *sw, u16 vid, u32 mode); 165 int prestera_hw_fdb_flush_port_vlan(struct prestera_port *port, u16 vid, 166 u32 mode); 167 168 /* Bridge API */ 169 int prestera_hw_bridge_create(struct prestera_switch *sw, u16 *bridge_id); 170 int prestera_hw_bridge_delete(struct prestera_switch *sw, u16 bridge_id); 171 int prestera_hw_bridge_port_add(struct prestera_port *port, u16 bridge_id); 172 int prestera_hw_bridge_port_delete(struct prestera_port *port, u16 bridge_id); 173 174 /* Event handlers */ 175 int prestera_hw_event_handler_register(struct prestera_switch *sw, 176 enum prestera_event_type type, 177 prestera_event_cb_t fn, 178 void *arg); 179 void prestera_hw_event_handler_unregister(struct prestera_switch *sw, 180 enum prestera_event_type type, 181 prestera_event_cb_t fn); 182 183 /* RX/TX */ 184 int prestera_hw_rxtx_init(struct prestera_switch *sw, 185 struct prestera_rxtx_params *params); 186 int prestera_hw_rxtx_port_init(struct prestera_port *port); 187 188 /* LAG API */ 189 int prestera_hw_lag_member_add(struct prestera_port *port, u16 lag_id); 190 int prestera_hw_lag_member_del(struct prestera_port *port, u16 lag_id); 191 int prestera_hw_lag_member_enable(struct prestera_port *port, u16 lag_id, 192 bool enable); 193 int prestera_hw_lag_fdb_add(struct prestera_switch *sw, u16 lag_id, 194 const unsigned char *mac, u16 vid, bool dynamic); 195 int prestera_hw_lag_fdb_del(struct prestera_switch *sw, u16 lag_id, 196 const unsigned char *mac, u16 vid); 197 int prestera_hw_fdb_flush_lag(struct prestera_switch *sw, u16 lag_id, 198 u32 mode); 199 int prestera_hw_fdb_flush_lag_vlan(struct prestera_switch *sw, 200 u16 lag_id, u16 vid, u32 mode); 201 202 /* HW trap/drop counters API */ 203 int 204 prestera_hw_cpu_code_counters_get(struct prestera_switch *sw, u8 code, 205 enum prestera_hw_cpu_code_cnt_t counter_type, 206 u64 *packet_count); 207 208 #endif /* _PRESTERA_HW_H_ */ 209