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_H_ 5 #define _PRESTERA_H_ 6 7 #include <linux/notifier.h> 8 #include <linux/skbuff.h> 9 #include <linux/workqueue.h> 10 #include <net/devlink.h> 11 #include <uapi/linux/if_ether.h> 12 13 #define PRESTERA_DRV_NAME "prestera" 14 15 #define PRESTERA_DEFAULT_VID 1 16 17 struct prestera_fw_rev { 18 u16 maj; 19 u16 min; 20 u16 sub; 21 }; 22 23 struct prestera_port_stats { 24 u64 good_octets_received; 25 u64 bad_octets_received; 26 u64 mac_trans_error; 27 u64 broadcast_frames_received; 28 u64 multicast_frames_received; 29 u64 frames_64_octets; 30 u64 frames_65_to_127_octets; 31 u64 frames_128_to_255_octets; 32 u64 frames_256_to_511_octets; 33 u64 frames_512_to_1023_octets; 34 u64 frames_1024_to_max_octets; 35 u64 excessive_collision; 36 u64 multicast_frames_sent; 37 u64 broadcast_frames_sent; 38 u64 fc_sent; 39 u64 fc_received; 40 u64 buffer_overrun; 41 u64 undersize; 42 u64 fragments; 43 u64 oversize; 44 u64 jabber; 45 u64 rx_error_frame_received; 46 u64 bad_crc; 47 u64 collisions; 48 u64 late_collision; 49 u64 unicast_frames_received; 50 u64 unicast_frames_sent; 51 u64 sent_multiple; 52 u64 sent_deferred; 53 u64 good_octets_sent; 54 }; 55 56 struct prestera_port_caps { 57 u64 supp_link_modes; 58 u8 supp_fec; 59 u8 type; 60 u8 transceiver; 61 }; 62 63 struct prestera_lag { 64 struct net_device *dev; 65 struct list_head members; 66 u16 member_count; 67 u16 lag_id; 68 }; 69 70 struct prestera_flow_block; 71 72 struct prestera_port { 73 struct net_device *dev; 74 struct prestera_switch *sw; 75 struct prestera_flow_block *flow_block; 76 struct devlink_port dl_port; 77 struct list_head lag_member; 78 struct prestera_lag *lag; 79 u32 id; 80 u32 hw_id; 81 u32 dev_id; 82 u16 fp_id; 83 u16 pvid; 84 bool autoneg; 85 u64 adver_link_modes; 86 u8 adver_fec; 87 struct prestera_port_caps caps; 88 struct list_head list; 89 struct list_head vlans_list; 90 struct { 91 struct prestera_port_stats stats; 92 struct delayed_work caching_dw; 93 } cached_hw_stats; 94 }; 95 96 struct prestera_device { 97 struct device *dev; 98 u8 __iomem *ctl_regs; 99 u8 __iomem *pp_regs; 100 struct prestera_fw_rev fw_rev; 101 void *priv; 102 103 /* called by device driver to handle received packets */ 104 void (*recv_pkt)(struct prestera_device *dev); 105 106 /* called by device driver to pass event up to the higher layer */ 107 int (*recv_msg)(struct prestera_device *dev, void *msg, size_t size); 108 109 /* called by higher layer to send request to the firmware */ 110 int (*send_req)(struct prestera_device *dev, void *in_msg, 111 size_t in_size, void *out_msg, size_t out_size, 112 unsigned int wait); 113 }; 114 115 enum prestera_event_type { 116 PRESTERA_EVENT_TYPE_UNSPEC, 117 118 PRESTERA_EVENT_TYPE_PORT, 119 PRESTERA_EVENT_TYPE_FDB, 120 PRESTERA_EVENT_TYPE_RXTX, 121 122 PRESTERA_EVENT_TYPE_MAX 123 }; 124 125 enum prestera_rxtx_event_id { 126 PRESTERA_RXTX_EVENT_UNSPEC, 127 PRESTERA_RXTX_EVENT_RCV_PKT, 128 }; 129 130 enum prestera_port_event_id { 131 PRESTERA_PORT_EVENT_UNSPEC, 132 PRESTERA_PORT_EVENT_STATE_CHANGED, 133 }; 134 135 struct prestera_port_event { 136 u32 port_id; 137 union { 138 u32 oper_state; 139 } data; 140 }; 141 142 enum prestera_fdb_entry_type { 143 PRESTERA_FDB_ENTRY_TYPE_REG_PORT, 144 PRESTERA_FDB_ENTRY_TYPE_LAG, 145 PRESTERA_FDB_ENTRY_TYPE_MAX 146 }; 147 148 enum prestera_fdb_event_id { 149 PRESTERA_FDB_EVENT_UNSPEC, 150 PRESTERA_FDB_EVENT_LEARNED, 151 PRESTERA_FDB_EVENT_AGED, 152 }; 153 154 struct prestera_fdb_event { 155 enum prestera_fdb_entry_type type; 156 union { 157 u32 port_id; 158 u16 lag_id; 159 } dest; 160 u32 vid; 161 union { 162 u8 mac[ETH_ALEN]; 163 } data; 164 }; 165 166 struct prestera_event { 167 u16 id; 168 union { 169 struct prestera_port_event port_evt; 170 struct prestera_fdb_event fdb_evt; 171 }; 172 }; 173 174 struct prestera_switchdev; 175 struct prestera_span; 176 struct prestera_rxtx; 177 struct prestera_trap_data; 178 struct prestera_acl; 179 180 struct prestera_switch { 181 struct prestera_device *dev; 182 struct prestera_switchdev *swdev; 183 struct prestera_rxtx *rxtx; 184 struct prestera_acl *acl; 185 struct prestera_span *span; 186 struct list_head event_handlers; 187 struct notifier_block netdev_nb; 188 struct prestera_trap_data *trap_data; 189 char base_mac[ETH_ALEN]; 190 struct list_head port_list; 191 rwlock_t port_list_lock; 192 u32 port_count; 193 u32 mtu_min; 194 u32 mtu_max; 195 u8 id; 196 struct prestera_lag *lags; 197 u8 lag_member_max; 198 u8 lag_max; 199 }; 200 201 struct prestera_rxtx_params { 202 bool use_sdma; 203 u32 map_addr; 204 }; 205 206 #define prestera_dev(sw) ((sw)->dev->dev) 207 208 static inline void prestera_write(const struct prestera_switch *sw, 209 unsigned int reg, u32 val) 210 { 211 writel(val, sw->dev->pp_regs + reg); 212 } 213 214 static inline u32 prestera_read(const struct prestera_switch *sw, 215 unsigned int reg) 216 { 217 return readl(sw->dev->pp_regs + reg); 218 } 219 220 int prestera_device_register(struct prestera_device *dev); 221 void prestera_device_unregister(struct prestera_device *dev); 222 223 struct prestera_port *prestera_port_find_by_hwid(struct prestera_switch *sw, 224 u32 dev_id, u32 hw_id); 225 226 int prestera_port_autoneg_set(struct prestera_port *port, bool enable, 227 u64 adver_link_modes, u8 adver_fec); 228 229 struct prestera_port *prestera_find_port(struct prestera_switch *sw, u32 id); 230 231 struct prestera_port *prestera_port_dev_lower_find(struct net_device *dev); 232 233 int prestera_port_pvid_set(struct prestera_port *port, u16 vid); 234 235 bool prestera_netdev_check(const struct net_device *dev); 236 237 bool prestera_port_is_lag_member(const struct prestera_port *port); 238 239 struct prestera_lag *prestera_lag_by_id(struct prestera_switch *sw, u16 id); 240 241 u16 prestera_port_lag_id(const struct prestera_port *port); 242 243 #endif /* _PRESTERA_H_ */ 244