net/liquidio: add APIs to allocate and free SC buffer pool
[dpdk.git] / drivers / net / liquidio / lio_struct.h
1 /*
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2017 Cavium, Inc.. 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 Cavium, Inc. 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(S) 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 _LIO_STRUCT_H_
35 #define _LIO_STRUCT_H_
36
37 #include <stdio.h>
38 #include <stdint.h>
39 #include <sys/queue.h>
40
41 #include <rte_spinlock.h>
42 #include <rte_atomic.h>
43
44 #include "lio_hw_defs.h"
45
46 struct lio_version {
47         uint16_t major;
48         uint16_t minor;
49         uint16_t micro;
50         uint16_t reserved;
51 };
52
53 /** The txpciq info passed to host from the firmware */
54 union octeon_txpciq {
55         uint64_t txpciq64;
56
57         struct {
58 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
59                 uint64_t q_no : 8;
60                 uint64_t port : 8;
61                 uint64_t pkind : 6;
62                 uint64_t use_qpg : 1;
63                 uint64_t qpg : 11;
64                 uint64_t aura_num : 10;
65                 uint64_t reserved : 20;
66 #else
67                 uint64_t reserved : 20;
68                 uint64_t aura_num : 10;
69                 uint64_t qpg : 11;
70                 uint64_t use_qpg : 1;
71                 uint64_t pkind : 6;
72                 uint64_t port : 8;
73                 uint64_t q_no : 8;
74 #endif
75         } s;
76 };
77
78 /** The instruction (input) queue.
79  *  The input queue is used to post raw (instruction) mode data or packet
80  *  data to Octeon device from the host. Each input queue for
81  *  a LIO device has one such structure to represent it.
82  */
83 struct lio_instr_queue {
84         /** A spinlock to protect access to the input ring.  */
85         rte_spinlock_t lock;
86
87         rte_spinlock_t post_lock;
88
89         struct lio_device *lio_dev;
90
91         uint32_t pkt_in_done;
92
93         rte_atomic64_t iq_flush_running;
94
95         /** Flag that indicates if the queue uses 64 byte commands. */
96         uint32_t iqcmd_64B:1;
97
98         /** Queue info. */
99         union octeon_txpciq txpciq;
100
101         uint32_t rsvd:17;
102
103         uint32_t status:8;
104
105         /** Maximum no. of instructions in this queue. */
106         uint32_t max_count;
107
108         /** Index in input ring where the driver should write the next packet */
109         uint32_t host_write_index;
110
111         /** Index in input ring where Octeon is expected to read the next
112          *  packet.
113          */
114         uint32_t lio_read_index;
115
116         /** This index aids in finding the window in the queue where Octeon
117          *  has read the commands.
118          */
119         uint32_t flush_index;
120
121         /** This field keeps track of the instructions pending in this queue. */
122         rte_atomic64_t instr_pending;
123
124         /** Pointer to the Virtual Base addr of the input ring. */
125         uint8_t *base_addr;
126
127         struct lio_request_list *request_list;
128
129         /** Octeon doorbell register for the ring. */
130         void *doorbell_reg;
131
132         /** Octeon instruction count register for this ring. */
133         void *inst_cnt_reg;
134
135         /** Number of instructions pending to be posted to Octeon. */
136         uint32_t fill_cnt;
137
138         /** DMA mapped base address of the input descriptor ring. */
139         uint64_t base_addr_dma;
140
141         /** Application context */
142         void *app_ctx;
143
144         /* network stack queue index */
145         int q_index;
146
147         /* Memory zone */
148         const struct rte_memzone *iq_mz;
149 };
150
151 struct lio_io_enable {
152         uint64_t iq;
153         uint64_t oq;
154         uint64_t iq64B;
155 };
156
157 struct lio_fn_list {
158         void (*setup_iq_regs)(struct lio_device *, uint32_t);
159
160         int (*setup_mbox)(struct lio_device *);
161         void (*free_mbox)(struct lio_device *);
162
163         int (*setup_device_regs)(struct lio_device *);
164 };
165
166 struct lio_pf_vf_hs_word {
167 #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
168         /** PKIND value assigned for the DPI interface */
169         uint64_t pkind : 8;
170
171         /** OCTEON core clock multiplier */
172         uint64_t core_tics_per_us : 16;
173
174         /** OCTEON coprocessor clock multiplier */
175         uint64_t coproc_tics_per_us : 16;
176
177         /** app that currently running on OCTEON */
178         uint64_t app_mode : 8;
179
180         /** RESERVED */
181         uint64_t reserved : 16;
182
183 #elif RTE_BYTE_ORDER == RTE_BIG_ENDIAN
184
185         /** RESERVED */
186         uint64_t reserved : 16;
187
188         /** app that currently running on OCTEON */
189         uint64_t app_mode : 8;
190
191         /** OCTEON coprocessor clock multiplier */
192         uint64_t coproc_tics_per_us : 16;
193
194         /** OCTEON core clock multiplier */
195         uint64_t core_tics_per_us : 16;
196
197         /** PKIND value assigned for the DPI interface */
198         uint64_t pkind : 8;
199 #endif
200 };
201
202 struct lio_sriov_info {
203         /** Number of rings assigned to VF */
204         uint32_t rings_per_vf;
205
206         /** Number of VF devices enabled */
207         uint32_t num_vfs;
208 };
209
210 /* Structure to define the configuration attributes for each Input queue. */
211 struct lio_iq_config {
212         /* Max number of IQs available */
213         uint8_t max_iqs;
214
215         /** Pending list size (usually set to the sum of the size of all Input
216          *  queues)
217          */
218         uint32_t pending_list_size;
219
220         /** Command size - 32 or 64 bytes */
221         uint32_t instr_type;
222 };
223
224 /* Structure to define the configuration attributes for each Output queue. */
225 struct lio_oq_config {
226         /* Max number of OQs available */
227         uint8_t max_oqs;
228
229         /** If set, the Output queue uses info-pointer mode. (Default: 1 ) */
230         uint32_t info_ptr;
231
232         /** The number of buffers that were consumed during packet processing by
233          *  the driver on this Output queue before the driver attempts to
234          *  replenish the descriptor ring with new buffers.
235          */
236         uint32_t refill_threshold;
237 };
238
239 /* Structure to define the configuration. */
240 struct lio_config {
241         uint16_t card_type;
242         const char *card_name;
243
244         /** Input Queue attributes. */
245         struct lio_iq_config iq;
246
247         /** Output Queue attributes. */
248         struct lio_oq_config oq;
249
250         int num_nic_ports;
251
252         int num_def_tx_descs;
253
254         /* Num of desc for rx rings */
255         int num_def_rx_descs;
256
257         int def_rx_buf_size;
258 };
259
260 /* -----------------------  THE LIO DEVICE  --------------------------- */
261 /** The lio device.
262  *  Each lio device has this structure to represent all its
263  *  components.
264  */
265 struct lio_device {
266         /** PCI device pointer */
267         struct rte_pci_device *pci_dev;
268
269         /** Octeon Chip type */
270         uint16_t chip_id;
271         uint16_t pf_num;
272         uint16_t vf_num;
273
274         uint8_t *hw_addr;
275
276         struct lio_fn_list fn_list;
277
278         uint32_t num_iqs;
279
280         /* The pool containing pre allocated buffers used for soft commands */
281         struct rte_mempool *sc_buf_pool;
282
283         /** The input instruction queues */
284         struct lio_instr_queue *instr_queue[LIO_MAX_POSSIBLE_INSTR_QUEUES];
285
286         struct lio_io_enable io_qmask;
287
288         struct lio_sriov_info sriov_info;
289
290         struct lio_pf_vf_hs_word pfvf_hsword;
291
292         /** Mail Box details of each lio queue. */
293         struct lio_mbox **mbox;
294
295         char dev_string[LIO_DEVICE_NAME_LEN]; /* Device print string */
296
297         const struct lio_config *default_config;
298
299         struct rte_eth_dev      *eth_dev;
300
301         uint8_t max_rx_queues;
302         uint8_t max_tx_queues;
303         uint8_t nb_rx_queues;
304         uint8_t nb_tx_queues;
305         uint8_t port_configured;
306         uint8_t port_id;
307 };
308 #endif /* _LIO_STRUCT_H_ */