mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-08-05 16:54:27 +00:00
sfc: functions to register for conntrack zone offload
Bind a stub callback to the netfilter flow table. Reviewed-by: Pieter Jansen van Vuuren <pieter.jansen-van-vuuren@amd.com> Reviewed-by: Simon Horman <horms@kernel.org> Signed-off-by: Edward Cree <ecree.xilinx@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
3bf969e88a
commit
c3bb5c6acd
5 changed files with 156 additions and 1 deletions
|
@ -11,7 +11,7 @@ sfc-y += efx.o efx_common.o efx_channels.o nic.o \
|
||||||
sfc-$(CONFIG_SFC_MTD) += mtd.o
|
sfc-$(CONFIG_SFC_MTD) += mtd.o
|
||||||
sfc-$(CONFIG_SFC_SRIOV) += sriov.o ef10_sriov.o ef100_sriov.o ef100_rep.o \
|
sfc-$(CONFIG_SFC_SRIOV) += sriov.o ef10_sriov.o ef100_sriov.o ef100_rep.o \
|
||||||
mae.o tc.o tc_bindings.o tc_counters.o \
|
mae.o tc.o tc_bindings.o tc_counters.o \
|
||||||
tc_encap_actions.o
|
tc_encap_actions.o tc_conntrack.o
|
||||||
|
|
||||||
obj-$(CONFIG_SFC) += sfc.o
|
obj-$(CONFIG_SFC) += sfc.o
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
#include "tc.h"
|
#include "tc.h"
|
||||||
#include "tc_bindings.h"
|
#include "tc_bindings.h"
|
||||||
#include "tc_encap_actions.h"
|
#include "tc_encap_actions.h"
|
||||||
|
#include "tc_conntrack.h"
|
||||||
#include "mae.h"
|
#include "mae.h"
|
||||||
#include "ef100_rep.h"
|
#include "ef100_rep.h"
|
||||||
#include "efx.h"
|
#include "efx.h"
|
||||||
|
@ -1747,6 +1748,9 @@ int efx_init_struct_tc(struct efx_nic *efx)
|
||||||
rc = rhashtable_init(&efx->tc->match_action_ht, &efx_tc_match_action_ht_params);
|
rc = rhashtable_init(&efx->tc->match_action_ht, &efx_tc_match_action_ht_params);
|
||||||
if (rc < 0)
|
if (rc < 0)
|
||||||
goto fail_match_action_ht;
|
goto fail_match_action_ht;
|
||||||
|
rc = efx_tc_init_conntrack(efx);
|
||||||
|
if (rc < 0)
|
||||||
|
goto fail_conntrack;
|
||||||
efx->tc->reps_filter_uc = -1;
|
efx->tc->reps_filter_uc = -1;
|
||||||
efx->tc->reps_filter_mc = -1;
|
efx->tc->reps_filter_mc = -1;
|
||||||
INIT_LIST_HEAD(&efx->tc->dflt.pf.acts.list);
|
INIT_LIST_HEAD(&efx->tc->dflt.pf.acts.list);
|
||||||
|
@ -1759,6 +1763,8 @@ int efx_init_struct_tc(struct efx_nic *efx)
|
||||||
efx->tc->facts.reps.fw_id = MC_CMD_MAE_ACTION_SET_ALLOC_OUT_ACTION_SET_ID_NULL;
|
efx->tc->facts.reps.fw_id = MC_CMD_MAE_ACTION_SET_ALLOC_OUT_ACTION_SET_ID_NULL;
|
||||||
efx->extra_channel_type[EFX_EXTRA_CHANNEL_TC] = &efx_tc_channel_type;
|
efx->extra_channel_type[EFX_EXTRA_CHANNEL_TC] = &efx_tc_channel_type;
|
||||||
return 0;
|
return 0;
|
||||||
|
fail_conntrack:
|
||||||
|
rhashtable_destroy(&efx->tc->match_action_ht);
|
||||||
fail_match_action_ht:
|
fail_match_action_ht:
|
||||||
rhashtable_destroy(&efx->tc->encap_match_ht);
|
rhashtable_destroy(&efx->tc->encap_match_ht);
|
||||||
fail_encap_match_ht:
|
fail_encap_match_ht:
|
||||||
|
@ -1792,6 +1798,7 @@ void efx_fini_struct_tc(struct efx_nic *efx)
|
||||||
efx);
|
efx);
|
||||||
rhashtable_free_and_destroy(&efx->tc->encap_match_ht,
|
rhashtable_free_and_destroy(&efx->tc->encap_match_ht,
|
||||||
efx_tc_encap_match_free, NULL);
|
efx_tc_encap_match_free, NULL);
|
||||||
|
efx_tc_fini_conntrack(efx);
|
||||||
efx_tc_fini_counters(efx);
|
efx_tc_fini_counters(efx);
|
||||||
efx_tc_fini_encap_actions(efx);
|
efx_tc_fini_encap_actions(efx);
|
||||||
mutex_unlock(&efx->tc->mutex);
|
mutex_unlock(&efx->tc->mutex);
|
||||||
|
|
|
@ -196,6 +196,7 @@ struct efx_tc_table_ct { /* TABLE_ID_CONNTRACK_TABLE */
|
||||||
* @encap_ht: Hashtable of TC encap actions
|
* @encap_ht: Hashtable of TC encap actions
|
||||||
* @encap_match_ht: Hashtable of TC encap matches
|
* @encap_match_ht: Hashtable of TC encap matches
|
||||||
* @match_action_ht: Hashtable of TC match-action rules
|
* @match_action_ht: Hashtable of TC match-action rules
|
||||||
|
* @ct_zone_ht: Hashtable of TC conntrack flowtable bindings
|
||||||
* @neigh_ht: Hashtable of neighbour watches (&struct efx_neigh_binder)
|
* @neigh_ht: Hashtable of neighbour watches (&struct efx_neigh_binder)
|
||||||
* @meta_ct: MAE table layout for conntrack table
|
* @meta_ct: MAE table layout for conntrack table
|
||||||
* @reps_mport_id: MAE port allocated for representor RX
|
* @reps_mport_id: MAE port allocated for representor RX
|
||||||
|
@ -228,6 +229,7 @@ struct efx_tc_state {
|
||||||
struct rhashtable encap_ht;
|
struct rhashtable encap_ht;
|
||||||
struct rhashtable encap_match_ht;
|
struct rhashtable encap_match_ht;
|
||||||
struct rhashtable match_action_ht;
|
struct rhashtable match_action_ht;
|
||||||
|
struct rhashtable ct_zone_ht;
|
||||||
struct rhashtable neigh_ht;
|
struct rhashtable neigh_ht;
|
||||||
struct efx_tc_table_ct meta_ct;
|
struct efx_tc_table_ct meta_ct;
|
||||||
u32 reps_mport_id, reps_mport_vport_id;
|
u32 reps_mport_id, reps_mport_vport_id;
|
||||||
|
|
109
drivers/net/ethernet/sfc/tc_conntrack.c
Normal file
109
drivers/net/ethernet/sfc/tc_conntrack.c
Normal file
|
@ -0,0 +1,109 @@
|
||||||
|
// SPDX-License-Identifier: GPL-2.0-only
|
||||||
|
/****************************************************************************
|
||||||
|
* Driver for Solarflare network controllers and boards
|
||||||
|
* Copyright 2023, Advanced Micro Devices, Inc.
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License version 2 as published
|
||||||
|
* by the Free Software Foundation, incorporated herein by reference.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "tc_conntrack.h"
|
||||||
|
#include "tc.h"
|
||||||
|
#include "mae.h"
|
||||||
|
|
||||||
|
static int efx_tc_flow_block(enum tc_setup_type type, void *type_data,
|
||||||
|
void *cb_priv);
|
||||||
|
|
||||||
|
static const struct rhashtable_params efx_tc_ct_zone_ht_params = {
|
||||||
|
.key_len = offsetof(struct efx_tc_ct_zone, linkage),
|
||||||
|
.key_offset = 0,
|
||||||
|
.head_offset = offsetof(struct efx_tc_ct_zone, linkage),
|
||||||
|
};
|
||||||
|
|
||||||
|
static void efx_tc_ct_zone_free(void *ptr, void *arg)
|
||||||
|
{
|
||||||
|
struct efx_tc_ct_zone *zone = ptr;
|
||||||
|
struct efx_nic *efx = zone->efx;
|
||||||
|
|
||||||
|
netif_err(efx, drv, efx->net_dev,
|
||||||
|
"tc ct_zone %u still present at teardown, removing\n",
|
||||||
|
zone->zone);
|
||||||
|
|
||||||
|
nf_flow_table_offload_del_cb(zone->nf_ft, efx_tc_flow_block, zone);
|
||||||
|
kfree(zone);
|
||||||
|
}
|
||||||
|
|
||||||
|
int efx_tc_init_conntrack(struct efx_nic *efx)
|
||||||
|
{
|
||||||
|
int rc;
|
||||||
|
|
||||||
|
rc = rhashtable_init(&efx->tc->ct_zone_ht, &efx_tc_ct_zone_ht_params);
|
||||||
|
if (rc < 0)
|
||||||
|
return rc;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void efx_tc_fini_conntrack(struct efx_nic *efx)
|
||||||
|
{
|
||||||
|
rhashtable_free_and_destroy(&efx->tc->ct_zone_ht, efx_tc_ct_zone_free, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int efx_tc_flow_block(enum tc_setup_type type, void *type_data,
|
||||||
|
void *cb_priv)
|
||||||
|
{
|
||||||
|
return -EOPNOTSUPP;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct efx_tc_ct_zone *efx_tc_ct_register_zone(struct efx_nic *efx, u16 zone,
|
||||||
|
struct nf_flowtable *ct_ft)
|
||||||
|
{
|
||||||
|
struct efx_tc_ct_zone *ct_zone, *old;
|
||||||
|
int rc;
|
||||||
|
|
||||||
|
ct_zone = kzalloc(sizeof(*ct_zone), GFP_USER);
|
||||||
|
if (!ct_zone)
|
||||||
|
return ERR_PTR(-ENOMEM);
|
||||||
|
ct_zone->zone = zone;
|
||||||
|
old = rhashtable_lookup_get_insert_fast(&efx->tc->ct_zone_ht,
|
||||||
|
&ct_zone->linkage,
|
||||||
|
efx_tc_ct_zone_ht_params);
|
||||||
|
if (old) {
|
||||||
|
/* don't need our new entry */
|
||||||
|
kfree(ct_zone);
|
||||||
|
if (!refcount_inc_not_zero(&old->ref))
|
||||||
|
return ERR_PTR(-EAGAIN);
|
||||||
|
/* existing entry found */
|
||||||
|
WARN_ON_ONCE(old->nf_ft != ct_ft);
|
||||||
|
netif_dbg(efx, drv, efx->net_dev,
|
||||||
|
"Found existing ct_zone for %u\n", zone);
|
||||||
|
return old;
|
||||||
|
}
|
||||||
|
ct_zone->nf_ft = ct_ft;
|
||||||
|
ct_zone->efx = efx;
|
||||||
|
rc = nf_flow_table_offload_add_cb(ct_ft, efx_tc_flow_block, ct_zone);
|
||||||
|
netif_dbg(efx, drv, efx->net_dev, "Adding new ct_zone for %u, rc %d\n",
|
||||||
|
zone, rc);
|
||||||
|
if (rc < 0)
|
||||||
|
goto fail;
|
||||||
|
refcount_set(&ct_zone->ref, 1);
|
||||||
|
return ct_zone;
|
||||||
|
fail:
|
||||||
|
rhashtable_remove_fast(&efx->tc->ct_zone_ht, &ct_zone->linkage,
|
||||||
|
efx_tc_ct_zone_ht_params);
|
||||||
|
kfree(ct_zone);
|
||||||
|
return ERR_PTR(rc);
|
||||||
|
}
|
||||||
|
|
||||||
|
void efx_tc_ct_unregister_zone(struct efx_nic *efx,
|
||||||
|
struct efx_tc_ct_zone *ct_zone)
|
||||||
|
{
|
||||||
|
if (!refcount_dec_and_test(&ct_zone->ref))
|
||||||
|
return; /* still in use */
|
||||||
|
nf_flow_table_offload_del_cb(ct_zone->nf_ft, efx_tc_flow_block, ct_zone);
|
||||||
|
rhashtable_remove_fast(&efx->tc->ct_zone_ht, &ct_zone->linkage,
|
||||||
|
efx_tc_ct_zone_ht_params);
|
||||||
|
netif_dbg(efx, drv, efx->net_dev, "Removed ct_zone for %u\n",
|
||||||
|
ct_zone->zone);
|
||||||
|
kfree(ct_zone);
|
||||||
|
}
|
37
drivers/net/ethernet/sfc/tc_conntrack.h
Normal file
37
drivers/net/ethernet/sfc/tc_conntrack.h
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||||
|
/****************************************************************************
|
||||||
|
* Driver for Solarflare network controllers and boards
|
||||||
|
* Copyright 2023, Advanced Micro Devices, Inc.
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License version 2 as published
|
||||||
|
* by the Free Software Foundation, incorporated herein by reference.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef EFX_TC_CONNTRACK_H
|
||||||
|
#define EFX_TC_CONNTRACK_H
|
||||||
|
#include "net_driver.h"
|
||||||
|
|
||||||
|
#if IS_ENABLED(CONFIG_SFC_SRIOV)
|
||||||
|
#include <linux/refcount.h>
|
||||||
|
#include <net/netfilter/nf_flow_table.h>
|
||||||
|
|
||||||
|
struct efx_tc_ct_zone {
|
||||||
|
u16 zone;
|
||||||
|
struct rhash_head linkage;
|
||||||
|
refcount_t ref;
|
||||||
|
struct nf_flowtable *nf_ft;
|
||||||
|
struct efx_nic *efx;
|
||||||
|
};
|
||||||
|
|
||||||
|
/* create/teardown hashtables */
|
||||||
|
int efx_tc_init_conntrack(struct efx_nic *efx);
|
||||||
|
void efx_tc_fini_conntrack(struct efx_nic *efx);
|
||||||
|
|
||||||
|
struct efx_tc_ct_zone *efx_tc_ct_register_zone(struct efx_nic *efx, u16 zone,
|
||||||
|
struct nf_flowtable *ct_ft);
|
||||||
|
void efx_tc_ct_unregister_zone(struct efx_nic *efx,
|
||||||
|
struct efx_tc_ct_zone *ct_zone);
|
||||||
|
|
||||||
|
#endif /* CONFIG_SFC_SRIOV */
|
||||||
|
#endif /* EFX_TC_CONNTRACK_H */
|
Loading…
Add table
Reference in a new issue