Loading...
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 */
14struct 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
40struct vnic_rx_bytes_counter {
41 unsigned int small_pkt_bytes_cnt;
42 unsigned int large_pkt_bytes_cnt;
43};
44
45struct 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
59static 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
100void vnic_cq_free(struct vnic_cq *cq);
101int vnic_cq_alloc(struct vnic_dev *vdev, struct vnic_cq *cq, unsigned int index,
102 unsigned int desc_count, unsigned int desc_size);
103void 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);
108void vnic_cq_clean(struct vnic_cq *cq);
109
110#endif /* _VNIC_CQ_H_ */
1/*
2 * Copyright 2008-2010 Cisco Systems, Inc. All rights reserved.
3 * Copyright 2007 Nuova Systems, Inc. All rights reserved.
4 *
5 * This program is free software; you may redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; version 2 of the License.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
10 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
11 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
12 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
13 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
14 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
15 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
16 * SOFTWARE.
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/* Completion queue control */
27struct vnic_cq_ctrl {
28 u64 ring_base; /* 0x00 */
29 u32 ring_size; /* 0x08 */
30 u32 pad0;
31 u32 flow_control_enable; /* 0x10 */
32 u32 pad1;
33 u32 color_enable; /* 0x18 */
34 u32 pad2;
35 u32 cq_head; /* 0x20 */
36 u32 pad3;
37 u32 cq_tail; /* 0x28 */
38 u32 pad4;
39 u32 cq_tail_color; /* 0x30 */
40 u32 pad5;
41 u32 interrupt_enable; /* 0x38 */
42 u32 pad6;
43 u32 cq_entry_enable; /* 0x40 */
44 u32 pad7;
45 u32 cq_message_enable; /* 0x48 */
46 u32 pad8;
47 u32 interrupt_offset; /* 0x50 */
48 u32 pad9;
49 u64 cq_message_addr; /* 0x58 */
50 u32 pad10;
51};
52
53struct vnic_rx_bytes_counter {
54 unsigned int small_pkt_bytes_cnt;
55 unsigned int large_pkt_bytes_cnt;
56};
57
58struct vnic_cq {
59 unsigned int index;
60 struct vnic_dev *vdev;
61 struct vnic_cq_ctrl __iomem *ctrl; /* memory-mapped */
62 struct vnic_dev_ring ring;
63 unsigned int to_clean;
64 unsigned int last_color;
65 unsigned int interrupt_offset;
66 struct vnic_rx_bytes_counter pkt_size_counter;
67 unsigned int cur_rx_coal_timeval;
68 unsigned int tobe_rx_coal_timeval;
69 ktime_t prev_ts;
70};
71
72static inline unsigned int vnic_cq_service(struct vnic_cq *cq,
73 unsigned int work_to_do,
74 int (*q_service)(struct vnic_dev *vdev, struct cq_desc *cq_desc,
75 u8 type, u16 q_number, u16 completed_index, void *opaque),
76 void *opaque)
77{
78 struct cq_desc *cq_desc;
79 unsigned int work_done = 0;
80 u16 q_number, completed_index;
81 u8 type, color;
82
83 cq_desc = (struct cq_desc *)((u8 *)cq->ring.descs +
84 cq->ring.desc_size * cq->to_clean);
85 cq_desc_dec(cq_desc, &type, &color,
86 &q_number, &completed_index);
87
88 while (color != cq->last_color) {
89
90 if ((*q_service)(cq->vdev, cq_desc, type,
91 q_number, completed_index, opaque))
92 break;
93
94 cq->to_clean++;
95 if (cq->to_clean == cq->ring.desc_count) {
96 cq->to_clean = 0;
97 cq->last_color = cq->last_color ? 0 : 1;
98 }
99
100 cq_desc = (struct cq_desc *)((u8 *)cq->ring.descs +
101 cq->ring.desc_size * cq->to_clean);
102 cq_desc_dec(cq_desc, &type, &color,
103 &q_number, &completed_index);
104
105 work_done++;
106 if (work_done >= work_to_do)
107 break;
108 }
109
110 return work_done;
111}
112
113void vnic_cq_free(struct vnic_cq *cq);
114int vnic_cq_alloc(struct vnic_dev *vdev, struct vnic_cq *cq, unsigned int index,
115 unsigned int desc_count, unsigned int desc_size);
116void vnic_cq_init(struct vnic_cq *cq, unsigned int flow_control_enable,
117 unsigned int color_enable, unsigned int cq_head, unsigned int cq_tail,
118 unsigned int cq_tail_color, unsigned int interrupt_enable,
119 unsigned int cq_entry_enable, unsigned int message_enable,
120 unsigned int interrupt_offset, u64 message_addr);
121void vnic_cq_clean(struct vnic_cq *cq);
122
123#endif /* _VNIC_CQ_H_ */