bb36b6a4084a39121672460966fe7c147cad6f6c
[dpdk.git] / drivers / raw / octeontx2_ep / otx2_ep_rawdev.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(C) 2019 Marvell International Ltd.
3  */
4
5 #ifndef _OTX2_EP_RAWDEV_H_
6 #define _OTX2_EP_RAWDEV_H_
7
8 #include <rte_byteorder.h>
9 #include <rte_spinlock.h>
10
11
12 /* Input Request Header format */
13 struct sdp_instr_irh {
14         /* Request ID  */
15         uint64_t rid:16;
16
17         /* PCIe port to use for response */
18         uint64_t pcie_port:3;
19
20         /* Scatter indicator  1=scatter */
21         uint64_t scatter:1;
22
23         /* Size of Expected result OR no. of entries in scatter list */
24         uint64_t rlenssz:14;
25
26         /* Desired destination port for result */
27         uint64_t dport:6;
28
29         /* Opcode Specific parameters */
30         uint64_t param:8;
31
32         /* Opcode for the return packet  */
33         uint64_t opcode:16;
34 };
35
36 /* SDP 32B instruction format */
37 struct sdp_instr_32B {
38         /* Pointer where the input data is available. */
39         uint64_t dptr;
40
41         /* SDP Instruction Header.  */
42         uint64_t ih;
43
44         /** Pointer where the response for a RAW mode packet
45          *  will be written by OCTEON TX2.
46          */
47         uint64_t rptr;
48
49         /* Input Request Header. Additional info about the input. */
50         uint64_t irh;
51 };
52 #define SDP_32B_INSTR_SIZE      (sizeof(sdp_instr_32B))
53
54 /* SDP 64B instruction format */
55 struct sdp_instr_64B {
56         /* Pointer where the input data is available. */
57         uint64_t dptr;
58
59         /* SDP Instruction Header. */
60         uint64_t ih;
61
62         /** Pointer where the response for a RAW mode packet
63          * will be written by OCTEON TX2.
64          */
65         uint64_t rptr;
66
67         /* Input Request Header. */
68         uint64_t irh;
69
70         /* Additional headers available in a 64-byte instruction. */
71         uint64_t exhdr[4];
72 };
73 #define SDP_64B_INSTR_SIZE      (sizeof(sdp_instr_64B))
74
75 struct sdp_soft_instr {
76         /** Input data pointer. It is either pointing directly to input data
77          *  or to a gather list.
78          */
79         void *dptr;
80
81         /** Response from OCTEON TX2 comes at this address. It is either
82          *  directlty pointing to output data buffer or to a scatter list.
83          */
84         void *rptr;
85
86         /* The instruction header. All input commands have this field. */
87         struct sdp_instr_ih ih;
88
89         /* Input request header. */
90         struct sdp_instr_irh irh;
91
92         /** The PCI instruction to be sent to OCTEON TX2. This is stored in the
93          *  instr to retrieve the physical address of buffers when instr is
94          *  freed.
95          */
96         struct sdp_instr_64B command;
97
98         /** If a gather list was allocated, this ptr points to the buffer used
99          *  for the gather list. The gather list has to be 8B aligned, so this
100          *  value may be different from dptr.
101          */
102         void *gather_ptr;
103
104         /* Total data bytes transferred in the gather mode request. */
105         uint64_t gather_bytes;
106
107         /** If a scatter list was allocated, this ptr points to the buffer used
108          *  for the scatter list. The scatter list has to be 8B aligned, so
109          *  this value may be different from rptr.
110          */
111         void *scatter_ptr;
112
113         /* Total data bytes to be received in the scatter mode request. */
114         uint64_t scatter_bytes;
115
116         /* IQ number to which this instruction has to be submitted. */
117         uint32_t q_no;
118
119         /* IQ instruction request type. */
120         uint32_t reqtype;
121 };
122 #define SDP_SOFT_INSTR_SIZE     (sizeof(sdp_soft_instr))
123
124 /* SDP IQ request list */
125 struct sdp_instr_list {
126         void *buf;
127         uint32_t reqtype;
128 };
129 #define SDP_IQREQ_LIST_SIZE     (sizeof(struct sdp_instr_list))
130
131 /* Structure to define the configuration attributes for each Input queue. */
132 struct sdp_iq_config {
133         /* Max number of IQs available */
134         uint16_t max_iqs;
135
136         /* Command size - 32 or 64 bytes */
137         uint16_t instr_type;
138
139         /* Pending list size, usually set to the sum of the size of all IQs */
140         uint32_t pending_list_size;
141 };
142
143 /** The instruction (input) queue.
144  *  The input queue is used to post raw (instruction) mode data or packet data
145  *  to OCTEON TX2 device from the host. Each IQ of a SDP EP VF device has one
146  *  such structure to represent it.
147  */
148 struct sdp_instr_queue {
149         /* A spinlock to protect access to the input ring.  */
150         rte_spinlock_t lock;
151         rte_spinlock_t post_lock;
152
153         struct sdp_device *sdp_dev;
154         rte_atomic64_t iq_flush_running;
155
156         uint32_t q_no;
157         uint32_t pkt_in_done;
158
159         /* Flag for 64 byte commands. */
160         uint32_t iqcmd_64B:1;
161         uint32_t rsvd:17;
162         uint32_t status:8;
163
164         /* Number of  descriptors in this ring. */
165         uint32_t nb_desc;
166
167         /* Input ring index, where the driver should write the next packet */
168         uint32_t host_write_index;
169
170         /* Input ring index, where the OCTEON TX2 should read the next packet */
171         uint32_t otx_read_index;
172
173         /** This index aids in finding the window in the queue where OCTEON TX2
174          *  has read the commands.
175          */
176         uint32_t flush_index;
177
178         /* This keeps track of the instructions pending in this queue. */
179         rte_atomic64_t instr_pending;
180
181         uint32_t reset_instr_cnt;
182
183         /* Pointer to the Virtual Base addr of the input ring. */
184         uint8_t *base_addr;
185
186         /* This IQ request list */
187         struct sdp_instr_list *req_list;
188
189         /* SDP doorbell register for the ring. */
190         void *doorbell_reg;
191
192         /* SDP instruction count register for this ring. */
193         void *inst_cnt_reg;
194
195         /* Number of instructions pending to be posted to OCTEON TX2. */
196         uint32_t fill_cnt;
197
198         /* DMA mapped base address of the input descriptor ring. */
199         uint64_t base_addr_dma;
200
201         /* Memory zone */
202         const struct rte_memzone *iq_mz;
203 };
204
205 /* DROQ packet format for application i/f. */
206 struct sdp_droq_pkt {
207         /* DROQ packet data buffer pointer. */
208         uint8_t  *data;
209
210         /* DROQ packet data length */
211         uint32_t len;
212
213         uint32_t misc;
214 };
215
216 /** Descriptor format.
217  *  The descriptor ring is made of descriptors which have 2 64-bit values:
218  *  -# Physical (bus) address of the data buffer.
219  *  -# Physical (bus) address of a sdp_droq_info structure.
220  *  The device DMA's incoming packets and its information at the address
221  *  given by these descriptor fields.
222  */
223 struct sdp_droq_desc {
224         /* The buffer pointer */
225         uint64_t buffer_ptr;
226
227         /* The Info pointer */
228         uint64_t info_ptr;
229 };
230 #define SDP_DROQ_DESC_SIZE      (sizeof(struct sdp_droq_desc))
231
232 /* Receive Header */
233 union sdp_rh {
234         uint64_t rh64;
235 };
236 #define SDP_RH_SIZE (sizeof(union sdp_rh))
237
238 /** Information about packet DMA'ed by OCTEON TX2.
239  *  The format of the information available at Info Pointer after OCTEON TX2
240  *  has posted a packet. Not all descriptors have valid information. Only
241  *  the Info field of the first descriptor for a packet has information
242  *  about the packet.
243  */
244 struct sdp_droq_info {
245         /* The Output Receive Header. */
246         union sdp_rh rh;
247
248         /* The Length of the packet. */
249         uint64_t length;
250 };
251 #define SDP_DROQ_INFO_SIZE      (sizeof(struct sdp_droq_info))
252
253 /** Pointer to data buffer.
254  *  Driver keeps a pointer to the data buffer that it made available to
255  *  the OCTEON TX2 device. Since the descriptor ring keeps physical (bus)
256  *  addresses, this field is required for the driver to keep track of
257  *  the virtual address pointers.
258  */
259 struct sdp_recv_buffer {
260         /* Packet buffer, including meta data. */
261         void *buffer;
262
263         /* Data in the packet buffer. */
264         /* uint8_t *data; */
265 };
266 #define SDP_DROQ_RECVBUF_SIZE   (sizeof(struct sdp_recv_buffer))
267
268 /* Structure to define the configuration attributes for each Output queue. */
269 struct sdp_oq_config {
270         /* Max number of OQs available */
271         uint16_t max_oqs;
272
273         /* If set, the Output queue uses info-pointer mode. (Default: 1 ) */
274         uint16_t info_ptr;
275
276         /** The number of buffers that were consumed during packet processing by
277          *  the driver on this Output queue before the driver attempts to
278          *  replenish the descriptor ring with new buffers.
279          */
280         uint32_t refill_threshold;
281 };
282
283 /* The Descriptor Ring Output Queue(DROQ) structure. */
284 struct sdp_droq {
285         /* A spinlock to protect access to this ring. */
286         rte_spinlock_t lock;
287
288         struct sdp_device *sdp_dev;
289         /* The 8B aligned descriptor ring starts at this address. */
290         struct sdp_droq_desc *desc_ring;
291
292         uint32_t q_no;
293         uint32_t last_pkt_count;
294
295         /* Driver should read the next packet at this index */
296         uint32_t read_idx;
297
298         /* OCTEON TX2 will write the next packet at this index */
299         uint32_t write_idx;
300
301         /* At this index, the driver will refill the descriptor's buffer */
302         uint32_t refill_idx;
303
304         /* Packets pending to be processed */
305         rte_atomic64_t pkts_pending;
306
307         /* Number of descriptors in this ring. */
308         uint32_t nb_desc;
309
310         /* The number of descriptors pending to refill. */
311         uint32_t refill_count;
312
313         uint32_t refill_threshold;
314
315         /* The 8B aligned info ptrs begin from this address. */
316         struct sdp_droq_info *info_list;
317
318         /* receive buffer list contains virtual addresses of the buffers. */
319         struct sdp_recv_buffer *recv_buf_list;
320
321         /* The size of each buffer pointed by the buffer pointer. */
322         uint32_t buffer_size;
323
324         /** Pointer to the mapped packet credit register.
325          *  Host writes number of info/buffer ptrs available to this register
326          */
327         void *pkts_credit_reg;
328
329         /** Pointer to the mapped packet sent register. OCTEON TX2 writes the
330          *  number of packets DMA'ed to host memory in this register.
331          */
332         void *pkts_sent_reg;
333
334         /* DMA mapped address of the DROQ descriptor ring. */
335         size_t desc_ring_dma;
336
337         /* Info_ptr list is allocated at this virtual address. */
338         size_t info_base_addr;
339
340         /* DMA mapped address of the info list */
341         size_t info_list_dma;
342
343         /* Allocated size of info list. */
344         uint32_t info_alloc_size;
345
346         /* Memory zone **/
347         const struct rte_memzone *desc_ring_mz;
348         const struct rte_memzone *info_mz;
349 };
350 #define SDP_DROQ_SIZE           (sizeof(struct sdp_droq))
351
352 /* IQ/OQ mask */
353 struct sdp_io_enable {
354         uint64_t iq;
355         uint64_t oq;
356         uint64_t iq64B;
357 };
358
359 /* Structure to define the configuration. */
360 struct sdp_config {
361         /* Input Queue attributes. */
362         struct sdp_iq_config iq;
363
364         /* Output Queue attributes. */
365         struct sdp_oq_config oq;
366
367         /* Num of desc for IQ rings */
368         uint32_t num_iqdef_descs;
369
370         /* Num of desc for OQ rings */
371         uint32_t num_oqdef_descs;
372
373         /* OQ buffer size */
374         uint32_t oqdef_buf_size;
375 };
376
377 /* Required functions for each VF device */
378 struct sdp_fn_list {
379         void (*setup_iq_regs)(struct sdp_device *sdpvf, uint32_t q_no);
380         void (*setup_oq_regs)(struct sdp_device *sdpvf, uint32_t q_no);
381         int (*setup_device_regs)(struct sdp_device *sdpvf);
382         void (*enable_io_queues)(struct sdp_device *sdpvf);
383         void (*enable_iq)(struct sdp_device *sdpvf, uint32_t q_no);
384         void (*enable_oq)(struct sdp_device *sdpvf, uint32_t q_no);
385 };
386
387 /* SRIOV information */
388 struct sdp_sriov_info {
389         /* Number of rings assigned to VF */
390         uint32_t rings_per_vf;
391
392         /* Number of VF devices enabled */
393         uint32_t num_vfs;
394 };
395
396
397 /* Information to be passed from application */
398 struct sdp_rawdev_info {
399         struct rte_mempool *enqdeq_mpool;
400         const struct sdp_config *app_conf;
401 };
402
403 /* SDP EP VF device */
404 struct sdp_device {
405         /* PCI device pointer */
406         struct rte_pci_device *pci_dev;
407         uint16_t chip_id;
408         uint16_t pf_num;
409         uint16_t vf_num;
410
411         /* This device's PCIe port used for traffic. */
412         uint16_t pcie_port;
413         uint32_t pkind;
414
415         /* The state of this device */
416         rte_atomic64_t status;
417
418         /* Memory mapped h/w address */
419         uint8_t *hw_addr;
420
421         struct sdp_fn_list fn_list;
422
423         /* Num IQs */
424         uint32_t num_iqs;
425
426         /* The input instruction queues */
427         struct sdp_instr_queue *instr_queue[SDP_VF_MAX_IOQS_PER_RAWDEV];
428
429         /* Num OQs */
430         uint32_t num_oqs;
431
432         /* The DROQ output queues  */
433         struct sdp_droq *droq[SDP_VF_MAX_IOQS_PER_RAWDEV];
434
435         /* IOQ data buffer pool */
436         struct rte_mempool *enqdeq_mpool;
437
438         /* IOQ mask */
439         struct sdp_io_enable io_qmask;
440
441         /* SR-IOV info */
442         struct sdp_sriov_info sriov_info;
443
444         /* Device configuration */
445         const struct sdp_config *conf;
446 };
447
448 const struct sdp_config *sdp_get_defconf(struct sdp_device *sdp_dev);
449 int sdp_setup_iqs(struct sdp_device *sdpvf, uint32_t iq_no);
450
451 int sdp_setup_oqs(struct sdp_device *sdpvf, uint32_t oq_no);
452
453 #endif /* _OTX2_EP_RAWDEV_H_ */