net/bnx2x: get cache line size from build configuration
[dpdk.git] / drivers / net / bnxt / bnxt_stats.c
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) Broadcom Limited.
5  *   All rights reserved.
6  *
7  *   Redistribution and use in source and binary forms, with or without
8  *   modification, are permitted provided that the following conditions
9  *   are met:
10  *
11  *     * Redistributions of source code must retain the above copyright
12  *       notice, this list of conditions and the following disclaimer.
13  *     * Redistributions in binary form must reproduce the above copyright
14  *       notice, this list of conditions and the following disclaimer in
15  *       the documentation and/or other materials provided with the
16  *       distribution.
17  *     * Neither the name of Broadcom Corporation nor the names of its
18  *       contributors may be used to endorse or promote products derived
19  *       from this software without specific prior written permission.
20  *
21  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33
34 #include <inttypes.h>
35
36 #include <rte_byteorder.h>
37
38 #include "bnxt.h"
39 #include "bnxt_cpr.h"
40 #include "bnxt_hwrm.h"
41 #include "bnxt_rxq.h"
42 #include "bnxt_stats.h"
43 #include "bnxt_txq.h"
44 #include "hsi_struct_def_dpdk.h"
45
46 /*
47  * Statistics functions
48  */
49
50 void bnxt_free_stats(struct bnxt *bp)
51 {
52         int i;
53
54         for (i = 0; i < (int)bp->tx_cp_nr_rings; i++) {
55                 struct bnxt_tx_queue *txq = bp->tx_queues[i];
56
57                 bnxt_free_txq_stats(txq);
58         }
59         for (i = 0; i < (int)bp->rx_cp_nr_rings; i++) {
60                 struct bnxt_rx_queue *rxq = bp->rx_queues[i];
61
62                 bnxt_free_rxq_stats(rxq);
63         }
64 }
65
66 void bnxt_stats_get_op(struct rte_eth_dev *eth_dev,
67                            struct rte_eth_stats *bnxt_stats)
68 {
69         unsigned int i;
70         struct bnxt *bp = eth_dev->data->dev_private;
71
72         memset(bnxt_stats, 0, sizeof(*bnxt_stats));
73
74         for (i = 0; i < bp->rx_cp_nr_rings; i++) {
75                 struct bnxt_rx_queue *rxq = bp->rx_queues[i];
76                 struct bnxt_cp_ring_info *cpr = rxq->cp_ring;
77                 struct ctx_hw_stats64 *hw_stats =
78                     (struct ctx_hw_stats64 *)cpr->hw_stats;
79
80                 bnxt_stats->q_ipackets[i] +=
81                     rte_le_to_cpu_64(hw_stats->rx_ucast_pkts);
82                 bnxt_stats->q_ipackets[i] +=
83                     rte_le_to_cpu_64(hw_stats->rx_mcast_pkts);
84                 bnxt_stats->q_ipackets[i] +=
85                     rte_le_to_cpu_64(hw_stats->rx_bcast_pkts);
86
87                 bnxt_stats->q_ibytes[i] +=
88                     rte_le_to_cpu_64(hw_stats->rx_ucast_bytes);
89                 bnxt_stats->q_ibytes[i] +=
90                     rte_le_to_cpu_64(hw_stats->rx_mcast_bytes);
91                 bnxt_stats->q_ibytes[i] +=
92                     rte_le_to_cpu_64(hw_stats->rx_bcast_bytes);
93
94                 /*
95                  * TBD: No clear mapping to this... we don't seem
96                  * to have a stat specifically for dropped due to
97                  * insufficient mbufs.
98                  */
99                 bnxt_stats->q_errors[i] = 0;
100
101                 /* These get replaced once the *_QSTATS commands work */
102                 bnxt_stats->ipackets += bnxt_stats->q_ipackets[i];
103                 bnxt_stats->ibytes += bnxt_stats->q_ibytes[i];
104                 bnxt_stats->imissed += bnxt_stats->q_errors[i];
105                 bnxt_stats->ierrors +=
106                                 rte_le_to_cpu_64(hw_stats->rx_discard_pkts);
107         }
108
109         for (i = 0; i < bp->tx_cp_nr_rings; i++) {
110                 struct bnxt_tx_queue *txq = bp->tx_queues[i];
111                 struct bnxt_cp_ring_info *cpr = txq->cp_ring;
112                 struct ctx_hw_stats64 *hw_stats =
113                     (struct ctx_hw_stats64 *)cpr->hw_stats;
114
115                 bnxt_stats->q_opackets[i] +=
116                     rte_le_to_cpu_64(hw_stats->tx_ucast_pkts);
117                 bnxt_stats->q_opackets[i] +=
118                     rte_le_to_cpu_64(hw_stats->tx_mcast_pkts);
119                 bnxt_stats->q_opackets[i] +=
120                     rte_le_to_cpu_64(hw_stats->tx_bcast_pkts);
121
122                 bnxt_stats->q_obytes[i] +=
123                     rte_le_to_cpu_64(hw_stats->tx_ucast_bytes);
124                 bnxt_stats->q_obytes[i] +=
125                     rte_le_to_cpu_64(hw_stats->tx_mcast_bytes);
126                 bnxt_stats->q_obytes[i] +=
127                     rte_le_to_cpu_64(hw_stats->tx_bcast_bytes);
128
129                 /* These get replaced once the *_QSTATS commands work */
130                 bnxt_stats->opackets += bnxt_stats->q_opackets[i];
131                 bnxt_stats->obytes +=  bnxt_stats->q_obytes[i];
132                 bnxt_stats->oerrors += rte_le_to_cpu_64(hw_stats->tx_drop_pkts);
133                 bnxt_stats->oerrors += rte_le_to_cpu_64(hw_stats->tx_discard_pkts);
134         }
135 }
136
137 void bnxt_stats_reset_op(struct rte_eth_dev *eth_dev)
138 {
139         struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
140
141         bnxt_clear_all_hwrm_stat_ctxs(bp);
142 }