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_to_clean(struct vnic_cq * cq)59 static inline void *vnic_cq_to_clean(struct vnic_cq *cq)
60 {
61 return ((u8 *)cq->ring.descs + cq->ring.desc_size * cq->to_clean);
62 }
63
vnic_cq_inc_to_clean(struct vnic_cq * cq)64 static inline void vnic_cq_inc_to_clean(struct vnic_cq *cq)
65 {
66 cq->to_clean++;
67 if (cq->to_clean == cq->ring.desc_count) {
68 cq->to_clean = 0;
69 cq->last_color = cq->last_color ? 0 : 1;
70 }
71 }
72
73 void vnic_cq_free(struct vnic_cq *cq);
74 int vnic_cq_alloc(struct vnic_dev *vdev, struct vnic_cq *cq, unsigned int index,
75 unsigned int desc_count, unsigned int desc_size);
76 void vnic_cq_init(struct vnic_cq *cq, unsigned int flow_control_enable,
77 unsigned int color_enable, unsigned int cq_head, unsigned int cq_tail,
78 unsigned int cq_tail_color, unsigned int interrupt_enable,
79 unsigned int cq_entry_enable, unsigned int message_enable,
80 unsigned int interrupt_offset, u64 message_addr);
81 void vnic_cq_clean(struct vnic_cq *cq);
82
83 #endif /* _VNIC_CQ_H_ */
84