1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /****************************************************************************
3  * Driver for Solarflare network controllers and boards
4  * Copyright 2022 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_COUNTERS_H
12 #define EFX_TC_COUNTERS_H
13 #include <linux/refcount.h>
14 #include "net_driver.h"
15 
16 #include "mcdi_pcol.h" /* for MAE_COUNTER_TYPE_* */
17 
18 enum efx_tc_counter_type {
19 	EFX_TC_COUNTER_TYPE_AR = MAE_COUNTER_TYPE_AR,
20 	EFX_TC_COUNTER_TYPE_CT = MAE_COUNTER_TYPE_CT,
21 	EFX_TC_COUNTER_TYPE_OR = MAE_COUNTER_TYPE_OR,
22 	EFX_TC_COUNTER_TYPE_MAX
23 };
24 
25 struct efx_tc_counter {
26 	u32 fw_id; /* index in firmware counter table */
27 	enum efx_tc_counter_type type;
28 	struct rhash_head linkage; /* efx->tc->counter_ht */
29 	spinlock_t lock; /* Serialises updates to counter values */
30 	u32 gen; /* Generation count at which this counter is current */
31 	u64 packets, bytes;
32 	u64 old_packets, old_bytes; /* Values last time passed to userspace */
33 	/* jiffies of the last time we saw packets increase */
34 	unsigned long touched;
35 	struct work_struct work; /* For notifying encap actions */
36 	/* owners of corresponding count actions */
37 	struct list_head users;
38 };
39 
40 struct efx_tc_counter_index {
41 	unsigned long cookie;
42 	struct rhash_head linkage; /* efx->tc->counter_id_ht */
43 	refcount_t ref;
44 	struct efx_tc_counter *cnt;
45 };
46 
47 /* create/uncreate/teardown hashtables */
48 int efx_tc_init_counters(struct efx_nic *efx);
49 void efx_tc_destroy_counters(struct efx_nic *efx);
50 void efx_tc_fini_counters(struct efx_nic *efx);
51 
52 struct efx_tc_counter *efx_tc_flower_allocate_counter(struct efx_nic *efx,
53 						      int type);
54 void efx_tc_flower_release_counter(struct efx_nic *efx,
55 				   struct efx_tc_counter *cnt);
56 struct efx_tc_counter_index *efx_tc_flower_get_counter_index(
57 				struct efx_nic *efx, unsigned long cookie,
58 				enum efx_tc_counter_type type);
59 void efx_tc_flower_put_counter_index(struct efx_nic *efx,
60 				     struct efx_tc_counter_index *ctr);
61 struct efx_tc_counter_index *efx_tc_flower_find_counter_index(
62 				struct efx_nic *efx, unsigned long cookie);
63 
64 extern const struct efx_channel_type efx_tc_channel_type;
65 
66 #endif /* EFX_TC_COUNTERS_H */
67