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