net/i40e: fix Rx packet statistics
[dpdk.git] / drivers / net / vmxnet3 / vmxnet3_ring.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2014 Intel Corporation
3  */
4
5 #ifndef _VMXNET3_RING_H_
6 #define _VMXNET3_RING_H_
7
8 #define VMXNET3_RX_CMDRING_SIZE 2
9
10 #define VMXNET3_DRIVER_VERSION_NUM 0x01012000
11
12 /* Default ring size */
13 #define VMXNET3_DEF_TX_RING_SIZE 512
14 #define VMXNET3_DEF_RX_RING_SIZE 128
15
16 /* Default rx data ring desc size */
17 #define VMXNET3_DEF_RXDATA_DESC_SIZE 256
18
19 #define VMXNET3_SUCCESS 0
20 #define VMXNET3_FAIL   -1
21
22 #define TRUE  1
23 #define FALSE 0
24
25
26 typedef struct vmxnet3_buf_info {
27         uint16_t               len;
28         struct rte_mbuf        *m;
29         uint64_t               bufPA;
30 } vmxnet3_buf_info_t;
31
32 typedef struct vmxnet3_cmd_ring {
33         vmxnet3_buf_info_t     *buf_info;
34         uint32_t               size;
35         uint32_t               next2fill;
36         uint32_t               next2comp;
37         uint8_t                gen;
38         uint8_t                rid;
39         Vmxnet3_GenericDesc    *base;
40         uint64_t               basePA;
41 } vmxnet3_cmd_ring_t;
42
43 static inline void
44 vmxnet3_cmd_ring_adv_next2fill(struct vmxnet3_cmd_ring *ring)
45 {
46         ring->next2fill++;
47         if (unlikely(ring->next2fill == ring->size)) {
48                 ring->next2fill = 0;
49                 ring->gen = (uint8_t)(ring->gen ^ 1);
50         }
51 }
52
53 static inline void
54 vmxnet3_cmd_ring_adv_next2comp(struct vmxnet3_cmd_ring *ring)
55 {
56         VMXNET3_INC_RING_IDX_ONLY(ring->next2comp, ring->size);
57 }
58
59 static inline uint32_t
60 vmxnet3_cmd_ring_desc_avail(struct vmxnet3_cmd_ring *ring)
61 {
62         return (ring->next2comp > ring->next2fill ? 0 : ring->size) +
63                    ring->next2comp - ring->next2fill - 1;
64 }
65
66 static inline bool
67 vmxnet3_cmd_ring_desc_empty(struct vmxnet3_cmd_ring *ring)
68 {
69         return ring->next2comp == ring->next2fill;
70 }
71
72 typedef struct vmxnet3_comp_ring {
73         uint32_t               size;
74         uint32_t               next2proc;
75         uint8_t                gen;
76         uint8_t                intr_idx;
77         Vmxnet3_GenericDesc    *base;
78         uint64_t               basePA;
79 } vmxnet3_comp_ring_t;
80
81 struct vmxnet3_data_ring {
82         struct Vmxnet3_TxDataDesc *base;
83         uint32_t                  size;
84         uint64_t                  basePA;
85 };
86
87 static inline void
88 vmxnet3_comp_ring_adv_next2proc(struct vmxnet3_comp_ring *ring)
89 {
90         ring->next2proc++;
91         if (unlikely(ring->next2proc == ring->size)) {
92                 ring->next2proc = 0;
93                 ring->gen = (uint8_t)(ring->gen ^ 1);
94         }
95 }
96
97 struct vmxnet3_txq_stats {
98         uint64_t        drop_total; /* # of pkts dropped by the driver,
99                                      * the counters below track droppings due to
100                                      * different reasons
101                                      */
102         uint64_t        drop_too_many_segs;
103         uint64_t        drop_tso;
104         uint64_t        tx_ring_full;
105 };
106
107 typedef struct vmxnet3_tx_queue {
108         struct vmxnet3_hw            *hw;
109         struct vmxnet3_cmd_ring      cmd_ring;
110         struct vmxnet3_comp_ring     comp_ring;
111         struct vmxnet3_data_ring     data_ring;
112         uint32_t                     qid;
113         struct Vmxnet3_TxQueueDesc   *shared;
114         struct vmxnet3_txq_stats     stats;
115         const struct rte_memzone     *mz;
116         bool                         stopped;
117         uint16_t                     queue_id;      /**< Device TX queue index. */
118         uint16_t                     port_id;       /**< Device port identifier. */
119         uint16_t                     txdata_desc_size;
120 } vmxnet3_tx_queue_t;
121
122 struct vmxnet3_rxq_stats {
123         uint64_t                     drop_total;
124         uint64_t                     drop_err;
125         uint64_t                     drop_fcs;
126         uint64_t                     rx_buf_alloc_failure;
127 };
128
129 struct vmxnet3_rx_data_ring {
130         uint8_t  *base;
131         uint64_t basePA;
132         uint32_t size;
133 };
134
135 typedef struct vmxnet3_rx_queue {
136         struct rte_mempool          *mp;
137         struct vmxnet3_hw           *hw;
138         struct vmxnet3_cmd_ring     cmd_ring[VMXNET3_RX_CMDRING_SIZE];
139         struct vmxnet3_comp_ring    comp_ring;
140         struct vmxnet3_rx_data_ring data_ring;
141         uint16_t                    data_desc_size;
142         uint32_t                    qid1;
143         uint32_t                    qid2;
144         /* rqID in RCD for buffer from data ring */
145         uint32_t                    data_ring_qid;
146         Vmxnet3_RxQueueDesc         *shared;
147         struct rte_mbuf             *start_seg;
148         struct rte_mbuf             *last_seg;
149         struct vmxnet3_rxq_stats    stats;
150         const struct rte_memzone    *mz;
151         bool                        stopped;
152         uint16_t                    queue_id;      /**< Device RX queue index. */
153         uint16_t                    port_id;       /**< Device port identifier. */
154 } vmxnet3_rx_queue_t;
155
156 #endif /* _VMXNET3_RING_H_ */