Merge tag 'nds32-for-linus-4.18' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux-2.6-microblaze.git] / drivers / net / ethernet / mellanox / mlxsw / spectrum_span.h
1 /*
2  * drivers/net/ethernet/mellanox/mlxsw/mlxsw_span.h
3  * Copyright (c) 2018 Mellanox Technologies. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. Neither the names of the copyright holders nor the names of its
14  *    contributors may be used to endorse or promote products derived from
15  *    this software without specific prior written permission.
16  *
17  * Alternatively, this software may be distributed under the terms of the
18  * GNU General Public License ("GPL") version 2 as published by the Free
19  * Software Foundation.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
25  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31  * POSSIBILITY OF SUCH DAMAGE.
32  */
33
34 #ifndef _MLXSW_SPECTRUM_SPAN_H
35 #define _MLXSW_SPECTRUM_SPAN_H
36
37 #include <linux/types.h>
38 #include <linux/if_ether.h>
39
40 #include "spectrum_router.h"
41
42 struct mlxsw_sp;
43 struct mlxsw_sp_port;
44
45 enum mlxsw_sp_span_type {
46         MLXSW_SP_SPAN_EGRESS,
47         MLXSW_SP_SPAN_INGRESS
48 };
49
50 struct mlxsw_sp_span_inspected_port {
51         struct list_head list;
52         enum mlxsw_sp_span_type type;
53         u8 local_port;
54
55         /* Whether this is a directly bound mirror (port-to-port) or an ACL. */
56         bool bound;
57 };
58
59 struct mlxsw_sp_span_parms {
60         struct mlxsw_sp_port *dest_port; /* NULL for unoffloaded SPAN. */
61         unsigned int ttl;
62         unsigned char dmac[ETH_ALEN];
63         unsigned char smac[ETH_ALEN];
64         union mlxsw_sp_l3addr daddr;
65         union mlxsw_sp_l3addr saddr;
66         u16 vid;
67 };
68
69 struct mlxsw_sp_span_entry_ops;
70
71 struct mlxsw_sp_span_entry {
72         const struct net_device *to_dev;
73         const struct mlxsw_sp_span_entry_ops *ops;
74         struct mlxsw_sp_span_parms parms;
75         struct list_head bound_ports_list;
76         int ref_count;
77         int id;
78 };
79
80 struct mlxsw_sp_span_entry_ops {
81         bool (*can_handle)(const struct net_device *to_dev);
82         int (*parms)(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
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);
92
93 int mlxsw_sp_span_mirror_add(struct mlxsw_sp_port *from,
94                              const struct net_device *to_dev,
95                              enum mlxsw_sp_span_type type,
96                              bool bind, int *p_span_id);
97 void mlxsw_sp_span_mirror_del(struct mlxsw_sp_port *from, int span_id,
98                               enum mlxsw_sp_span_type type, bool bind);
99 struct mlxsw_sp_span_entry *
100 mlxsw_sp_span_entry_find_by_port(struct mlxsw_sp *mlxsw_sp,
101                                  const struct net_device *to_dev);
102
103 void mlxsw_sp_span_entry_invalidate(struct mlxsw_sp *mlxsw_sp,
104                                     struct mlxsw_sp_span_entry *span_entry);
105
106 int mlxsw_sp_span_port_mtu_update(struct mlxsw_sp_port *port, u16 mtu);
107
108 #endif