1 /* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */
2 /* Copyright (c) 2017-2018 Mellanox Technologies. All rights reserved */
4 #ifndef _MLXSW_SPECTRUM_MCROUTER_H
5 #define _MLXSW_SPECTRUM_MCROUTER_H
7 #include <linux/mroute.h>
8 #include <linux/mroute6.h>
9 #include "spectrum_router.h"
12 enum mlxsw_sp_mr_route_action {
13 MLXSW_SP_MR_ROUTE_ACTION_FORWARD,
14 MLXSW_SP_MR_ROUTE_ACTION_TRAP,
15 MLXSW_SP_MR_ROUTE_ACTION_TRAP_AND_FORWARD,
18 struct mlxsw_sp_mr_route_key {
20 enum mlxsw_sp_l3proto proto;
21 union mlxsw_sp_l3addr group;
22 union mlxsw_sp_l3addr group_mask;
23 union mlxsw_sp_l3addr source;
24 union mlxsw_sp_l3addr source_mask;
27 struct mlxsw_sp_mr_route_info {
28 enum mlxsw_sp_mr_route_action route_action;
35 struct mlxsw_sp_mr_route_params {
36 struct mlxsw_sp_mr_route_key key;
37 struct mlxsw_sp_mr_route_info value;
38 enum mlxsw_sp_mr_route_prio prio;
41 struct mlxsw_sp_mr_ops {
44 int (*init)(struct mlxsw_sp *mlxsw_sp, void *priv);
45 int (*route_create)(struct mlxsw_sp *mlxsw_sp, void *priv,
47 struct mlxsw_sp_mr_route_params *route_params);
48 int (*route_update)(struct mlxsw_sp *mlxsw_sp, void *route_priv,
49 struct mlxsw_sp_mr_route_info *route_info);
50 int (*route_stats)(struct mlxsw_sp *mlxsw_sp, void *route_priv,
51 u64 *packets, u64 *bytes);
52 int (*route_action_update)(struct mlxsw_sp *mlxsw_sp, void *route_priv,
53 enum mlxsw_sp_mr_route_action route_action);
54 int (*route_min_mtu_update)(struct mlxsw_sp *mlxsw_sp, void *route_priv,
56 int (*route_irif_update)(struct mlxsw_sp *mlxsw_sp, void *route_priv,
58 int (*route_erif_add)(struct mlxsw_sp *mlxsw_sp, void *route_priv,
60 int (*route_erif_del)(struct mlxsw_sp *mlxsw_sp, void *route_priv,
62 void (*route_destroy)(struct mlxsw_sp *mlxsw_sp, void *priv,
64 void (*fini)(struct mlxsw_sp *mlxsw_sp, void *priv);
68 struct mlxsw_sp_mr_table;
70 int mlxsw_sp_mr_init(struct mlxsw_sp *mlxsw_sp,
71 const struct mlxsw_sp_mr_ops *mr_ops);
72 void mlxsw_sp_mr_fini(struct mlxsw_sp *mlxsw_sp);
73 int mlxsw_sp_mr_route_add(struct mlxsw_sp_mr_table *mr_table,
74 struct mr_mfc *mfc, bool replace);
75 void mlxsw_sp_mr_route_del(struct mlxsw_sp_mr_table *mr_table,
77 int mlxsw_sp_mr_vif_add(struct mlxsw_sp_mr_table *mr_table,
78 struct net_device *dev, vifi_t vif_index,
79 unsigned long vif_flags,
80 const struct mlxsw_sp_rif *rif);
81 void mlxsw_sp_mr_vif_del(struct mlxsw_sp_mr_table *mr_table, vifi_t vif_index);
82 int mlxsw_sp_mr_rif_add(struct mlxsw_sp_mr_table *mr_table,
83 const struct mlxsw_sp_rif *rif);
84 void mlxsw_sp_mr_rif_del(struct mlxsw_sp_mr_table *mr_table,
85 const struct mlxsw_sp_rif *rif);
86 void mlxsw_sp_mr_rif_mtu_update(struct mlxsw_sp_mr_table *mr_table,
87 const struct mlxsw_sp_rif *rif, int mtu);
88 struct mlxsw_sp_mr_table *mlxsw_sp_mr_table_create(struct mlxsw_sp *mlxsw_sp,
90 enum mlxsw_sp_l3proto proto);
91 void mlxsw_sp_mr_table_destroy(struct mlxsw_sp_mr_table *mr_table);
92 void mlxsw_sp_mr_table_flush(struct mlxsw_sp_mr_table *mr_table);
93 bool mlxsw_sp_mr_table_empty(const struct mlxsw_sp_mr_table *mr_table);