xref: /dpdk/drivers/net/nfp/nfp_mtr.h (revision 2a8c7fa64d13fc95fbbf2717a1d434372afe189a)
1434c66e7SJin Liu /* SPDX-License-Identifier: BSD-3-Clause
2434c66e7SJin Liu  * Copyright(c) 2022 Corigine, Inc.
3434c66e7SJin Liu  * All rights reserved.
4434c66e7SJin Liu  */
5434c66e7SJin Liu 
6434c66e7SJin Liu #ifndef __NFP_MTR_H__
7434c66e7SJin Liu #define __NFP_MTR_H__
8434c66e7SJin Liu 
9fb409131SJin Liu #include <rte_mtr.h>
10fb409131SJin Liu 
11*0b372d14SChaoyong He #include "flower/nfp_flower_cmsg.h"
12*0b372d14SChaoyong He 
13434c66e7SJin Liu /**
14434c66e7SJin Liu  * The max meter count is determined by firmware.
15434c66e7SJin Liu  * The max count is 65536 defined by OF_METER_COUNT.
16434c66e7SJin Liu  */
17434c66e7SJin Liu #define NFP_MAX_MTR_CNT                65536
18434c66e7SJin Liu 
19434c66e7SJin Liu /**
20434c66e7SJin Liu  * Struct nfp_mtr_profile - meter profile, stored in driver
21434c66e7SJin Liu  * Can only be used by one meter
22434c66e7SJin Liu  * @next:        next meter profile object
23434c66e7SJin Liu  * @profile_id:  meter profile id
24434c66e7SJin Liu  * @conf:        meter profile config
25434c66e7SJin Liu  * @in_use:      if profile is been used by meter
26434c66e7SJin Liu  */
27434c66e7SJin Liu struct nfp_mtr_profile {
28434c66e7SJin Liu 	LIST_ENTRY(nfp_mtr_profile) next;
29434c66e7SJin Liu 	uint32_t profile_id;
30434c66e7SJin Liu 	struct nfp_profile_conf conf;
31434c66e7SJin Liu 	bool in_use;
32434c66e7SJin Liu };
33434c66e7SJin Liu 
34434c66e7SJin Liu /**
35fb409131SJin Liu  * Struct nfp_mtr_policy - meter policy information
36fb409131SJin Liu  * @next:        next meter policy object
37fb409131SJin Liu  * @policy_id:   meter policy id
38fb409131SJin Liu  * @ref_cnt:     reference count by meter
39fb409131SJin Liu  * @policy:      RTE_FLOW policy information
40fb409131SJin Liu  */
41fb409131SJin Liu struct nfp_mtr_policy {
42fb409131SJin Liu 	LIST_ENTRY(nfp_mtr_policy) next;
43fb409131SJin Liu 	uint32_t policy_id;
44fb409131SJin Liu 	uint32_t ref_cnt;
45fb409131SJin Liu 	struct rte_mtr_meter_policy_params policy;
46fb409131SJin Liu };
47fb409131SJin Liu 
48fb409131SJin Liu /**
49e411f4e5SJin Liu  * Struct nfp_mtr_stats - meter stats information
50e411f4e5SJin Liu  * @pass_bytes:        count of passed bytes for meter
51e411f4e5SJin Liu  * @pass_pkts:         count of passed packets for meter
52e411f4e5SJin Liu  * @drop_bytes:        count of dropped bytes for meter
53e411f4e5SJin Liu  * @drop_pkts:         count of dropped packets for meter
54e411f4e5SJin Liu  */
55e411f4e5SJin Liu struct nfp_mtr_stats {
56e411f4e5SJin Liu 	uint64_t pass_bytes;
57e411f4e5SJin Liu 	uint64_t pass_pkts;
58e411f4e5SJin Liu 	uint64_t drop_bytes;
59e411f4e5SJin Liu 	uint64_t drop_pkts;
60e411f4e5SJin Liu };
61e411f4e5SJin Liu 
62e411f4e5SJin Liu /**
632caf84a7SJin Liu  * Struct nfp_mtr - meter object information
642caf84a7SJin Liu  * @next:        next meter object
652caf84a7SJin Liu  * @mtr_id:      meter id
662caf84a7SJin Liu  * @ref_cnt:     reference count by flow
672caf84a7SJin Liu  * @shared:      if meter can be used by multiple flows
682caf84a7SJin Liu  * @enable:      if meter is enable to use
692caf84a7SJin Liu  * @mtr_profile: the pointer of profile
702caf84a7SJin Liu  * @mtr_policy:  the pointer of policy
71e411f4e5SJin Liu  * @stats_mask:  supported meter stats mask
72e411f4e5SJin Liu  * @curr:        current meter stats
73e411f4e5SJin Liu  * @prev:        previous meter stats
742caf84a7SJin Liu  */
752caf84a7SJin Liu struct nfp_mtr {
762caf84a7SJin Liu 	LIST_ENTRY(nfp_mtr) next;
772caf84a7SJin Liu 	uint32_t mtr_id;
782caf84a7SJin Liu 	uint32_t ref_cnt;
792caf84a7SJin Liu 	bool shared;
802caf84a7SJin Liu 	bool enable;
812caf84a7SJin Liu 	struct nfp_mtr_profile *mtr_profile;
822caf84a7SJin Liu 	struct nfp_mtr_policy *mtr_policy;
83e411f4e5SJin Liu 	uint64_t stats_mask;
84e411f4e5SJin Liu 	struct {
85e411f4e5SJin Liu 		struct nfp_mtr_stats curr;
86e411f4e5SJin Liu 		struct nfp_mtr_stats prev;
87e411f4e5SJin Liu 	} mtr_stats;
882caf84a7SJin Liu };
892caf84a7SJin Liu 
902caf84a7SJin Liu /**
91434c66e7SJin Liu  * Struct nfp_mtr_priv - meter private data
92434c66e7SJin Liu  * @profiles:        the head node of profile list
93fb409131SJin Liu  * @policies:        the head node of policy list
942caf84a7SJin Liu  * @mtrs:            the head node of mtrs list
95e411f4e5SJin Liu  * @mtr_stats_lock:  spinlock for meter stats
96434c66e7SJin Liu  */
97434c66e7SJin Liu struct nfp_mtr_priv {
98434c66e7SJin Liu 	LIST_HEAD(, nfp_mtr_profile) profiles;
99fb409131SJin Liu 	LIST_HEAD(, nfp_mtr_policy) policies;
1002caf84a7SJin Liu 	LIST_HEAD(, nfp_mtr) mtrs;
101e411f4e5SJin Liu 	rte_spinlock_t mtr_stats_lock;
102434c66e7SJin Liu };
103434c66e7SJin Liu 
104434c66e7SJin Liu int nfp_net_mtr_ops_get(struct rte_eth_dev *dev, void *arg);
105434c66e7SJin Liu int nfp_mtr_priv_init(struct nfp_pf_dev *pf_dev);
106434c66e7SJin Liu void nfp_mtr_priv_uninit(struct nfp_pf_dev *pf_dev);
1072caf84a7SJin Liu struct nfp_mtr *nfp_mtr_find_by_mtr_id(struct nfp_mtr_priv *priv,
1082caf84a7SJin Liu 		uint32_t mtr_id);
109e411f4e5SJin Liu struct nfp_mtr *nfp_mtr_find_by_profile_id(struct nfp_mtr_priv *priv,
110e411f4e5SJin Liu 		uint32_t profile_id);
1114ed0c858SJin Liu int nfp_mtr_update_ref_cnt(struct nfp_mtr_priv *priv,
1124ed0c858SJin Liu 		uint32_t mtr_id, bool add);
113434c66e7SJin Liu 
114434c66e7SJin Liu #endif /* __NFP_MTR_H__ */
115