1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20#ifndef _VNIC_WQ_H_
21#define _VNIC_WQ_H_
22
23#include <linux/pci.h>
24
25#include "vnic_dev.h"
26#include "vnic_cq.h"
27
28
29struct vnic_wq_ctrl {
30 u64 ring_base;
31 u32 ring_size;
32 u32 pad0;
33 u32 posted_index;
34 u32 pad1;
35 u32 cq_index;
36 u32 pad2;
37 u32 enable;
38 u32 pad3;
39 u32 running;
40 u32 pad4;
41 u32 fetch_index;
42 u32 pad5;
43 u32 dca_value;
44 u32 pad6;
45 u32 error_interrupt_enable;
46 u32 pad7;
47 u32 error_interrupt_offset;
48 u32 pad8;
49 u32 error_status;
50 u32 pad9;
51};
52
53struct vnic_wq_buf {
54 struct vnic_wq_buf *next;
55 dma_addr_t dma_addr;
56 void *os_buf;
57 unsigned int len;
58 unsigned int index;
59 int sop;
60 void *desc;
61 uint64_t wr_id;
62 uint8_t cq_entry;
63 uint8_t desc_skip_cnt;
64 uint8_t compressed_send;
65};
66
67
68#define VNIC_WQ_BUF_MIN_BLK_ENTRIES 32
69#define VNIC_WQ_BUF_DFLT_BLK_ENTRIES 64
70#define VNIC_WQ_BUF_BLK_ENTRIES(entries) \
71 ((unsigned int)((entries < VNIC_WQ_BUF_DFLT_BLK_ENTRIES) ? \
72 VNIC_WQ_BUF_MIN_BLK_ENTRIES : VNIC_WQ_BUF_DFLT_BLK_ENTRIES))
73#define VNIC_WQ_BUF_BLK_SZ(entries) \
74 (VNIC_WQ_BUF_BLK_ENTRIES(entries) * sizeof(struct vnic_wq_buf))
75#define VNIC_WQ_BUF_BLKS_NEEDED(entries) \
76 DIV_ROUND_UP(entries, VNIC_WQ_BUF_BLK_ENTRIES(entries))
77#define VNIC_WQ_BUF_BLKS_MAX VNIC_WQ_BUF_BLKS_NEEDED(4096)
78
79struct vnic_wq {
80 unsigned int index;
81 struct vnic_dev *vdev;
82 struct vnic_wq_ctrl __iomem *ctrl;
83 struct vnic_dev_ring ring;
84 struct vnic_wq_buf *bufs[VNIC_WQ_BUF_BLKS_MAX];
85 struct vnic_wq_buf *to_use;
86 struct vnic_wq_buf *to_clean;
87 unsigned int pkts_outstanding;
88};
89
90static inline unsigned int vnic_wq_desc_avail(struct vnic_wq *wq)
91{
92
93 return wq->ring.desc_avail;
94}
95
96static inline unsigned int vnic_wq_desc_used(struct vnic_wq *wq)
97{
98
99 return wq->ring.desc_count - wq->ring.desc_avail - 1;
100}
101
102static inline void *vnic_wq_next_desc(struct vnic_wq *wq)
103{
104 return wq->to_use->desc;
105}
106
107static inline void vnic_wq_post(struct vnic_wq *wq,
108 void *os_buf, dma_addr_t dma_addr,
109 unsigned int len, int sop, int eop,
110 uint8_t desc_skip_cnt, uint8_t cq_entry,
111 uint8_t compressed_send, uint64_t wrid)
112{
113 struct vnic_wq_buf *buf = wq->to_use;
114
115 buf->sop = sop;
116 buf->cq_entry = cq_entry;
117 buf->compressed_send = compressed_send;
118 buf->desc_skip_cnt = desc_skip_cnt;
119 buf->os_buf = eop ? os_buf : NULL;
120 buf->dma_addr = dma_addr;
121 buf->len = len;
122 buf->wr_id = wrid;
123
124 buf = buf->next;
125 if (eop) {
126
127
128
129
130
131 wmb();
132 iowrite32(buf->index, &wq->ctrl->posted_index);
133 }
134 wq->to_use = buf;
135
136 wq->ring.desc_avail -= desc_skip_cnt;
137}
138
139static inline void vnic_wq_service(struct vnic_wq *wq,
140 struct cq_desc *cq_desc, u16 completed_index,
141 void (*buf_service)(struct vnic_wq *wq,
142 struct cq_desc *cq_desc, struct vnic_wq_buf *buf, void *opaque),
143 void *opaque)
144{
145 struct vnic_wq_buf *buf;
146
147 buf = wq->to_clean;
148 while (1) {
149
150 (*buf_service)(wq, cq_desc, buf, opaque);
151
152 wq->ring.desc_avail++;
153
154 wq->to_clean = buf->next;
155
156 if (buf->index == completed_index)
157 break;
158
159 buf = wq->to_clean;
160 }
161}
162
163void vnic_wq_free(struct vnic_wq *wq);
164int vnic_wq_alloc(struct vnic_dev *vdev, struct vnic_wq *wq, unsigned int index,
165 unsigned int desc_count, unsigned int desc_size);
166void vnic_wq_init(struct vnic_wq *wq, unsigned int cq_index,
167 unsigned int error_interrupt_enable,
168 unsigned int error_interrupt_offset);
169unsigned int vnic_wq_error_status(struct vnic_wq *wq);
170void vnic_wq_enable(struct vnic_wq *wq);
171int vnic_wq_disable(struct vnic_wq *wq);
172void vnic_wq_clean(struct vnic_wq *wq,
173 void (*buf_clean)(struct vnic_wq *wq, struct vnic_wq_buf *buf));
174
175#endif
176