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 struct mlxsw_sp_span_parms {
17 	struct mlxsw_sp_port *dest_port; /* NULL for unoffloaded SPAN. */
18 	unsigned int ttl;
19 	unsigned char dmac[ETH_ALEN];
20 	unsigned char smac[ETH_ALEN];
21 	union mlxsw_sp_l3addr daddr;
22 	union mlxsw_sp_l3addr saddr;
23 	u16 vid;
24 };
25 
26 enum mlxsw_sp_span_trigger {
27 	MLXSW_SP_SPAN_TRIGGER_INGRESS,
28 	MLXSW_SP_SPAN_TRIGGER_EGRESS,
29 };
30 
31 struct mlxsw_sp_span_trigger_parms {
32 	int span_id;
33 };
34 
35 struct mlxsw_sp_span_entry_ops;
36 
37 struct mlxsw_sp_span_entry {
38 	const struct net_device *to_dev;
39 	const struct mlxsw_sp_span_entry_ops *ops;
40 	struct mlxsw_sp_span_parms parms;
41 	refcount_t ref_count;
42 	int id;
43 };
44 
45 struct mlxsw_sp_span_entry_ops {
46 	bool (*can_handle)(const struct net_device *to_dev);
47 	int (*parms_set)(const struct net_device *to_dev,
48 			 struct mlxsw_sp_span_parms *sparmsp);
49 	int (*configure)(struct mlxsw_sp_span_entry *span_entry,
50 			 struct mlxsw_sp_span_parms sparms);
51 	void (*deconfigure)(struct mlxsw_sp_span_entry *span_entry);
52 };
53 
54 int mlxsw_sp_span_init(struct mlxsw_sp *mlxsw_sp);
55 void mlxsw_sp_span_fini(struct mlxsw_sp *mlxsw_sp);
56 void mlxsw_sp_span_respin(struct mlxsw_sp *mlxsw_sp);
57 
58 struct mlxsw_sp_span_entry *
59 mlxsw_sp_span_entry_find_by_port(struct mlxsw_sp *mlxsw_sp,
60 				 const struct net_device *to_dev);
61 
62 void mlxsw_sp_span_entry_invalidate(struct mlxsw_sp *mlxsw_sp,
63 				    struct mlxsw_sp_span_entry *span_entry);
64 
65 int mlxsw_sp_span_port_mtu_update(struct mlxsw_sp_port *port, u16 mtu);
66 void mlxsw_sp_span_speed_update_work(struct work_struct *work);
67 
68 int mlxsw_sp_span_agent_get(struct mlxsw_sp *mlxsw_sp,
69 			    const struct net_device *to_dev, int *p_span_id);
70 void mlxsw_sp_span_agent_put(struct mlxsw_sp *mlxsw_sp, int span_id);
71 int mlxsw_sp_span_analyzed_port_get(struct mlxsw_sp_port *mlxsw_sp_port,
72 				    bool ingress);
73 void mlxsw_sp_span_analyzed_port_put(struct mlxsw_sp_port *mlxsw_sp_port,
74 				     bool ingress);
75 int mlxsw_sp_span_agent_bind(struct mlxsw_sp *mlxsw_sp,
76 			     enum mlxsw_sp_span_trigger trigger,
77 			     struct mlxsw_sp_port *mlxsw_sp_port,
78 			     const struct mlxsw_sp_span_trigger_parms *parms);
79 void
80 mlxsw_sp_span_agent_unbind(struct mlxsw_sp *mlxsw_sp,
81 			   enum mlxsw_sp_span_trigger trigger,
82 			   struct mlxsw_sp_port *mlxsw_sp_port,
83 			   const struct mlxsw_sp_span_trigger_parms *parms);
84 
85 #endif
86