1 /* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */
2 /* Copyright (c) 2018 Mellanox Technologies. All rights reserved */
4 #ifndef _MLXSW_SPECTRUM_SPAN_H
5 #define _MLXSW_SPECTRUM_SPAN_H
7 #include <linux/types.h>
8 #include <linux/if_ether.h>
9 #include <linux/refcount.h>
11 #include "spectrum_router.h"
16 /* SPAN session identifiers that correspond to MLXSW_TRAP_ID_MIRROR_SESSION<i>
17 * trap identifiers. The session identifier is an attribute of the SPAN agent,
18 * which determines the trap identifier of packets that are mirrored to the
19 * CPU. Packets that are trapped to the CPU for the same logical reason (e.g.,
20 * buffer drops) should use the same session identifier.
22 enum mlxsw_sp_span_session_id {
23 MLXSW_SP_SPAN_SESSION_ID_BUFFER,
24 MLXSW_SP_SPAN_SESSION_ID_SAMPLING,
26 __MLXSW_SP_SPAN_SESSION_ID_MAX = 8,
29 struct mlxsw_sp_span_parms {
30 struct mlxsw_sp_port *dest_port; /* NULL for unoffloaded SPAN. */
32 unsigned char dmac[ETH_ALEN];
33 unsigned char smac[ETH_ALEN];
34 union mlxsw_sp_l3addr daddr;
35 union mlxsw_sp_l3addr saddr;
39 enum mlxsw_sp_span_session_id session_id;
42 enum 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,
50 struct mlxsw_sp_span_trigger_parms {
55 struct mlxsw_sp_span_agent_parms {
56 const struct net_device *to_dev;
59 enum mlxsw_sp_span_session_id session_id;
62 struct mlxsw_sp_span_entry_ops;
64 struct mlxsw_sp_span_ops {
65 int (*init)(struct mlxsw_sp *mlxsw_sp);
66 int (*policer_id_base_set)(struct mlxsw_sp *mlxsw_sp,
70 struct 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;
78 struct mlxsw_sp_span_entry_ops {
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);
89 int mlxsw_sp_span_init(struct mlxsw_sp *mlxsw_sp);
90 void mlxsw_sp_span_fini(struct mlxsw_sp *mlxsw_sp);
91 void mlxsw_sp_span_respin(struct mlxsw_sp *mlxsw_sp);
93 struct mlxsw_sp_span_entry *
94 mlxsw_sp_span_entry_find_by_port(struct mlxsw_sp *mlxsw_sp,
95 const struct net_device *to_dev);
97 void mlxsw_sp_span_entry_invalidate(struct mlxsw_sp *mlxsw_sp,
98 struct mlxsw_sp_span_entry *span_entry);
100 int mlxsw_sp_span_port_mtu_update(struct mlxsw_sp_port *port, u16 mtu);
101 void mlxsw_sp_span_speed_update_work(struct work_struct *work);
103 int mlxsw_sp_span_agent_get(struct mlxsw_sp *mlxsw_sp, int *p_span_id,
104 const struct mlxsw_sp_span_agent_parms *parms);
105 void mlxsw_sp_span_agent_put(struct mlxsw_sp *mlxsw_sp, int span_id);
106 int mlxsw_sp_span_analyzed_port_get(struct mlxsw_sp_port *mlxsw_sp_port,
108 void mlxsw_sp_span_analyzed_port_put(struct mlxsw_sp_port *mlxsw_sp_port,
110 int 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);
115 mlxsw_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);
119 int mlxsw_sp_span_trigger_enable(struct mlxsw_sp_port *mlxsw_sp_port,
120 enum mlxsw_sp_span_trigger trigger, u8 tc);
121 void mlxsw_sp_span_trigger_disable(struct mlxsw_sp_port *mlxsw_sp_port,
122 enum mlxsw_sp_span_trigger trigger, u8 tc);
124 extern const struct mlxsw_sp_span_ops mlxsw_sp1_span_ops;
125 extern const struct mlxsw_sp_span_ops mlxsw_sp2_span_ops;
126 extern const struct mlxsw_sp_span_ops mlxsw_sp3_span_ops;