1 /* 2 * drivers/net/ethernet/mellanox/mlxsw/mlxsw_span.h 3 * Copyright (c) 2018 Mellanox Technologies. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 3. Neither the names of the copyright holders nor the names of its 14 * contributors may be used to endorse or promote products derived from 15 * this software without specific prior written permission. 16 * 17 * Alternatively, this software may be distributed under the terms of the 18 * GNU General Public License ("GPL") version 2 as published by the Free 19 * Software Foundation. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 25 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 * POSSIBILITY OF SUCH DAMAGE. 32 */ 33 34 #ifndef _MLXSW_SPECTRUM_SPAN_H 35 #define _MLXSW_SPECTRUM_SPAN_H 36 37 #include <linux/types.h> 38 #include <linux/if_ether.h> 39 40 #include "spectrum_router.h" 41 42 struct mlxsw_sp; 43 struct mlxsw_sp_port; 44 45 enum mlxsw_sp_span_type { 46 MLXSW_SP_SPAN_EGRESS, 47 MLXSW_SP_SPAN_INGRESS 48 }; 49 50 struct mlxsw_sp_span_inspected_port { 51 struct list_head list; 52 enum mlxsw_sp_span_type type; 53 u8 local_port; 54 55 /* Whether this is a directly bound mirror (port-to-port) or an ACL. */ 56 bool bound; 57 }; 58 59 struct mlxsw_sp_span_parms { 60 struct mlxsw_sp_port *dest_port; /* NULL for unoffloaded SPAN. */ 61 unsigned int ttl; 62 unsigned char dmac[ETH_ALEN]; 63 unsigned char smac[ETH_ALEN]; 64 union mlxsw_sp_l3addr daddr; 65 union mlxsw_sp_l3addr saddr; 66 }; 67 68 struct mlxsw_sp_span_entry_ops; 69 70 struct mlxsw_sp_span_entry { 71 const struct net_device *to_dev; 72 const struct mlxsw_sp_span_entry_ops *ops; 73 struct mlxsw_sp_span_parms parms; 74 struct list_head bound_ports_list; 75 int ref_count; 76 int id; 77 }; 78 79 struct mlxsw_sp_span_entry_ops { 80 bool (*can_handle)(const struct net_device *to_dev); 81 int (*parms)(const struct net_device *to_dev, 82 struct mlxsw_sp_span_parms *sparmsp); 83 int (*configure)(struct mlxsw_sp_span_entry *span_entry, 84 struct mlxsw_sp_span_parms sparms); 85 void (*deconfigure)(struct mlxsw_sp_span_entry *span_entry); 86 }; 87 88 int mlxsw_sp_span_init(struct mlxsw_sp *mlxsw_sp); 89 void mlxsw_sp_span_fini(struct mlxsw_sp *mlxsw_sp); 90 void mlxsw_sp_span_respin(struct mlxsw_sp *mlxsw_sp); 91 92 int mlxsw_sp_span_mirror_add(struct mlxsw_sp_port *from, 93 const struct net_device *to_dev, 94 enum mlxsw_sp_span_type type, 95 bool bind, int *p_span_id); 96 void mlxsw_sp_span_mirror_del(struct mlxsw_sp_port *from, int span_id, 97 enum mlxsw_sp_span_type type, bool bind); 98 struct mlxsw_sp_span_entry * 99 mlxsw_sp_span_entry_find_by_port(struct mlxsw_sp *mlxsw_sp, 100 const struct net_device *to_dev); 101 102 void mlxsw_sp_span_entry_invalidate(struct mlxsw_sp *mlxsw_sp, 103 struct mlxsw_sp_span_entry *span_entry); 104 105 int mlxsw_sp_span_port_mtu_update(struct mlxsw_sp_port *port, u16 mtu); 106 107 #endif 108