Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright (C), 2025, Wuxi Stars Micro System Technologies Co., Ltd.
3 : : */
4 : :
5 : : #include <rte_eal.h>
6 : :
7 : : #include "sxe2_ethdev.h"
8 : : #include "sxe2_vsi.h"
9 : : #include "sxe2_common_log.h"
10 : : #include "sxe2_stats.h"
11 : : #include "sxe2_queue.h"
12 : : #include "sxe2_cmd_chnl.h"
13 : : #include "sxe2_mp.h"
14 : :
15 : : #define SXE2_XSTAT_CNT_PF RTE_DIM(sxe2_xstats_field_pf)
16 : : #define SXE2_XSTAT_CNT_VF RTE_DIM(sxe2_xstats_field_vf)
17 : :
18 : : static struct sxe2_stats_field sxe2_xstats_field_pf[] = {
19 : : {"rx_qblock_drop", offsetof(struct sxe2_stats, rx_qblock_drop)},
20 : : {"rx_out_of_buffer", offsetof(struct sxe2_stats, rx_out_of_buffer)},
21 : : {"tx_packets_phy", offsetof(struct sxe2_stats, tx_frame_good)},
22 : : {"rx_packets_phy", offsetof(struct sxe2_stats, rx_frame_good)},
23 : : {"rx_crc_errors_phy", offsetof(struct sxe2_stats, rx_crc_errors)},
24 : : {"tx_bytes_phy", offsetof(struct sxe2_stats, tx_bytes_good)},
25 : : {"rx_bytes_phy", offsetof(struct sxe2_stats, rx_bytes_good)},
26 : : {"tx_multicast_phy", offsetof(struct sxe2_stats, tx_multicast_good)},
27 : : {"tx_broadcast_phy", offsetof(struct sxe2_stats, tx_broadcast_good)},
28 : : {"rx_multicast_phy", offsetof(struct sxe2_stats, rx_multicast_good)},
29 : : {"rx_broadcast_phy", offsetof(struct sxe2_stats, rx_broadcast_good)},
30 : : {"rx_in_range_len_errs_phy", offsetof(struct sxe2_stats, rx_len_errors)},
31 : : {"rx_out_of_range_len_phy", offsetof(struct sxe2_stats, rx_out_of_range_errors)},
32 : : {"rx_oversize_pkts_phy", offsetof(struct sxe2_stats, rx_oversize_pkts_phy)},
33 : : {"rx_symbol_err_phy", offsetof(struct sxe2_stats, rx_symbol_err)},
34 : : {"rx_pause_ctrl_phy", offsetof(struct sxe2_stats, rx_pause_frame)},
35 : : {"tx_pause_ctrl_phy", offsetof(struct sxe2_stats, tx_pause_frame)},
36 : : {"rx_discards_phy", offsetof(struct sxe2_stats, rx_discards_phy)},
37 : : {"rx_discards_ips_phy", offsetof(struct sxe2_stats, rx_discards_ips_phy)},
38 : : {"tx_dropped_link_down_phy", offsetof(struct sxe2_stats, tx_dropped_link_down)},
39 : : {"rx_undersize_pkts_phy", offsetof(struct sxe2_stats, rx_undersize_good)},
40 : : {"rx_fragments_phy", offsetof(struct sxe2_stats, rx_runt_error)},
41 : : {"tx_bytes_all_phy", offsetof(struct sxe2_stats, tx_bytes_good_bad)},
42 : : {"tx_packets_all_phy", offsetof(struct sxe2_stats, tx_frame_good_bad)},
43 : : {"rx_jabbers_phy", offsetof(struct sxe2_stats, rx_jabbers)},
44 : : {"rx_64_bytes_phy", offsetof(struct sxe2_stats, rx_size_64)},
45 : : {"rx_65_to_127_bytes_phy", offsetof(struct sxe2_stats, rx_size_65_127)},
46 : : {"rx_128_to_255_bytes_phy", offsetof(struct sxe2_stats, rx_size_128_255)},
47 : : {"rx_256_to_511_bytes_phy", offsetof(struct sxe2_stats, rx_size_256_511)},
48 : : {"rx_512_to_1023_bytes_phy", offsetof(struct sxe2_stats, rx_size_512_1023)},
49 : : {"rx_1024_to_1522_bytes_phy", offsetof(struct sxe2_stats, rx_size_1024_1522)},
50 : : {"rx_1523_to_max_bytes_phy", offsetof(struct sxe2_stats, rx_size_1523_max)},
51 : : {"rx_pcs_symbol_err_phy", offsetof(struct sxe2_stats, rx_pcs_symbol_err_phy)},
52 : : {"rx_corrected_bits_phy", offsetof(struct sxe2_stats, rx_corrected_bits_phy)},
53 : : {"rx_err_lane_0_phy", offsetof(struct sxe2_stats, rx_err_lane_0_phy)},
54 : : {"rx_err_lane_1_phy", offsetof(struct sxe2_stats, rx_err_lane_1_phy)},
55 : : {"rx_err_lane_2_phy", offsetof(struct sxe2_stats, rx_err_lane_2_phy)},
56 : : {"rx_err_lane_3_phy", offsetof(struct sxe2_stats, rx_err_lane_3_phy)},
57 : : {"rx_illegal_bytes_phy", offsetof(struct sxe2_stats, rx_illegal_bytes)},
58 : : {"rx_oversize_good_phy", offsetof(struct sxe2_stats, rx_oversize_good)},
59 : : {"tx_unicast_all_phy", offsetof(struct sxe2_stats, tx_unicast)},
60 : : {"tx_broadcast_all_phy", offsetof(struct sxe2_stats, tx_broadcast)},
61 : : {"tx_multicast_all_phy", offsetof(struct sxe2_stats, tx_multicast)},
62 : : {"tx_vlan_packets_good_phy", offsetof(struct sxe2_stats, tx_vlan_packet_good)},
63 : : {"tx_64_bytes_phy", offsetof(struct sxe2_stats, tx_size_64)},
64 : : {"tx_65_to_127_bytes_phy", offsetof(struct sxe2_stats, tx_size_65_127)},
65 : : {"tx_128_to_255_bytes_phy", offsetof(struct sxe2_stats, tx_size_128_255)},
66 : : {"tx_256_to_511_bytes_phy", offsetof(struct sxe2_stats, tx_size_256_511)},
67 : : {"tx_512_to_1023_bytes_phy", offsetof(struct sxe2_stats, tx_size_512_1023)},
68 : : {"tx_1024_to_1522_bytes_phy", offsetof(struct sxe2_stats, tx_size_1024_1522)},
69 : : {"tx_1523_to_max_bytes_phy", offsetof(struct sxe2_stats, tx_size_1523_max)},
70 : : {"tx_underflow_error_phy", offsetof(struct sxe2_stats, tx_underflow_error)},
71 : : {"rx_bytes_all_phy", offsetof(struct sxe2_stats, rx_byte_good_bad)},
72 : : {"rx_packets_all_phy", offsetof(struct sxe2_stats, rx_frame_good_bad)},
73 : : {"rx_unicast_phy", offsetof(struct sxe2_stats, rx_unicast_good)},
74 : : {"rx_vlan_packets_phy", offsetof(struct sxe2_stats, rx_vlan_packets)},
75 : :
76 : : {"rx_vport_bytes", offsetof(struct sxe2_stats, rx_vsi_bytes)},
77 : : {"rx_vport_unicast_packets", offsetof(struct sxe2_stats, rx_vsi_unicast_packets)},
78 : : {"rx_vport_broadcast_packets", offsetof(struct sxe2_stats, rx_vsi_broadcast_packets)},
79 : : {"rx_vport_multicast_packets", offsetof(struct sxe2_stats, rx_vsi_multicast_packets)},
80 : : {"rx_sw_unicast_packets", offsetof(struct sxe2_stats, rx_sw_unicast_packets)},
81 : : {"rx_sw_broadcast_packets", offsetof(struct sxe2_stats, rx_sw_broadcast_packets)},
82 : : {"rx_sw_multicast_packets", offsetof(struct sxe2_stats, rx_sw_multicast_packets)},
83 : : {"rx_sw_drop_packets", offsetof(struct sxe2_stats, rx_sw_drop_packets)},
84 : : {"rx_sw_drop_bytes", offsetof(struct sxe2_stats, rx_sw_drop_bytes)},
85 : :
86 : : {"tx_vport_bytes", offsetof(struct sxe2_stats, tx_vsi_bytes)},
87 : : {"tx_vport_unicast_packets", offsetof(struct sxe2_stats, tx_vsi_unicast_packets)},
88 : : {"tx_vport_broadcast_packets", offsetof(struct sxe2_stats, tx_vsi_broadcast_packets)},
89 : : {"tx_vport_multicast_packets", offsetof(struct sxe2_stats, tx_vsi_multicast_packets)},
90 : : };
91 : :
92 : : static struct sxe2_stats_field sxe2_xstats_field_vf[] = {
93 : : {"rx_vport_bytes", offsetof(struct sxe2_stats, rx_vsi_bytes)},
94 : : {"rx_vport_unicast_packets", offsetof(struct sxe2_stats, rx_vsi_unicast_packets)},
95 : : {"rx_vport_broadcast_packets", offsetof(struct sxe2_stats, rx_vsi_broadcast_packets)},
96 : : {"rx_vport_multicast_packets", offsetof(struct sxe2_stats, rx_vsi_multicast_packets)},
97 : : {"rx_sw_unicast_packets", offsetof(struct sxe2_stats, rx_sw_unicast_packets)},
98 : : {"rx_sw_broadcast_packets", offsetof(struct sxe2_stats, rx_sw_broadcast_packets)},
99 : : {"rx_sw_multicast_packets", offsetof(struct sxe2_stats, rx_sw_multicast_packets)},
100 : : {"rx_sw_drop_packets", offsetof(struct sxe2_stats, rx_sw_drop_packets)},
101 : : {"rx_sw_drop_bytes", offsetof(struct sxe2_stats, rx_sw_drop_bytes)},
102 : :
103 : : {"tx_vport_bytes", offsetof(struct sxe2_stats, tx_vsi_bytes)},
104 : : {"tx_vport_unicast_packets", offsetof(struct sxe2_stats, tx_vsi_unicast_packets)},
105 : : {"tx_vport_broadcast_packets", offsetof(struct sxe2_stats, tx_vsi_broadcast_packets)},
106 : : {"tx_vport_multicast_packets", offsetof(struct sxe2_stats, tx_vsi_multicast_packets)},
107 : : };
108 : :
109 : 0 : static int32_t sxe2_xstat_pf_offset_get(uint32_t id, uint32_t *offset)
110 : : {
111 : 0 : int32_t ret = 0;
112 : 0 : uint32_t size = SXE2_XSTAT_CNT_PF;
113 : :
114 [ # # ]: 0 : if (id < size) {
115 : 0 : *offset = sxe2_xstats_field_pf[id].offset;
116 : : } else {
117 : 0 : ret = -EINVAL;
118 : 0 : PMD_LOG_ERR(DRV, "invalid id:%u exceed stats size cnt:%u", id, size);
119 : : }
120 : 0 : return ret;
121 : : }
122 : :
123 : 0 : static int32_t sxe2_xstat_vf_offset_get(uint32_t id, uint32_t *offset)
124 : : {
125 : 0 : int32_t ret = 0;
126 : 0 : uint32_t size = SXE2_XSTAT_CNT_VF;
127 : :
128 [ # # ]: 0 : if (id < size) {
129 : 0 : *offset = sxe2_xstats_field_vf[id].offset;
130 : : } else {
131 : 0 : ret = -EINVAL;
132 : 0 : PMD_LOG_ERR(DRV, "invalid id:%u exceed stats size cnt:%u", id, size);
133 : : }
134 : 0 : return ret;
135 : : }
136 : :
137 : 0 : static int32_t sxe2_mac_hw_stats_get_update(struct sxe2_adapter *adapter)
138 : : {
139 : 0 : int32_t ret = 0;
140 : :
141 : 0 : ret = sxe2_drv_get_mac_stats(adapter);
142 [ # # ]: 0 : if (ret) {
143 : 0 : PMD_LOG_ERR(DRV, "get mac stats failed, ret:%d.", ret);
144 : 0 : goto l_end;
145 : : }
146 : :
147 : 0 : l_end:
148 : 0 : return ret;
149 : : }
150 : :
151 : 0 : static int32_t sxe2_vsi_hw_stats_get_update(struct sxe2_adapter *adapter)
152 : : {
153 : 0 : int32_t ret = 0;
154 : :
155 : 0 : ret = sxe2_drv_get_vsi_stats(adapter);
156 [ # # ]: 0 : if (ret) {
157 [ # # ]: 0 : if (adapter->is_dev_repr) {
158 : 0 : PMD_LOG_WARN(DRV, "get repr vsi stats failed, ret:%d.", ret);
159 : 0 : ret = 0;
160 : : } else {
161 : 0 : PMD_LOG_ERR(DRV, "get vsi stats failed, ret:%d.", ret);
162 : : }
163 : 0 : goto l_end;
164 : : }
165 : :
166 : 0 : l_end:
167 : 0 : return ret;
168 : : }
169 : :
170 : 0 : static int32_t sxe2_vsi_sw_stats_get_update(struct sxe2_adapter *adapter)
171 : : {
172 : 0 : int32_t ret = 0;
173 : 0 : struct sxe2_vsi *vsi = adapter->vsi_ctxt.main_vsi;
174 : 0 : struct sxe2_stats *sw_stats = &vsi->vsi_stats.vsi_sw_stats;
175 : 0 : struct sxe2_rx_queue *rxq;
176 : 0 : uint32_t rx_queue_id;
177 : 0 : memset(sw_stats, 0, sizeof(struct sxe2_stats));
178 : :
179 [ # # ]: 0 : for (rx_queue_id = 0; rx_queue_id < adapter->dev_info.dev_data->nb_rx_queues;
180 : 0 : rx_queue_id++) {
181 : 0 : rxq = adapter->dev_info.dev_data->rx_queues[rx_queue_id];
182 [ # # ]: 0 : if (rxq) {
183 : 0 : sw_stats->ipackets += rxq->sw_stats.pkts;
184 : 0 : sw_stats->ierrors += rxq->sw_stats.drop_pkts;
185 : 0 : sw_stats->ibytes += rxq->sw_stats.bytes;
186 : :
187 : 0 : sw_stats->rx_sw_unicast_packets += rxq->sw_stats.unicast_pkts;
188 : 0 : sw_stats->rx_sw_broadcast_packets += rxq->sw_stats.broadcast_pkts;
189 : 0 : sw_stats->rx_sw_multicast_packets += rxq->sw_stats.multicast_pkts;
190 : 0 : sw_stats->rx_sw_drop_packets += rxq->sw_stats.drop_pkts;
191 : 0 : sw_stats->rx_sw_drop_bytes += rxq->sw_stats.drop_bytes;
192 : : }
193 : : }
194 : :
195 : 0 : return ret;
196 : : }
197 : :
198 : 0 : static void sxe2_stats_update(struct sxe2_adapter *adapter)
199 : : {
200 : 0 : struct sxe2_vsi *vsi = adapter->vsi_ctxt.main_vsi;
201 : 0 : struct sxe2_stats *stats = &vsi->vsi_stats.stats;
202 : 0 : struct sxe2_stats *hw_stats = &vsi->vsi_stats.vsi_hw_stats;
203 : 0 : struct sxe2_stats *sw_stats = &vsi->vsi_stats.vsi_sw_stats;
204 : 0 : struct sxe2_stats *sw_stats_prev = &vsi->vsi_stats.vsi_sw_stats_prev;
205 : 0 : uint8_t i = 0;
206 : :
207 [ # # ]: 0 : memset(stats, 0, sizeof(struct sxe2_stats));
208 : :
209 : 0 : stats->opackets = hw_stats->opackets;
210 : 0 : stats->obytes = hw_stats->tx_vsi_bytes;
211 : 0 : stats->tx_vsi_bytes = hw_stats->tx_vsi_bytes;
212 : 0 : stats->tx_vsi_unicast_packets = hw_stats->tx_vsi_unicast_packets;
213 : 0 : stats->tx_vsi_broadcast_packets = hw_stats->tx_vsi_broadcast_packets;
214 : 0 : stats->tx_vsi_multicast_packets = hw_stats->tx_vsi_multicast_packets;
215 : :
216 : 0 : stats->ierrors = sw_stats->ierrors + sw_stats_prev->ierrors;
217 : 0 : stats->ipackets = sw_stats->ipackets + sw_stats_prev->ipackets;
218 : 0 : stats->ibytes = sw_stats->ibytes + sw_stats_prev->ibytes;
219 : 0 : stats->rx_vsi_bytes = hw_stats->rx_vsi_bytes;
220 : 0 : stats->rx_vsi_unicast_packets = hw_stats->rx_vsi_unicast_packets;
221 : 0 : stats->rx_vsi_broadcast_packets = hw_stats->rx_vsi_broadcast_packets;
222 : 0 : stats->rx_vsi_multicast_packets = hw_stats->rx_vsi_multicast_packets;
223 : 0 : stats->rx_sw_unicast_packets = sw_stats->rx_sw_unicast_packets +
224 : 0 : sw_stats_prev->rx_sw_unicast_packets;
225 : 0 : stats->rx_sw_broadcast_packets = sw_stats->rx_sw_broadcast_packets +
226 : 0 : sw_stats_prev->rx_sw_broadcast_packets;
227 : 0 : stats->rx_sw_multicast_packets = sw_stats->rx_sw_multicast_packets +
228 : 0 : sw_stats_prev->rx_sw_multicast_packets;
229 : 0 : stats->rx_sw_drop_packets = sw_stats->rx_sw_drop_packets +
230 : 0 : sw_stats_prev->rx_sw_drop_packets;
231 : 0 : stats->rx_sw_drop_bytes = sw_stats->rx_sw_drop_bytes +
232 : 0 : sw_stats_prev->rx_sw_drop_bytes;
233 : :
234 [ # # # # ]: 0 : if (adapter->dev_type != SXE2_DEV_T_VF && !adapter->is_dev_repr) {
235 : 0 : stats->rx_out_of_buffer = hw_stats->rx_out_of_buffer;
236 : 0 : stats->rx_qblock_drop = hw_stats->rx_qblock_drop;
237 : 0 : stats->tx_frame_good = hw_stats->tx_frame_good;
238 : 0 : stats->rx_frame_good = hw_stats->rx_frame_good;
239 : 0 : stats->rx_crc_errors = hw_stats->rx_crc_errors;
240 : 0 : stats->tx_bytes_good = hw_stats->tx_bytes_good;
241 : 0 : stats->rx_bytes_good = hw_stats->rx_bytes_good;
242 : 0 : stats->tx_multicast_good = hw_stats->tx_multicast_good;
243 : 0 : stats->tx_broadcast_good = hw_stats->tx_broadcast_good;
244 : 0 : stats->rx_multicast_good = hw_stats->rx_multicast_good;
245 : 0 : stats->rx_broadcast_good = hw_stats->rx_broadcast_good;
246 : 0 : stats->rx_len_errors = hw_stats->rx_len_errors;
247 : 0 : stats->rx_out_of_range_errors = hw_stats->rx_out_of_range_errors;
248 : 0 : stats->rx_oversize_pkts_phy = hw_stats->rx_oversize_pkts_phy;
249 : 0 : stats->rx_symbol_err = hw_stats->rx_symbol_err;
250 : 0 : stats->rx_pause_frame = hw_stats->rx_pause_frame;
251 : 0 : stats->tx_pause_frame = hw_stats->tx_pause_frame;
252 : 0 : stats->rx_discards_phy = hw_stats->rx_discards_phy;
253 : 0 : stats->rx_discards_ips_phy = hw_stats->rx_discards_ips_phy;
254 : 0 : stats->tx_dropped_link_down = hw_stats->tx_dropped_link_down;
255 : 0 : stats->rx_undersize_good = hw_stats->rx_undersize_good;
256 : 0 : stats->rx_runt_error = hw_stats->rx_runt_error;
257 : 0 : stats->tx_bytes_good_bad = hw_stats->tx_bytes_good_bad;
258 : 0 : stats->tx_frame_good_bad = hw_stats->tx_frame_good_bad;
259 : 0 : stats->rx_jabbers = hw_stats->rx_jabbers;
260 : 0 : stats->rx_size_64 = hw_stats->rx_size_64;
261 : 0 : stats->rx_size_65_127 = hw_stats->rx_size_65_127;
262 : 0 : stats->rx_size_128_255 = hw_stats->rx_size_128_255;
263 : 0 : stats->rx_size_256_511 = hw_stats->rx_size_256_511;
264 : 0 : stats->rx_size_512_1023 = hw_stats->rx_size_512_1023;
265 : 0 : stats->rx_size_1024_1522 = hw_stats->rx_size_1024_1522;
266 : 0 : stats->rx_size_1523_max = hw_stats->rx_size_1523_max;
267 : 0 : stats->rx_pcs_symbol_err_phy = hw_stats->rx_pcs_symbol_err_phy;
268 : 0 : stats->rx_corrected_bits_phy = hw_stats->rx_corrected_bits_phy;
269 : 0 : stats->rx_err_lane_0_phy = hw_stats->rx_err_lane_0_phy;
270 : 0 : stats->rx_err_lane_1_phy = hw_stats->rx_err_lane_1_phy;
271 : 0 : stats->rx_err_lane_2_phy = hw_stats->rx_err_lane_2_phy;
272 : 0 : stats->rx_err_lane_3_phy = hw_stats->rx_err_lane_3_phy;
273 : 0 : stats->rx_illegal_bytes = hw_stats->rx_illegal_bytes;
274 : 0 : stats->rx_oversize_good = hw_stats->rx_oversize_good;
275 : 0 : stats->tx_unicast = hw_stats->tx_unicast;
276 : 0 : stats->tx_broadcast = hw_stats->tx_broadcast;
277 : 0 : stats->tx_multicast = hw_stats->tx_multicast;
278 : 0 : stats->tx_vlan_packet_good = hw_stats->tx_vlan_packet_good;
279 : 0 : stats->tx_size_64 = hw_stats->tx_size_64;
280 : 0 : stats->tx_size_65_127 = hw_stats->tx_size_65_127;
281 : 0 : stats->tx_size_128_255 = hw_stats->tx_size_128_255;
282 : 0 : stats->tx_size_256_511 = hw_stats->tx_size_256_511;
283 : 0 : stats->tx_size_512_1023 = hw_stats->tx_size_512_1023;
284 : 0 : stats->tx_size_1024_1522 = hw_stats->tx_size_1024_1522;
285 : 0 : stats->tx_size_1523_max = hw_stats->tx_size_1523_max;
286 : 0 : stats->tx_underflow_error = hw_stats->tx_underflow_error;
287 : 0 : stats->rx_byte_good_bad = hw_stats->rx_byte_good_bad;
288 : 0 : stats->rx_frame_good_bad = hw_stats->rx_frame_good_bad;
289 : 0 : stats->rx_unicast_good = hw_stats->rx_unicast_good;
290 : 0 : stats->rx_vlan_packets = hw_stats->rx_vlan_packets;
291 : 0 : rte_memcpy(stats->rx_prio_buf_discard, hw_stats->rx_prio_buf_discard,
292 : : sizeof(hw_stats->rx_prio_buf_discard));
293 : 0 : rte_memcpy(stats->prio_xoff_rx, hw_stats->prio_xoff_rx,
294 : : sizeof(hw_stats->prio_xoff_rx));
295 : 0 : rte_memcpy(stats->prio_xon_rx, hw_stats->prio_xon_rx,
296 : : sizeof(hw_stats->prio_xon_rx));
297 : 0 : rte_memcpy(stats->prio_xon_tx, hw_stats->prio_xon_tx,
298 : : sizeof(hw_stats->prio_xon_tx));
299 : 0 : rte_memcpy(stats->prio_xoff_tx, hw_stats->prio_xoff_tx,
300 : : sizeof(hw_stats->prio_xoff_tx));
301 : 0 : rte_memcpy(stats->prio_xon_2_xoff, hw_stats->prio_xon_2_xoff,
302 : : sizeof(hw_stats->prio_xon_2_xoff));
303 : :
304 : 0 : stats->imissed = hw_stats->rx_out_of_buffer +
305 : : hw_stats->rx_qblock_drop;
306 [ # # ]: 0 : for (i = 0; i < SXE2_MAX_USER_PRIORITY; i++)
307 : 0 : stats->imissed += hw_stats->rx_prio_buf_discard[i];
308 : : }
309 : 0 : }
310 : :
311 : 0 : int32_t sxe2_stats_info_get(struct rte_eth_dev *dev,
312 : : struct rte_eth_stats *stats,
313 : : struct eth_queue_stats *qstats)
314 : : {
315 : 0 : int32_t ret = 0;
316 : 0 : struct sxe2_adapter *adapter = SXE2_DEV_PRIVATE_TO_ADAPTER(dev);
317 : 0 : struct sxe2_vsi *vsi = adapter->vsi_ctxt.main_vsi;
318 : 0 : struct sxe2_stats *stats_out = &vsi->vsi_stats.stats;
319 : :
320 [ # # ]: 0 : if (rte_eal_process_type() == RTE_PROC_SECONDARY)
321 : 0 : return sxe2_mp_req_get_stats(dev, stats, qstats);
322 : :
323 : 0 : ret = sxe2_vsi_hw_stats_get_update(adapter);
324 [ # # ]: 0 : if (ret)
325 : 0 : goto end;
326 : :
327 : 0 : ret = sxe2_vsi_sw_stats_get_update(adapter);
328 [ # # ]: 0 : if (ret)
329 : 0 : goto end;
330 : :
331 [ # # ]: 0 : if (qstats != NULL) {
332 : 0 : ret = sxe2_drv_queue_info_get_update(adapter, qstats);
333 [ # # ]: 0 : if (ret)
334 : 0 : goto end;
335 : : }
336 : :
337 : 0 : sxe2_stats_update(adapter);
338 : :
339 : 0 : stats->ipackets = stats_out->ipackets;
340 : 0 : stats->ibytes = stats_out->ibytes;
341 : 0 : stats->ierrors = stats_out->ierrors;
342 : 0 : stats->imissed = stats_out->imissed;
343 : 0 : stats->rx_nombuf = dev->data->rx_mbuf_alloc_failed;
344 : :
345 : 0 : stats->opackets = stats_out->opackets;
346 : 0 : stats->obytes = stats_out->obytes;
347 : :
348 : 0 : ret = 0;
349 : :
350 : : end:
351 : : return ret;
352 : : }
353 : :
354 : 0 : int32_t sxe2_xstats_info_get(struct rte_eth_dev *dev,
355 : : struct rte_eth_xstat *xstats, uint32_t usr_cnt)
356 : : {
357 : 0 : uint32_t i = 0;
358 : 0 : uint32_t cnt = 0;
359 : 0 : int32_t ret = 0;
360 : 0 : uint32_t offset = 0;
361 : 0 : uint32_t xstats_cnt = 0;
362 : 0 : struct sxe2_adapter *adapter = SXE2_DEV_PRIVATE_TO_ADAPTER(dev);
363 : 0 : struct sxe2_vsi *vsi = adapter->vsi_ctxt.main_vsi;
364 : 0 : struct sxe2_vsi_stats *xstats_out = &vsi->vsi_stats;
365 : :
366 [ # # ]: 0 : if (rte_eal_process_type() == RTE_PROC_SECONDARY)
367 : 0 : return sxe2_mp_req_get_xstats(dev, xstats, usr_cnt);
368 : :
369 [ # # # # ]: 0 : if (adapter->dev_type == SXE2_DEV_T_VF || adapter->is_dev_repr)
370 : : xstats_cnt = SXE2_XSTAT_CNT_VF;
371 : : else
372 : 0 : xstats_cnt = SXE2_XSTAT_CNT_PF;
373 : :
374 [ # # ]: 0 : if (usr_cnt < xstats_cnt) {
375 : 0 : ret = xstats_cnt;
376 : 0 : PMD_LOG_ERR(DRV, "user usr_cnt:%u less than stats cnt:%u", usr_cnt, ret);
377 : 0 : goto end;
378 : : }
379 : :
380 : 0 : ret = sxe2_vsi_hw_stats_get_update(adapter);
381 [ # # ]: 0 : if (ret) {
382 : 0 : ret = xstats_cnt;
383 : 0 : goto end;
384 : : }
385 : :
386 : 0 : ret = sxe2_vsi_sw_stats_get_update(adapter);
387 [ # # ]: 0 : if (ret) {
388 : 0 : ret = xstats_cnt;
389 : 0 : goto end;
390 : : }
391 : :
392 [ # # # # ]: 0 : if (adapter->dev_type == SXE2_DEV_T_VF || adapter->is_dev_repr) {
393 : 0 : sxe2_stats_update(adapter);
394 [ # # ]: 0 : for (i = 0; i < xstats_cnt; i++) {
395 : 0 : (void)sxe2_xstat_vf_offset_get(i, &offset);
396 : 0 : xstats[cnt].value = *(uint64_t *)(((int8_t *)(&xstats_out->stats)) +
397 : : offset);
398 : 0 : xstats[cnt].id = cnt;
399 : 0 : cnt++;
400 : : }
401 : : } else {
402 : 0 : ret = sxe2_mac_hw_stats_get_update(adapter);
403 [ # # ]: 0 : if (ret) {
404 : 0 : ret = xstats_cnt;
405 : 0 : goto end;
406 : : }
407 : :
408 : 0 : sxe2_stats_update(adapter);
409 : :
410 [ # # ]: 0 : for (i = 0; i < xstats_cnt; i++) {
411 : 0 : (void)sxe2_xstat_pf_offset_get(i, &offset);
412 : 0 : xstats[cnt].value = *(uint64_t *)(((int8_t *)(&xstats_out->stats)) +
413 : : offset);
414 : 0 : xstats[cnt].id = cnt;
415 : 0 : cnt++;
416 : : }
417 : : }
418 : 0 : ret = cnt;
419 : 0 : PMD_LOG_DEBUG(DRV, "usr_cnt:%u stats cnt:%u stats done", usr_cnt, cnt);
420 : :
421 : : end:
422 : : return ret;
423 : : }
424 : :
425 : 0 : int32_t sxe2_xstats_names_get(__rte_unused struct rte_eth_dev *dev,
426 : : struct rte_eth_xstat_name *xstats_names,
427 : : __rte_unused unsigned int usr_cnt)
428 : : {
429 : 0 : struct sxe2_adapter *adapter = SXE2_DEV_PRIVATE_TO_ADAPTER(dev);
430 : 0 : struct sxe2_stats_field *field = NULL;
431 : 0 : uint32_t i = 0;
432 : 0 : uint32_t cnt = 0;
433 : 0 : int32_t ret = -1;
434 : 0 : uint32_t xstats_cnt = 0;
435 : :
436 [ # # # # ]: 0 : if (adapter->dev_type == SXE2_DEV_T_VF || adapter->is_dev_repr) {
437 : : field = sxe2_xstats_field_vf;
438 : : xstats_cnt = SXE2_XSTAT_CNT_VF;
439 : : } else {
440 : 0 : field = sxe2_xstats_field_pf;
441 : 0 : xstats_cnt = SXE2_XSTAT_CNT_PF;
442 : : }
443 : :
444 [ # # ]: 0 : if (!xstats_names) {
445 : 0 : ret = xstats_cnt;
446 : 0 : PMD_LOG_DEBUG(DRV, "xstats field size:%u", ret);
447 : 0 : goto l_out;
448 : : }
449 : :
450 [ # # ]: 0 : if (usr_cnt < xstats_cnt) {
451 : 0 : ret = -EINVAL;
452 : 0 : PMD_LOG_ERR(DRV, "max:%d usr_cnt:%u invalid (err:%d)", xstats_cnt, usr_cnt, ret);
453 : 0 : goto l_out;
454 : : }
455 : :
456 [ # # ]: 0 : for (i = 0; i < xstats_cnt; i++) {
457 : 0 : (void)strlcpy(xstats_names[cnt].name, field[i].name,
458 : : sizeof(xstats_names[cnt].name));
459 : 0 : cnt++;
460 : : }
461 : :
462 : 0 : ret = cnt;
463 : :
464 : 0 : l_out:
465 : 0 : return ret;
466 : : }
467 : :
468 : 0 : int32_t sxe2_stats_hw_reset(struct rte_eth_dev *dev)
469 : : {
470 : 0 : int32_t ret = 0;
471 : 0 : struct sxe2_adapter *adapter = SXE2_DEV_PRIVATE_TO_ADAPTER(dev);
472 : 0 : struct sxe2_vsi *vsi = adapter->vsi_ctxt.main_vsi;
473 : 0 : struct sxe2_rx_queue *rxq;
474 : 0 : uint32_t rx_queue_id;
475 : :
476 : 0 : ret = sxe2_drv_vsi_stats_reset(adapter);
477 [ # # ]: 0 : if (ret) {
478 : 0 : PMD_LOG_ERR(DRV, "reset vsi stats failed, ret:%d.", ret);
479 : 0 : goto l_end;
480 : : }
481 [ # # # # ]: 0 : if (adapter->dev_type != SXE2_DEV_T_VF && !adapter->is_dev_repr) {
482 : 0 : ret = sxe2_drv_mac_stats_reset(adapter);
483 [ # # ]: 0 : if (ret) {
484 : 0 : PMD_LOG_ERR(DRV, "reset mac stats failed, ret:%d.", ret);
485 : 0 : goto l_end;
486 : : }
487 : : }
488 : :
489 : 0 : memset(&vsi->vsi_stats, 0, sizeof(vsi->vsi_stats));
490 [ # # ]: 0 : for (rx_queue_id = 0; rx_queue_id < dev->data->nb_rx_queues; rx_queue_id++) {
491 : 0 : rxq = dev->data->rx_queues[rx_queue_id];
492 [ # # ]: 0 : if (rxq)
493 : 0 : memset(&rxq->sw_stats, 0, sizeof(rxq->sw_stats));
494 : : }
495 : :
496 : 0 : l_end:
497 : 0 : return ret;
498 : : }
499 : :
500 : 0 : int32_t sxe2_stats_info_reset(struct rte_eth_dev *dev)
501 : : {
502 [ # # ]: 0 : if (rte_eal_process_type() == RTE_PROC_SECONDARY)
503 : 0 : return sxe2_mp_req_reset_stats(dev);
504 : :
505 : 0 : return sxe2_stats_hw_reset(dev);
506 : : }
507 : :
508 : 0 : int32_t sxe2_stats_init(struct rte_eth_dev *dev)
509 : : {
510 : 0 : PMD_INIT_FUNC_TRACE();
511 : :
512 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
513 : : return 0;
514 : :
515 : 0 : dev->data->dev_flags |= RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS;
516 : :
517 : 0 : return sxe2_stats_hw_reset(dev);
518 : : }
|