4d67eb684f0e4aa3ca589e7c458f2d349b5291af
[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 Descriptor Ring Output Queue structure.
60  *  This structure has all the information required to implement a
61  *  DROQ.
62  */
63 struct lio_droq {
64         /** A spinlock to protect access to this ring. */
65         rte_spinlock_t lock;
66
67         uint32_t q_no;
68
69         uint32_t pkt_count;
70
71         struct lio_device *lio_dev;
72
73         /** The 8B aligned descriptor ring starts at this address. */
74         struct lio_droq_desc *desc_ring;
75
76         /** Index in the ring where the driver should read the next packet */
77         uint32_t read_idx;
78
79         /** Index in the ring where Octeon will write the next packet */
80         uint32_t write_idx;
81
82         /** Index in the ring where the driver will refill the descriptor's
83          * buffer
84          */
85         uint32_t refill_idx;
86
87         /** Packets pending to be processed */
88         rte_atomic64_t pkts_pending;
89
90         /** Number of  descriptors in this ring. */
91         uint32_t max_count;
92
93         /** The number of descriptors pending refill. */
94         uint32_t refill_count;
95
96         uint32_t refill_threshold;
97
98         /** The 8B aligned info ptrs begin from this address. */
99         struct lio_droq_info *info_list;
100
101         /** The receive buffer list. This list has the virtual addresses of the
102          *  buffers.
103          */
104         struct lio_recv_buffer *recv_buf_list;
105
106         /** The size of each buffer pointed by the buffer pointer. */
107         uint32_t buffer_size;
108
109         /** Pointer to the mapped packet credit register.
110          *  Host writes number of info/buffer ptrs available to this register
111          */
112         void *pkts_credit_reg;
113
114         /** Pointer to the mapped packet sent register.
115          *  Octeon writes the number of packets DMA'ed to host memory
116          *  in this register.
117          */
118         void *pkts_sent_reg;
119
120         /** DMA mapped address of the DROQ descriptor ring. */
121         size_t desc_ring_dma;
122
123         /** Info ptr list are allocated at this virtual address. */
124         size_t info_base_addr;
125
126         /** DMA mapped address of the info list */
127         size_t info_list_dma;
128
129         /** Allocated size of info list. */
130         uint32_t info_alloc_size;
131
132         /** Memory zone **/
133         const struct rte_memzone *desc_ring_mz;
134         const struct rte_memzone *info_mz;
135         struct rte_mempool *mpool;
136 };
137
138 /** Receive Header */
139 union octeon_rh {
140 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
141         uint64_t rh64;
142         struct  {
143                 uint64_t opcode : 4;
144                 uint64_t subcode : 8;
145                 uint64_t len : 3; /** additional 64-bit words */
146                 uint64_t reserved : 17;
147                 uint64_t ossp : 32; /** opcode/subcode specific parameters */
148         } r;
149         struct  {
150                 uint64_t opcode : 4;
151                 uint64_t subcode : 8;
152                 uint64_t len : 3; /** additional 64-bit words */
153                 uint64_t extra : 28;
154                 uint64_t vlan : 12;
155                 uint64_t priority : 3;
156                 uint64_t csum_verified : 3; /** checksum verified. */
157                 uint64_t has_hwtstamp : 1; /** Has hardware timestamp.1 = yes.*/
158                 uint64_t encap_on : 1;
159                 uint64_t has_hash : 1; /** Has hash (rth or rss). 1 = yes. */
160         } r_dh;
161         struct {
162                 uint64_t opcode : 4;
163                 uint64_t subcode : 8;
164                 uint64_t len : 3; /** additional 64-bit words */
165                 uint64_t reserved : 8;
166                 uint64_t extra : 25;
167                 uint64_t gmxport : 16;
168         } r_nic_info;
169 #else
170         uint64_t rh64;
171         struct {
172                 uint64_t ossp : 32; /** opcode/subcode specific parameters */
173                 uint64_t reserved : 17;
174                 uint64_t len : 3; /** additional 64-bit words */
175                 uint64_t subcode : 8;
176                 uint64_t opcode : 4;
177         } r;
178         struct {
179                 uint64_t has_hash : 1; /** Has hash (rth or rss). 1 = yes. */
180                 uint64_t encap_on : 1;
181                 uint64_t has_hwtstamp : 1;  /** 1 = has hwtstamp */
182                 uint64_t csum_verified : 3; /** checksum verified. */
183                 uint64_t priority : 3;
184                 uint64_t vlan : 12;
185                 uint64_t extra : 28;
186                 uint64_t len : 3; /** additional 64-bit words */
187                 uint64_t subcode : 8;
188                 uint64_t opcode : 4;
189         } r_dh;
190         struct {
191                 uint64_t gmxport : 16;
192                 uint64_t extra : 25;
193                 uint64_t reserved : 8;
194                 uint64_t len : 3; /** additional 64-bit words */
195                 uint64_t subcode : 8;
196                 uint64_t opcode : 4;
197         } r_nic_info;
198 #endif
199 };
200
201 #define OCTEON_RH_SIZE (sizeof(union octeon_rh))
202
203 /** The txpciq info passed to host from the firmware */
204 union octeon_txpciq {
205         uint64_t txpciq64;
206
207         struct {
208 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
209                 uint64_t q_no : 8;
210                 uint64_t port : 8;
211                 uint64_t pkind : 6;
212                 uint64_t use_qpg : 1;
213                 uint64_t qpg : 11;
214                 uint64_t aura_num : 10;
215                 uint64_t reserved : 20;
216 #else
217                 uint64_t reserved : 20;
218                 uint64_t aura_num : 10;
219                 uint64_t qpg : 11;
220                 uint64_t use_qpg : 1;
221                 uint64_t pkind : 6;
222                 uint64_t port : 8;
223                 uint64_t q_no : 8;
224 #endif
225         } s;
226 };
227
228 /** The instruction (input) queue.
229  *  The input queue is used to post raw (instruction) mode data or packet
230  *  data to Octeon device from the host. Each input queue for
231  *  a LIO device has one such structure to represent it.
232  */
233 struct lio_instr_queue {
234         /** A spinlock to protect access to the input ring.  */
235         rte_spinlock_t lock;
236
237         rte_spinlock_t post_lock;
238
239         struct lio_device *lio_dev;
240
241         uint32_t pkt_in_done;
242
243         rte_atomic64_t iq_flush_running;
244
245         /** Flag that indicates if the queue uses 64 byte commands. */
246         uint32_t iqcmd_64B:1;
247
248         /** Queue info. */
249         union octeon_txpciq txpciq;
250
251         uint32_t rsvd:17;
252
253         uint32_t status:8;
254
255         /** Maximum no. of instructions in this queue. */
256         uint32_t max_count;
257
258         /** Index in input ring where the driver should write the next packet */
259         uint32_t host_write_index;
260
261         /** Index in input ring where Octeon is expected to read the next
262          *  packet.
263          */
264         uint32_t lio_read_index;
265
266         /** This index aids in finding the window in the queue where Octeon
267          *  has read the commands.
268          */
269         uint32_t flush_index;
270
271         /** This field keeps track of the instructions pending in this queue. */
272         rte_atomic64_t instr_pending;
273
274         /** Pointer to the Virtual Base addr of the input ring. */
275         uint8_t *base_addr;
276
277         struct lio_request_list *request_list;
278
279         /** Octeon doorbell register for the ring. */
280         void *doorbell_reg;
281
282         /** Octeon instruction count register for this ring. */
283         void *inst_cnt_reg;
284
285         /** Number of instructions pending to be posted to Octeon. */
286         uint32_t fill_cnt;
287
288         /** DMA mapped base address of the input descriptor ring. */
289         uint64_t base_addr_dma;
290
291         /** Application context */
292         void *app_ctx;
293
294         /* network stack queue index */
295         int q_index;
296
297         /* Memory zone */
298         const struct rte_memzone *iq_mz;
299 };
300
301 /* The Scatter-Gather List Entry. The scatter or gather component used with
302  * input instruction has this format.
303  */
304 struct lio_sg_entry {
305         /** The first 64 bit gives the size of data in each dptr. */
306         union {
307                 uint16_t size[4];
308                 uint64_t size64;
309         } u;
310
311         /** The 4 dptr pointers for this entry. */
312         uint64_t ptr[4];
313 };
314
315 #define LIO_SG_ENTRY_SIZE       (sizeof(struct lio_sg_entry))
316
317 /** Structure of a node in list of gather components maintained by
318  *  driver for each network device.
319  */
320 struct lio_gather {
321         /** List manipulation. Next and prev pointers. */
322         struct lio_stailq_node list;
323
324         /** Size of the gather component at sg in bytes. */
325         int sg_size;
326
327         /** Number of bytes that sg was adjusted to make it 8B-aligned. */
328         int adjust;
329
330         /** Gather component that can accommodate max sized fragment list
331          *  received from the IP layer.
332          */
333         struct lio_sg_entry *sg;
334 };
335
336 struct lio_io_enable {
337         uint64_t iq;
338         uint64_t oq;
339         uint64_t iq64B;
340 };
341
342 struct lio_fn_list {
343         void (*setup_iq_regs)(struct lio_device *, uint32_t);
344         void (*setup_oq_regs)(struct lio_device *, uint32_t);
345
346         int (*setup_mbox)(struct lio_device *);
347         void (*free_mbox)(struct lio_device *);
348
349         int (*setup_device_regs)(struct lio_device *);
350 };
351
352 struct lio_pf_vf_hs_word {
353 #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
354         /** PKIND value assigned for the DPI interface */
355         uint64_t pkind : 8;
356
357         /** OCTEON core clock multiplier */
358         uint64_t core_tics_per_us : 16;
359
360         /** OCTEON coprocessor clock multiplier */
361         uint64_t coproc_tics_per_us : 16;
362
363         /** app that currently running on OCTEON */
364         uint64_t app_mode : 8;
365
366         /** RESERVED */
367         uint64_t reserved : 16;
368
369 #elif RTE_BYTE_ORDER == RTE_BIG_ENDIAN
370
371         /** RESERVED */
372         uint64_t reserved : 16;
373
374         /** app that currently running on OCTEON */
375         uint64_t app_mode : 8;
376
377         /** OCTEON coprocessor clock multiplier */
378         uint64_t coproc_tics_per_us : 16;
379
380         /** OCTEON core clock multiplier */
381         uint64_t core_tics_per_us : 16;
382
383         /** PKIND value assigned for the DPI interface */
384         uint64_t pkind : 8;
385 #endif
386 };
387
388 struct lio_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 /* Head of a response list */
397 struct lio_response_list {
398         /** List structure to add delete pending entries to */
399         struct lio_stailq_head head;
400
401         /** A lock for this response list */
402         rte_spinlock_t lock;
403
404         rte_atomic64_t pending_req_count;
405 };
406
407 /* Structure to define the configuration attributes for each Input queue. */
408 struct lio_iq_config {
409         /* Max number of IQs available */
410         uint8_t max_iqs;
411
412         /** Pending list size (usually set to the sum of the size of all Input
413          *  queues)
414          */
415         uint32_t pending_list_size;
416
417         /** Command size - 32 or 64 bytes */
418         uint32_t instr_type;
419 };
420
421 /* Structure to define the configuration attributes for each Output queue. */
422 struct lio_oq_config {
423         /* Max number of OQs available */
424         uint8_t max_oqs;
425
426         /** If set, the Output queue uses info-pointer mode. (Default: 1 ) */
427         uint32_t info_ptr;
428
429         /** The number of buffers that were consumed during packet processing by
430          *  the driver on this Output queue before the driver attempts to
431          *  replenish the descriptor ring with new buffers.
432          */
433         uint32_t refill_threshold;
434 };
435
436 /* Structure to define the configuration. */
437 struct lio_config {
438         uint16_t card_type;
439         const char *card_name;
440
441         /** Input Queue attributes. */
442         struct lio_iq_config iq;
443
444         /** Output Queue attributes. */
445         struct lio_oq_config oq;
446
447         int num_nic_ports;
448
449         int num_def_tx_descs;
450
451         /* Num of desc for rx rings */
452         int num_def_rx_descs;
453
454         int def_rx_buf_size;
455 };
456
457 /** Status of a RGMII Link on Octeon as seen by core driver. */
458 union octeon_link_status {
459         uint64_t link_status64;
460
461         struct {
462 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
463                 uint64_t duplex : 8;
464                 uint64_t mtu : 16;
465                 uint64_t speed : 16;
466                 uint64_t link_up : 1;
467                 uint64_t autoneg : 1;
468                 uint64_t if_mode : 5;
469                 uint64_t pause : 1;
470                 uint64_t flashing : 1;
471                 uint64_t reserved : 15;
472 #else
473                 uint64_t reserved : 15;
474                 uint64_t flashing : 1;
475                 uint64_t pause : 1;
476                 uint64_t if_mode : 5;
477                 uint64_t autoneg : 1;
478                 uint64_t link_up : 1;
479                 uint64_t speed : 16;
480                 uint64_t mtu : 16;
481                 uint64_t duplex : 8;
482 #endif
483         } s;
484 };
485
486 /** The rxpciq info passed to host from the firmware */
487 union octeon_rxpciq {
488         uint64_t rxpciq64;
489
490         struct {
491 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
492                 uint64_t q_no : 8;
493                 uint64_t reserved : 56;
494 #else
495                 uint64_t reserved : 56;
496                 uint64_t q_no : 8;
497 #endif
498         } s;
499 };
500
501 /** Information for a OCTEON ethernet interface shared between core & host. */
502 struct octeon_link_info {
503         union octeon_link_status link;
504         uint64_t hw_addr;
505
506 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
507         uint64_t gmxport : 16;
508         uint64_t macaddr_is_admin_assigned : 1;
509         uint64_t vlan_is_admin_assigned : 1;
510         uint64_t rsvd : 30;
511         uint64_t num_txpciq : 8;
512         uint64_t num_rxpciq : 8;
513 #else
514         uint64_t num_rxpciq : 8;
515         uint64_t num_txpciq : 8;
516         uint64_t rsvd : 30;
517         uint64_t vlan_is_admin_assigned : 1;
518         uint64_t macaddr_is_admin_assigned : 1;
519         uint64_t gmxport : 16;
520 #endif
521
522         union octeon_txpciq txpciq[LIO_MAX_IOQS_PER_IF];
523         union octeon_rxpciq rxpciq[LIO_MAX_IOQS_PER_IF];
524 };
525
526 /* -----------------------  THE LIO DEVICE  --------------------------- */
527 /** The lio device.
528  *  Each lio device has this structure to represent all its
529  *  components.
530  */
531 struct lio_device {
532         /** PCI device pointer */
533         struct rte_pci_device *pci_dev;
534
535         /** Octeon Chip type */
536         uint16_t chip_id;
537         uint16_t pf_num;
538         uint16_t vf_num;
539
540         /** This device's PCIe port used for traffic. */
541         uint16_t pcie_port;
542
543         /** The state of this device */
544         rte_atomic64_t status;
545
546         struct octeon_link_info linfo;
547
548         uint8_t *hw_addr;
549
550         struct lio_fn_list fn_list;
551
552         uint32_t num_iqs;
553
554         /** Guards each glist */
555         rte_spinlock_t *glist_lock;
556         /** Array of gather component linked lists */
557         struct lio_stailq_head *glist_head;
558
559         /* The pool containing pre allocated buffers used for soft commands */
560         struct rte_mempool *sc_buf_pool;
561
562         /** The input instruction queues */
563         struct lio_instr_queue *instr_queue[LIO_MAX_POSSIBLE_INSTR_QUEUES];
564
565         /** The singly-linked tail queues of instruction response */
566         struct lio_response_list response_list;
567
568         uint32_t num_oqs;
569
570         /** The DROQ output queues  */
571         struct lio_droq *droq[LIO_MAX_POSSIBLE_OUTPUT_QUEUES];
572
573         struct lio_io_enable io_qmask;
574
575         struct lio_sriov_info sriov_info;
576
577         struct lio_pf_vf_hs_word pfvf_hsword;
578
579         /** Mail Box details of each lio queue. */
580         struct lio_mbox **mbox;
581
582         char dev_string[LIO_DEVICE_NAME_LEN]; /* Device print string */
583
584         const struct lio_config *default_config;
585
586         struct rte_eth_dev      *eth_dev;
587
588         uint64_t ifflags;
589         uint8_t max_rx_queues;
590         uint8_t max_tx_queues;
591         uint8_t nb_rx_queues;
592         uint8_t nb_tx_queues;
593         uint8_t port_configured;
594         uint8_t port_id;
595 };
596 #endif /* _LIO_STRUCT_H_ */