1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20#ifndef _VNIC_CQ_H_
21#define _VNIC_CQ_H_
22
23#include "cq_desc.h"
24#include "vnic_dev.h"
25
26
27struct vnic_cq_ctrl {
28 u64 ring_base;
29 u32 ring_size;
30 u32 pad0;
31 u32 flow_control_enable;
32 u32 pad1;
33 u32 color_enable;
34 u32 pad2;
35 u32 cq_head;
36 u32 pad3;
37 u32 cq_tail;
38 u32 pad4;
39 u32 cq_tail_color;
40 u32 pad5;
41 u32 interrupt_enable;
42 u32 pad6;
43 u32 cq_entry_enable;
44 u32 pad7;
45 u32 cq_message_enable;
46 u32 pad8;
47 u32 interrupt_offset;
48 u32 pad9;
49 u64 cq_message_addr;
50 u32 pad10;
51};
52
53struct vnic_cq {
54 unsigned int index;
55 struct vnic_dev *vdev;
56 struct vnic_cq_ctrl __iomem *ctrl;
57 struct vnic_dev_ring ring;
58 unsigned int to_clean;
59 unsigned int last_color;
60 unsigned int interrupt_offset;
61};
62
63static inline unsigned int vnic_cq_service(struct vnic_cq *cq,
64 unsigned int work_to_do,
65 int (*q_service)(struct vnic_dev *vdev, struct cq_desc *cq_desc,
66 u8 type, u16 q_number, u16 completed_index, void *opaque),
67 void *opaque)
68{
69 struct cq_desc *cq_desc;
70 unsigned int work_done = 0;
71 u16 q_number, completed_index;
72 u8 type, color;
73
74 cq_desc = (struct cq_desc *)((u8 *)cq->ring.descs +
75 cq->ring.desc_size * cq->to_clean);
76 cq_desc_dec(cq_desc, &type, &color,
77 &q_number, &completed_index);
78
79 while (color != cq->last_color) {
80
81 if ((*q_service)(cq->vdev, cq_desc, type,
82 q_number, completed_index, opaque))
83 break;
84
85 cq->to_clean++;
86 if (cq->to_clean == cq->ring.desc_count) {
87 cq->to_clean = 0;
88 cq->last_color = cq->last_color ? 0 : 1;
89 }
90
91 cq_desc = (struct cq_desc *)((u8 *)cq->ring.descs +
92 cq->ring.desc_size * cq->to_clean);
93 cq_desc_dec(cq_desc, &type, &color,
94 &q_number, &completed_index);
95
96 work_done++;
97 if (work_done >= work_to_do)
98 break;
99 }
100
101 return work_done;
102}
103
104void vnic_cq_free(struct vnic_cq *cq);
105int vnic_cq_alloc(struct vnic_dev *vdev, struct vnic_cq *cq, unsigned int index,
106 unsigned int desc_count, unsigned int desc_size);
107void vnic_cq_init(struct vnic_cq *cq, unsigned int flow_control_enable,
108 unsigned int color_enable, unsigned int cq_head, unsigned int cq_tail,
109 unsigned int cq_tail_color, unsigned int interrupt_enable,
110 unsigned int cq_entry_enable, unsigned int message_enable,
111 unsigned int interrupt_offset, u64 message_addr);
112void vnic_cq_clean(struct vnic_cq *cq);
113
114#endif
115