162306a36Sopenharmony_ci/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */
262306a36Sopenharmony_ci/* Copyright (c) 2017-2018 Mellanox Technologies. All rights reserved */
362306a36Sopenharmony_ci
462306a36Sopenharmony_ci#ifndef _MLXSW_SPECTRUM_MCROUTER_H
562306a36Sopenharmony_ci#define _MLXSW_SPECTRUM_MCROUTER_H
662306a36Sopenharmony_ci
762306a36Sopenharmony_ci#include <linux/mroute.h>
862306a36Sopenharmony_ci#include <linux/mroute6.h>
962306a36Sopenharmony_ci#include "spectrum_router.h"
1062306a36Sopenharmony_ci#include "spectrum.h"
1162306a36Sopenharmony_ci
1262306a36Sopenharmony_cienum mlxsw_sp_mr_route_action {
1362306a36Sopenharmony_ci	MLXSW_SP_MR_ROUTE_ACTION_FORWARD,
1462306a36Sopenharmony_ci	MLXSW_SP_MR_ROUTE_ACTION_TRAP,
1562306a36Sopenharmony_ci	MLXSW_SP_MR_ROUTE_ACTION_TRAP_AND_FORWARD,
1662306a36Sopenharmony_ci};
1762306a36Sopenharmony_ci
1862306a36Sopenharmony_cistruct mlxsw_sp_mr_route_key {
1962306a36Sopenharmony_ci	int vrid;
2062306a36Sopenharmony_ci	enum mlxsw_sp_l3proto proto;
2162306a36Sopenharmony_ci	union mlxsw_sp_l3addr group;
2262306a36Sopenharmony_ci	union mlxsw_sp_l3addr group_mask;
2362306a36Sopenharmony_ci	union mlxsw_sp_l3addr source;
2462306a36Sopenharmony_ci	union mlxsw_sp_l3addr source_mask;
2562306a36Sopenharmony_ci};
2662306a36Sopenharmony_ci
2762306a36Sopenharmony_cistruct mlxsw_sp_mr_route_info {
2862306a36Sopenharmony_ci	enum mlxsw_sp_mr_route_action route_action;
2962306a36Sopenharmony_ci	u16 irif_index;
3062306a36Sopenharmony_ci	u16 *erif_indices;
3162306a36Sopenharmony_ci	size_t erif_num;
3262306a36Sopenharmony_ci	u16 min_mtu;
3362306a36Sopenharmony_ci};
3462306a36Sopenharmony_ci
3562306a36Sopenharmony_cistruct mlxsw_sp_mr_route_params {
3662306a36Sopenharmony_ci	struct mlxsw_sp_mr_route_key key;
3762306a36Sopenharmony_ci	struct mlxsw_sp_mr_route_info value;
3862306a36Sopenharmony_ci	enum mlxsw_sp_mr_route_prio prio;
3962306a36Sopenharmony_ci};
4062306a36Sopenharmony_ci
4162306a36Sopenharmony_cistruct mlxsw_sp_mr_ops {
4262306a36Sopenharmony_ci	int priv_size;
4362306a36Sopenharmony_ci	int route_priv_size;
4462306a36Sopenharmony_ci	int (*init)(struct mlxsw_sp *mlxsw_sp, void *priv);
4562306a36Sopenharmony_ci	int (*route_create)(struct mlxsw_sp *mlxsw_sp, void *priv,
4662306a36Sopenharmony_ci			    void *route_priv,
4762306a36Sopenharmony_ci			    struct mlxsw_sp_mr_route_params *route_params);
4862306a36Sopenharmony_ci	int (*route_update)(struct mlxsw_sp *mlxsw_sp, void *route_priv,
4962306a36Sopenharmony_ci			    struct mlxsw_sp_mr_route_info *route_info);
5062306a36Sopenharmony_ci	int (*route_stats)(struct mlxsw_sp *mlxsw_sp, void *route_priv,
5162306a36Sopenharmony_ci			   u64 *packets, u64 *bytes);
5262306a36Sopenharmony_ci	int (*route_action_update)(struct mlxsw_sp *mlxsw_sp, void *route_priv,
5362306a36Sopenharmony_ci				   enum mlxsw_sp_mr_route_action route_action);
5462306a36Sopenharmony_ci	int (*route_min_mtu_update)(struct mlxsw_sp *mlxsw_sp, void *route_priv,
5562306a36Sopenharmony_ci				    u16 min_mtu);
5662306a36Sopenharmony_ci	int (*route_irif_update)(struct mlxsw_sp *mlxsw_sp, void *route_priv,
5762306a36Sopenharmony_ci				 u16 irif_index);
5862306a36Sopenharmony_ci	int (*route_erif_add)(struct mlxsw_sp *mlxsw_sp, void *route_priv,
5962306a36Sopenharmony_ci			      u16 erif_index);
6062306a36Sopenharmony_ci	int (*route_erif_del)(struct mlxsw_sp *mlxsw_sp, void *route_priv,
6162306a36Sopenharmony_ci			      u16 erif_index);
6262306a36Sopenharmony_ci	void (*route_destroy)(struct mlxsw_sp *mlxsw_sp, void *priv,
6362306a36Sopenharmony_ci			      void *route_priv);
6462306a36Sopenharmony_ci	void (*fini)(struct mlxsw_sp *mlxsw_sp, void *priv);
6562306a36Sopenharmony_ci};
6662306a36Sopenharmony_ci
6762306a36Sopenharmony_cistruct mlxsw_sp_mr;
6862306a36Sopenharmony_cistruct mlxsw_sp_mr_table;
6962306a36Sopenharmony_ci
7062306a36Sopenharmony_ciint mlxsw_sp_mr_init(struct mlxsw_sp *mlxsw_sp,
7162306a36Sopenharmony_ci		     const struct mlxsw_sp_mr_ops *mr_ops);
7262306a36Sopenharmony_civoid mlxsw_sp_mr_fini(struct mlxsw_sp *mlxsw_sp);
7362306a36Sopenharmony_ciint mlxsw_sp_mr_route_add(struct mlxsw_sp_mr_table *mr_table,
7462306a36Sopenharmony_ci			  struct mr_mfc *mfc, bool replace);
7562306a36Sopenharmony_civoid mlxsw_sp_mr_route_del(struct mlxsw_sp_mr_table *mr_table,
7662306a36Sopenharmony_ci			   struct mr_mfc *mfc);
7762306a36Sopenharmony_ciint mlxsw_sp_mr_vif_add(struct mlxsw_sp_mr_table *mr_table,
7862306a36Sopenharmony_ci			struct net_device *dev, vifi_t vif_index,
7962306a36Sopenharmony_ci			unsigned long vif_flags,
8062306a36Sopenharmony_ci			const struct mlxsw_sp_rif *rif);
8162306a36Sopenharmony_civoid mlxsw_sp_mr_vif_del(struct mlxsw_sp_mr_table *mr_table, vifi_t vif_index);
8262306a36Sopenharmony_ciint mlxsw_sp_mr_rif_add(struct mlxsw_sp_mr_table *mr_table,
8362306a36Sopenharmony_ci			const struct mlxsw_sp_rif *rif);
8462306a36Sopenharmony_civoid mlxsw_sp_mr_rif_del(struct mlxsw_sp_mr_table *mr_table,
8562306a36Sopenharmony_ci			 const struct mlxsw_sp_rif *rif);
8662306a36Sopenharmony_civoid mlxsw_sp_mr_rif_mtu_update(struct mlxsw_sp_mr_table *mr_table,
8762306a36Sopenharmony_ci				const struct mlxsw_sp_rif *rif, int mtu);
8862306a36Sopenharmony_cistruct mlxsw_sp_mr_table *mlxsw_sp_mr_table_create(struct mlxsw_sp *mlxsw_sp,
8962306a36Sopenharmony_ci						   u32 tb_id,
9062306a36Sopenharmony_ci						   enum mlxsw_sp_l3proto proto);
9162306a36Sopenharmony_civoid mlxsw_sp_mr_table_destroy(struct mlxsw_sp_mr_table *mr_table);
9262306a36Sopenharmony_civoid mlxsw_sp_mr_table_flush(struct mlxsw_sp_mr_table *mr_table);
9362306a36Sopenharmony_cibool mlxsw_sp_mr_table_empty(const struct mlxsw_sp_mr_table *mr_table);
9462306a36Sopenharmony_ci
9562306a36Sopenharmony_ci#endif
96