1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 /**************************************************************************** 3 * Driver for Solarflare network controllers and boards 4 * Copyright 2023, Advanced Micro Devices, Inc. 5 * 6 * This program is free software; you can redistribute it and/or modify it 7 * under the terms of the GNU General Public License version 2 as published 8 * by the Free Software Foundation, incorporated herein by reference. 9 */ 10 11 #ifndef EFX_TC_ENCAP_ACTIONS_H 12 #define EFX_TC_ENCAP_ACTIONS_H 13 #include "net_driver.h" 14 15 #include <linux/refcount.h> 16 #include <net/tc_act/tc_tunnel_key.h> 17 18 /** 19 * struct efx_neigh_binder - driver state for a neighbour entry 20 * @net: the network namespace in which this neigh resides 21 * @dst_ip: the IPv4 destination address resolved by this neigh 22 * @dst_ip6: the IPv6 destination address resolved by this neigh 23 * @ha: the hardware (Ethernet) address of the neighbour 24 * @n_valid: true if the neighbour is in NUD_VALID state 25 * @lock: protects @ha and @n_valid 26 * @ttl: Time To Live associated with the route used 27 * @dying: set when egdev is going away, to skip further updates 28 * @egdev: egress device from the route lookup. Holds a reference 29 * @dev_tracker: reference tracker entry for @egdev 30 * @ns_tracker: reference tracker entry for @ns 31 * @ref: counts encap actions referencing this entry 32 * @used: jiffies of last time traffic hit any encap action using this. 33 * When counter reads update this, a new neighbour event is sent to 34 * indicate that the neighbour entry is still in use. 35 * @users: list of &struct efx_tc_encap_action 36 * @linkage: entry in efx->neigh_ht (keys are @net, @dst_ip, @dst_ip6). 37 * @work: processes neighbour state changes, updates the encap actions 38 * @efx: owning NIC instance. 39 * 40 * Associates a neighbour entry with the encap actions that are 41 * interested in it, allowing the latter to be updated when the 42 * neighbour details change. 43 * Whichever of @dst_ip and @dst_ip6 is not in use will be all-zeroes, 44 * this distinguishes IPv4 from IPv6 entries. 45 */ 46 struct efx_neigh_binder { 47 struct net *net; 48 __be32 dst_ip; 49 struct in6_addr dst_ip6; 50 char ha[ETH_ALEN]; 51 bool n_valid; 52 rwlock_t lock; 53 u8 ttl; 54 bool dying; 55 struct net_device *egdev; 56 netdevice_tracker dev_tracker; 57 netns_tracker ns_tracker; 58 refcount_t ref; 59 unsigned long used; 60 struct list_head users; 61 struct rhash_head linkage; 62 struct work_struct work; 63 struct efx_nic *efx; 64 }; 65 66 /* This limit is arbitrary; current hardware (SN1022) handles encap headers 67 * of up to 126 bytes, but that limit is not enshrined in the MCDI protocol. 68 */ 69 #define EFX_TC_MAX_ENCAP_HDR 126 70 struct efx_tc_encap_action { 71 enum efx_encap_type type; 72 struct ip_tunnel_key key; /* 52 bytes */ 73 u32 dest_mport; /* is copied into struct efx_tc_action_set */ 74 u8 encap_hdr_len; 75 bool n_valid; 76 u8 encap_hdr[EFX_TC_MAX_ENCAP_HDR]; 77 struct efx_neigh_binder *neigh; 78 struct list_head list; /* entry on neigh->users list */ 79 struct list_head users; /* action sets using this encap_md */ 80 struct rhash_head linkage; /* efx->tc_encap_ht */ 81 refcount_t ref; 82 u32 fw_id; /* index of this entry in firmware encap table */ 83 }; 84 85 /* create/uncreate/teardown hashtables */ 86 int efx_tc_init_encap_actions(struct efx_nic *efx); 87 void efx_tc_destroy_encap_actions(struct efx_nic *efx); 88 void efx_tc_fini_encap_actions(struct efx_nic *efx); 89 90 struct efx_tc_flow_rule; 91 bool efx_tc_check_ready(struct efx_nic *efx, struct efx_tc_flow_rule *rule); 92 93 struct efx_tc_encap_action *efx_tc_flower_create_encap_md( 94 struct efx_nic *efx, const struct ip_tunnel_info *info, 95 struct net_device *egdev, struct netlink_ext_ack *extack); 96 void efx_tc_flower_release_encap_md(struct efx_nic *efx, 97 struct efx_tc_encap_action *encap); 98 99 void efx_tc_unregister_egdev(struct efx_nic *efx, struct net_device *net_dev); 100 int efx_tc_netevent_event(struct efx_nic *efx, unsigned long event, 101 void *ptr); 102 103 #endif /* EFX_TC_ENCAP_ACTIONS_H */ 104