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