xref: /linux/drivers/net/ethernet/mellanox/mlxsw/spectrum_span.h (revision 40e79150c1686263e6a031d7702aec63aff31332)
1 /* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */
2 /* Copyright (c) 2018 Mellanox Technologies. All rights reserved */
3 
4 #ifndef _MLXSW_SPECTRUM_SPAN_H
5 #define _MLXSW_SPECTRUM_SPAN_H
6 
7 #include <linux/types.h>
8 #include <linux/if_ether.h>
9 #include <linux/refcount.h>
10 
11 #include "spectrum_router.h"
12 
13 struct mlxsw_sp;
14 struct mlxsw_sp_port;
15 
16 enum mlxsw_sp_span_type {
17 	MLXSW_SP_SPAN_EGRESS,
18 	MLXSW_SP_SPAN_INGRESS
19 };
20 
21 struct mlxsw_sp_span_inspected_port {
22 	struct list_head list;
23 	enum mlxsw_sp_span_type type;
24 	u8 local_port;
25 
26 	/* Whether this is a directly bound mirror (port-to-port) or an ACL. */
27 	bool bound;
28 };
29 
30 struct mlxsw_sp_span_parms {
31 	struct mlxsw_sp_port *dest_port; /* NULL for unoffloaded SPAN. */
32 	unsigned int ttl;
33 	unsigned char dmac[ETH_ALEN];
34 	unsigned char smac[ETH_ALEN];
35 	union mlxsw_sp_l3addr daddr;
36 	union mlxsw_sp_l3addr saddr;
37 	u16 vid;
38 };
39 
40 struct mlxsw_sp_span_entry_ops;
41 
42 struct mlxsw_sp_span_entry {
43 	const struct net_device *to_dev;
44 	const struct mlxsw_sp_span_entry_ops *ops;
45 	struct mlxsw_sp_span_parms parms;
46 	struct list_head bound_ports_list;
47 	refcount_t ref_count;
48 	int id;
49 };
50 
51 struct mlxsw_sp_span_entry_ops {
52 	bool (*can_handle)(const struct net_device *to_dev);
53 	int (*parms_set)(const struct net_device *to_dev,
54 			 struct mlxsw_sp_span_parms *sparmsp);
55 	int (*configure)(struct mlxsw_sp_span_entry *span_entry,
56 			 struct mlxsw_sp_span_parms sparms);
57 	void (*deconfigure)(struct mlxsw_sp_span_entry *span_entry);
58 };
59 
60 int mlxsw_sp_span_init(struct mlxsw_sp *mlxsw_sp);
61 void mlxsw_sp_span_fini(struct mlxsw_sp *mlxsw_sp);
62 void mlxsw_sp_span_respin(struct mlxsw_sp *mlxsw_sp);
63 
64 int mlxsw_sp_span_mirror_add(struct mlxsw_sp_port *from,
65 			     const struct net_device *to_dev,
66 			     enum mlxsw_sp_span_type type,
67 			     bool bind, int *p_span_id);
68 void mlxsw_sp_span_mirror_del(struct mlxsw_sp_port *from, int span_id,
69 			      enum mlxsw_sp_span_type type, bool bind);
70 struct mlxsw_sp_span_entry *
71 mlxsw_sp_span_entry_find_by_port(struct mlxsw_sp *mlxsw_sp,
72 				 const struct net_device *to_dev);
73 
74 void mlxsw_sp_span_entry_invalidate(struct mlxsw_sp *mlxsw_sp,
75 				    struct mlxsw_sp_span_entry *span_entry);
76 
77 int mlxsw_sp_span_port_mtu_update(struct mlxsw_sp_port *port, u16 mtu);
78 void mlxsw_sp_span_speed_update_work(struct work_struct *work);
79 
80 #endif
81