2 * drivers/net/ethernet/mellanox/mlxsw/spectrum_mr.h
3 * Copyright (c) 2017 Mellanox Technologies. All rights reserved.
4 * Copyright (c) 2017 Yotam Gigi <yotamg@mellanox.com>
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. Neither the names of the copyright holders nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * Alternatively, this software may be distributed under the terms of the
19 * GNU General Public License ("GPL") version 2 as published by the Free
20 * Software Foundation.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
26 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
35 #ifndef _MLXSW_SPECTRUM_MCROUTER_H
36 #define _MLXSW_SPECTRUM_MCROUTER_H
38 #include <linux/mroute.h>
39 #include "spectrum_router.h"
42 enum mlxsw_sp_mr_route_action
{
43 MLXSW_SP_MR_ROUTE_ACTION_FORWARD
,
44 MLXSW_SP_MR_ROUTE_ACTION_TRAP
,
45 MLXSW_SP_MR_ROUTE_ACTION_TRAP_AND_FORWARD
,
48 enum mlxsw_sp_mr_route_prio
{
49 MLXSW_SP_MR_ROUTE_PRIO_SG
,
50 MLXSW_SP_MR_ROUTE_PRIO_STARG
,
51 MLXSW_SP_MR_ROUTE_PRIO_CATCHALL
,
52 __MLXSW_SP_MR_ROUTE_PRIO_MAX
55 #define MLXSW_SP_MR_ROUTE_PRIO_MAX (__MLXSW_SP_MR_ROUTE_PRIO_MAX - 1)
57 struct mlxsw_sp_mr_route_key
{
59 enum mlxsw_sp_l3proto proto
;
60 union mlxsw_sp_l3addr group
;
61 union mlxsw_sp_l3addr group_mask
;
62 union mlxsw_sp_l3addr source
;
63 union mlxsw_sp_l3addr source_mask
;
66 struct mlxsw_sp_mr_route_info
{
67 enum mlxsw_sp_mr_route_action route_action
;
74 struct mlxsw_sp_mr_route_params
{
75 struct mlxsw_sp_mr_route_key key
;
76 struct mlxsw_sp_mr_route_info value
;
77 enum mlxsw_sp_mr_route_prio prio
;
80 struct mlxsw_sp_mr_ops
{
83 int (*init
)(struct mlxsw_sp
*mlxsw_sp
, void *priv
);
84 int (*route_create
)(struct mlxsw_sp
*mlxsw_sp
, void *priv
,
86 struct mlxsw_sp_mr_route_params
*route_params
);
87 int (*route_update
)(struct mlxsw_sp
*mlxsw_sp
, void *route_priv
,
88 struct mlxsw_sp_mr_route_info
*route_info
);
89 int (*route_stats
)(struct mlxsw_sp
*mlxsw_sp
, void *route_priv
,
90 u64
*packets
, u64
*bytes
);
91 int (*route_action_update
)(struct mlxsw_sp
*mlxsw_sp
, void *route_priv
,
92 enum mlxsw_sp_mr_route_action route_action
);
93 int (*route_min_mtu_update
)(struct mlxsw_sp
*mlxsw_sp
, void *route_priv
,
95 int (*route_irif_update
)(struct mlxsw_sp
*mlxsw_sp
, void *route_priv
,
97 int (*route_erif_add
)(struct mlxsw_sp
*mlxsw_sp
, void *route_priv
,
99 int (*route_erif_del
)(struct mlxsw_sp
*mlxsw_sp
, void *route_priv
,
101 void (*route_destroy
)(struct mlxsw_sp
*mlxsw_sp
, void *priv
,
103 void (*fini
)(void *priv
);
107 struct mlxsw_sp_mr_table
;
109 int mlxsw_sp_mr_init(struct mlxsw_sp
*mlxsw_sp
,
110 const struct mlxsw_sp_mr_ops
*mr_ops
);
111 void mlxsw_sp_mr_fini(struct mlxsw_sp
*mlxsw_sp
);
112 int mlxsw_sp_mr_route4_add(struct mlxsw_sp_mr_table
*mr_table
,
113 struct mfc_cache
*mfc
, bool replace
);
114 void mlxsw_sp_mr_route4_del(struct mlxsw_sp_mr_table
*mr_table
,
115 struct mfc_cache
*mfc
);
116 int mlxsw_sp_mr_vif_add(struct mlxsw_sp_mr_table
*mr_table
,
117 struct net_device
*dev
, vifi_t vif_index
,
118 unsigned long vif_flags
,
119 const struct mlxsw_sp_rif
*rif
);
120 void mlxsw_sp_mr_vif_del(struct mlxsw_sp_mr_table
*mr_table
, vifi_t vif_index
);
121 int mlxsw_sp_mr_rif_add(struct mlxsw_sp_mr_table
*mr_table
,
122 const struct mlxsw_sp_rif
*rif
);
123 void mlxsw_sp_mr_rif_del(struct mlxsw_sp_mr_table
*mr_table
,
124 const struct mlxsw_sp_rif
*rif
);
125 void mlxsw_sp_mr_rif_mtu_update(struct mlxsw_sp_mr_table
*mr_table
,
126 const struct mlxsw_sp_rif
*rif
, int mtu
);
127 struct mlxsw_sp_mr_table
*mlxsw_sp_mr_table_create(struct mlxsw_sp
*mlxsw_sp
,
129 enum mlxsw_sp_l3proto proto
);
130 void mlxsw_sp_mr_table_destroy(struct mlxsw_sp_mr_table
*mr_table
);
131 void mlxsw_sp_mr_table_flush(struct mlxsw_sp_mr_table
*mr_table
);
132 bool mlxsw_sp_mr_table_empty(const struct mlxsw_sp_mr_table
*mr_table
);