net/mlx5e: Avoid unbounded peer devices when unpairing TC hairpin rules
[sfrench/cifs-2.6.git] / drivers / net / ethernet / mellanox / mlxsw / spectrum_span.h
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
10 #include "spectrum_router.h"
11
12 struct mlxsw_sp;
13 struct mlxsw_sp_port;
14
15 enum mlxsw_sp_span_type {
16         MLXSW_SP_SPAN_EGRESS,
17         MLXSW_SP_SPAN_INGRESS
18 };
19
20 struct mlxsw_sp_span_inspected_port {
21         struct list_head list;
22         enum mlxsw_sp_span_type type;
23         u8 local_port;
24
25         /* Whether this is a directly bound mirror (port-to-port) or an ACL. */
26         bool bound;
27 };
28
29 struct mlxsw_sp_span_parms {
30         struct mlxsw_sp_port *dest_port; /* NULL for unoffloaded SPAN. */
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 };
38
39 struct mlxsw_sp_span_entry_ops;
40
41 struct mlxsw_sp_span_entry {
42         const struct net_device *to_dev;
43         const struct mlxsw_sp_span_entry_ops *ops;
44         struct mlxsw_sp_span_parms parms;
45         struct list_head bound_ports_list;
46         int ref_count;
47         int id;
48 };
49
50 struct mlxsw_sp_span_entry_ops {
51         bool (*can_handle)(const struct net_device *to_dev);
52         int (*parms)(const struct net_device *to_dev,
53                      struct mlxsw_sp_span_parms *sparmsp);
54         int (*configure)(struct mlxsw_sp_span_entry *span_entry,
55                          struct mlxsw_sp_span_parms sparms);
56         void (*deconfigure)(struct mlxsw_sp_span_entry *span_entry);
57 };
58
59 int mlxsw_sp_span_init(struct mlxsw_sp *mlxsw_sp);
60 void mlxsw_sp_span_fini(struct mlxsw_sp *mlxsw_sp);
61 void mlxsw_sp_span_respin(struct mlxsw_sp *mlxsw_sp);
62
63 int mlxsw_sp_span_mirror_add(struct mlxsw_sp_port *from,
64                              const struct net_device *to_dev,
65                              enum mlxsw_sp_span_type type,
66                              bool bind, int *p_span_id);
67 void mlxsw_sp_span_mirror_del(struct mlxsw_sp_port *from, int span_id,
68                               enum mlxsw_sp_span_type type, bool bind);
69 struct mlxsw_sp_span_entry *
70 mlxsw_sp_span_entry_find_by_port(struct mlxsw_sp *mlxsw_sp,
71                                  const struct net_device *to_dev);
72
73 void mlxsw_sp_span_entry_invalidate(struct mlxsw_sp *mlxsw_sp,
74                                     struct mlxsw_sp_span_entry *span_entry);
75
76 int mlxsw_sp_span_port_mtu_update(struct mlxsw_sp_port *port, u16 mtu);
77
78 #endif