1
2
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
13struct mlxsw_sp;
14struct mlxsw_sp_port;
15
16
17
18
19
20
21
22enum mlxsw_sp_span_session_id {
23 MLXSW_SP_SPAN_SESSION_ID_BUFFER,
24 MLXSW_SP_SPAN_SESSION_ID_SAMPLING,
25
26 __MLXSW_SP_SPAN_SESSION_ID_MAX = 8,
27};
28
29struct mlxsw_sp_span_parms {
30 struct mlxsw_sp_port *dest_port;
31 unsigned int ttl;
32 unsigned char dmac[ETH_ALEN];
33 unsigned char smac[ETH_ALEN];
34 union mlxsw_sp_l3addr daddr;
35 union mlxsw_sp_l3addr saddr;
36 u16 vid;
37 u16 policer_id;
38 bool policer_enable;
39 enum mlxsw_sp_span_session_id session_id;
40};
41
42enum mlxsw_sp_span_trigger {
43 MLXSW_SP_SPAN_TRIGGER_INGRESS,
44 MLXSW_SP_SPAN_TRIGGER_EGRESS,
45 MLXSW_SP_SPAN_TRIGGER_TAIL_DROP,
46 MLXSW_SP_SPAN_TRIGGER_EARLY_DROP,
47 MLXSW_SP_SPAN_TRIGGER_ECN,
48};
49
50struct mlxsw_sp_span_trigger_parms {
51 int span_id;
52 u32 probability_rate;
53};
54
55struct mlxsw_sp_span_agent_parms {
56 const struct net_device *to_dev;
57 u16 policer_id;
58 bool policer_enable;
59 enum mlxsw_sp_span_session_id session_id;
60};
61
62struct mlxsw_sp_span_entry_ops;
63
64struct mlxsw_sp_span_ops {
65 int (*init)(struct mlxsw_sp *mlxsw_sp);
66 int (*policer_id_base_set)(struct mlxsw_sp *mlxsw_sp,
67 u16 policer_id_base);
68};
69
70struct mlxsw_sp_span_entry {
71 const struct net_device *to_dev;
72 const struct mlxsw_sp_span_entry_ops *ops;
73 struct mlxsw_sp_span_parms parms;
74 refcount_t ref_count;
75 int id;
76};
77
78struct mlxsw_sp_span_entry_ops {
79 bool is_static;
80 bool (*can_handle)(const struct net_device *to_dev);
81 int (*parms_set)(struct mlxsw_sp *mlxsw_sp,
82 const struct net_device *to_dev,
83 struct mlxsw_sp_span_parms *sparmsp);
84 int (*configure)(struct mlxsw_sp_span_entry *span_entry,
85 struct mlxsw_sp_span_parms sparms);
86 void (*deconfigure)(struct mlxsw_sp_span_entry *span_entry);
87};
88
89int mlxsw_sp_span_init(struct mlxsw_sp *mlxsw_sp);
90void mlxsw_sp_span_fini(struct mlxsw_sp *mlxsw_sp);
91void mlxsw_sp_span_respin(struct mlxsw_sp *mlxsw_sp);
92
93struct mlxsw_sp_span_entry *
94mlxsw_sp_span_entry_find_by_port(struct mlxsw_sp *mlxsw_sp,
95 const struct net_device *to_dev);
96
97void mlxsw_sp_span_entry_invalidate(struct mlxsw_sp *mlxsw_sp,
98 struct mlxsw_sp_span_entry *span_entry);
99
100int mlxsw_sp_span_port_mtu_update(struct mlxsw_sp_port *port, u16 mtu);
101void mlxsw_sp_span_speed_update_work(struct work_struct *work);
102
103int mlxsw_sp_span_agent_get(struct mlxsw_sp *mlxsw_sp, int *p_span_id,
104 const struct mlxsw_sp_span_agent_parms *parms);
105void mlxsw_sp_span_agent_put(struct mlxsw_sp *mlxsw_sp, int span_id);
106int mlxsw_sp_span_analyzed_port_get(struct mlxsw_sp_port *mlxsw_sp_port,
107 bool ingress);
108void mlxsw_sp_span_analyzed_port_put(struct mlxsw_sp_port *mlxsw_sp_port,
109 bool ingress);
110int mlxsw_sp_span_agent_bind(struct mlxsw_sp *mlxsw_sp,
111 enum mlxsw_sp_span_trigger trigger,
112 struct mlxsw_sp_port *mlxsw_sp_port,
113 const struct mlxsw_sp_span_trigger_parms *parms);
114void
115mlxsw_sp_span_agent_unbind(struct mlxsw_sp *mlxsw_sp,
116 enum mlxsw_sp_span_trigger trigger,
117 struct mlxsw_sp_port *mlxsw_sp_port,
118 const struct mlxsw_sp_span_trigger_parms *parms);
119int mlxsw_sp_span_trigger_enable(struct mlxsw_sp_port *mlxsw_sp_port,
120 enum mlxsw_sp_span_trigger trigger, u8 tc);
121void mlxsw_sp_span_trigger_disable(struct mlxsw_sp_port *mlxsw_sp_port,
122 enum mlxsw_sp_span_trigger trigger, u8 tc);
123
124extern const struct mlxsw_sp_span_ops mlxsw_sp1_span_ops;
125extern const struct mlxsw_sp_span_ops mlxsw_sp2_span_ops;
126extern const struct mlxsw_sp_span_ops mlxsw_sp3_span_ops;
127
128#endif
129