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