18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */ 28c2ecf20Sopenharmony_ci/* Copyright (c) 2018 Mellanox Technologies. All rights reserved */ 38c2ecf20Sopenharmony_ci 48c2ecf20Sopenharmony_ci#ifndef _MLXSW_SPECTRUM_SPAN_H 58c2ecf20Sopenharmony_ci#define _MLXSW_SPECTRUM_SPAN_H 68c2ecf20Sopenharmony_ci 78c2ecf20Sopenharmony_ci#include <linux/types.h> 88c2ecf20Sopenharmony_ci#include <linux/if_ether.h> 98c2ecf20Sopenharmony_ci#include <linux/refcount.h> 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_ci#include "spectrum_router.h" 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_cistruct mlxsw_sp; 148c2ecf20Sopenharmony_cistruct mlxsw_sp_port; 158c2ecf20Sopenharmony_ci 168c2ecf20Sopenharmony_cistruct mlxsw_sp_span_parms { 178c2ecf20Sopenharmony_ci struct mlxsw_sp_port *dest_port; /* NULL for unoffloaded SPAN. */ 188c2ecf20Sopenharmony_ci unsigned int ttl; 198c2ecf20Sopenharmony_ci unsigned char dmac[ETH_ALEN]; 208c2ecf20Sopenharmony_ci unsigned char smac[ETH_ALEN]; 218c2ecf20Sopenharmony_ci union mlxsw_sp_l3addr daddr; 228c2ecf20Sopenharmony_ci union mlxsw_sp_l3addr saddr; 238c2ecf20Sopenharmony_ci u16 vid; 248c2ecf20Sopenharmony_ci u16 policer_id; 258c2ecf20Sopenharmony_ci bool policer_enable; 268c2ecf20Sopenharmony_ci}; 278c2ecf20Sopenharmony_ci 288c2ecf20Sopenharmony_cienum mlxsw_sp_span_trigger { 298c2ecf20Sopenharmony_ci MLXSW_SP_SPAN_TRIGGER_INGRESS, 308c2ecf20Sopenharmony_ci MLXSW_SP_SPAN_TRIGGER_EGRESS, 318c2ecf20Sopenharmony_ci MLXSW_SP_SPAN_TRIGGER_TAIL_DROP, 328c2ecf20Sopenharmony_ci MLXSW_SP_SPAN_TRIGGER_EARLY_DROP, 338c2ecf20Sopenharmony_ci MLXSW_SP_SPAN_TRIGGER_ECN, 348c2ecf20Sopenharmony_ci}; 358c2ecf20Sopenharmony_ci 368c2ecf20Sopenharmony_cistruct mlxsw_sp_span_trigger_parms { 378c2ecf20Sopenharmony_ci int span_id; 388c2ecf20Sopenharmony_ci}; 398c2ecf20Sopenharmony_ci 408c2ecf20Sopenharmony_cistruct mlxsw_sp_span_agent_parms { 418c2ecf20Sopenharmony_ci const struct net_device *to_dev; 428c2ecf20Sopenharmony_ci u16 policer_id; 438c2ecf20Sopenharmony_ci bool policer_enable; 448c2ecf20Sopenharmony_ci}; 458c2ecf20Sopenharmony_ci 468c2ecf20Sopenharmony_cistruct mlxsw_sp_span_entry_ops; 478c2ecf20Sopenharmony_ci 488c2ecf20Sopenharmony_cistruct mlxsw_sp_span_ops { 498c2ecf20Sopenharmony_ci int (*init)(struct mlxsw_sp *mlxsw_sp); 508c2ecf20Sopenharmony_ci int (*policer_id_base_set)(struct mlxsw_sp *mlxsw_sp, 518c2ecf20Sopenharmony_ci u16 policer_id_base); 528c2ecf20Sopenharmony_ci}; 538c2ecf20Sopenharmony_ci 548c2ecf20Sopenharmony_cistruct mlxsw_sp_span_entry { 558c2ecf20Sopenharmony_ci const struct net_device *to_dev; 568c2ecf20Sopenharmony_ci const struct mlxsw_sp_span_entry_ops *ops; 578c2ecf20Sopenharmony_ci struct mlxsw_sp_span_parms parms; 588c2ecf20Sopenharmony_ci refcount_t ref_count; 598c2ecf20Sopenharmony_ci int id; 608c2ecf20Sopenharmony_ci}; 618c2ecf20Sopenharmony_ci 628c2ecf20Sopenharmony_cistruct mlxsw_sp_span_entry_ops { 638c2ecf20Sopenharmony_ci bool is_static; 648c2ecf20Sopenharmony_ci bool (*can_handle)(const struct net_device *to_dev); 658c2ecf20Sopenharmony_ci int (*parms_set)(struct mlxsw_sp *mlxsw_sp, 668c2ecf20Sopenharmony_ci const struct net_device *to_dev, 678c2ecf20Sopenharmony_ci struct mlxsw_sp_span_parms *sparmsp); 688c2ecf20Sopenharmony_ci int (*configure)(struct mlxsw_sp_span_entry *span_entry, 698c2ecf20Sopenharmony_ci struct mlxsw_sp_span_parms sparms); 708c2ecf20Sopenharmony_ci void (*deconfigure)(struct mlxsw_sp_span_entry *span_entry); 718c2ecf20Sopenharmony_ci}; 728c2ecf20Sopenharmony_ci 738c2ecf20Sopenharmony_ciint mlxsw_sp_span_init(struct mlxsw_sp *mlxsw_sp); 748c2ecf20Sopenharmony_civoid mlxsw_sp_span_fini(struct mlxsw_sp *mlxsw_sp); 758c2ecf20Sopenharmony_civoid mlxsw_sp_span_respin(struct mlxsw_sp *mlxsw_sp); 768c2ecf20Sopenharmony_ci 778c2ecf20Sopenharmony_cistruct mlxsw_sp_span_entry * 788c2ecf20Sopenharmony_cimlxsw_sp_span_entry_find_by_port(struct mlxsw_sp *mlxsw_sp, 798c2ecf20Sopenharmony_ci const struct net_device *to_dev); 808c2ecf20Sopenharmony_ci 818c2ecf20Sopenharmony_civoid mlxsw_sp_span_entry_invalidate(struct mlxsw_sp *mlxsw_sp, 828c2ecf20Sopenharmony_ci struct mlxsw_sp_span_entry *span_entry); 838c2ecf20Sopenharmony_ci 848c2ecf20Sopenharmony_ciint mlxsw_sp_span_port_mtu_update(struct mlxsw_sp_port *port, u16 mtu); 858c2ecf20Sopenharmony_civoid mlxsw_sp_span_speed_update_work(struct work_struct *work); 868c2ecf20Sopenharmony_ci 878c2ecf20Sopenharmony_ciint mlxsw_sp_span_agent_get(struct mlxsw_sp *mlxsw_sp, int *p_span_id, 888c2ecf20Sopenharmony_ci const struct mlxsw_sp_span_agent_parms *parms); 898c2ecf20Sopenharmony_civoid mlxsw_sp_span_agent_put(struct mlxsw_sp *mlxsw_sp, int span_id); 908c2ecf20Sopenharmony_ciint mlxsw_sp_span_analyzed_port_get(struct mlxsw_sp_port *mlxsw_sp_port, 918c2ecf20Sopenharmony_ci bool ingress); 928c2ecf20Sopenharmony_civoid mlxsw_sp_span_analyzed_port_put(struct mlxsw_sp_port *mlxsw_sp_port, 938c2ecf20Sopenharmony_ci bool ingress); 948c2ecf20Sopenharmony_ciint mlxsw_sp_span_agent_bind(struct mlxsw_sp *mlxsw_sp, 958c2ecf20Sopenharmony_ci enum mlxsw_sp_span_trigger trigger, 968c2ecf20Sopenharmony_ci struct mlxsw_sp_port *mlxsw_sp_port, 978c2ecf20Sopenharmony_ci const struct mlxsw_sp_span_trigger_parms *parms); 988c2ecf20Sopenharmony_civoid 998c2ecf20Sopenharmony_cimlxsw_sp_span_agent_unbind(struct mlxsw_sp *mlxsw_sp, 1008c2ecf20Sopenharmony_ci enum mlxsw_sp_span_trigger trigger, 1018c2ecf20Sopenharmony_ci struct mlxsw_sp_port *mlxsw_sp_port, 1028c2ecf20Sopenharmony_ci const struct mlxsw_sp_span_trigger_parms *parms); 1038c2ecf20Sopenharmony_ciint mlxsw_sp_span_trigger_enable(struct mlxsw_sp_port *mlxsw_sp_port, 1048c2ecf20Sopenharmony_ci enum mlxsw_sp_span_trigger trigger, u8 tc); 1058c2ecf20Sopenharmony_civoid mlxsw_sp_span_trigger_disable(struct mlxsw_sp_port *mlxsw_sp_port, 1068c2ecf20Sopenharmony_ci enum mlxsw_sp_span_trigger trigger, u8 tc); 1078c2ecf20Sopenharmony_ci 1088c2ecf20Sopenharmony_ciextern const struct mlxsw_sp_span_ops mlxsw_sp1_span_ops; 1098c2ecf20Sopenharmony_ciextern const struct mlxsw_sp_span_ops mlxsw_sp2_span_ops; 1108c2ecf20Sopenharmony_ciextern const struct mlxsw_sp_span_ops mlxsw_sp3_span_ops; 1118c2ecf20Sopenharmony_ci 1128c2ecf20Sopenharmony_ci#endif 113