1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Copyright 2008-2010 Cisco Systems, Inc. All rights reserved.
4 * Copyright 2007 Nuova Systems, Inc. All rights reserved.
13 /* Completion queue control */
15 u64 ring_base
; /* 0x00 */
16 u32 ring_size
; /* 0x08 */
18 u32 flow_control_enable
; /* 0x10 */
20 u32 color_enable
; /* 0x18 */
22 u32 cq_head
; /* 0x20 */
24 u32 cq_tail
; /* 0x28 */
26 u32 cq_tail_color
; /* 0x30 */
28 u32 interrupt_enable
; /* 0x38 */
30 u32 cq_entry_enable
; /* 0x40 */
32 u32 cq_message_enable
; /* 0x48 */
34 u32 interrupt_offset
; /* 0x50 */
36 u64 cq_message_addr
; /* 0x58 */
40 struct vnic_rx_bytes_counter
{
41 unsigned int small_pkt_bytes_cnt
;
42 unsigned int large_pkt_bytes_cnt
;
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
;
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
),
65 struct cq_desc
*cq_desc
;
66 unsigned int work_done
= 0;
67 u16 q_number
, completed_index
;
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
);
75 while (color
!= cq
->last_color
) {
77 if ((*q_service
)(cq
->vdev
, cq_desc
, type
,
78 q_number
, completed_index
, opaque
))
82 if (cq
->to_clean
== cq
->ring
.desc_count
) {
84 cq
->last_color
= cq
->last_color
? 0 : 1;
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
);
93 if (work_done
>= work_to_do
)
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
);
110 #endif /* _VNIC_CQ_H_ */