1*9c067b84SDoug Ambrisko /* SPDX-License-Identifier: BSD-3-Clause
2*9c067b84SDoug Ambrisko * Copyright 2008-2017 Cisco Systems, Inc. All rights reserved.
3*9c067b84SDoug Ambrisko * Copyright 2007 Nuova Systems, Inc. All rights reserved.
4*9c067b84SDoug Ambrisko */
5*9c067b84SDoug Ambrisko
6*9c067b84SDoug Ambrisko #ifndef _VNIC_CQ_H_
7*9c067b84SDoug Ambrisko #define _VNIC_CQ_H_
8*9c067b84SDoug Ambrisko
9*9c067b84SDoug Ambrisko #include "cq_desc.h"
10*9c067b84SDoug Ambrisko #include "vnic_dev.h"
11*9c067b84SDoug Ambrisko
12*9c067b84SDoug Ambrisko /* Completion queue control */
13*9c067b84SDoug Ambrisko struct vnic_cq_ctrl {
14*9c067b84SDoug Ambrisko u64 ring_base; /* 0x00 */
15*9c067b84SDoug Ambrisko #define CQ_RING_BASE 0x00
16*9c067b84SDoug Ambrisko u32 ring_size; /* 0x08 */
17*9c067b84SDoug Ambrisko #define CQ_RING_SIZE 0x08
18*9c067b84SDoug Ambrisko u32 pad0;
19*9c067b84SDoug Ambrisko u32 flow_control_enable; /* 0x10 */
20*9c067b84SDoug Ambrisko #define CQ_FLOW_CONTROL_ENABLE 0x10
21*9c067b84SDoug Ambrisko u32 pad1;
22*9c067b84SDoug Ambrisko u32 color_enable; /* 0x18 */
23*9c067b84SDoug Ambrisko #define CQ_COLOR_ENABLE 0x18
24*9c067b84SDoug Ambrisko u32 pad2;
25*9c067b84SDoug Ambrisko u32 cq_head; /* 0x20 */
26*9c067b84SDoug Ambrisko #define CQ_HEAD 0x20
27*9c067b84SDoug Ambrisko u32 pad3;
28*9c067b84SDoug Ambrisko u32 cq_tail; /* 0x28 */
29*9c067b84SDoug Ambrisko #define CQ_TAIL 0x28
30*9c067b84SDoug Ambrisko u32 pad4;
31*9c067b84SDoug Ambrisko u32 cq_tail_color; /* 0x30 */
32*9c067b84SDoug Ambrisko #define CQ_TAIL_COLOR 0x30
33*9c067b84SDoug Ambrisko u32 pad5;
34*9c067b84SDoug Ambrisko u32 interrupt_enable; /* 0x38 */
35*9c067b84SDoug Ambrisko #define CQ_INTR_ENABLE 0x38
36*9c067b84SDoug Ambrisko u32 pad6;
37*9c067b84SDoug Ambrisko u32 cq_entry_enable; /* 0x40 */
38*9c067b84SDoug Ambrisko #define CQ_ENTRY_ENABLE 0x40
39*9c067b84SDoug Ambrisko u32 pad7;
40*9c067b84SDoug Ambrisko u32 cq_message_enable; /* 0x48 */
41*9c067b84SDoug Ambrisko #define CQ_MESSAGE_ENABLE 0x48
42*9c067b84SDoug Ambrisko u32 pad8;
43*9c067b84SDoug Ambrisko u32 interrupt_offset; /* 0x50 */
44*9c067b84SDoug Ambrisko #define CQ_INTR_OFFSET 0x50
45*9c067b84SDoug Ambrisko u32 pad9;
46*9c067b84SDoug Ambrisko u64 cq_message_addr; /* 0x58 */
47*9c067b84SDoug Ambrisko #define CQ_MESSAGE_ADDR 0x58
48*9c067b84SDoug Ambrisko u32 pad10;
49*9c067b84SDoug Ambrisko };
50*9c067b84SDoug Ambrisko
51*9c067b84SDoug Ambrisko #ifdef ENIC_AIC
52*9c067b84SDoug Ambrisko struct vnic_rx_bytes_counter {
53*9c067b84SDoug Ambrisko unsigned int small_pkt_bytes_cnt;
54*9c067b84SDoug Ambrisko unsigned int large_pkt_bytes_cnt;
55*9c067b84SDoug Ambrisko };
56*9c067b84SDoug Ambrisko #endif
57*9c067b84SDoug Ambrisko
58*9c067b84SDoug Ambrisko struct vnic_cq {
59*9c067b84SDoug Ambrisko unsigned int index;
60*9c067b84SDoug Ambrisko struct vnic_dev *vdev;
61*9c067b84SDoug Ambrisko struct vnic_res *ctrl;
62*9c067b84SDoug Ambrisko struct vnic_dev_ring ring;
63*9c067b84SDoug Ambrisko unsigned int to_clean;
64*9c067b84SDoug Ambrisko unsigned int last_color;
65*9c067b84SDoug Ambrisko unsigned int interrupt_offset;
66*9c067b84SDoug Ambrisko #ifdef ENIC_AIC
67*9c067b84SDoug Ambrisko struct vnic_rx_bytes_counter pkt_size_counter;
68*9c067b84SDoug Ambrisko unsigned int cur_rx_coal_timeval;
69*9c067b84SDoug Ambrisko unsigned int tobe_rx_coal_timeval;
70*9c067b84SDoug Ambrisko ktime_t prev_ts;
71*9c067b84SDoug Ambrisko #endif
72*9c067b84SDoug Ambrisko int ntxqsets;
73*9c067b84SDoug Ambrisko int nrxqsets;
74*9c067b84SDoug Ambrisko int ntxqsets_start;
75*9c067b84SDoug Ambrisko int nrxqsets_start;
76*9c067b84SDoug Ambrisko };
77*9c067b84SDoug Ambrisko
78*9c067b84SDoug Ambrisko void vnic_cq_free(struct vnic_cq *cq);
79*9c067b84SDoug Ambrisko void vnic_cq_init(struct vnic_cq *cq, unsigned int flow_control_enable,
80*9c067b84SDoug Ambrisko unsigned int color_enable, unsigned int cq_head, unsigned int cq_tail,
81*9c067b84SDoug Ambrisko unsigned int cq_tail_color, unsigned int interrupt_enable,
82*9c067b84SDoug Ambrisko unsigned int cq_entry_enable, unsigned int message_enable,
83*9c067b84SDoug Ambrisko unsigned int interrupt_offset, u64 message_addr);
84*9c067b84SDoug Ambrisko void vnic_cq_clean(struct vnic_cq *cq);
85*9c067b84SDoug Ambrisko int vnic_cq_mem_size(struct vnic_cq *cq, unsigned int desc_count,
86*9c067b84SDoug Ambrisko unsigned int desc_size);
87*9c067b84SDoug Ambrisko
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)88*9c067b84SDoug Ambrisko static inline unsigned int vnic_cq_service(struct vnic_cq *cq,
89*9c067b84SDoug Ambrisko unsigned int work_to_do,
90*9c067b84SDoug Ambrisko int (*q_service)(struct vnic_dev *vdev, struct cq_desc *cq_desc,
91*9c067b84SDoug Ambrisko u8 type, u16 q_number, u16 completed_index, void *opaque),
92*9c067b84SDoug Ambrisko void *opaque)
93*9c067b84SDoug Ambrisko {
94*9c067b84SDoug Ambrisko struct cq_desc *cq_desc;
95*9c067b84SDoug Ambrisko unsigned int work_done = 0;
96*9c067b84SDoug Ambrisko u16 q_number, completed_index;
97*9c067b84SDoug Ambrisko u8 type, color;
98*9c067b84SDoug Ambrisko
99*9c067b84SDoug Ambrisko cq_desc = (struct cq_desc *)((u8 *)cq->ring.descs +
100*9c067b84SDoug Ambrisko cq->ring.desc_size * cq->to_clean);
101*9c067b84SDoug Ambrisko cq_desc_dec(cq_desc, &type, &color,
102*9c067b84SDoug Ambrisko &q_number, &completed_index);
103*9c067b84SDoug Ambrisko
104*9c067b84SDoug Ambrisko while (color != cq->last_color) {
105*9c067b84SDoug Ambrisko if ((*q_service)(cq->vdev, cq_desc, type,
106*9c067b84SDoug Ambrisko q_number, completed_index, opaque))
107*9c067b84SDoug Ambrisko break;
108*9c067b84SDoug Ambrisko
109*9c067b84SDoug Ambrisko cq->to_clean++;
110*9c067b84SDoug Ambrisko if (cq->to_clean == cq->ring.desc_count) {
111*9c067b84SDoug Ambrisko cq->to_clean = 0;
112*9c067b84SDoug Ambrisko cq->last_color = cq->last_color ? 0 : 1;
113*9c067b84SDoug Ambrisko }
114*9c067b84SDoug Ambrisko
115*9c067b84SDoug Ambrisko cq_desc = (struct cq_desc *)((u8 *)cq->ring.descs +
116*9c067b84SDoug Ambrisko cq->ring.desc_size * cq->to_clean);
117*9c067b84SDoug Ambrisko cq_desc_dec(cq_desc, &type, &color,
118*9c067b84SDoug Ambrisko &q_number, &completed_index);
119*9c067b84SDoug Ambrisko
120*9c067b84SDoug Ambrisko work_done++;
121*9c067b84SDoug Ambrisko if (work_done >= work_to_do)
122*9c067b84SDoug Ambrisko break;
123*9c067b84SDoug Ambrisko }
124*9c067b84SDoug Ambrisko
125*9c067b84SDoug Ambrisko return work_done;
126*9c067b84SDoug Ambrisko }
127*9c067b84SDoug Ambrisko
vnic_cq_work(struct vnic_cq * cq,unsigned int work_to_do)128*9c067b84SDoug Ambrisko static inline unsigned int vnic_cq_work(struct vnic_cq *cq,
129*9c067b84SDoug Ambrisko unsigned int work_to_do)
130*9c067b84SDoug Ambrisko {
131*9c067b84SDoug Ambrisko struct cq_desc *cq_desc;
132*9c067b84SDoug Ambrisko unsigned int work_avail = 0;
133*9c067b84SDoug Ambrisko u16 q_number, completed_index;
134*9c067b84SDoug Ambrisko u8 type, color;
135*9c067b84SDoug Ambrisko u32 to_clean, last_color;
136*9c067b84SDoug Ambrisko
137*9c067b84SDoug Ambrisko to_clean = cq->to_clean;
138*9c067b84SDoug Ambrisko last_color = cq->last_color;
139*9c067b84SDoug Ambrisko cq_desc = (struct cq_desc *)((u8 *)cq->ring.descs +
140*9c067b84SDoug Ambrisko cq->ring.desc_size * to_clean);
141*9c067b84SDoug Ambrisko cq_desc_dec(cq_desc, &type, &color,
142*9c067b84SDoug Ambrisko &q_number, &completed_index);
143*9c067b84SDoug Ambrisko
144*9c067b84SDoug Ambrisko while (color != last_color) {
145*9c067b84SDoug Ambrisko to_clean++;
146*9c067b84SDoug Ambrisko if (to_clean == cq->ring.desc_count) {
147*9c067b84SDoug Ambrisko to_clean = 0;
148*9c067b84SDoug Ambrisko last_color = last_color ? 0 : 1;
149*9c067b84SDoug Ambrisko }
150*9c067b84SDoug Ambrisko
151*9c067b84SDoug Ambrisko cq_desc = (struct cq_desc *)((u8 *)cq->ring.descs +
152*9c067b84SDoug Ambrisko cq->ring.desc_size * to_clean);
153*9c067b84SDoug Ambrisko cq_desc_dec(cq_desc, &type, &color,
154*9c067b84SDoug Ambrisko &q_number, &completed_index);
155*9c067b84SDoug Ambrisko
156*9c067b84SDoug Ambrisko work_avail++;
157*9c067b84SDoug Ambrisko if (work_avail >= work_to_do)
158*9c067b84SDoug Ambrisko break;
159*9c067b84SDoug Ambrisko }
160*9c067b84SDoug Ambrisko
161*9c067b84SDoug Ambrisko return work_avail;
162*9c067b84SDoug Ambrisko }
163*9c067b84SDoug Ambrisko
164*9c067b84SDoug Ambrisko #endif /* _VNIC_CQ_H_ */
165