xref: /dpdk/drivers/net/nfp/nfp_mtr.h (revision 2a8c7fa64d13fc95fbbf2717a1d434372afe189a)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2022 Corigine, Inc.
3  * All rights reserved.
4  */
5 
6 #ifndef __NFP_MTR_H__
7 #define __NFP_MTR_H__
8 
9 #include <rte_mtr.h>
10 
11 #include "flower/nfp_flower_cmsg.h"
12 
13 /**
14  * The max meter count is determined by firmware.
15  * The max count is 65536 defined by OF_METER_COUNT.
16  */
17 #define NFP_MAX_MTR_CNT                65536
18 
19 /**
20  * Struct nfp_mtr_profile - meter profile, stored in driver
21  * Can only be used by one meter
22  * @next:        next meter profile object
23  * @profile_id:  meter profile id
24  * @conf:        meter profile config
25  * @in_use:      if profile is been used by meter
26  */
27 struct nfp_mtr_profile {
28 	LIST_ENTRY(nfp_mtr_profile) next;
29 	uint32_t profile_id;
30 	struct nfp_profile_conf conf;
31 	bool in_use;
32 };
33 
34 /**
35  * Struct nfp_mtr_policy - meter policy information
36  * @next:        next meter policy object
37  * @policy_id:   meter policy id
38  * @ref_cnt:     reference count by meter
39  * @policy:      RTE_FLOW policy information
40  */
41 struct nfp_mtr_policy {
42 	LIST_ENTRY(nfp_mtr_policy) next;
43 	uint32_t policy_id;
44 	uint32_t ref_cnt;
45 	struct rte_mtr_meter_policy_params policy;
46 };
47 
48 /**
49  * Struct nfp_mtr_stats - meter stats information
50  * @pass_bytes:        count of passed bytes for meter
51  * @pass_pkts:         count of passed packets for meter
52  * @drop_bytes:        count of dropped bytes for meter
53  * @drop_pkts:         count of dropped packets for meter
54  */
55 struct nfp_mtr_stats {
56 	uint64_t pass_bytes;
57 	uint64_t pass_pkts;
58 	uint64_t drop_bytes;
59 	uint64_t drop_pkts;
60 };
61 
62 /**
63  * Struct nfp_mtr - meter object information
64  * @next:        next meter object
65  * @mtr_id:      meter id
66  * @ref_cnt:     reference count by flow
67  * @shared:      if meter can be used by multiple flows
68  * @enable:      if meter is enable to use
69  * @mtr_profile: the pointer of profile
70  * @mtr_policy:  the pointer of policy
71  * @stats_mask:  supported meter stats mask
72  * @curr:        current meter stats
73  * @prev:        previous meter stats
74  */
75 struct nfp_mtr {
76 	LIST_ENTRY(nfp_mtr) next;
77 	uint32_t mtr_id;
78 	uint32_t ref_cnt;
79 	bool shared;
80 	bool enable;
81 	struct nfp_mtr_profile *mtr_profile;
82 	struct nfp_mtr_policy *mtr_policy;
83 	uint64_t stats_mask;
84 	struct {
85 		struct nfp_mtr_stats curr;
86 		struct nfp_mtr_stats prev;
87 	} mtr_stats;
88 };
89 
90 /**
91  * Struct nfp_mtr_priv - meter private data
92  * @profiles:        the head node of profile list
93  * @policies:        the head node of policy list
94  * @mtrs:            the head node of mtrs list
95  * @mtr_stats_lock:  spinlock for meter stats
96  */
97 struct nfp_mtr_priv {
98 	LIST_HEAD(, nfp_mtr_profile) profiles;
99 	LIST_HEAD(, nfp_mtr_policy) policies;
100 	LIST_HEAD(, nfp_mtr) mtrs;
101 	rte_spinlock_t mtr_stats_lock;
102 };
103 
104 int nfp_net_mtr_ops_get(struct rte_eth_dev *dev, void *arg);
105 int nfp_mtr_priv_init(struct nfp_pf_dev *pf_dev);
106 void nfp_mtr_priv_uninit(struct nfp_pf_dev *pf_dev);
107 struct nfp_mtr *nfp_mtr_find_by_mtr_id(struct nfp_mtr_priv *priv,
108 		uint32_t mtr_id);
109 struct nfp_mtr *nfp_mtr_find_by_profile_id(struct nfp_mtr_priv *priv,
110 		uint32_t profile_id);
111 int nfp_mtr_update_ref_cnt(struct nfp_mtr_priv *priv,
112 		uint32_t mtr_id, bool add);
113 
114 #endif /* __NFP_MTR_H__ */
115