1 /* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */
2 /* Copyright (c) 2019-2020 Marvell International Ltd. All rights reserved. */
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>
13 #define PRESTERA_DRV_NAME "prestera"
15 #define PRESTERA_DEFAULT_VID 1
17 struct prestera_fw_rev {
23 struct prestera_port_stats {
24 u64 good_octets_received;
25 u64 bad_octets_received;
27 u64 broadcast_frames_received;
28 u64 multicast_frames_received;
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;
45 u64 rx_error_frame_received;
49 u64 unicast_frames_received;
50 u64 unicast_frames_sent;
56 #define PRESTERA_AP_PORT_MAX (10)
58 struct prestera_port_caps {
66 struct net_device *dev;
67 struct list_head members;
72 struct prestera_flow_block;
74 struct prestera_port_mac_state {
83 struct prestera_port_phy_state {
92 struct prestera_port_mac_config {
101 struct prestera_port_phy_config {
107 struct prestera_port {
108 struct net_device *dev;
109 struct prestera_switch *sw;
110 struct prestera_flow_block *flow_block;
111 struct devlink_port dl_port;
112 struct list_head lag_member;
113 struct prestera_lag *lag;
120 u64 adver_link_modes;
122 struct prestera_port_caps caps;
123 struct list_head list;
124 struct list_head vlans_list;
126 struct prestera_port_stats stats;
127 struct delayed_work caching_dw;
129 struct prestera_port_mac_config cfg_mac;
130 struct prestera_port_phy_config cfg_phy;
131 struct prestera_port_mac_state state_mac;
132 struct prestera_port_phy_state state_phy;
135 struct prestera_device {
137 u8 __iomem *ctl_regs;
139 struct prestera_fw_rev fw_rev;
142 /* called by device driver to handle received packets */
143 void (*recv_pkt)(struct prestera_device *dev);
145 /* called by device driver to pass event up to the higher layer */
146 int (*recv_msg)(struct prestera_device *dev, void *msg, size_t size);
148 /* called by higher layer to send request to the firmware */
149 int (*send_req)(struct prestera_device *dev, int qid, void *in_msg,
150 size_t in_size, void *out_msg, size_t out_size,
154 enum prestera_event_type {
155 PRESTERA_EVENT_TYPE_UNSPEC,
157 PRESTERA_EVENT_TYPE_PORT,
158 PRESTERA_EVENT_TYPE_FDB,
159 PRESTERA_EVENT_TYPE_RXTX,
161 PRESTERA_EVENT_TYPE_MAX
164 enum prestera_rxtx_event_id {
165 PRESTERA_RXTX_EVENT_UNSPEC,
166 PRESTERA_RXTX_EVENT_RCV_PKT,
169 enum prestera_port_event_id {
170 PRESTERA_PORT_EVENT_UNSPEC,
171 PRESTERA_PORT_EVENT_MAC_STATE_CHANGED,
174 struct prestera_port_event {
196 enum prestera_fdb_entry_type {
197 PRESTERA_FDB_ENTRY_TYPE_REG_PORT,
198 PRESTERA_FDB_ENTRY_TYPE_LAG,
199 PRESTERA_FDB_ENTRY_TYPE_MAX
202 enum prestera_fdb_event_id {
203 PRESTERA_FDB_EVENT_UNSPEC,
204 PRESTERA_FDB_EVENT_LEARNED,
205 PRESTERA_FDB_EVENT_AGED,
208 struct prestera_fdb_event {
209 enum prestera_fdb_entry_type type;
220 struct prestera_event {
223 struct prestera_port_event port_evt;
224 struct prestera_fdb_event fdb_evt;
228 enum prestera_if_type {
229 /* the interface is of port type (dev,port) */
230 PRESTERA_IF_PORT_E = 0,
232 /* the interface is of lag type (lag-id) */
233 PRESTERA_IF_LAG_E = 1,
235 /* the interface is of Vid type (vlan-id) */
236 PRESTERA_IF_VID_E = 3,
239 struct prestera_iface {
240 enum prestera_if_type type;
251 struct prestera_switchdev;
252 struct prestera_span;
253 struct prestera_rxtx;
254 struct prestera_trap_data;
257 struct prestera_switch {
258 struct prestera_device *dev;
259 struct prestera_switchdev *swdev;
260 struct prestera_rxtx *rxtx;
261 struct prestera_acl *acl;
262 struct prestera_span *span;
263 struct list_head event_handlers;
264 struct notifier_block netdev_nb;
265 struct prestera_trap_data *trap_data;
266 char base_mac[ETH_ALEN];
267 struct list_head port_list;
268 rwlock_t port_list_lock;
273 struct prestera_router *router;
274 struct prestera_lag *lags;
275 struct prestera_counter *counter;
280 struct prestera_router {
281 struct prestera_switch *sw;
282 struct list_head vr_list;
283 struct list_head rif_entry_list;
284 struct rhashtable fib_ht;
285 struct rhashtable kern_fib_cache_ht;
286 struct notifier_block inetaddr_nb;
287 struct notifier_block inetaddr_valid_nb;
288 struct notifier_block fib_nb;
291 struct prestera_rxtx_params {
296 #define prestera_dev(sw) ((sw)->dev->dev)
298 static inline void prestera_write(const struct prestera_switch *sw,
299 unsigned int reg, u32 val)
301 writel(val, sw->dev->pp_regs + reg);
304 static inline u32 prestera_read(const struct prestera_switch *sw,
307 return readl(sw->dev->pp_regs + reg);
310 int prestera_device_register(struct prestera_device *dev);
311 void prestera_device_unregister(struct prestera_device *dev);
313 struct prestera_port *prestera_port_find_by_hwid(struct prestera_switch *sw,
314 u32 dev_id, u32 hw_id);
316 int prestera_port_autoneg_set(struct prestera_port *port, u64 link_modes);
318 int prestera_router_init(struct prestera_switch *sw);
319 void prestera_router_fini(struct prestera_switch *sw);
321 struct prestera_port *prestera_find_port(struct prestera_switch *sw, u32 id);
323 int prestera_port_cfg_mac_read(struct prestera_port *port,
324 struct prestera_port_mac_config *cfg);
326 int prestera_port_cfg_mac_write(struct prestera_port *port,
327 struct prestera_port_mac_config *cfg);
329 struct prestera_port *prestera_port_dev_lower_find(struct net_device *dev);
331 void prestera_queue_work(struct work_struct *work);
333 int prestera_port_pvid_set(struct prestera_port *port, u16 vid);
335 bool prestera_netdev_check(const struct net_device *dev);
337 int prestera_is_valid_mac_addr(struct prestera_port *port, const u8 *addr);
339 bool prestera_port_is_lag_member(const struct prestera_port *port);
341 struct prestera_lag *prestera_lag_by_id(struct prestera_switch *sw, u16 id);
343 u16 prestera_port_lag_id(const struct prestera_port *port);
345 #endif /* _PRESTERA_H_ */