xref: /linux/drivers/net/ethernet/sfc/tc_counters.h (revision a1c613ae4c322ddd58d5a8539dbfba2a0380a8c0)
125730d8bSEdward Cree /* SPDX-License-Identifier: GPL-2.0-only */
225730d8bSEdward Cree /****************************************************************************
325730d8bSEdward Cree  * Driver for Solarflare network controllers and boards
425730d8bSEdward Cree  * Copyright 2022 Advanced Micro Devices, Inc.
525730d8bSEdward Cree  *
625730d8bSEdward Cree  * This program is free software; you can redistribute it and/or modify it
725730d8bSEdward Cree  * under the terms of the GNU General Public License version 2 as published
825730d8bSEdward Cree  * by the Free Software Foundation, incorporated herein by reference.
925730d8bSEdward Cree  */
1025730d8bSEdward Cree 
1125730d8bSEdward Cree #ifndef EFX_TC_COUNTERS_H
1225730d8bSEdward Cree #define EFX_TC_COUNTERS_H
1319a0c989SEdward Cree #include <linux/refcount.h>
1425730d8bSEdward Cree #include "net_driver.h"
1525730d8bSEdward Cree 
1625730d8bSEdward Cree #include "mcdi_pcol.h" /* for MAE_COUNTER_TYPE_* */
1725730d8bSEdward Cree 
1825730d8bSEdward Cree enum efx_tc_counter_type {
1925730d8bSEdward Cree 	EFX_TC_COUNTER_TYPE_AR = MAE_COUNTER_TYPE_AR,
2025730d8bSEdward Cree 	EFX_TC_COUNTER_TYPE_CT = MAE_COUNTER_TYPE_CT,
2125730d8bSEdward Cree 	EFX_TC_COUNTER_TYPE_OR = MAE_COUNTER_TYPE_OR,
2225730d8bSEdward Cree 	EFX_TC_COUNTER_TYPE_MAX
2325730d8bSEdward Cree };
2425730d8bSEdward Cree 
2519a0c989SEdward Cree struct efx_tc_counter {
2619a0c989SEdward Cree 	u32 fw_id; /* index in firmware counter table */
2719a0c989SEdward Cree 	enum efx_tc_counter_type type;
2819a0c989SEdward Cree 	struct rhash_head linkage; /* efx->tc->counter_ht */
29c4bad432SEdward Cree 	spinlock_t lock; /* Serialises updates to counter values */
300363aa29SEdward Cree 	u32 gen; /* Generation count at which this counter is current */
31c4bad432SEdward Cree 	u64 packets, bytes;
3250f8f2f7SEdward Cree 	u64 old_packets, old_bytes; /* Values last time passed to userspace */
33c4bad432SEdward Cree 	/* jiffies of the last time we saw packets increase */
34c4bad432SEdward Cree 	unsigned long touched;
359a14f2e3SEdward Cree 	struct work_struct work; /* For notifying encap actions */
369a14f2e3SEdward Cree 	/* owners of corresponding count actions */
379a14f2e3SEdward Cree 	struct list_head users;
3819a0c989SEdward Cree };
3919a0c989SEdward Cree 
4019a0c989SEdward Cree struct efx_tc_counter_index {
4119a0c989SEdward Cree 	unsigned long cookie;
4219a0c989SEdward Cree 	struct rhash_head linkage; /* efx->tc->counter_id_ht */
4319a0c989SEdward Cree 	refcount_t ref;
4419a0c989SEdward Cree 	struct efx_tc_counter *cnt;
4519a0c989SEdward Cree };
4619a0c989SEdward Cree 
4719a0c989SEdward Cree /* create/uncreate/teardown hashtables */
4819a0c989SEdward Cree int efx_tc_init_counters(struct efx_nic *efx);
4919a0c989SEdward Cree void efx_tc_destroy_counters(struct efx_nic *efx);
5019a0c989SEdward Cree void efx_tc_fini_counters(struct efx_nic *efx);
5119a0c989SEdward Cree 
52*1909387fSEdward Cree struct efx_tc_counter *efx_tc_flower_allocate_counter(struct efx_nic *efx,
53*1909387fSEdward Cree 						      int type);
54*1909387fSEdward Cree void efx_tc_flower_release_counter(struct efx_nic *efx,
55*1909387fSEdward Cree 				   struct efx_tc_counter *cnt);
560363aa29SEdward Cree struct efx_tc_counter_index *efx_tc_flower_get_counter_index(
570363aa29SEdward Cree 				struct efx_nic *efx, unsigned long cookie,
580363aa29SEdward Cree 				enum efx_tc_counter_type type);
590363aa29SEdward Cree void efx_tc_flower_put_counter_index(struct efx_nic *efx,
600363aa29SEdward Cree 				     struct efx_tc_counter_index *ctr);
6150f8f2f7SEdward Cree struct efx_tc_counter_index *efx_tc_flower_find_counter_index(
6250f8f2f7SEdward Cree 				struct efx_nic *efx, unsigned long cookie);
630363aa29SEdward Cree 
6425730d8bSEdward Cree extern const struct efx_channel_type efx_tc_channel_type;
6525730d8bSEdward Cree 
6625730d8bSEdward Cree #endif /* EFX_TC_COUNTERS_H */
67