1*4882a593Smuzhiyun /* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */ 2*4882a593Smuzhiyun /* Copyright (c) 2017-2018 Mellanox Technologies. All rights reserved */ 3*4882a593Smuzhiyun 4*4882a593Smuzhiyun #ifndef _MLXSW_SPECTRUM_MCROUTER_H 5*4882a593Smuzhiyun #define _MLXSW_SPECTRUM_MCROUTER_H 6*4882a593Smuzhiyun 7*4882a593Smuzhiyun #include <linux/mroute.h> 8*4882a593Smuzhiyun #include <linux/mroute6.h> 9*4882a593Smuzhiyun #include "spectrum_router.h" 10*4882a593Smuzhiyun #include "spectrum.h" 11*4882a593Smuzhiyun 12*4882a593Smuzhiyun enum mlxsw_sp_mr_route_action { 13*4882a593Smuzhiyun MLXSW_SP_MR_ROUTE_ACTION_FORWARD, 14*4882a593Smuzhiyun MLXSW_SP_MR_ROUTE_ACTION_TRAP, 15*4882a593Smuzhiyun MLXSW_SP_MR_ROUTE_ACTION_TRAP_AND_FORWARD, 16*4882a593Smuzhiyun }; 17*4882a593Smuzhiyun 18*4882a593Smuzhiyun struct mlxsw_sp_mr_route_key { 19*4882a593Smuzhiyun int vrid; 20*4882a593Smuzhiyun enum mlxsw_sp_l3proto proto; 21*4882a593Smuzhiyun union mlxsw_sp_l3addr group; 22*4882a593Smuzhiyun union mlxsw_sp_l3addr group_mask; 23*4882a593Smuzhiyun union mlxsw_sp_l3addr source; 24*4882a593Smuzhiyun union mlxsw_sp_l3addr source_mask; 25*4882a593Smuzhiyun }; 26*4882a593Smuzhiyun 27*4882a593Smuzhiyun struct mlxsw_sp_mr_route_info { 28*4882a593Smuzhiyun enum mlxsw_sp_mr_route_action route_action; 29*4882a593Smuzhiyun u16 irif_index; 30*4882a593Smuzhiyun u16 *erif_indices; 31*4882a593Smuzhiyun size_t erif_num; 32*4882a593Smuzhiyun u16 min_mtu; 33*4882a593Smuzhiyun }; 34*4882a593Smuzhiyun 35*4882a593Smuzhiyun struct mlxsw_sp_mr_route_params { 36*4882a593Smuzhiyun struct mlxsw_sp_mr_route_key key; 37*4882a593Smuzhiyun struct mlxsw_sp_mr_route_info value; 38*4882a593Smuzhiyun enum mlxsw_sp_mr_route_prio prio; 39*4882a593Smuzhiyun }; 40*4882a593Smuzhiyun 41*4882a593Smuzhiyun struct mlxsw_sp_mr_ops { 42*4882a593Smuzhiyun int priv_size; 43*4882a593Smuzhiyun int route_priv_size; 44*4882a593Smuzhiyun int (*init)(struct mlxsw_sp *mlxsw_sp, void *priv); 45*4882a593Smuzhiyun int (*route_create)(struct mlxsw_sp *mlxsw_sp, void *priv, 46*4882a593Smuzhiyun void *route_priv, 47*4882a593Smuzhiyun struct mlxsw_sp_mr_route_params *route_params); 48*4882a593Smuzhiyun int (*route_update)(struct mlxsw_sp *mlxsw_sp, void *route_priv, 49*4882a593Smuzhiyun struct mlxsw_sp_mr_route_info *route_info); 50*4882a593Smuzhiyun int (*route_stats)(struct mlxsw_sp *mlxsw_sp, void *route_priv, 51*4882a593Smuzhiyun u64 *packets, u64 *bytes); 52*4882a593Smuzhiyun int (*route_action_update)(struct mlxsw_sp *mlxsw_sp, void *route_priv, 53*4882a593Smuzhiyun enum mlxsw_sp_mr_route_action route_action); 54*4882a593Smuzhiyun int (*route_min_mtu_update)(struct mlxsw_sp *mlxsw_sp, void *route_priv, 55*4882a593Smuzhiyun u16 min_mtu); 56*4882a593Smuzhiyun int (*route_irif_update)(struct mlxsw_sp *mlxsw_sp, void *route_priv, 57*4882a593Smuzhiyun u16 irif_index); 58*4882a593Smuzhiyun int (*route_erif_add)(struct mlxsw_sp *mlxsw_sp, void *route_priv, 59*4882a593Smuzhiyun u16 erif_index); 60*4882a593Smuzhiyun int (*route_erif_del)(struct mlxsw_sp *mlxsw_sp, void *route_priv, 61*4882a593Smuzhiyun u16 erif_index); 62*4882a593Smuzhiyun void (*route_destroy)(struct mlxsw_sp *mlxsw_sp, void *priv, 63*4882a593Smuzhiyun void *route_priv); 64*4882a593Smuzhiyun void (*fini)(struct mlxsw_sp *mlxsw_sp, void *priv); 65*4882a593Smuzhiyun }; 66*4882a593Smuzhiyun 67*4882a593Smuzhiyun struct mlxsw_sp_mr; 68*4882a593Smuzhiyun struct mlxsw_sp_mr_table; 69*4882a593Smuzhiyun 70*4882a593Smuzhiyun int mlxsw_sp_mr_init(struct mlxsw_sp *mlxsw_sp, 71*4882a593Smuzhiyun const struct mlxsw_sp_mr_ops *mr_ops); 72*4882a593Smuzhiyun void mlxsw_sp_mr_fini(struct mlxsw_sp *mlxsw_sp); 73*4882a593Smuzhiyun int mlxsw_sp_mr_route_add(struct mlxsw_sp_mr_table *mr_table, 74*4882a593Smuzhiyun struct mr_mfc *mfc, bool replace); 75*4882a593Smuzhiyun void mlxsw_sp_mr_route_del(struct mlxsw_sp_mr_table *mr_table, 76*4882a593Smuzhiyun struct mr_mfc *mfc); 77*4882a593Smuzhiyun int mlxsw_sp_mr_vif_add(struct mlxsw_sp_mr_table *mr_table, 78*4882a593Smuzhiyun struct net_device *dev, vifi_t vif_index, 79*4882a593Smuzhiyun unsigned long vif_flags, 80*4882a593Smuzhiyun const struct mlxsw_sp_rif *rif); 81*4882a593Smuzhiyun void mlxsw_sp_mr_vif_del(struct mlxsw_sp_mr_table *mr_table, vifi_t vif_index); 82*4882a593Smuzhiyun int mlxsw_sp_mr_rif_add(struct mlxsw_sp_mr_table *mr_table, 83*4882a593Smuzhiyun const struct mlxsw_sp_rif *rif); 84*4882a593Smuzhiyun void mlxsw_sp_mr_rif_del(struct mlxsw_sp_mr_table *mr_table, 85*4882a593Smuzhiyun const struct mlxsw_sp_rif *rif); 86*4882a593Smuzhiyun void mlxsw_sp_mr_rif_mtu_update(struct mlxsw_sp_mr_table *mr_table, 87*4882a593Smuzhiyun const struct mlxsw_sp_rif *rif, int mtu); 88*4882a593Smuzhiyun struct mlxsw_sp_mr_table *mlxsw_sp_mr_table_create(struct mlxsw_sp *mlxsw_sp, 89*4882a593Smuzhiyun u32 tb_id, 90*4882a593Smuzhiyun enum mlxsw_sp_l3proto proto); 91*4882a593Smuzhiyun void mlxsw_sp_mr_table_destroy(struct mlxsw_sp_mr_table *mr_table); 92*4882a593Smuzhiyun void mlxsw_sp_mr_table_flush(struct mlxsw_sp_mr_table *mr_table); 93*4882a593Smuzhiyun bool mlxsw_sp_mr_table_empty(const struct mlxsw_sp_mr_table *mr_table); 94*4882a593Smuzhiyun 95*4882a593Smuzhiyun #endif 96