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 };
36 
37 struct efx_tc_counter_index {
38 	unsigned long cookie;
39 	struct rhash_head linkage; /* efx->tc->counter_id_ht */
40 	refcount_t ref;
41 	struct efx_tc_counter *cnt;
42 };
43 
44 /* create/uncreate/teardown hashtables */
45 int efx_tc_init_counters(struct efx_nic *efx);
46 void efx_tc_destroy_counters(struct efx_nic *efx);
47 void efx_tc_fini_counters(struct efx_nic *efx);
48 
49 struct efx_tc_counter_index *efx_tc_flower_get_counter_index(
50 				struct efx_nic *efx, unsigned long cookie,
51 				enum efx_tc_counter_type type);
52 void efx_tc_flower_put_counter_index(struct efx_nic *efx,
53 				     struct efx_tc_counter_index *ctr);
54 struct efx_tc_counter_index *efx_tc_flower_find_counter_index(
55 				struct efx_nic *efx, unsigned long cookie);
56 
57 extern const struct efx_channel_type efx_tc_channel_type;
58 
59 #endif /* EFX_TC_COUNTERS_H */
60