net/mlx5: fix packet length assert in MPRQ
[dpdk.git] / drivers / net / nfb / nfb_stats.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2019 Cesnet
3  * Copyright(c) 2019 Netcope Technologies, a.s. <info@netcope.com>
4  * All rights reserved.
5  */
6
7 #include "nfb_stats.h"
8 #include "nfb.h"
9
10 int
11 nfb_eth_stats_get(struct rte_eth_dev *dev,
12         struct rte_eth_stats *stats)
13 {
14         uint16_t i;
15         uint16_t nb_rx = dev->data->nb_rx_queues;
16         uint16_t nb_tx = dev->data->nb_tx_queues;
17         uint64_t rx_total = 0;
18         uint64_t tx_total = 0;
19         uint64_t tx_err_total = 0;
20         uint64_t rx_total_bytes = 0;
21         uint64_t tx_total_bytes = 0;
22
23         struct ndp_rx_queue *rx_queue = *((struct ndp_rx_queue **)
24                 dev->data->rx_queues);
25         struct ndp_tx_queue *tx_queue = *((struct ndp_tx_queue **)
26                 dev->data->tx_queues);
27
28         for (i = 0; i < nb_rx; i++) {
29                 if (i < RTE_ETHDEV_QUEUE_STAT_CNTRS) {
30                         stats->q_ipackets[i] = rx_queue[i].rx_pkts;
31                         stats->q_ibytes[i] = rx_queue[i].rx_bytes;
32                 }
33                 rx_total += rx_queue[i].rx_pkts;
34                 rx_total_bytes += rx_queue[i].rx_bytes;
35         }
36
37         for (i = 0; i < nb_tx; i++) {
38                 if (i < RTE_ETHDEV_QUEUE_STAT_CNTRS) {
39                         stats->q_opackets[i] = tx_queue[i].tx_pkts;
40                         stats->q_obytes[i] = tx_queue[i].tx_bytes;
41                 }
42                 tx_total += tx_queue[i].tx_pkts;
43                 tx_total_bytes += tx_queue[i].tx_bytes;
44                 tx_err_total += tx_queue[i].err_pkts;
45         }
46
47         stats->ipackets = rx_total;
48         stats->opackets = tx_total;
49         stats->ibytes = rx_total_bytes;
50         stats->obytes = tx_total_bytes;
51         stats->oerrors = tx_err_total;
52         return 0;
53 }
54
55 int
56 nfb_eth_stats_reset(struct rte_eth_dev *dev)
57 {
58         uint16_t i;
59         uint16_t nb_rx = dev->data->nb_rx_queues;
60         uint16_t nb_tx = dev->data->nb_tx_queues;
61
62         struct ndp_rx_queue *rx_queue = *((struct ndp_rx_queue **)
63                 dev->data->rx_queues);
64         struct ndp_tx_queue *tx_queue = *((struct ndp_tx_queue **)
65                 dev->data->tx_queues);
66
67         for (i = 0; i < nb_rx; i++) {
68                 rx_queue[i].rx_pkts = 0;
69                 rx_queue[i].rx_bytes = 0;
70                 rx_queue[i].err_pkts = 0;
71         }
72         for (i = 0; i < nb_tx; i++) {
73                 tx_queue[i].tx_pkts = 0;
74                 tx_queue[i].tx_bytes = 0;
75                 tx_queue[i].err_pkts = 0;
76         }
77
78         return 0;
79 }