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