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 struct prestera_switch; 93 struct prestera_port; 94 struct prestera_port_stats; 95 struct prestera_port_caps; 96 enum prestera_event_type; 97 struct prestera_event; 98 99 typedef void (*prestera_event_cb_t) 100 (struct prestera_switch *sw, struct prestera_event *evt, void *arg); 101 102 struct prestera_rxtx_params; 103 104 /* Switch API */ 105 int prestera_hw_switch_init(struct prestera_switch *sw); 106 void prestera_hw_switch_fini(struct prestera_switch *sw); 107 int prestera_hw_switch_ageing_set(struct prestera_switch *sw, u32 ageing_ms); 108 int prestera_hw_switch_mac_set(struct prestera_switch *sw, const char *mac); 109 110 /* Port API */ 111 int prestera_hw_port_info_get(const struct prestera_port *port, 112 u32 *dev_id, u32 *hw_id, u16 *fp_id); 113 int prestera_hw_port_state_set(const struct prestera_port *port, 114 bool admin_state); 115 int prestera_hw_port_mtu_set(const struct prestera_port *port, u32 mtu); 116 int prestera_hw_port_mtu_get(const struct prestera_port *port, u32 *mtu); 117 int prestera_hw_port_mac_set(const struct prestera_port *port, const char *mac); 118 int prestera_hw_port_mac_get(const struct prestera_port *port, char *mac); 119 int prestera_hw_port_cap_get(const struct prestera_port *port, 120 struct prestera_port_caps *caps); 121 int prestera_hw_port_remote_cap_get(const struct prestera_port *port, 122 u64 *link_mode_bitmap); 123 int prestera_hw_port_remote_fc_get(const struct prestera_port *port, 124 bool *pause, bool *asym_pause); 125 int prestera_hw_port_type_get(const struct prestera_port *port, u8 *type); 126 int prestera_hw_port_fec_get(const struct prestera_port *port, u8 *fec); 127 int prestera_hw_port_fec_set(const struct prestera_port *port, u8 fec); 128 int prestera_hw_port_autoneg_set(const struct prestera_port *port, 129 bool autoneg, u64 link_modes, u8 fec); 130 int prestera_hw_port_autoneg_restart(struct prestera_port *port); 131 int prestera_hw_port_duplex_get(const struct prestera_port *port, u8 *duplex); 132 int prestera_hw_port_stats_get(const struct prestera_port *port, 133 struct prestera_port_stats *stats); 134 int prestera_hw_port_link_mode_set(const struct prestera_port *port, u32 mode); 135 int prestera_hw_port_link_mode_get(const struct prestera_port *port, u32 *mode); 136 int prestera_hw_port_mdix_get(const struct prestera_port *port, u8 *status, 137 u8 *admin_mode); 138 int prestera_hw_port_mdix_set(const struct prestera_port *port, u8 mode); 139 int prestera_hw_port_speed_get(const struct prestera_port *port, u32 *speed); 140 int prestera_hw_port_learning_set(struct prestera_port *port, bool enable); 141 int prestera_hw_port_flood_set(struct prestera_port *port, unsigned long mask, 142 unsigned long val); 143 int prestera_hw_port_accept_frm_type(struct prestera_port *port, 144 enum prestera_accept_frm_type type); 145 /* Vlan API */ 146 int prestera_hw_vlan_create(struct prestera_switch *sw, u16 vid); 147 int prestera_hw_vlan_delete(struct prestera_switch *sw, u16 vid); 148 int prestera_hw_vlan_port_set(struct prestera_port *port, u16 vid, 149 bool is_member, bool untagged); 150 int prestera_hw_vlan_port_vid_set(struct prestera_port *port, u16 vid); 151 int prestera_hw_vlan_port_stp_set(struct prestera_port *port, u16 vid, u8 state); 152 153 /* FDB API */ 154 int prestera_hw_fdb_add(struct prestera_port *port, const unsigned char *mac, 155 u16 vid, bool dynamic); 156 int prestera_hw_fdb_del(struct prestera_port *port, const unsigned char *mac, 157 u16 vid); 158 int prestera_hw_fdb_flush_port(struct prestera_port *port, u32 mode); 159 int prestera_hw_fdb_flush_vlan(struct prestera_switch *sw, u16 vid, u32 mode); 160 int prestera_hw_fdb_flush_port_vlan(struct prestera_port *port, u16 vid, 161 u32 mode); 162 163 /* Bridge API */ 164 int prestera_hw_bridge_create(struct prestera_switch *sw, u16 *bridge_id); 165 int prestera_hw_bridge_delete(struct prestera_switch *sw, u16 bridge_id); 166 int prestera_hw_bridge_port_add(struct prestera_port *port, u16 bridge_id); 167 int prestera_hw_bridge_port_delete(struct prestera_port *port, u16 bridge_id); 168 169 /* Event handlers */ 170 int prestera_hw_event_handler_register(struct prestera_switch *sw, 171 enum prestera_event_type type, 172 prestera_event_cb_t fn, 173 void *arg); 174 void prestera_hw_event_handler_unregister(struct prestera_switch *sw, 175 enum prestera_event_type type, 176 prestera_event_cb_t fn); 177 178 /* RX/TX */ 179 int prestera_hw_rxtx_init(struct prestera_switch *sw, 180 struct prestera_rxtx_params *params); 181 int prestera_hw_rxtx_port_init(struct prestera_port *port); 182 183 #endif /* _PRESTERA_HW_H_ */ 184