remove trailing whitespaces
[dpdk.git] / lib / librte_pmd_vmxnet3 / vmxnet3_ring.h
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
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 Intel 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 #ifndef _VMXNET3_RING_H_
35 #define _VMXNET3_RING_H_
36
37 #define VMXNET3_RX_CMDRING_SIZE 2
38
39 #define VMXNET3_DRIVER_VERSION_NUM 0x01012000
40
41 /* Default ring size */
42 #define VMXNET3_DEF_TX_RING_SIZE 512
43 #define VMXNET3_DEF_RX_RING_SIZE 128
44
45 #define VMXNET3_SUCCESS 0
46 #define VMXNET3_FAIL   -1
47
48 #define TRUE  1
49 #define FALSE 0
50
51
52 typedef struct vmxnet3_buf_info {
53         uint16_t               len;
54         struct rte_mbuf       *m;
55         uint64_t             bufPA;
56 }vmxnet3_buf_info_t;
57
58 typedef struct vmxnet3_cmd_ring {
59         vmxnet3_buf_info_t     *buf_info;
60         uint32_t               size;
61         uint32_t               next2fill;
62         uint32_t               next2comp;
63         uint8_t                gen;
64         uint8_t                rid;
65         Vmxnet3_GenericDesc    *base;
66         uint64_t               basePA;
67 } vmxnet3_cmd_ring_t;
68
69 static inline void
70 vmxnet3_cmd_ring_adv_next2fill(struct vmxnet3_cmd_ring *ring)
71 {
72         ring->next2fill++;
73         if (unlikely(ring->next2fill == ring->size)) {
74                 ring->next2fill = 0;
75                 ring->gen = (uint8_t)(ring->gen ^ 1);
76         }
77 }
78
79 static inline void
80 vmxnet3_cmd_ring_adv_next2comp(struct vmxnet3_cmd_ring *ring)
81 {
82    VMXNET3_INC_RING_IDX_ONLY(ring->next2comp, ring->size);
83 }
84
85 static inline uint32_t
86 vmxnet3_cmd_ring_desc_avail(struct vmxnet3_cmd_ring *ring)
87 {
88         return (ring->next2comp > ring->next2fill ? 0 : ring->size) +
89                    ring->next2comp - ring->next2fill - 1;
90 }
91
92 static inline bool
93 vmxnet3_cmd_ring_desc_empty(struct vmxnet3_cmd_ring *ring)
94 {
95         return (ring->next2comp == ring->next2fill);
96 }
97
98 typedef struct vmxnet3_comp_ring {
99         uint32_t               size;
100         uint32_t               next2proc;
101         uint8_t                gen;
102         uint8_t                intr_idx;
103         Vmxnet3_GenericDesc    *base;
104         uint64_t               basePA;
105 } vmxnet3_comp_ring_t;
106
107 static inline void
108 vmxnet3_comp_ring_adv_next2proc(struct vmxnet3_comp_ring *ring)
109 {
110         ring->next2proc++;
111         if (unlikely(ring->next2proc == ring->size)) {
112                 ring->next2proc = 0;
113                 ring->gen = (uint8_t)(ring->gen ^ 1);
114         }
115 }
116
117 struct vmxnet3_txq_stats {
118         uint64_t               drop_total; /* # of pkts dropped by the driver, the
119                                                                            * counters below track droppings due to
120                                                                            * different reasons
121                                                                            */
122         uint64_t               drop_oversized;
123         uint64_t               drop_hdr_inspect_err;
124         uint64_t               drop_tso;
125         uint64_t               deferred;
126         uint64_t               tx_ring_full;
127         uint64_t               linearized;  /* # of pkts linearized */
128 };
129
130 typedef struct vmxnet3_tx_ctx {
131         int      ip_type;
132         bool     is_vlan;
133         bool     is_cso;
134
135         uint16_t evl_tag;               /* only valid when is_vlan == TRUE */
136         uint32_t eth_hdr_size;  /* only valid for pkts requesting tso or csum
137                                                          * offloading */
138         uint32_t ip_hdr_size;
139         uint32_t l4_hdr_size;
140 } vmxnet3_tx_ctx_t;
141
142 typedef struct vmxnet3_tx_queue {
143         struct vmxnet3_hw            *hw;
144         struct vmxnet3_cmd_ring      cmd_ring;
145         struct vmxnet3_comp_ring     comp_ring;
146         uint32_t                     qid;
147         struct Vmxnet3_TxQueueDesc   *shared;
148         struct vmxnet3_txq_stats     stats;
149         bool                         stopped;
150         uint16_t                     queue_id;      /**< Device TX queue index. */
151         uint8_t                      port_id;       /**< Device port identifier. */
152 } vmxnet3_tx_queue_t;
153
154
155 struct vmxnet3_rxq_stats {
156         uint64_t                     drop_total;
157         uint64_t                     drop_err;
158         uint64_t                     drop_fcs;
159         uint64_t                     rx_buf_alloc_failure;
160 };
161
162 typedef struct vmxnet3_rx_queue {
163         struct rte_mempool          *mp;
164         struct vmxnet3_hw           *hw;
165         struct vmxnet3_cmd_ring     cmd_ring[VMXNET3_RX_CMDRING_SIZE];
166         struct vmxnet3_comp_ring    comp_ring;
167         uint32_t                    qid1;
168         uint32_t                    qid2;
169         Vmxnet3_RxQueueDesc         *shared;
170         struct vmxnet3_rxq_stats    stats;
171         bool                        stopped;
172         uint16_t                    queue_id;      /**< Device RX queue index. */
173         uint8_t                     port_id;       /**< Device port identifier. */
174 } vmxnet3_rx_queue_t;
175
176 #endif /* _VMXNET3_RING_H_ */