1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun * Copyright 2008 Cisco Systems, Inc. All rights reserved.
3*4882a593Smuzhiyun * Copyright 2007 Nuova Systems, Inc. All rights reserved.
4*4882a593Smuzhiyun *
5*4882a593Smuzhiyun * This program is free software; you may redistribute it and/or modify
6*4882a593Smuzhiyun * it under the terms of the GNU General Public License as published by
7*4882a593Smuzhiyun * the Free Software Foundation; version 2 of the License.
8*4882a593Smuzhiyun *
9*4882a593Smuzhiyun * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
10*4882a593Smuzhiyun * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
11*4882a593Smuzhiyun * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
12*4882a593Smuzhiyun * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
13*4882a593Smuzhiyun * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
14*4882a593Smuzhiyun * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
15*4882a593Smuzhiyun * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
16*4882a593Smuzhiyun * SOFTWARE.
17*4882a593Smuzhiyun */
18*4882a593Smuzhiyun #ifndef _VNIC_CQ_COPY_H_
19*4882a593Smuzhiyun #define _VNIC_CQ_COPY_H_
20*4882a593Smuzhiyun
21*4882a593Smuzhiyun #include "fcpio.h"
22*4882a593Smuzhiyun
vnic_cq_copy_service(struct vnic_cq * cq,int (* q_service)(struct vnic_dev * vdev,unsigned int index,struct fcpio_fw_req * desc),unsigned int work_to_do)23*4882a593Smuzhiyun static inline unsigned int vnic_cq_copy_service(
24*4882a593Smuzhiyun struct vnic_cq *cq,
25*4882a593Smuzhiyun int (*q_service)(struct vnic_dev *vdev,
26*4882a593Smuzhiyun unsigned int index,
27*4882a593Smuzhiyun struct fcpio_fw_req *desc),
28*4882a593Smuzhiyun unsigned int work_to_do)
29*4882a593Smuzhiyun
30*4882a593Smuzhiyun {
31*4882a593Smuzhiyun struct fcpio_fw_req *desc;
32*4882a593Smuzhiyun unsigned int work_done = 0;
33*4882a593Smuzhiyun u8 color;
34*4882a593Smuzhiyun
35*4882a593Smuzhiyun desc = (struct fcpio_fw_req *)((u8 *)cq->ring.descs +
36*4882a593Smuzhiyun cq->ring.desc_size * cq->to_clean);
37*4882a593Smuzhiyun fcpio_color_dec(desc, &color);
38*4882a593Smuzhiyun
39*4882a593Smuzhiyun while (color != cq->last_color) {
40*4882a593Smuzhiyun
41*4882a593Smuzhiyun if ((*q_service)(cq->vdev, cq->index, desc))
42*4882a593Smuzhiyun break;
43*4882a593Smuzhiyun
44*4882a593Smuzhiyun cq->to_clean++;
45*4882a593Smuzhiyun if (cq->to_clean == cq->ring.desc_count) {
46*4882a593Smuzhiyun cq->to_clean = 0;
47*4882a593Smuzhiyun cq->last_color = cq->last_color ? 0 : 1;
48*4882a593Smuzhiyun }
49*4882a593Smuzhiyun
50*4882a593Smuzhiyun desc = (struct fcpio_fw_req *)((u8 *)cq->ring.descs +
51*4882a593Smuzhiyun cq->ring.desc_size * cq->to_clean);
52*4882a593Smuzhiyun fcpio_color_dec(desc, &color);
53*4882a593Smuzhiyun
54*4882a593Smuzhiyun work_done++;
55*4882a593Smuzhiyun if (work_done >= work_to_do)
56*4882a593Smuzhiyun break;
57*4882a593Smuzhiyun }
58*4882a593Smuzhiyun
59*4882a593Smuzhiyun return work_done;
60*4882a593Smuzhiyun }
61*4882a593Smuzhiyun
62*4882a593Smuzhiyun #endif /* _VNIC_CQ_COPY_H_ */
63