net/ice: support extended statistics in DCF mode
[dpdk.git] / drivers / net / ice / ice_dcf.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2020 Intel Corporation
3  */
4
5 #ifndef _ICE_DCF_H_
6 #define _ICE_DCF_H_
7
8 #include <ethdev_driver.h>
9 #include <rte_tm_driver.h>
10
11 #include <iavf_prototype.h>
12 #include <iavf_adminq_cmd.h>
13 #include <iavf_type.h>
14
15 #include "base/ice_type.h"
16 #include "ice_logs.h"
17
18 /* ICE_DCF_DEV_PRIVATE_TO */
19 #define ICE_DCF_DEV_PRIVATE_TO_ADAPTER(adapter) \
20         ((struct ice_dcf_adapter *)adapter)
21 #define ICE_DCF_DEV_PRIVATE_TO_VF(adapter) \
22         (&((struct ice_dcf_adapter *)adapter)->vf)
23
24 struct dcf_virtchnl_cmd {
25         TAILQ_ENTRY(dcf_virtchnl_cmd) next;
26
27         enum virtchnl_ops v_op;
28         enum iavf_status v_ret;
29
30         uint16_t req_msglen;
31         uint8_t *req_msg;
32
33         uint16_t rsp_msglen;
34         uint16_t rsp_buflen;
35         uint8_t *rsp_msgbuf;
36
37         volatile int pending;
38 };
39
40 struct ice_dcf_tm_shaper_profile {
41         TAILQ_ENTRY(ice_dcf_tm_shaper_profile) node;
42         uint32_t shaper_profile_id;
43         uint32_t reference_count;
44         struct rte_tm_shaper_params profile;
45 };
46
47 TAILQ_HEAD(ice_dcf_shaper_profile_list, ice_dcf_tm_shaper_profile);
48
49 /* Struct to store Traffic Manager node configuration. */
50 struct ice_dcf_tm_node {
51         TAILQ_ENTRY(ice_dcf_tm_node) node;
52         uint32_t id;
53         uint32_t tc;
54         uint32_t priority;
55         uint32_t weight;
56         uint32_t reference_count;
57         struct ice_dcf_tm_node *parent;
58         struct ice_dcf_tm_shaper_profile *shaper_profile;
59         struct rte_tm_node_params params;
60 };
61
62 TAILQ_HEAD(ice_dcf_tm_node_list, ice_dcf_tm_node);
63
64 /* node type of Traffic Manager */
65 enum ice_dcf_tm_node_type {
66         ICE_DCF_TM_NODE_TYPE_PORT,
67         ICE_DCF_TM_NODE_TYPE_TC,
68         ICE_DCF_TM_NODE_TYPE_VSI,
69         ICE_DCF_TM_NODE_TYPE_MAX,
70 };
71
72 /* Struct to store all the Traffic Manager configuration. */
73 struct ice_dcf_tm_conf {
74         struct ice_dcf_shaper_profile_list shaper_profile_list;
75         struct ice_dcf_tm_node *root; /* root node - port */
76         struct ice_dcf_tm_node_list tc_list; /* node list for all the TCs */
77         struct ice_dcf_tm_node_list vsi_list; /* node list for all the queues */
78         uint32_t nb_tc_node;
79         uint32_t nb_vsi_node;
80         bool committed;
81 };
82
83 struct ice_dcf_eth_stats {
84         u64 rx_bytes;                   /* gorc */
85         u64 rx_unicast;                 /* uprc */
86         u64 rx_multicast;               /* mprc */
87         u64 rx_broadcast;               /* bprc */
88         u64 rx_discards;                /* rdpc */
89         u64 rx_unknown_protocol;        /* rupp */
90         u64 tx_bytes;                   /* gotc */
91         u64 tx_unicast;                 /* uptc */
92         u64 tx_multicast;               /* mptc */
93         u64 tx_broadcast;               /* bptc */
94         u64 tx_discards;                /* tdpc */
95         u64 tx_errors;                  /* tepc */
96         u64 rx_no_desc;                 /* repc */
97         u64 rx_errors;                  /* repc */
98 };
99 struct ice_dcf_hw {
100         struct iavf_hw avf;
101
102         rte_spinlock_t vc_cmd_send_lock;
103         rte_spinlock_t vc_cmd_queue_lock;
104         TAILQ_HEAD(, dcf_virtchnl_cmd) vc_cmd_queue;
105         void (*vc_event_msg_cb)(struct ice_dcf_hw *dcf_hw,
106                                 uint8_t *msg, uint16_t msglen);
107
108         uint8_t *arq_buf;
109
110         uint16_t num_vfs;
111         uint16_t *vf_vsi_map;
112         uint16_t pf_vsi_id;
113
114         struct ice_dcf_tm_conf tm_conf;
115         struct virtchnl_dcf_bw_cfg_list **qos_bw_cfg;
116         struct ice_aqc_port_ets_elem *ets_config;
117         struct virtchnl_version_info virtchnl_version;
118         struct virtchnl_vf_resource *vf_res; /* VF resource */
119         struct virtchnl_vsi_resource *vsi_res; /* LAN VSI */
120         uint16_t vsi_id;
121
122         struct rte_eth_dev *eth_dev;
123         uint8_t *rss_lut;
124         uint8_t *rss_key;
125         uint64_t supported_rxdid;
126         uint16_t num_queue_pairs;
127
128         uint16_t msix_base;
129         uint16_t nb_msix;
130         uint16_t rxq_map[16];
131         struct virtchnl_eth_stats eth_stats_offset;
132
133         /* Link status */
134         bool link_up;
135         uint32_t link_speed;
136
137         bool resetting;
138 };
139
140 int ice_dcf_execute_virtchnl_cmd(struct ice_dcf_hw *hw,
141                                  struct dcf_virtchnl_cmd *cmd);
142 int ice_dcf_send_aq_cmd(void *dcf_hw, struct ice_aq_desc *desc,
143                         void *buf, uint16_t buf_size);
144 int ice_dcf_handle_vsi_update_event(struct ice_dcf_hw *hw);
145 int ice_dcf_init_hw(struct rte_eth_dev *eth_dev, struct ice_dcf_hw *hw);
146 void ice_dcf_uninit_hw(struct rte_eth_dev *eth_dev, struct ice_dcf_hw *hw);
147 int ice_dcf_configure_rss_key(struct ice_dcf_hw *hw);
148 int ice_dcf_configure_rss_lut(struct ice_dcf_hw *hw);
149 int ice_dcf_init_rss(struct ice_dcf_hw *hw);
150 int ice_dcf_configure_queues(struct ice_dcf_hw *hw);
151 int ice_dcf_config_irq_map(struct ice_dcf_hw *hw);
152 int ice_dcf_switch_queue(struct ice_dcf_hw *hw, uint16_t qid, bool rx, bool on);
153 int ice_dcf_disable_queues(struct ice_dcf_hw *hw);
154 int ice_dcf_query_stats(struct ice_dcf_hw *hw,
155                         struct virtchnl_eth_stats *pstats);
156 int ice_dcf_add_del_all_mac_addr(struct ice_dcf_hw *hw,
157                                  struct rte_ether_addr *addr, bool add,
158                                  uint8_t type);
159 int ice_dcf_link_update(struct rte_eth_dev *dev,
160                     __rte_unused int wait_to_complete);
161 void ice_dcf_tm_conf_init(struct rte_eth_dev *dev);
162 void ice_dcf_tm_conf_uninit(struct rte_eth_dev *dev);
163 int ice_dcf_replay_vf_bw(struct ice_dcf_hw *hw, uint16_t vf_id);
164 int ice_dcf_clear_bw(struct ice_dcf_hw *hw);
165
166 #endif /* _ICE_DCF_H_ */