New upstream version 18.05
[deb_dpdk.git] / drivers / net / enic / base / vnic_rq.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright 2008-2017 Cisco Systems, Inc.  All rights reserved.
3  * Copyright 2007 Nuova Systems, Inc.  All rights reserved.
4  */
5
6 #ifndef _VNIC_RQ_H_
7 #define _VNIC_RQ_H_
8
9 #include <stdbool.h>
10
11 #include "vnic_dev.h"
12 #include "vnic_cq.h"
13
14 /* Receive queue control */
15 struct vnic_rq_ctrl {
16         u64 ring_base;                  /* 0x00 */
17         u32 ring_size;                  /* 0x08 */
18         u32 pad0;
19         u32 posted_index;               /* 0x10 */
20         u32 pad1;
21         u32 cq_index;                   /* 0x18 */
22         u32 pad2;
23         u32 enable;                     /* 0x20 */
24         u32 pad3;
25         u32 running;                    /* 0x28 */
26         u32 pad4;
27         u32 fetch_index;                /* 0x30 */
28         u32 pad5;
29         u32 error_interrupt_enable;     /* 0x38 */
30         u32 pad6;
31         u32 error_interrupt_offset;     /* 0x40 */
32         u32 pad7;
33         u32 error_status;               /* 0x48 */
34         u32 pad8;
35         u32 tcp_sn;                     /* 0x50 */
36         u32 pad9;
37         u32 unused;                     /* 0x58 */
38         u32 pad10;
39         u32 dca_select;                 /* 0x60 */
40         u32 pad11;
41         u32 dca_value;                  /* 0x68 */
42         u32 pad12;
43         u32 data_ring;                  /* 0x70 */
44         u32 pad13;
45         u32 header_split;               /* 0x78 */
46         u32 pad14;
47 };
48
49 struct vnic_rq {
50         unsigned int index;
51         unsigned int posted_index;
52         struct vnic_dev *vdev;
53         struct vnic_rq_ctrl __iomem *ctrl;      /* memory-mapped */
54         struct vnic_dev_ring ring;
55         struct rte_mbuf **mbuf_ring;            /* array of allocated mbufs */
56         unsigned int mbuf_next_idx;             /* next mb to consume */
57         void *os_buf_head;
58         unsigned int pkts_outstanding;
59         uint16_t rx_nb_hold;
60         uint16_t rx_free_thresh;
61         unsigned int socket_id;
62         struct rte_mempool *mp;
63         uint16_t rxst_idx;
64         uint32_t tot_pkts;
65         uint16_t data_queue_idx;
66         uint8_t data_queue_enable;
67         uint8_t is_sop;
68         uint8_t in_use;
69         struct rte_mbuf *pkt_first_seg;
70         struct rte_mbuf *pkt_last_seg;
71         unsigned int max_mbufs_per_pkt;
72         uint16_t tot_nb_desc;
73         bool need_initial_post;
74 };
75
76 static inline unsigned int vnic_rq_desc_avail(struct vnic_rq *rq)
77 {
78         /* how many does SW own? */
79         return rq->ring.desc_avail;
80 }
81
82 static inline unsigned int vnic_rq_desc_used(struct vnic_rq *rq)
83 {
84         /* how many does HW own? */
85         return rq->ring.desc_count - rq->ring.desc_avail - 1;
86 }
87
88
89
90 enum desc_return_options {
91         VNIC_RQ_RETURN_DESC,
92         VNIC_RQ_DEFER_RETURN_DESC,
93 };
94
95 static inline int vnic_rq_fill(struct vnic_rq *rq,
96         int (*buf_fill)(struct vnic_rq *rq))
97 {
98         int err;
99
100         while (vnic_rq_desc_avail(rq) > 0) {
101
102                 err = (*buf_fill)(rq);
103                 if (err)
104                         return err;
105         }
106
107         return 0;
108 }
109
110 static inline int vnic_rq_fill_count(struct vnic_rq *rq,
111         int (*buf_fill)(struct vnic_rq *rq), unsigned int count)
112 {
113         int err;
114
115         while ((vnic_rq_desc_avail(rq) > 0) && (count--)) {
116
117                 err = (*buf_fill)(rq);
118                 if (err)
119                         return err;
120         }
121
122         return 0;
123 }
124
125 void vnic_rq_free(struct vnic_rq *rq);
126 int vnic_rq_alloc(struct vnic_dev *vdev, struct vnic_rq *rq, unsigned int index,
127         unsigned int desc_count, unsigned int desc_size);
128 void vnic_rq_init_start(struct vnic_rq *rq, unsigned int cq_index,
129         unsigned int fetch_index, unsigned int posted_index,
130         unsigned int error_interrupt_enable,
131         unsigned int error_interrupt_offset);
132 void vnic_rq_init(struct vnic_rq *rq, unsigned int cq_index,
133         unsigned int error_interrupt_enable,
134         unsigned int error_interrupt_offset);
135 void vnic_rq_error_out(struct vnic_rq *rq, unsigned int error);
136 unsigned int vnic_rq_error_status(struct vnic_rq *rq);
137 void vnic_rq_enable(struct vnic_rq *rq);
138 int vnic_rq_disable(struct vnic_rq *rq);
139 void vnic_rq_clean(struct vnic_rq *rq,
140         void (*buf_clean)(struct rte_mbuf **buf));
141 #endif /* _VNIC_RQ_H_ */