18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */
28c2ecf20Sopenharmony_ci/* Copyright (c) 2017-2018 Mellanox Technologies. All rights reserved */
38c2ecf20Sopenharmony_ci
48c2ecf20Sopenharmony_ci#ifndef _MLXSW_SPECTRUM_MCROUTER_H
58c2ecf20Sopenharmony_ci#define _MLXSW_SPECTRUM_MCROUTER_H
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_ci#include <linux/mroute.h>
88c2ecf20Sopenharmony_ci#include <linux/mroute6.h>
98c2ecf20Sopenharmony_ci#include "spectrum_router.h"
108c2ecf20Sopenharmony_ci#include "spectrum.h"
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_cienum mlxsw_sp_mr_route_action {
138c2ecf20Sopenharmony_ci	MLXSW_SP_MR_ROUTE_ACTION_FORWARD,
148c2ecf20Sopenharmony_ci	MLXSW_SP_MR_ROUTE_ACTION_TRAP,
158c2ecf20Sopenharmony_ci	MLXSW_SP_MR_ROUTE_ACTION_TRAP_AND_FORWARD,
168c2ecf20Sopenharmony_ci};
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_cistruct mlxsw_sp_mr_route_key {
198c2ecf20Sopenharmony_ci	int vrid;
208c2ecf20Sopenharmony_ci	enum mlxsw_sp_l3proto proto;
218c2ecf20Sopenharmony_ci	union mlxsw_sp_l3addr group;
228c2ecf20Sopenharmony_ci	union mlxsw_sp_l3addr group_mask;
238c2ecf20Sopenharmony_ci	union mlxsw_sp_l3addr source;
248c2ecf20Sopenharmony_ci	union mlxsw_sp_l3addr source_mask;
258c2ecf20Sopenharmony_ci};
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_cistruct mlxsw_sp_mr_route_info {
288c2ecf20Sopenharmony_ci	enum mlxsw_sp_mr_route_action route_action;
298c2ecf20Sopenharmony_ci	u16 irif_index;
308c2ecf20Sopenharmony_ci	u16 *erif_indices;
318c2ecf20Sopenharmony_ci	size_t erif_num;
328c2ecf20Sopenharmony_ci	u16 min_mtu;
338c2ecf20Sopenharmony_ci};
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_cistruct mlxsw_sp_mr_route_params {
368c2ecf20Sopenharmony_ci	struct mlxsw_sp_mr_route_key key;
378c2ecf20Sopenharmony_ci	struct mlxsw_sp_mr_route_info value;
388c2ecf20Sopenharmony_ci	enum mlxsw_sp_mr_route_prio prio;
398c2ecf20Sopenharmony_ci};
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_cistruct mlxsw_sp_mr_ops {
428c2ecf20Sopenharmony_ci	int priv_size;
438c2ecf20Sopenharmony_ci	int route_priv_size;
448c2ecf20Sopenharmony_ci	int (*init)(struct mlxsw_sp *mlxsw_sp, void *priv);
458c2ecf20Sopenharmony_ci	int (*route_create)(struct mlxsw_sp *mlxsw_sp, void *priv,
468c2ecf20Sopenharmony_ci			    void *route_priv,
478c2ecf20Sopenharmony_ci			    struct mlxsw_sp_mr_route_params *route_params);
488c2ecf20Sopenharmony_ci	int (*route_update)(struct mlxsw_sp *mlxsw_sp, void *route_priv,
498c2ecf20Sopenharmony_ci			    struct mlxsw_sp_mr_route_info *route_info);
508c2ecf20Sopenharmony_ci	int (*route_stats)(struct mlxsw_sp *mlxsw_sp, void *route_priv,
518c2ecf20Sopenharmony_ci			   u64 *packets, u64 *bytes);
528c2ecf20Sopenharmony_ci	int (*route_action_update)(struct mlxsw_sp *mlxsw_sp, void *route_priv,
538c2ecf20Sopenharmony_ci				   enum mlxsw_sp_mr_route_action route_action);
548c2ecf20Sopenharmony_ci	int (*route_min_mtu_update)(struct mlxsw_sp *mlxsw_sp, void *route_priv,
558c2ecf20Sopenharmony_ci				    u16 min_mtu);
568c2ecf20Sopenharmony_ci	int (*route_irif_update)(struct mlxsw_sp *mlxsw_sp, void *route_priv,
578c2ecf20Sopenharmony_ci				 u16 irif_index);
588c2ecf20Sopenharmony_ci	int (*route_erif_add)(struct mlxsw_sp *mlxsw_sp, void *route_priv,
598c2ecf20Sopenharmony_ci			      u16 erif_index);
608c2ecf20Sopenharmony_ci	int (*route_erif_del)(struct mlxsw_sp *mlxsw_sp, void *route_priv,
618c2ecf20Sopenharmony_ci			      u16 erif_index);
628c2ecf20Sopenharmony_ci	void (*route_destroy)(struct mlxsw_sp *mlxsw_sp, void *priv,
638c2ecf20Sopenharmony_ci			      void *route_priv);
648c2ecf20Sopenharmony_ci	void (*fini)(struct mlxsw_sp *mlxsw_sp, void *priv);
658c2ecf20Sopenharmony_ci};
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_cistruct mlxsw_sp_mr;
688c2ecf20Sopenharmony_cistruct mlxsw_sp_mr_table;
698c2ecf20Sopenharmony_ci
708c2ecf20Sopenharmony_ciint mlxsw_sp_mr_init(struct mlxsw_sp *mlxsw_sp,
718c2ecf20Sopenharmony_ci		     const struct mlxsw_sp_mr_ops *mr_ops);
728c2ecf20Sopenharmony_civoid mlxsw_sp_mr_fini(struct mlxsw_sp *mlxsw_sp);
738c2ecf20Sopenharmony_ciint mlxsw_sp_mr_route_add(struct mlxsw_sp_mr_table *mr_table,
748c2ecf20Sopenharmony_ci			  struct mr_mfc *mfc, bool replace);
758c2ecf20Sopenharmony_civoid mlxsw_sp_mr_route_del(struct mlxsw_sp_mr_table *mr_table,
768c2ecf20Sopenharmony_ci			   struct mr_mfc *mfc);
778c2ecf20Sopenharmony_ciint mlxsw_sp_mr_vif_add(struct mlxsw_sp_mr_table *mr_table,
788c2ecf20Sopenharmony_ci			struct net_device *dev, vifi_t vif_index,
798c2ecf20Sopenharmony_ci			unsigned long vif_flags,
808c2ecf20Sopenharmony_ci			const struct mlxsw_sp_rif *rif);
818c2ecf20Sopenharmony_civoid mlxsw_sp_mr_vif_del(struct mlxsw_sp_mr_table *mr_table, vifi_t vif_index);
828c2ecf20Sopenharmony_ciint mlxsw_sp_mr_rif_add(struct mlxsw_sp_mr_table *mr_table,
838c2ecf20Sopenharmony_ci			const struct mlxsw_sp_rif *rif);
848c2ecf20Sopenharmony_civoid mlxsw_sp_mr_rif_del(struct mlxsw_sp_mr_table *mr_table,
858c2ecf20Sopenharmony_ci			 const struct mlxsw_sp_rif *rif);
868c2ecf20Sopenharmony_civoid mlxsw_sp_mr_rif_mtu_update(struct mlxsw_sp_mr_table *mr_table,
878c2ecf20Sopenharmony_ci				const struct mlxsw_sp_rif *rif, int mtu);
888c2ecf20Sopenharmony_cistruct mlxsw_sp_mr_table *mlxsw_sp_mr_table_create(struct mlxsw_sp *mlxsw_sp,
898c2ecf20Sopenharmony_ci						   u32 tb_id,
908c2ecf20Sopenharmony_ci						   enum mlxsw_sp_l3proto proto);
918c2ecf20Sopenharmony_civoid mlxsw_sp_mr_table_destroy(struct mlxsw_sp_mr_table *mr_table);
928c2ecf20Sopenharmony_civoid mlxsw_sp_mr_table_flush(struct mlxsw_sp_mr_table *mr_table);
938c2ecf20Sopenharmony_cibool mlxsw_sp_mr_table_empty(const struct mlxsw_sp_mr_table *mr_table);
948c2ecf20Sopenharmony_ci
958c2ecf20Sopenharmony_ci#endif
96