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 	u16 policer_id;
25 	bool policer_enable;
26 };
27 
28 enum mlxsw_sp_span_trigger {
29 	MLXSW_SP_SPAN_TRIGGER_INGRESS,
30 	MLXSW_SP_SPAN_TRIGGER_EGRESS,
31 	MLXSW_SP_SPAN_TRIGGER_TAIL_DROP,
32 	MLXSW_SP_SPAN_TRIGGER_EARLY_DROP,
33 	MLXSW_SP_SPAN_TRIGGER_ECN,
34 };
35 
36 struct mlxsw_sp_span_trigger_parms {
37 	int span_id;
38 };
39 
40 struct mlxsw_sp_span_agent_parms {
41 	const struct net_device *to_dev;
42 	u16 policer_id;
43 	bool policer_enable;
44 };
45 
46 struct mlxsw_sp_span_entry_ops;
47 
48 struct mlxsw_sp_span_ops {
49 	int (*init)(struct mlxsw_sp *mlxsw_sp);
50 	int (*policer_id_base_set)(struct mlxsw_sp *mlxsw_sp,
51 				   u16 policer_id_base);
52 };
53 
54 struct mlxsw_sp_span_entry {
55 	const struct net_device *to_dev;
56 	const struct mlxsw_sp_span_entry_ops *ops;
57 	struct mlxsw_sp_span_parms parms;
58 	refcount_t ref_count;
59 	int id;
60 };
61 
62 struct mlxsw_sp_span_entry_ops {
63 	bool (*can_handle)(const struct net_device *to_dev);
64 	int (*parms_set)(struct mlxsw_sp *mlxsw_sp,
65 			 const struct net_device *to_dev,
66 			 struct mlxsw_sp_span_parms *sparmsp);
67 	int (*configure)(struct mlxsw_sp_span_entry *span_entry,
68 			 struct mlxsw_sp_span_parms sparms);
69 	void (*deconfigure)(struct mlxsw_sp_span_entry *span_entry);
70 };
71 
72 int mlxsw_sp_span_init(struct mlxsw_sp *mlxsw_sp);
73 void mlxsw_sp_span_fini(struct mlxsw_sp *mlxsw_sp);
74 void mlxsw_sp_span_respin(struct mlxsw_sp *mlxsw_sp);
75 
76 struct mlxsw_sp_span_entry *
77 mlxsw_sp_span_entry_find_by_port(struct mlxsw_sp *mlxsw_sp,
78 				 const struct net_device *to_dev);
79 
80 void mlxsw_sp_span_entry_invalidate(struct mlxsw_sp *mlxsw_sp,
81 				    struct mlxsw_sp_span_entry *span_entry);
82 
83 int mlxsw_sp_span_port_mtu_update(struct mlxsw_sp_port *port, u16 mtu);
84 void mlxsw_sp_span_speed_update_work(struct work_struct *work);
85 
86 int mlxsw_sp_span_agent_get(struct mlxsw_sp *mlxsw_sp, int *p_span_id,
87 			    const struct mlxsw_sp_span_agent_parms *parms);
88 void mlxsw_sp_span_agent_put(struct mlxsw_sp *mlxsw_sp, int span_id);
89 int mlxsw_sp_span_analyzed_port_get(struct mlxsw_sp_port *mlxsw_sp_port,
90 				    bool ingress);
91 void mlxsw_sp_span_analyzed_port_put(struct mlxsw_sp_port *mlxsw_sp_port,
92 				     bool ingress);
93 int mlxsw_sp_span_agent_bind(struct mlxsw_sp *mlxsw_sp,
94 			     enum mlxsw_sp_span_trigger trigger,
95 			     struct mlxsw_sp_port *mlxsw_sp_port,
96 			     const struct mlxsw_sp_span_trigger_parms *parms);
97 void
98 mlxsw_sp_span_agent_unbind(struct mlxsw_sp *mlxsw_sp,
99 			   enum mlxsw_sp_span_trigger trigger,
100 			   struct mlxsw_sp_port *mlxsw_sp_port,
101 			   const struct mlxsw_sp_span_trigger_parms *parms);
102 int mlxsw_sp_span_trigger_enable(struct mlxsw_sp_port *mlxsw_sp_port,
103 				 enum mlxsw_sp_span_trigger trigger, u8 tc);
104 void mlxsw_sp_span_trigger_disable(struct mlxsw_sp_port *mlxsw_sp_port,
105 				   enum mlxsw_sp_span_trigger trigger, u8 tc);
106 
107 extern const struct mlxsw_sp_span_ops mlxsw_sp1_span_ops;
108 extern const struct mlxsw_sp_span_ops mlxsw_sp2_span_ops;
109 extern const struct mlxsw_sp_span_ops mlxsw_sp3_span_ops;
110 
111 #endif
112