net/hns3: log time delta in decimal format
[dpdk.git] / drivers / net / hns3 / hns3_tm.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2020-2021 HiSilicon Limited.
3  */
4
5 #ifndef _HNS3_TM_H_
6 #define _HNS3_TM_H_
7
8 #include <stdint.h>
9 #include <rte_tailq.h>
10 #include <rte_tm_driver.h>
11
12 enum hns3_tm_node_type {
13         HNS3_TM_NODE_TYPE_PORT,
14         HNS3_TM_NODE_TYPE_TC,
15         HNS3_TM_NODE_TYPE_QUEUE,
16         HNS3_TM_NODE_TYPE_MAX,
17 };
18
19 enum hns3_tm_node_level {
20         HNS3_TM_NODE_LEVEL_PORT,
21         HNS3_TM_NODE_LEVEL_TC,
22         HNS3_TM_NODE_LEVEL_QUEUE,
23         HNS3_TM_NODE_LEVEL_MAX,
24 };
25
26 struct hns3_tm_shaper_profile {
27         TAILQ_ENTRY(hns3_tm_shaper_profile) node;
28         uint32_t shaper_profile_id;
29         uint32_t reference_count;
30         struct rte_tm_shaper_params profile;
31 };
32
33 TAILQ_HEAD(hns3_shaper_profile_list, hns3_tm_shaper_profile);
34
35 struct hns3_tm_node {
36         TAILQ_ENTRY(hns3_tm_node) node;
37         uint32_t id;
38         uint32_t reference_count;
39         struct hns3_tm_node *parent;
40         struct hns3_tm_shaper_profile *shaper_profile;
41         struct rte_tm_node_params params;
42 };
43
44 TAILQ_HEAD(hns3_tm_node_list, hns3_tm_node);
45
46 struct hns3_tm_conf {
47         uint32_t nb_leaf_nodes_max; /* max numbers of leaf nodes */
48         uint32_t nb_nodes_max; /* max numbers of nodes */
49         uint32_t nb_shaper_profile_max; /* max numbers of shaper profile */
50
51         struct hns3_shaper_profile_list shaper_profile_list;
52         uint32_t nb_shaper_profile; /* number of shaper profile */
53
54         struct hns3_tm_node *root;
55         struct hns3_tm_node_list tc_list;
56         struct hns3_tm_node_list queue_list;
57         uint32_t nb_tc_node; /* number of added TC nodes */
58         uint32_t nb_queue_node; /* number of added queue nodes */
59
60         /*
61          * This flag is used to check if APP can change the TM node
62          * configuration.
63          * When it's true, means the configuration is applied to HW,
64          * APP should not add/delete the TM node configuration.
65          * When starting the port, APP should call the hierarchy_commit API to
66          * set this flag to true. When stopping the port, this flag should be
67          * set to false.
68          */
69         bool committed;
70 };
71
72 /*
73  * This API used to calc node TC no. User must make sure the node id is in the
74  * TC node id range.
75  *
76  * User could call rte_eth_dev_info_get API to get port's max_tx_queues, The TM
77  * id's assignment should following the below rules:
78  *     [0, max_tx_queues-1]: correspond queues's node id
79  *     max_tx_queues + 0   : correspond TC0's node id
80  *     max_tx_queues + 1   : correspond TC1's node id
81  *     ...
82  *     max_tx_queues + 7   : correspond TC7's node id
83  *     max_tx_queues + 8   : correspond port's node id
84  *
85  */
86 static inline uint8_t
87 hns3_tm_calc_node_tc_no(struct hns3_tm_conf *conf, uint32_t node_id)
88 {
89         if (node_id >= conf->nb_leaf_nodes_max &&
90             node_id < conf->nb_nodes_max - 1)
91                 return node_id - conf->nb_leaf_nodes_max;
92         else
93                 return 0;
94 }
95
96 void hns3_tm_conf_init(struct rte_eth_dev *dev);
97 void hns3_tm_conf_uninit(struct rte_eth_dev *dev);
98 int hns3_tm_ops_get(struct rte_eth_dev *dev __rte_unused, void *arg);
99 void hns3_tm_dev_start_proc(struct hns3_hw *hw);
100 void hns3_tm_dev_stop_proc(struct hns3_hw *hw);
101 int hns3_tm_conf_update(struct hns3_hw *hw);
102
103 #endif /* _HNS3_TM_H */