xref: /dpdk/drivers/net/enic/base/vnic_rq.h (revision 00ce43111dc5b364722c882cdd37d3664d87b6cc)
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 	uint64_t ring_base;			/* 0x00 */
17 	uint32_t ring_size;			/* 0x08 */
18 	uint32_t pad0;
19 	uint32_t posted_index;			/* 0x10 */
20 	uint32_t pad1;
21 	uint32_t cq_index;			/* 0x18 */
22 	uint32_t pad2;
23 	uint32_t enable;			/* 0x20 */
24 	uint32_t pad3;
25 	uint32_t running;			/* 0x28 */
26 	uint32_t pad4;
27 	uint32_t fetch_index;			/* 0x30 */
28 	uint32_t pad5;
29 	uint32_t error_interrupt_enable;	/* 0x38 */
30 	uint32_t pad6;
31 	uint32_t error_interrupt_offset;	/* 0x40 */
32 	uint32_t pad7;
33 	uint32_t error_status;			/* 0x48 */
34 	uint32_t pad8;
35 	uint32_t tcp_sn;			/* 0x50 */
36 	uint32_t pad9;
37 	uint32_t unused;			/* 0x58 */
38 	uint32_t pad10;
39 	uint32_t dca_select;			/* 0x60 */
40 	uint32_t pad11;
41 	uint32_t dca_value;			/* 0x68 */
42 	uint32_t pad12;
43 	uint32_t data_ring;			/* 0x70 */
44 	uint32_t pad13;
45 	uint32_t header_split;			/* 0x78 */
46 	uint32_t 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 **free_mbufs;		/* reserve of free mbufs */
56 	int num_free_mbufs;
57 	struct rte_mbuf **mbuf_ring;		/* array of allocated mbufs */
58 	unsigned int mbuf_next_idx;		/* next mb to consume */
59 	void *os_buf_head;
60 	unsigned int pkts_outstanding;
61 	uint16_t rx_nb_hold;
62 	uint16_t rx_free_thresh;
63 	unsigned int socket_id;
64 	struct rte_mempool *mp;
65 	uint16_t rxst_idx;
66 	uint32_t tot_pkts;
67 	uint16_t data_queue_idx;
68 	uint8_t data_queue_enable;
69 	uint8_t is_sop;
70 	uint8_t in_use;
71 	struct rte_mbuf *pkt_first_seg;
72 	struct rte_mbuf *pkt_last_seg;
73 	unsigned int max_mbufs_per_pkt;
74 	uint16_t tot_nb_desc;
75 	bool need_initial_post;
76 	bool admin_chan;
77 	const struct rte_memzone *admin_msg_rz;
78 	int admin_next_idx;
79 	uint64_t soft_stats_pkts;
80 	uint64_t soft_stats_bytes;
81 };
82 
83 static inline unsigned int vnic_rq_desc_avail(struct vnic_rq *rq)
84 {
85 	/* how many does SW own? */
86 	return rq->ring.desc_avail;
87 }
88 
89 static inline unsigned int vnic_rq_desc_used(struct vnic_rq *rq)
90 {
91 	/* how many does HW own? */
92 	return rq->ring.desc_count - rq->ring.desc_avail - 1;
93 }
94 
95 
96 
97 enum desc_return_options {
98 	VNIC_RQ_RETURN_DESC,
99 	VNIC_RQ_DEFER_RETURN_DESC,
100 };
101 
102 static inline int vnic_rq_fill(struct vnic_rq *rq,
103 	int (*buf_fill)(struct vnic_rq *rq))
104 {
105 	int err;
106 
107 	while (vnic_rq_desc_avail(rq) > 0) {
108 
109 		err = (*buf_fill)(rq);
110 		if (err)
111 			return err;
112 	}
113 
114 	return 0;
115 }
116 
117 static inline int vnic_rq_fill_count(struct vnic_rq *rq,
118 	int (*buf_fill)(struct vnic_rq *rq), unsigned int count)
119 {
120 	int err;
121 
122 	while ((vnic_rq_desc_avail(rq) > 0) && (count--)) {
123 
124 		err = (*buf_fill)(rq);
125 		if (err)
126 			return err;
127 	}
128 
129 	return 0;
130 }
131 
132 void vnic_rq_free(struct vnic_rq *rq);
133 int vnic_rq_alloc(struct vnic_dev *vdev, struct vnic_rq *rq, unsigned int index,
134 	unsigned int desc_count, unsigned int desc_size);
135 int vnic_admin_rq_alloc(struct vnic_dev *vdev, struct vnic_rq *rq,
136 	unsigned int desc_count, unsigned int desc_size);
137 void vnic_rq_init_start(struct vnic_rq *rq, unsigned int cq_index,
138 	unsigned int fetch_index, unsigned int posted_index,
139 	unsigned int error_interrupt_enable,
140 	unsigned int error_interrupt_offset);
141 void vnic_rq_init(struct vnic_rq *rq, unsigned int cq_index,
142 	unsigned int error_interrupt_enable,
143 	unsigned int error_interrupt_offset);
144 void vnic_rq_error_out(struct vnic_rq *rq, unsigned int error);
145 unsigned int vnic_rq_error_status(struct vnic_rq *rq);
146 void vnic_rq_enable(struct vnic_rq *rq);
147 int vnic_rq_disable(struct vnic_rq *rq);
148 void vnic_rq_clean(struct vnic_rq *rq,
149 	void (*buf_clean)(struct rte_mbuf **buf));
150 #endif /* _VNIC_RQ_H_ */
151