enic: move to drivers/net/
[dpdk.git] / drivers / net / enic / base / 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  * Copyright (c) 2014, Cisco Systems, Inc.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in
17  * the documentation and/or other materials provided with the
18  * distribution.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31  * POSSIBILITY OF SUCH DAMAGE.
32  *
33  */
34 #ident "$Id: vnic_cq.h 173398 2014-05-19 09:17:02Z gvaradar $"
35
36 #ifndef _VNIC_CQ_H_
37 #define _VNIC_CQ_H_
38
39 #include <rte_mbuf.h>
40
41 #include "cq_desc.h"
42 #include "vnic_dev.h"
43
44 /* Completion queue control */
45 struct vnic_cq_ctrl {
46         u64 ring_base;                  /* 0x00 */
47         u32 ring_size;                  /* 0x08 */
48         u32 pad0;
49         u32 flow_control_enable;        /* 0x10 */
50         u32 pad1;
51         u32 color_enable;               /* 0x18 */
52         u32 pad2;
53         u32 cq_head;                    /* 0x20 */
54         u32 pad3;
55         u32 cq_tail;                    /* 0x28 */
56         u32 pad4;
57         u32 cq_tail_color;              /* 0x30 */
58         u32 pad5;
59         u32 interrupt_enable;           /* 0x38 */
60         u32 pad6;
61         u32 cq_entry_enable;            /* 0x40 */
62         u32 pad7;
63         u32 cq_message_enable;          /* 0x48 */
64         u32 pad8;
65         u32 interrupt_offset;           /* 0x50 */
66         u32 pad9;
67         u64 cq_message_addr;            /* 0x58 */
68         u32 pad10;
69 };
70
71 #ifdef ENIC_AIC
72 struct vnic_rx_bytes_counter {
73         unsigned int small_pkt_bytes_cnt;
74         unsigned int large_pkt_bytes_cnt;
75 };
76 #endif
77
78 struct vnic_cq {
79         unsigned int index;
80         struct vnic_dev *vdev;
81         struct vnic_cq_ctrl __iomem *ctrl;              /* memory-mapped */
82         struct vnic_dev_ring ring;
83         unsigned int to_clean;
84         unsigned int last_color;
85         unsigned int interrupt_offset;
86 #ifdef ENIC_AIC
87         struct vnic_rx_bytes_counter pkt_size_counter;
88         unsigned int cur_rx_coal_timeval;
89         unsigned int tobe_rx_coal_timeval;
90         ktime_t prev_ts;
91 #endif
92 };
93
94 static inline unsigned int vnic_cq_service(struct vnic_cq *cq,
95         unsigned int work_to_do,
96         int (*q_service)(struct vnic_dev *vdev, struct cq_desc *cq_desc,
97         u8 type, u16 q_number, u16 completed_index, void *opaque),
98         void *opaque)
99 {
100         struct cq_desc *cq_desc;
101         unsigned int work_done = 0;
102         u16 q_number, completed_index;
103         u8 type, color;
104         struct rte_mbuf **rx_pkts = opaque;
105         unsigned int ret;
106
107         cq_desc = (struct cq_desc *)((u8 *)cq->ring.descs +
108                 cq->ring.desc_size * cq->to_clean);
109         cq_desc_dec(cq_desc, &type, &color,
110                 &q_number, &completed_index);
111
112         while (color != cq->last_color) {
113                 if (opaque)
114                         opaque = (void *)&(rx_pkts[work_done]);
115
116                 ret = (*q_service)(cq->vdev, cq_desc, type,
117                         q_number, completed_index, opaque);
118                 cq->to_clean++;
119                 if (cq->to_clean == cq->ring.desc_count) {
120                         cq->to_clean = 0;
121                         cq->last_color = cq->last_color ? 0 : 1;
122                 }
123
124                 cq_desc = (struct cq_desc *)((u8 *)cq->ring.descs +
125                         cq->ring.desc_size * cq->to_clean);
126                 cq_desc_dec(cq_desc, &type, &color,
127                         &q_number, &completed_index);
128
129                 if (ret)
130                         work_done++;
131                 if (work_done >= work_to_do)
132                         break;
133         }
134
135         return work_done;
136 }
137
138 void vnic_cq_free(struct vnic_cq *cq);
139 int vnic_cq_alloc(struct vnic_dev *vdev, struct vnic_cq *cq, unsigned int index,
140         unsigned int socket_id,
141         unsigned int desc_count, unsigned int desc_size);
142 void vnic_cq_init(struct vnic_cq *cq, unsigned int flow_control_enable,
143         unsigned int color_enable, unsigned int cq_head, unsigned int cq_tail,
144         unsigned int cq_tail_color, unsigned int interrupt_enable,
145         unsigned int cq_entry_enable, unsigned int message_enable,
146         unsigned int interrupt_offset, u64 message_addr);
147 void vnic_cq_clean(struct vnic_cq *cq);
148 int vnic_cq_mem_size(struct vnic_cq *cq, unsigned int desc_count,
149         unsigned int desc_size);
150
151 #endif /* _VNIC_CQ_H_ */